Time measurement unit.
Time measurement unit.
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.
An I right? If so than I will commit my changes to trunk.
- 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.
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
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.
Giovanni wrote:you can have as many instances as you want
In that case we must change
Code: Select all
void tmInit(void)Code: Select all
void tmInit(TimeMeasurement *tm)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.
- 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.
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.
Hi,
Do you have any code snippets to show how to use this time measurement driver?
Thanks.
Do you have any code snippets to show how to use this time measurement driver?
Thanks.
Re: Time measurement unit.
It is very simple:
define measurement object
init it
than perform start and stop:
define measurement object
Code: Select all
static TimeMeasurement itg3200_tmup;init it
Code: Select all
tmObjectInit(&itg3200_tmup);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);-
Jevermeister
- Posts: 13
- Joined: Sun Nov 11, 2012 8:19 pm
Re: Time measurement unit.
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:
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
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
- 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.
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
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
-
Jevermeister
- Posts: 13
- Joined: Sun Nov 11, 2012 8:19 pm
Re: Time measurement unit.
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.
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.