Page 1 of 2
Time measurement unit.
Posted: Mon Apr 23, 2012 8:26 pm
by barthess
I am in doubt, how to use it in proper way. There is no exported variable for time measurement driver (like for USART, etc.) and void parameter passes to tmInit() function, so I can not pass to it pointer to my own TimeMeasurement structure. I added exported variable TMU1 to tm.h and tm.c and check the driver against hardware counter - results are equal.
An I right? If so than I will commit my changes to trunk.
Re: Time measurement unit.
Posted: Mon Apr 23, 2012 8:36 pm
by Giovanni
Hi,
The TMU is not a normal driver, you can have as many instances as you want, in practice you can make multiple measurements at the same time so there is no need to have a predefined one, it is the user that decides how many of those to allocate.
It is like the MMC_SPI, it does not defines fixed instances because it is not tied to a specific HW cell.
About the conversions you added, it is OK but right now the conversions truncate down to the next lower integer, should those round the result up to the next higher integer instead?
Giovanni
Re: Time measurement unit.
Posted: Mon Apr 23, 2012 9:01 pm
by barthess
Giovanni wrote:you can have as many instances as you want
In that case we must change
to
to allow creation and initialization of driver from userspace code. Ore there is different way to create measurement structure?
Giovanni wrote:should those round the result up to the next higher integer instead?
I think no. Because current implementation behaves like a regular hardware counter - it is most expected by user.
Re: Time measurement unit.
Posted: Mon Apr 23, 2012 9:08 pm
by Giovanni
I think no. Because current implementation behaves like a regular hardware counter - it is most expected by user.
Good point.
About the TM, tmInit() initializes the subsystem and performs a calibration that is required only once (it is invoked from halInit()). What you suggest is done by tmObjectInit() which initializes a measurement instance. Probably I should add examples of this, it is not used anywhere yet.
Giovanni
Re: Time measurement unit.
Posted: Mon May 28, 2012 7:10 pm
by manton
Hi,
Do you have any code snippets to show how to use this time measurement driver?
Thanks.
Re: Time measurement unit.
Posted: Mon May 28, 2012 8:07 pm
by barthess
It is very simple:
define measurement object
Code: Select all
static TimeMeasurement itg3200_tmup;
init it
than perform start and stop:
Code: Select all
tmStartMeasurement(&itg3200_tmup);
do some work here
tmStopMeasurement(&itg3200_tmup);
imu_update_period = RTT2US(itg3200_tmup.last);
Re: Time measurement unit.
Posted: Mon May 28, 2012 10:00 pm
by manton
Wow ! It is simple as you said.
Thank you very much for your help.
Re: Time measurement unit.
Posted: Fri Mar 08, 2013 2:59 pm
by Jevermeister
Hi, i'm trying to measure the time needed to complete one task loop.
The task is activated every ~5ms by an external interrupt which releases a semaphore.
code is like this:
Code: Select all
while (TRUE) {
tmStartMeasurement(&TimeMonitor);
chBSemWait(&semaphore);
doStuff();
chThdSleepMicroseconds(5000);
tmStopMeasurement(&TimeMonitor);
}
but the code execution time won't change if i let the thread sleep until i set it to ~9000 us which causes a FIFO buffer to overflow and add a huge delay. After passing the "magic" sleep of 9000 us every thread sleep increase is added directly to the execution time of the loop.
My CH_FREQUENCY is set to 10000 on a STM32F407 so it should be able to measure up to 100us precision. Why is the measured execution time of the loop not increased with values lower than 9000?
This is used as a PID controller loop and the thread sleep seems to have no influence on the behaviour until i pass the 9000 mark, then it behaves totally unstable.
Regards
Re: Time measurement unit.
Posted: Fri Mar 08, 2013 3:06 pm
by Giovanni
Hi,
Is the TimeMonitor object initialized using tmObjectInit()? note the measurement has one CPU clock cycle resolution, it is not related to CH_FREQUENCY.
The counter is 32bits wide so watch for overflows, the maximum period is 2^32 / CPUCLK.
Giovanni
Re: Time measurement unit.
Posted: Fri Mar 08, 2013 3:45 pm
by Jevermeister
It is initialised. The task takes about 6ms to complete and i want to measure up to 20ms. So this should be enough?
With a thread sleep of less than 9000 us, it always takes ~9900us to complete.
With a thread sleep of more than 9000 us, it takes ~9900us + x to complete, x is roughly threadsleep - 9000.