Page 1 of 1

64bit system timer issues

Posted: Fri Jan 29, 2021 11:01 pm
by DrTon
Hello!

On ChibiOS/RT 20.3 (https://github.com/ChibiOS/ChibiOS/tree/stable_20.3.x) I'm trying to switch system timer to 64 bit mode.
If system tick frequency is 10 000 everything works. But if I change it to 1000 000 (I need 1 microsecond time precision) or even 100 000, then everything goes wrong, e.g. chThdSleep() sleeps for incorrect time (and every time different).

In 32 bit mode everything works fine.
Didn't find any demos in 64 bit mode, is it fully supported?

```
CPU: STM32F765II

#define CH_CFG_ST_RESOLUTION 64
#define CH_CFG_ST_FREQUENCY 100000
#define CH_CFG_INTERVALS_SIZE 64
#define CH_CFG_TIME_TYPES_SIZE 32
#define CH_CFG_ST_TIMEDELTA 2

#define STM32_ST_USE_TIMER 5
```

Re: 64bit system timer issues

Posted: Sat Jan 30, 2021 7:27 am
by Giovanni
Hi,

Try increasing the delta parameter, it is required when going to higher frequencies, you need to find the value experimentally because it depends also on the duration of your timer callbacks. Keep assertions enabled while doing this.

Giovanni

Re: 64bit system timer issues

Posted: Sat Jan 30, 2021 10:25 am
by steved
If you don't need "global" 1us resolution, have a look at the last post here. It uses a separate counter to implement a high resolution virtual-timer style timer. Might need a little tweaking for your platform. I've also done something similar limited to the two or four comparators of a timer; limits the number of active timers, but less overhead.