[riot-devel] Question about hwtimer_now implementation..
mike at burg.me
Wed Oct 15 02:27:27 CEST 2014
Thanks for the replies. My problem was the timer code wasn't quite
making sense to me in terms of using a counting up value, and the low
The FRDM-KL46Z is very similar to the Kinetis boards. The PIT module has
two 32-bit channels each running at 24mhz. The channels can be chained
The solution I came up with is to use one channel for the time now
value, and the other channel to provide the RIOT timer. Also, I modified
vtimer, hwtimer, and board timer code to use 64-bit unsigned integers
for the tick values - now a overflow doesn't happen until some 59,000+
years from boot, not in a few seconds as was previously happening.
I highly suggest going with a different implementation for the higher
level timers to use a larger integer, or split it into seconds &
microseconds (like timex_t). A 32-bit value is just way too low since a
1-mhz timer will overflow in just over a hour, or in a few seconds for
boards like the KL46Z or Kinetis which have a higher clock rate.
The particular project I want to use this on has the requirement of both
using short timers, in microseconds & seconds, and long timers that have
durations in hours.
Thanks again for the help,
> Hello Michael, Joakim and list,
> On Tue, 14 Oct 2014 22:06:53 +0200
> Joakim Gebart <joakim.gebart at eistec.se> wrote:
>> Hello Michael and list,
>> This is a problem that I ran into as well when porting RIOT to another
>> Freescale CPU (K60, Cortex-M4). I have 4x 32 bit timers (called the
>> PIT module), all running at 48 MHz, which means it will overflow after
>> only 90-ish seconds, or another timer running at 32.768 kHz (called
>> the LPTMR module), but it is only 16 bit, so it will overflow after 2
>> seconds. Another trivial problem is the fact that many timers on the
>> K60 are down counting. It is however possible to chain the PIT timers
>> to each other to achieve a frequency lower than 48 MHz by using two or
>> more timers/counters together.
> I work currently also on a Kinetis Cortex-M4. All PITs are down counting. My
> temporary solution is to chain the PITs.
>> I don't know how much alike the KL46Z and the K60 are, I guess that
>> there are many major differences (Cortex-M4 vs. Cortex-M0+), but maybe
> As I understand, the peripheral is common to all Kinetis. Who is still working
> with the Kinetis? Can we work on cpu/kinetis_common together?
>> you could find something of use for your porting efforts in my WIP
>> branch. I have been meaning to change the hwtimer implementation to
>> use the LPTMR module instead of the PIT module in order to keep
>> running even during STOP modes to conserve power, but I haven't gotten
>> around to it yet. I only work on this project when I have some spare
>> time in the evenings or weekends.
More information about the devel