Page 1 of 1

Time Measurement Unit on STM32F0

Posted: Thu Nov 21, 2013 2:20 pm
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

Re: Time Measurement Unit on STM32F0

Posted: Thu Nov 21, 2013 2:40 pm
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

Re: Time Measurement Unit on STM32F0

Posted: Thu Nov 21, 2013 2:53 pm
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

Re: Time Measurement Unit on STM32F0

Posted: Thu Nov 21, 2013 2:56 pm
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

Re: Time Measurement Unit on STM32F0

Posted: Thu Nov 21, 2013 3:06 pm
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?

Re: Time Measurement Unit on STM32F0

Posted: Thu Nov 21, 2013 3:08 pm
by goeck
Well, I found a implementation on github:

Code: Select all

define ST2MS(st)   ((st / CH_FREQUENCY) * 1000L)

Re: Time Measurement Unit on STM32F0

Posted: Thu Nov 21, 2013 3:16 pm
by Giovanni
This is really odd, I was sure the implementation was already provided, I'll add those macros in 2.6.2.

Giovanni

Re: Time Measurement Unit on STM32F0

Posted: Thu Nov 21, 2013 3:46 pm
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.

Re: Time Measurement Unit on STM32F0

Posted: Thu Nov 21, 2013 3:50 pm
by Giovanni
I meant correct macros :) look at the existing ones in chvt.h, the interger arithmetic is considered.

Giovanni

Re: Time Measurement Unit on STM32F0

Posted: Thu Nov 21, 2013 3:57 pm
by goeck
hihi ;-) nice one. just wanted to share my experience...