My Atmega328 will record data from an external sensor at around 100Hz over several minutes. Communication is done through I2C requests to the sensor. I need to store the time of measurement (relative to the first measurement) together with the sensor data. Precision of at least 1ms is required.
My plan is:
- Start Counter1 (16 bit) at an appropriate scaling
- Whenever Counter1 wraps, increment some register
- When sensor data is requested, also store the values of Counter1 and the wrap-count register
Is this a good plan? Are there better solutions?