2018-10-19 10:51 PM
I would like to have an interrupt every second on my TIM1 I use a STM32F103C8T6
Here is my timer init:
static void MX_TIM1_Init(void)
{
TIM_ClockConfigTypeDef sClockSourceConfig;
TIM_MasterConfigTypeDef sMasterConfig;
htim1.Instance = TIM1;
htim1.Init.Prescaler = 1124;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.Period = 63999;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
And here is the PeriodElapsedCallback part:
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance==TIM1) //check if the interrupt comes from TIM1
{
old_enc_value = enc_value;
enc_value = __HAL_TIM_GET_COUNTER(&htim4)+ MULT1K*1000;
//RPM = (int) round(((enc_value - old_enc_value)* Resolution_broche) *60);
RPM++;
}
}
I configured TIM2 the exact same way and it's working fine, but impossible to have a value with TIM1. With this basic code i should have the variable RPM increasing from 1 every second but it's stuck to 0 in debug mode. all interrupts are enabled in NVIC /CubeMX Did I missed something ?
Thank you
Solved! Go to Solution.
2018-10-20 12:58 AM
2018-10-20 12:58 AM
I found my mistake:
HAL_TIM_Base_Start_IT(&htim1);
was commented ...!