2024-02-06 09:04 AM
I need to generate a timestamp for data logging, but I'm not sure how to do it.
The data packets are received via the UART at a 100ms rate and each packet of data consists of 10 bytes of serial data
These data packets are written to an SD card, but I need to prepend each data packet with a timestamp.
I initially considered using the RTC then converting it to a 32-bit UNIX time, but then realised several issues:
1. The precision of UNIX time is only 1 second, but the rate of the data packets is currently 100ms (this could be changed to a faster rate such as 10ms).
2. The other extreme is that the UNIX time contains year, month and day. This would not be needed for every data packet, its wasteful to store this when each data packet is being logged at a 100ms rate !
What is the best way to time stamp each data packet ? The only thing I can think of, is to capture the date and time and write it to the start of the log file. This would be the reference time for the rest of the log file.
Then setup a timer (e.g with a 1ms resolution) and use that timer to stamp each data packet. When plotting the data, the time stamp for each data packet would be added to the reference time captured at the start of the log file.
Or is there a better solution ?
PS. The data on the SD card will need to be post processed using MATLAB, Python etc
PPS. I am using the NUCLEO-L433RC-P dev board.
Solved! Go to Solution.
2024-02-06 09:10 AM
You can also use Systick timer using HAL_GetTick() that provides 1ms rate.
2024-02-06 09:10 AM
You can also use Systick timer using HAL_GetTick() that provides 1ms rate.
2024-02-06 09:27 AM
I implemented Microsoft's SYSTEMTIME for my own purposes.
I don't much care for HAL_GetTick() beyond timeouts, but the SysTick can do additional things. Can use a 32-bit or 64-bit count over whatever epoch you want, UNIX, MICROSOFT, GPS, etc. Sub milli-second you want to do with HW counts, not interrupts.
The RTC's can hold time and date.
A system with GPS/GNSS can have highly accurate time, and doesn't need user input. With a network connection (S)NTP. A lot of routers these days support NTP, and acquisition from pool.ntp.org type resources, but don't abuse.
2024-02-08 10:49 AM
Thanks all, I used HAL_GetTick() and it seems to work fine.
2024-09-26 11:55 AM
So i too am using an SNTP servers Ascii DT format parsed to the RTC Date/Time values. I'm sinking several MCU's from the AT event. However, i'm still not able to discern how to extrapolate the UNIX time from the RTC Time/Date type defs respectively? I'm trying to log telemetry info received from sensor/s too a .bin file on an SD card. I'm sure there's a solution I'm overlooking here, as i often find on these ST boards.... still in the rooky phase.. Anything short direction you can offer? Thank You.
2024-09-27 07:28 AM
So the long and short answer, there's no short answer! lol, I used time.h, and implemented DSL and Leap Year considerations.