Skip to content

Commit d0cc42d

Browse files
committed
Calibration functions fixed
1 parent 6559d46 commit d0cc42d

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

MCM_ATM90E32.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,20 @@ int ATM90E32::Read32Register(signed short regh_addr, signed short regl_addr)
127127
return (val);
128128
}
129129

130-
void ATM90E32::setOffset(unsigned short offset_reg, unsigned short val)
130+
void ATM90E32::setVIOffset(unsigned short VoffA, unsigned short VoffB, unsigned short VoffC, unsigned short IoffA, unsigned short IoffB, unsigned short IoffC)
131131
{
132132
CommEnergyIC(WRITE, CfgRegAccEn, 0x55AA); // 7F enable register config access
133-
CommEnergyIC(WRITE, offset_reg, (unsigned short)val);
133+
134+
// Voltage Offset Calibration
135+
CommEnergyIC(WRITE, UoffsetA, VoffA);
136+
CommEnergyIC(WRITE, UoffsetB, VoffB);
137+
CommEnergyIC(WRITE, UoffsetC, VoffC);
138+
139+
// Current Offset Calibration
140+
CommEnergyIC(WRITE, IoffsetA, IoffA);
141+
CommEnergyIC(WRITE, IoffsetB, IoffB);
142+
CommEnergyIC(WRITE, IoffsetC, IoffC);
143+
134144
CommEnergyIC(WRITE, CfgRegAccEn, 0x0000); // 7F end configuration
135145
}
136146

@@ -203,7 +213,7 @@ double ATM90E32::CalculatePowerOffset(unsigned short regh_addr, unsigned short r
203213
Serial.print("Reading: ");
204214
Serial.print(val);
205215

206-
val = (~val) + 1; // 2s compliment
216+
val = (~val) + 1; // 2s compliment
207217

208218
offset = val; // keep lower 16 bits
209219

MCM_ATM90E32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ class ATM90E32
329329
unsigned short GetMeterStatus1();
330330

331331
/*Set Offsets*/
332-
void setOffset(unsigned short address, unsigned short val);
332+
void setVIOffset(unsigned short VoffA, unsigned short VoffB, unsigned short VoffC, unsigned short IoffA, unsigned short IoffB, unsigned short IoffC);
333333

334334
};
335335
#endif

examples/Basic_Energy_Meter/Basic_Energy_Meter.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void setup() {
5151

5252
Serial.println("Start ATM90E32");
5353
mcm.begin(CS_pin, LineFreq, SumMode, IAGain, IBGain, ICGain, VoltageCal, CT1Cal, 0, CT2Cal);
54-
setVIoffset(64608, 64608, 64608, 64606, 64608, 64606); // Values obtained with VIoffsetCal()
54+
mcm.setVIOffset(64608, 64608, 64608, 64606, 64608, 64606); // Values obtained with VIoffsetCal()
5555
delay(1000);
5656
unsigned short sys0 = mcm.GetSysStatus0(); //EMMState0
5757

examples/Calibration_Example/Calibration_Example.ino

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void setup()
6969

7070
Serial.println("Start ATM90E32");
7171
mcm.begin(CS_pin, LineFreq, SumMode, IAGain, IBGain, ICGain, VoltageCal, CT1Cal, 0, CT2Cal);
72-
setVIoffset(64608, 64608, 64608, 64606, 64608, 64606); // Values obtained with VIoffsetCal()
72+
mcm.setVIOffset(64608, 64608, 64608, 64606, 64608, 64606); // Values obtained with VIoffsetCal()
7373
delay(1000);
7474
unsigned short sys0 = mcm.GetSysStatus0(); // EMMState0
7575

@@ -222,18 +222,6 @@ void VIoffsetCal()
222222
mcm.CalculateVIOffset(IrmsC, IrmsCLSB, IoffsetC);
223223
}
224224

225-
void setVIoffset(unsigned short VoffA, unsigned short VoffB, unsigned short VoffC, unsigned short IoffA, unsigned short IoffB, unsigned short IoffC)
226-
{
227-
// Voltage Offset Calibration
228-
mcm.setOffset(UoffsetA, VoffA);
229-
mcm.setOffset(UoffsetB, VoffB);
230-
mcm.setOffset(UoffsetC, VoffC);
231-
232-
// Current Offset Calibration
233-
mcm.setOffset(IoffsetA, IoffA);
234-
mcm.setOffset(IoffsetB, IoffB);
235-
mcm.setOffset(IoffsetC, IoffC);
236-
}
237225

238226
/*
239227
- Calibrate the Voltage Readings

0 commit comments

Comments
 (0)