cancel
Showing results for 
Search instead for 
Did you mean: 

Using STM32F103 to generate 1 millisecond interrupt

suresh
Associate II
Posted on July 25, 2016 at 23:20

Hello, trying to generate 1 millisecond interrupt using TIM4 timer with in STM32F103 series of processor. By selectinghtim4.Init.Period = 1 able to generate Two millisecond interrupt. When we configurehtim4.Init.Period = 0, not able to get any interrupt.

Here is the Init Code for TIM4:

void MX_TIM4_Init(void)
{
TIM_ClockConfigTypeDef sClockSourceConfig;
TIM_MasterConfigTypeDef sMasterConfig;
htim4.Instance = TIM4;
htim4.Init.Prescaler = 48000;
htim4.Init.CounterMode = TIM_COUNTERMODE_DOWN;
htim4.Init.Period = 0; //9;
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
HAL_TIM_Base_Init(&htim4);
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig);
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig);
}

Attached Clock configuration mxcube application in jpeg format.

Appreciate any help on this. Regards, Jim #- #stm32-timer #!stm32f103
1 REPLY 1
Posted on July 26, 2016 at 00:34

The values programmed as N-1

The value in prescaler should generally be the smaller of the two terms.

The Period=0 turns OFF the timer, it has nowhere to count

For 1ms from a 36 MHz source

Prescaler = 0

Period =  36000 - 1

For 1ms from a 48 MHz source

Prescaler = 0

Period =  48000 - 1

or more nominally

Prescaler = 0;

Period = (TIMCLK / 1000) - 1; // 1 KHz (1ms)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..