Hi,
I'm using a PID controller and not to loose the tuning values on re programming, those are, amongst others, stored in the simulated EEPROM.
I was wondering, what would be the best way to define the locations in the EEPROM. Ideally you don't want to care about the variable size, so sizeof should be used. This, however, refers to the variable before, which makes the code break easily on reordering of the EEPROM content. This also means that additions can easily be messed up, when referring to the wrong variables sizes. The best I could come up with by now is the following:
How do you define your EEPROM layout?
I'm using a PID controller and not to loose the tuning values on re programming, those are, amongst others, stored in the simulated EEPROM.
I was wondering, what would be the best way to define the locations in the EEPROM. Ideally you don't want to care about the variable size, so sizeof should be used. This, however, refers to the variable before, which makes the code break easily on reordering of the EEPROM content. This also means that additions can easily be messed up, when referring to the wrong variables sizes. The best I could come up with by now is the following:
Code:
#define EEPROMLocation(x, y) const uint16_t x = (eepromLocationCount += sizeof(y)) - sizeof(y)
unsigned int eepromLocationCount = 0;
float pidP = 0.005, pidI = 0.0001, pidD = 0.01;
EEPROMLocation(pidPeEPromLocation, pidP);
EEPROMLocation(pidIeEPromLocation, pidI);
EEPROMLocation(pidDeEPromLocation, pidD);
How do you define your EEPROM layout?