Microsecond delay.

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

Moderators: RoccoMarco, barthess

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

Re: Microsecond delay.

Postby ulikoehler » Mon Sep 14, 2015 3:45 pm

@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.

Postby hyOzd » Tue Sep 15, 2015 8:41 am

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: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Microsecond delay.

Postby Giovanni » Tue Sep 15, 2015 8:43 am

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.

Postby hyOzd » Tue Sep 15, 2015 8:54 am

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: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Microsecond delay.

Postby Giovanni » Tue Sep 15, 2015 8:56 am

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

Giovanni


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 17 guests