Time Measurement Unit on STM32F0

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

Moderator: RoccoMarco

Post Reply
goeck
Posts: 92
Joined: Mon Feb 11, 2013 12:00 pm

Time Measurement Unit on STM32F0

Post by goeck »

Hey,

I am trying to measure the time a portion of code needs on my STM32F0-Discovery with ms resolution.
First I was doing well when using chTimeNow() twice and doing the difference, but since I get same values too often in a row I am not trusting those results anymore. Also I used the difference as result already in [ms]; is this correct?
Secondly I wanted to use TimeMeasurmentUnit and found this seems not be supported by STM32F0?!

Can anyone give me an advice, please?
THX

Regards from Germany
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Time Measurement Unit on STM32F0

Post by Giovanni »

Hi,

The time measurement unit is not supported on the M0 because it lacks the realtime counter present on the M3 and M4. A new mechanism will be present in ChibiOS 3.0 but it cannot be backported to 2.6.

You may try to increase the system time resolution CH_FREQUENCY, it should be able to handle up to 5000/10000 and continue to use chTimeNow().

Giovanni
goeck
Posts: 92
Joined: Mon Feb 11, 2013 12:00 pm

Re: Time Measurement Unit on STM32F0

Post by goeck »

Hi Giovanni,

thanks for the quick info. My setting of CH_FREQUENCY is 1000 at the moment. What does this actually say? Doesn't it mean 1ms resolution of the chibiOS implemented system timer? So can't I use the output value of chTimeNow() directly as the system run time in [ms] then?

Cheers
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Time Measurement Unit on STM32F0

Post by Giovanni »

Hi,

Correct, chTimeNow() does not return milliseconds and is not meant to, it returns time in system tick time units, you can convert that to milliseconds using ST2MS() which compensates for timer resolution.

Giovanni
goeck
Posts: 92
Joined: Mon Feb 11, 2013 12:00 pm

Re: Time Measurement Unit on STM32F0

Post by goeck »

Sorry, Giovanni, compiler can't find ST2MS whereas I know MS2ST is defined in virtual timer code. Do I have to include or activate some thing else?
goeck
Posts: 92
Joined: Mon Feb 11, 2013 12:00 pm

Re: Time Measurement Unit on STM32F0

Post by goeck »

Well, I found a implementation on github:

Code: Select all

define ST2MS(st)   ((st / CH_FREQUENCY) * 1000L)
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Time Measurement Unit on STM32F0

Post by Giovanni »

This is really odd, I was sure the implementation was already provided, I'll add those macros in 2.6.2.

Giovanni
goeck
Posts: 92
Joined: Mon Feb 11, 2013 12:00 pm

Re: Time Measurement Unit on STM32F0

Post by goeck »

Actually this macro doesn't even get me what I want since there is integer division involved...
I only get 0 or i*1000ms out of this.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Time Measurement Unit on STM32F0

Post by Giovanni »

I meant correct macros :) look at the existing ones in chvt.h, the interger arithmetic is considered.

Giovanni
goeck
Posts: 92
Joined: Mon Feb 11, 2013 12:00 pm

Re: Time Measurement Unit on STM32F0

Post by goeck »

hihi ;-) nice one. just wanted to share my experience...
Post Reply