openenergymonitor / EmonLib

Electricity monitoring library - install in Arduino IDE's libraries folder then restart the IDE
openenergymonitor.org
GNU Affero General Public License v3.0
589 stars 419 forks source link

RW: Replaced the high-pass filter with a low-pass and subtract #14

Closed glynhudson closed 9 years ago

glynhudson commented 9 years ago

RW: low-pass filter to derive the offset and then subtract that from the input signal. Because the offset (hopefully) approximates to a steady direct voltage, initialising the filter is trivial.

I've replaced the high-pass filter with a low-pass and subtract, and I've tidied up the signed values that don't need to be signed (not that it matters - it still doesn't trigger a compiler warning if you get it wrong!). I've also replaced the mid-point + 50 and mid-point - 50 for deciding the zero-crossing point with ADC_COUNTS_0.55 and ADC_COUNTS_0.45 in order to maintain the proportion with a 12-bit ADC.

Test results: The measured values are reported correctly the first time calcVI or calcIrms is called. It is tolerant (showing no discernible effect) of changes in the offset voltage to well beyond the normal component tolerances. It however still takes many calls of the method for the filter to stabilise when the CT is unplugged and the input is grounded and then the plug is restored - this is expected and inevitable, and that's partly due to the fact that I've taken advantage of the preloaded value and reduced the filter's α so as to reduce the ripple, which should improve the small-signal performance.