This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

time on every data

I am using nrf52 developmemt kit. I am using mpu9250. the odr of mpu is 100 Hz. i am able to send data over ble using example code nrf5-ble-mpu-data-ready-interrupts. Now I want also to send timestamp of registered with each data point over ble on mobile device. I have looked on nrf5_calendar_example and also checked app_timer module, but i am not able to crack the solution of getting timestamp with mpu data points.

Parents Reply Children
  • To keep track of time I suggest that you do one of these things:

    1. Use either the RTC or Timer peripheral to generate an interrupt every 1 ms. In this interrupt increment a variable holding your unix time. Use either the Real Time Counter Example or the Timer Example for inspiration. This is probably the easiest method, but the downside is that you need to handle a lot of interrupts.
    2. A more elegant and power efficient, but also more complex method is to use two timer peripherals, one in timer mode and the other in counter mode. Configure the timer to trigger an event every 1 ms and use PPI to make that event trigger a count task in the counter. This way you can keep track of time without servicing interrupts all the time, but rather just read the counter value whenever needed, like for example on MPU data ready interrupts (remember to handle counter overflow events if necessary). Use the PPI Example for inspiration.

    If you need a unix timestamp with 1 ms resolution you will need to store the timestamp as a 64 bit integer. 

    Then I suggest that you add a timestamp field to the accel_values_t structure. E.g. like this:

    typedef struct
    {
        uint64_t timestamp;
        int16_t z;
        int16_t y;
        int16_t x;
    }accel_values_t;

    and finally update this field on every MPU data ready interrupt. I would recommend that you treat the time stamp as an integer instead of a human readable string, because converting it to a string requires a lot of processing time and because a human readable representation requires more bytes to be transmitted over the air. Hence it is best to convert the 64 bit integer on the central side (which usually has a lot more CPU power). 

Related