2016-09-01 12:47 PM
I am working on STM32F030 Discovery. I trying to generate 1ms interrupt. But the code doesn't work. But when change the htim3.Init.Period from 0 to 1, it works with 2ms interrupt. But I need 1ms interrupt. Frequency is set at 48MHz.
Here is my TIM3_Initvoid TIM3_Init(void){ TIM_ClockConfigTypeDef sClockSourceConfig; TIM_MasterConfigTypeDef sMasterConfig; htim3.Instance = TIM3; htim3.Init.Prescaler = 48000; htim3.Init.CounterMode = TIM_COUNTERMODE_UP; htim3.Init.Period = 0; htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; HAL_TIM_Base_Init(&htim3); sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig); sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig);} #!stm32-!cubemx #interrupts2016-09-01 01:43 PM
Put the smaller number in the Prescaler, review the diagrams in the Reference Manual to understand how the counting portion functions.
htim3.Init.Prescaler = 0; // DIV1
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 48000-1; // DIV48000, ie 0-47999, where final count before rollover is 47999