Page 1 of 1

AVR tickless mode

Posted: Mon Nov 05, 2018 11:08 am
by _Desh_
Hi,
I study ChibiOS and need some help.

When I tested tickless mode from Arduino Uno demo example, I found that prescaler value is hard-coded to 1024 (hal_st_lld.c) and tick frequency is set to 15625 (obviously F_CLK/1024). So I have a question:

- what is the basic principle on how to calculate prescaler in tickless mode if I want to set a 1000 Hz (1 ms) tick? How do we consider a hardware timer resolution in this matter? Why do we need to set tick frequency to the higher value than in the periodic tick mode?

Re: AVR tickless mode  Topic is solved

Posted: Mon Nov 05, 2018 9:34 pm
by Giovanni
Hi,

You can have the same tick frequency in tick and tickless mode, it does not need to be different.

Giovanni

Re: AVR tickless mode

Posted: Tue Nov 06, 2018 5:27 pm
by _Desh_
We can't set tick frequency to 1000 in this case because AVR timer1 is capable of counting with frequency of clk/1024 at minimum. I could set prescaler to a lesser value (not 1024, but 256 for example, then tick frequency is 16000000/256=62500). This means that system timer would have a better precision (it ticks more frequently) but at the same time it reduces maximum possible time delay by 4 times (65536/62500=1.048 seconds).

Thank you, I think I understand now.

Re: AVR tickless mode

Posted: Tue Nov 06, 2018 10:59 pm
by orion
The tickless implementation for the AVR port is not very flexible right now, IMO, for these reasons:
  • As you mentioned, the tick resolution is not configurable since it is hardcoded in os/hal/ports/AVR/MEGA/LLD/TIMv1/hal_st_lld.c to a frequency given by F_CPU/1024
  • Because of the above and a simple implementation using TIMER1, the systime_t type only works correctly when it's 16 bits, and this makes the maximum delay in a virtual timer to be about 4.2 seconds
  • Since it uses TIMER1, the gpt and input capture modules cannot be used in tickless mode; also the use of pwm module with TIMER1 is precluded.
I don't use the tickless mode except for toy examples, but I guess a more flexible implementation would not be that hard.