AnsweredAssumed Answered

TIM3 wrong counting?

Question asked by saviane.giorgio on Sep 4, 2012
Latest reply on Sep 10, 2012 by de_craemer.klaas
I need to generate a 20 ms interrupt into my firmware. HSE is 16 Mhz with STM8S208.
I put this initialization code into my firmware to accomplish that through the use of TIM3:

#define PRESC TIM3_PRESCALER_32  

    uint16_t counter = 10000;
    //counter = counter / 4 * 3; //correction to run closer to a 20 ms period
    TIM3_UpdateRequestConfig(TIM3_UPDATESOURCE_GLOBAL);
    TIM3_TimeBaseInit(TIM3_PRESCALER_32, counter);
    TIM3_UpdateDisableConfig(DISABLE);
    TIM3_PrescalerConfig (PRESCALER_32, TIM3_PSCRELOADMODE_UPDATE);
    TIM3_ARRPreloadConfig(ENABLE);
    TIM3_ITConfig(TIM3_IT_UPDATE, ENABLE);

To achieve the desired 20 ms period I initialized the counter to 10000, so that (16 Mhz / 32 presc = 500 Khz) / 10000 = 50 Hz.
Unfortunately the actual frequency is 75% of the expected one, so I need to uncomment the counter correction statement.

Does someone why does this happen?

Regards.

Giorgio

Outcomes