After running the calibration wizard, the calibration data must be saved.
For the calibration of the ACS71020, 6 values are required:
- crs_sns for setting the coarse gain
- sns_fine for the fine trim
- qvo_fine to set the offset
- pacc_trim for active power
- VRMS calibration factor
- IRMS calibration factor
The first 4 values are stores in the chips own memory. The IRMS and VRMS calibration factors are set in the code directly. To enable changing these values without reprogramming the teensy, another way of storing these values has to be chosen.
Last week, I was searching the ACS-chip for empty memory locations. A much easier solution is to use the internal EEPROM of the Teensy 4.0, which can store up to 1080 bytes of data. EEPROMs are known to be limited in write-cycles (100 000 cycles in this case), but usually a calibration won't be done that often anyways. Both calibration factors are only 32 bytes each, so there is enough space left.
The internal EEPROM can be accessed with the EEPROM-library easily. Each write stores 1 byte at a given address, so 4 writes have to be done in total. Reading values is analogous. An mcu_read() and a mcu_write() function serve as a wrapper to take care of this task.
Of course, a command from the serial input should be able to set those values as well.
The calcVRMS and calcIRMS function both use the calibration factors. The constants are now variables. Everything else remains the same under the assumption, that AC calibration will be done with 230Vrms.