20.06.2019, 13:10
Hi, I don't fully understand the current measurement and why do I have offsets on each input.
1st: outcome = outcome - 7300; why is this number subtracted? Is this line causing a zero drift on all current measurements?
2nd:
switch c.PowerFrequency {
case 60:
rmsFactor = 3493258.0 // 60Hz
case 50:
rmsFactor = 4191910.0 // 50Hz
In the datasheet it says clearly:
With the specified full-scale analog input signal of 0.5 V, the ADC produces an output code that is approximately ±5,928,256. The equivalent rms value of a full-scale sinusoidal signal is 4,191,910(0x3FF6A6), independent of the line frequency. If the integrator is enabled, that is when bit 0 (INTEN) in CONFIG[15:0] register is set to 1, the equivalent rms value of a full-scale sinusoidal signal at 50Hz is 4,191,910(0x3FF6A6) and at 60Hz is 3,493,258(0x354D8A).
So, only when integrator is enabled you should change rmsFactor with respect of line frequency. The integrator should be enabled only when using Rogowski coil, but your product comes with current transformers, so integrator bypassed should be the default setting.
Source: https://github.com/nDenerserve/SmartPi/b...ade7878.go
func ReadCurrent(d *i2c.Device, c *Config, phase Phase) (current float64) {
command := make([]byte, 2)
switch phase {
case PhaseA:
command = ADE7878REG["AIRMS"] // 0x43C0 (AIRMS; Current rms an A)
case PhaseB:
command = ADE7878REG["BIRMS"] // 0x43C2 (AIRMS; Current rms an B)
case PhaseC:
command = ADE7878REG["CIRMS"] // 0x43C4 (AIRMS; Current rms an C)
case PhaseN:
command = ADE7878REG["NIRMS"] // 0x43C6 (AIRMS; Current rms an N)
default:
panic(fmt.Errorf("Invalid phase %q", phase))
}
var rmsFactor float64
switch c.PowerFrequency {
case 60:
rmsFactor = 3493258.0 // 60Hz
case 50:
rmsFactor = 4191910.0 // 50Hz
default:
panic(fmt.Errorf("Invalid frequency %g", c.PowerFrequency))
}
if c.MeasureCurrent[phase] {
outcome := float64(DeviceFetchInt(d, 4, command))
cr := CTTypes[c.CTType[phase]].CurrentResistor
var ccf float64
if c.CTType[phase] == "YHDC_SCT013" {
ccf = CTTypes[c.CTType[phase]].CurrentClampFactor
} else {
ccf = 1.0 / (float64(c.CTTypePrimaryCurrent[phase]) / 100.0)
}
// fmt.Println("CalibrationfactorI: ", phase, " ", c.CalibrationfactorI[phase])
oc := CTTypes[c.CTType[phase]].OffsetCurrent
outcome = outcome - 7300
current = ((((outcome * 0.3535) / rmsFactor) / cr) / ccf) * 100.0 * oc * c.CalibrationfactorI[phase]
} else {
current = 0.0
}
return current
}
1st: outcome = outcome - 7300; why is this number subtracted? Is this line causing a zero drift on all current measurements?
2nd:
switch c.PowerFrequency {
case 60:
rmsFactor = 3493258.0 // 60Hz
case 50:
rmsFactor = 4191910.0 // 50Hz
In the datasheet it says clearly:
With the specified full-scale analog input signal of 0.5 V, the ADC produces an output code that is approximately ±5,928,256. The equivalent rms value of a full-scale sinusoidal signal is 4,191,910(0x3FF6A6), independent of the line frequency. If the integrator is enabled, that is when bit 0 (INTEN) in CONFIG[15:0] register is set to 1, the equivalent rms value of a full-scale sinusoidal signal at 50Hz is 4,191,910(0x3FF6A6) and at 60Hz is 3,493,258(0x354D8A).
So, only when integrator is enabled you should change rmsFactor with respect of line frequency. The integrator should be enabled only when using Rogowski coil, but your product comes with current transformers, so integrator bypassed should be the default setting.
Source: https://github.com/nDenerserve/SmartPi/b...ade7878.go
func ReadCurrent(d *i2c.Device, c *Config, phase Phase) (current float64) {
command := make([]byte, 2)
switch phase {
case PhaseA:
command = ADE7878REG["AIRMS"] // 0x43C0 (AIRMS; Current rms an A)
case PhaseB:
command = ADE7878REG["BIRMS"] // 0x43C2 (AIRMS; Current rms an B)
case PhaseC:
command = ADE7878REG["CIRMS"] // 0x43C4 (AIRMS; Current rms an C)
case PhaseN:
command = ADE7878REG["NIRMS"] // 0x43C6 (AIRMS; Current rms an N)
default:
panic(fmt.Errorf("Invalid phase %q", phase))
}
var rmsFactor float64
switch c.PowerFrequency {
case 60:
rmsFactor = 3493258.0 // 60Hz
case 50:
rmsFactor = 4191910.0 // 50Hz
default:
panic(fmt.Errorf("Invalid frequency %g", c.PowerFrequency))
}
if c.MeasureCurrent[phase] {
outcome := float64(DeviceFetchInt(d, 4, command))
cr := CTTypes[c.CTType[phase]].CurrentResistor
var ccf float64
if c.CTType[phase] == "YHDC_SCT013" {
ccf = CTTypes[c.CTType[phase]].CurrentClampFactor
} else {
ccf = 1.0 / (float64(c.CTTypePrimaryCurrent[phase]) / 100.0)
}
// fmt.Println("CalibrationfactorI: ", phase, " ", c.CalibrationfactorI[phase])
oc := CTTypes[c.CTType[phase]].OffsetCurrent
outcome = outcome - 7300
current = ((((outcome * 0.3535) / rmsFactor) / cr) / ccf) * 100.0 * oc * c.CalibrationfactorI[phase]
} else {
current = 0.0
}
return current
}