Skip to main content
Visitor II
August 14, 2008
Question

Timer0 Configuration Inaccuracy

  • August 14, 2008
  • 6 replies
  • 1236 views
Posted on August 14, 2008 at 06:17

Timer0 Configuration Inaccuracy

    This topic has been closed for replies.

    6 replies

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:54

    I am using Timer0 to overflow and interrupt every 10ms,

    and toggling a port in the Interrupt (and clearing flag).

    I am using the 25 MHz oscillator as the main clock,

    and the APB clock is set to 25 MHz / 4 = 6.25 MHz.

    I can achieve a timing of 10.00 ms with the following:

    Code:

    TIM_InitStructure.TIM_Prescaler = 25 - 1; // 6.25 mhz / 25 = 250 khz = 4 us period

    TIM_InitStructure.TIM_Full_Period = 2500 - 1; // 4 us * 2500 = 10ms

    However I get a timing of 10.14 ms with the following:

    Code:

    TIM_InitStructure.TIM_Prescaler = 250 - 1; // 6.25 mhz / 250 = 25 khz = 40 us period

    TIM_InitStructure.TIM_Full_Period = 250 - 1; // 40 us * 250 = 10 ms

    Please could someone explain why I get a discrepancy

    of 0.14 milliseconds with the second configuration?

    I am using STR912FW44X6 with no other peripherals on.

    Thanks,

    Paul.

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:54

    This forum seems quiet.

    The discrepancy occurs because the counter resets to 0xFFFC,

    rather than the assumed 0x0000, giving an extra four ticks.

    In the first instance this causes an undetected 16us.

    In the second instance this causes a 160us (0.16ms) difference.

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:54

    Paul,

    Is it part of normal behavior that timer resets to 0xFFFC or is it a silicon bug?

    May I ask you what type of tool chain you are using and if you work with floating points (this has nothing to do with your post)?

    Thank you in advance.

    Joel

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:54

    Well it's intentional, although i've no idea why.

    It's documented in the manual (e.g. figure 44).

    I'm using idealist (with sarm) which is great.

    I don't use floating point, fixed works fine :)

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:54

    Thank you for your feedback, I will be carefull when using Timer (expected soon along my current design).

    I also use Idealist which is the only tool chain I was able to use with floating point. With the other GCC tool chain (Yagarto, Crosswork, Ride,...) the result of printf with floating point was not succesfull. It is why I asked you this question.

    Regards,

    Joel

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 09:54

    Hello chifoukalou and all,

    I wanted just to clarify that the reset value 0xFFFC of the timer counter is not a bug. However, it represents the spec of the STR9 TIM and it is well detailed in the reference manual to do not make confusion for our customer.

    Best regards,

    mirou.