Other Parts Discussed in Thread: MSP430F5438
We have a device that rides on delivery trucks and measures dispensed product. Our software is developed on the IAR Workbench (full) for the TI MSP430F5438 (non-a)
Chip. The power to our device is usually turned off between deliveries. I use the on-board TI Supply voltage monitor to create an interrupt when we are losing power. The interrupt calls a function ShutdownSaveTotals() that saves 10 parameters to a flash memory INFO segment and sets a flag in that segment. As a wear leveling algorithm, I save the data in INFO C one time and INFO D next time. To handle the case where power is restored during the shutdown function, I then delay and force a reset by: WDTCTL = 0x5A24;
On startup, I check INFO C and INFO D to see if the flags are set. If the flag is set, I copy the data to RAM variables and set variable nextSaveSegment to alternate between using INFO C and INFO D as a wear-leveling strategy. I then print the recovered data to HyperTerminal using a serial port for diagnostic purposes. Then I erase the INFO segment where the recover data was found and if the flag in the other INFO segment does not == 0xff (erased byte, unsigned char). This ensures that the flash segments are ready for writing on the next power loss.
I have done some timing checks using DIO and a scope. It takes 28 ms to erase an INFO segment, 5 microseconds to load RAM from flash, and 1.5 ms to write RAM values to INFO segment
This setup has worked extremely well for several years in many different countries, but one or two of our customers are reporting lost or corrupted data. We can find no hardware problems with their setup. The only way we have been able to simulate their problems is to rig up a signal generator so that we are able to effect (beginning with the device running and valid data showing) a off/on/off/on sequence on the power input. As long as the sequence is off/on, everything works fine but the double dip mentioned above will cause data loss or corruption at certain frequencies of the sequence. We believe this occurs because we lose power during a flash erase operation. The frequency band of failure is quite small. For instance, at 1.18 hz all is well, failure at 1.9 hz, and again at 1.20 hz all is well. . We have tried to use a larger capacitor to guarantee we will not lose power until we have erased but there is a limit to the capacitance allowed and we are almost at maximum already.
We developed an algorithm that (we think) ensures that valid shutdown data will be left in one INFO segment and the other is always erased, ready for the next shutdown. For example, if, on startup, I find data in C, I load C to RAM, Erase D, Save RAM to D, then erase C.
We believe this should work, but it seems that if we lose power while erasing C, it not only corrupts C, but also D. Thus when power is restored, both C & D are invalid and default values are used in RAM rather than the lost data. We tried a 20 ms delay between saving RAM to D and erasing C, but no improvement, just moved problem to another frequency. On one instance, we noticed that losing power while erasing INFO C also caused the checksum protecting parameters in INFO A to fail, and another checksum protecting calibration data located in INFO B also failed. Once we caused a checksum to fail for CODE memory (Banks 0 – 3).
We are looking for insight and/or suggestions for diagnosing or avoiding these problems.
If anyone knows a better way to accomplish these goals, I would appreciate hearing from you.
Mike Raines
mraines@hofferflow.com