SparkFun Forums 

Where electronics enthusiasts find answers.

Questions &/or issues related to products in the Movement & IMU category should be posted in this forum.
User avatar
By zoran
#208253
Hi,
I am currently developing a project with the BNO080 IMU. I am interfacing this with an STM32F407 microcontroller based on the MikroC development environment.
I have everything working great and have validated the data from the IMU. However, i am unable to determine the best way to get an accurate timestamp for each sensor data from the BNO080. I am capturing the timebase value and delay value from every input report (currently only have accelerometer active).

According to the example in the datasheet, "The host will create a timestamp based on the assertion of HINT (call it T). The timebase reference provides a baseline reference of 120 * 100μs or 12ms. All sensor reports are thus timestamped as T-12ms + their own delay."
"In this example, the first sensor report should be timestamped as occurring at T-12ms and the second at T – 10.3ms (T - 12ms + 1.7ms)".

My questions are:
->What is meant by "the host will create a timestamp based on the assertion of HINT"? Does this mean that I need to use a timer on the host (STM32) to measure the time from the moment that HINT (BNO interrupt) is detected? When should this timer stop?
->Will this time (T) then be a constant i will use for the future timestamp calculations?
->I will also be activating the gyro, magnetometer, and rotation vector simulataneously from the IMU. Will i use the same (T) value with these input reports?

Cheers,
Zoran
User avatar
By TS-Chris
#208281
Hello Zoran, and thanks for your post.

SparkFun didn't write the data sheet for the BNO080, but I'll do my best to interpret what the author is trying to convey.
My questions are:
->What is meant by "the host will create a timestamp based on the assertion of HINT"? Does this mean that I need to use a timer on the host (STM32) to measure the time from the moment that HINT (BNO interrupt) is detected? When should this timer stop?
So what I'm reading into that is you want to craft your code to watch for an interrupt on the HINT (INT on our board) pin. Once your host (Arduino, ESP, whatever) sees activity on that pin, it should make a note of what the time is and add that to your output. The time could be a counter running on the host, or even time from a RTC module. Generally the timer never stops, otherwise you could have duplicate time stamps.
->Will this time (T) then be a constant i will use for the future timestamp calculations?
If the time was constant, every time stamp would have the same time on it. You could reset the time and add the new time to the old time to get current time, but that's extra work you need to code for. It might be good to do that if your timer might overflow though.
->I will also be activating the gyro, magnetometer, and rotation vector simulataneously from the IMU. Will i use the same (T) value with these input reports?
That's up to you, but it would make sense to use the same time source for everything that's happening to avoid needing multiple clocks or timers running in the background and for keeping a single timeline for every event, otherwise it might get really confusing to sort out what happened when.
User avatar
By zoran
#208427
Hi Chris,
Thank you for your feedback. You are very much correct with your approach. I did a little more digging and discovered that a timer/counter can be used to calculate the timestamps. And as you mentioned, this timer never stops. I also found this routine in the Hillcrest nucleo example: https://github.com/hcrest/sh2-demo-nucleo
It basically accumulates a 64-bit microsecond timestamp for each sensor input report.

Thanks again for your prompt reply and support.
Regards,
Zoran

// Produce 64-bit microsecond timestamp for a sensor event
static uint64_t touSTimestamp(uint32_t hostInt, int32_t referenceDelta, uint16_t delay)
{
static uint32_t lastHostInt = 0;
static uint32_t rollovers = 0;
uint64_t timestamp;

// Count times hostInt timestamps rolled over to produce upper bits
if (hostInt < lastHostInt) {
rollovers++;
}
lastHostInt = hostInt;

timestamp = ((uint64_t)rollovers << 32);
timestamp += hostInt + (referenceDelta + delay) * 100;

return timestamp;
}