Calculate an interval time

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Has thanked: 83 times
Been thanked: 67 times

Calculate an interval time

Post by RoccoMarco »

Hi to all, anyone know about some function to calculate some time interval with ChibiOS? I have to use an AHRS filter and I need to know how often the filter is updated in order to optimize the convergence of this filter. :mrgreen: Thank you
Kind regards
Rocco Marco
jscott
Posts: 129
Joined: Tue Jul 03, 2012 3:50 pm

Re: Calculate an interval time

Post by jscott »

Hi Rocco,

I have been playing with your functions and trying to add Magnetometer functions to it, looks like you are going faster then I am!! :D :D

For real time duration between calls to AHRS routines you can use halGetCounterValue().
Just get the time at the start of your routine, compare it to the time last time you started
your routine and calculate the time.

There are a few things to be aware of about this, however. This is a free running counter and
can overflow.

I think the counter is 32 bits and is clocked at 72Mhz on the stm32f3.


counter size clocked @ == overflow @ seconds
4294967296 / 72000000 = 59.6523236

It may be better to use a virtual timer and clock it slower. I doubt you need
timing down the 1/72,000,000 :shock:

Maybe create a Virtual Timer that clocks about 1mhz or so with a callback that
bumps a 32bit counter. Then you can read that timer to get a high resolution
time interval.

counter size clocked @ == overflow @ seconds
4,294,967,296 / 1,000,000 = 4294.9673 = 71.58 hours

You can play with the timer clocking speed to get different values of resolution
and period between overflows.

If you have any questions about any of this I will be more then happy to help.
Your libraries are looking better then mine!!!

-John Scott
http://www.atl123.com
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Calculate an interval time

Post by Giovanni »

You could consider the Time Measurement driver, which uses the function suggested by John internally.

Giovanni
jscott
Posts: 129
Joined: Tue Jul 03, 2012 3:50 pm

Re: Calculate an interval time

Post by jscott »

Giovanni,

I looked over the Time Measurement driver. As I understand it, it is designed to work
something like this:

From a post by barthess:
tmStartMeasurement(&itg3200_tmup);
do some work here
tmStopMeasurement(&itg3200_tmup);
imu_update_period = RTT2US(itg3200_tmup.last);


This will give a best, worst, and last execution period of the work between
the tmStartMeasurement and tmStopMeasurement functions. This is great if
what you want to know is how long the function takes to execute.

However, I don't think that is what is needed here.

Instead Rocco ( and I ), are looking for how much time has passed since
a function has run last. Something more like:
[/code]
void calculate_orientation()
{
period = time_elapsed_since_last_invocation();

read_gyro_acc_mag()

perform_lots_of_math_here();

store_orientation();
}
[code]

calculate_orientation() may not be called at a precise interval, however, the orientation
calculations depends on knowing how long has elapsed since the last sensor readings.

Is there another usage that is not clear?

thanks
-John Scott
http://www.atl123.com
User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Has thanked: 83 times
Been thanked: 67 times

Re: Calculate an interval time

Post by RoccoMarco »

I'm sorry for my late reply, i was busy.
jscott wrote:I have been playing with your functions and trying to add Magnetometer functions to it, looks like you are going faster then I am!! :D :D

About this, I can just say that it's only a feeling , but probably this (wrong) impression figures out from the fact that I have a special Master that helps me everyday, so I seem less stupid than how really I am, however thanks for kind words.

About "timing" actually I need a precision of millisecond... I remember of something like chSysTimeNow(), but i can't remember where I saw it... probably in shell demo. Tomorrow I'll check this! But, for an advanced future app, is good to know what kind of "temporal" instruments are at my disposal.
Thanks for tips, I'll try both of them and I'll give you some feedbacks
Post Reply