I have an STR75x application (IAR compiler) in a syringe pump that uses a FreeRTOS that I’ve customized in order to use interrupts more efficiently. I just downloaded version 5.0.0 and am merging in my changes. I’ve come to a point where the timebase timer is set up and I don’t think I understand how the auto reload value is computed in the prvSetupTimerInterrupt function in port.c.
The 60 MHz processor clock is fed through a divide-by-20 prescaler, giving the timebase timer an input frequency of 3 MHz. My application needs a 1 millisecond tick (configTICK_RATE_HZ = 1000) so it has an auto reload value of (configCPU_CLOCK_HZ / portPRESCALE) / configTICK_RATE_HZ, or (6 MHz / 20) / 1000 = 3000 counts. 3 MHz / 3000 counts = 1 mS between interrupts. I’ve done timing runs on the pump to insure the flow is accurate and my clock, which runs off the timer hook, runs very accurately with this setting (I’ve compared it with an external clock).
The FreeRTOS version 5 timebase setup still feeds a 60 MHz processor clock through a divide-by-20 prescaler so the input frequency into the timebase timer is still 3 MHz. But the auto reload value in version 5 is computed as ((configCPU_CLOCK_HZ / (portPRESCALE + 1)) / configTICK_RATE_HZ) + 1 which is (6 MHz / 21) / 1000 + 1, or 2858 counts, rounded. This means the clock is running at an actual tick rate of 1050 Hz instead of the expected 1000 so the clock would be running too fast, adding one second every 20 seconds. Is this correct or am I missing something here?
I’m going to leave my 3000 count setup alone since it’s working fine.