Millis() seems to reset for some reason

This may or may not help:

SparkFlash_write(flashindex,  (uint16_t)((pulsearray[storearrayindex] >> 16) & 0xffff));
SparkFlash_write(flashindex + 2, (uint16_t)(pulsearray[storearrayindex] & 0xffff));

If you notice, you have a lot of perfectly round numbers for timestamps... 4096, 256, 0, 18482, 4, 65792... all are just one bit high, or two bits high. To answer your question, millis() does not just randomly reset like you think it may be doing. It's likely just a saving, recalling, type casting issue.

Also, I question if you are truly getting "1 pulse per watt-hour". What generates the pulse? If it's a mechanical switch, I guarantee your interrupt routine is being slammed with repeated calls. You can look at my pinewood derby code here and see how I prevented that from being an issue:

1 Like