How to generate a timestamp for datalogging ?
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
- Byte 0: Temperature
- Byte 1: Voltage high byte
- Byte 2: Voltage low byte
- Byte 3: Current high byte
- Byte 4: Current low byte
- Byte 5: Consumption high byte
- Byte 6: Consumption low byte
- Byte 7: Rpm high byte
- Byte 8: Rpm low byte
- Byte 9: 8-bit CRC
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.
