cancel
Showing results for 
Search instead for 
Did you mean: 

Configuration timer interrupt 1ms

mahmoud_dhaiwi
Associate II
Posted on June 03, 2015 at 11:24

hello,

I use the stm32f103VD,

Clock 48MHz from the 8MHz HSI.

Can you help me and tell me if I configured the timer 3 correctly for counter each 1ms ?

I am not sure it's correct because the iterruption comes each 0.000999 ms ! I didn't understand why. any help plz ?

the code:    

//enable the timer clock

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

    //compute the prescaler value

    PrescalerValue = (uint16_t) (SystemCoreClock / 1000000) - 1;

    //time base configuration

    TIM_TimeBaseStructure.TIM_Period = 1 * 1000;

    TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;

    TIM_TimeBaseStructure.TIM_ClockDivision = 0;

    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

    //enable timer interrupt

    TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);

    //enable timer counter

    TIM_Cmd(TIM3, ENABLE);

thanks

#stm32-timer-inerrupt
3 REPLIES 3
Posted on June 03, 2015 at 14:49

iterruption comes each 0.000999 ms !

I'm just going to assume you mistyped that, as interrupting faster than a micro-second seems rather implausible.

A micro-second short of a milli-second?

Well the HSI isn't a high accuracy clock, have you looked at this in percent-error term? Consider using a more accuracy clock source.

Also the Period should be 1000-1, but that will make it a tad faster still.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mahmoud_dhaiwi
Associate II
Posted on June 03, 2015 at 15:37

Sorry ! there is an error...

'' the iterruption comes each

0.000999 s

 so each

0.999 ms

! ''

If I understand, so the period must be 1000 - 1 to have an interrupt at 1ms ??

Posted on June 03, 2015 at 16:46

Well making the number smaller will shrink the time further

999us instead of 1000us represents an error of 0.1%. HSI is specified to have error in the +/-2.5% or so range, over temperature.

You might want to measure the HSI or PLL frequencies via the MCO (PA8) pin to understand what they look like.

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