Microsecond delay.

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

ulikoehler
Posts: 71
Joined: Tue Mar 17, 2015 2:32 am
Been thanked: 3 times

Re: Microsecond delay.

Post by ulikoehler »

@hyOzd: What clock source are you using? Have you taken care of clock source tolerance/drift?

Uli
hyOzd
Posts: 20
Joined: Tue Jul 21, 2015 12:17 pm
Has thanked: 1 time
Been thanked: 2 times

Re: Microsecond delay.

Post 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 :oops: 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 :?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Microsecond delay.

Post by Giovanni »

Hi,

Assertions should catch incorrect values, make sure to enable them (and other debug options) in chconf.h during development.

Giovanni
hyOzd
Posts: 20
Joined: Tue Jul 21, 2015 12:17 pm
Has thanked: 1 time
Been thanked: 2 times

Re: Microsecond delay.

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Microsecond delay.

Post by Giovanni »

If you use ChibiStudio (or Eclipse), the ChibiOS debug plugin can retrieve the error message for you.

Giovanni
Post Reply