Page 3 of 3
Re: Microsecond delay.
Posted: Mon Sep 14, 2015 3:45 pm
by ulikoehler
@hyOzd: What clock source are you using? Have you taken care of clock source tolerance/drift?
Uli
Re: Microsecond delay.
Posted: Tue Sep 15, 2015 8:41 am
by hyOzd
Writing is a really good way of thinking : ) I was writing a lengthy post about my issue then I realised the problem.
Note that I was having this problem with 10MHz setting. Timer clock is set to the 84MHz. It's not possible to get 10MHz from 84MHz with a simple pre-scaler :s
Here is some simple math. Measurement shows that `delay_us(50)` is `48,05us`. With 10MHz this means a counter value of `500`. But my timer freq. isn't actually 10MHz its;
Code: Select all
prescaler = 84 MHz/10MHz = 8,4 => prescaler is rounded => 8
actual freq = 84MHz / 8 = 10,5 MHz
In this case, `500` counter value will give me
Code: Select all
delay = 500 * (1/10,5MHz) = 47,619048 µs
If I add constant 0,4 us delay to this;
Code: Select all
delay = 47,619048 µs + 0,4µs = 48,01 us
This is almost exactly the measured value.
Sorry for wasting your time

I have no idea how I missed this because this was the first thing that came to my mind! I checked the timer clock but didn't see the issue

Re: Microsecond delay.
Posted: Tue Sep 15, 2015 8:43 am
by Giovanni
Hi,
Assertions should catch incorrect values, make sure to enable them (and other debug options) in chconf.h during development.
Giovanni
Re: Microsecond delay.
Posted: Tue Sep 15, 2015 8:54 am
by hyOzd
Thanks for tip. I'm certainly doing this!
But how do I access the runtime debug messages when assert is enabled? I can see the crash at call stack when debugging. But is there any other way?
Re: Microsecond delay.
Posted: Tue Sep 15, 2015 8:56 am
by Giovanni
If you use ChibiStudio (or Eclipse), the ChibiOS debug plugin can retrieve the error message for you.
Giovanni