@hyOzd: What clock source are you using? Have you taken care of clock source tolerance/drift?
Uli
Microsecond delay.
Moderators: RoccoMarco, barthess
-
- Posts: 71
- Joined: Tue Mar 17, 2015 2:32 am
- Location: Munich, Germany
- Been thanked: 3 times
Re: Microsecond delay.
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;
In this case, `500` counter value will give me
If I add constant 0,4 us delay to this;
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
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
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Microsecond delay.
Hi,
Assertions should catch incorrect values, make sure to enable them (and other debug options) in chconf.h during development.
Giovanni
Assertions should catch incorrect values, make sure to enable them (and other debug options) in chconf.h during development.
Giovanni
Re: Microsecond delay.
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?
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?
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Microsecond delay.
If you use ChibiStudio (or Eclipse), the ChibiOS debug plugin can retrieve the error message for you.
Giovanni
Giovanni
Who is online
Users browsing this forum: No registered users and 17 guests