EmonLib version 1a654efaca was BROKEN

A very recent change to emonLib has resulted in totally erroneous values being produced. The version affected is 1a654efaca. To correct the error, remove these lines (round about line 86) from emonlib.cpp, save the file and restart the Arduino IDE:

// Initialise filter values (otherwise these will be random at power-on) https://github.com/openenergymonitor/EmonLib/issues/4 filteredV = sampleV = analogRead(inPinV); filteredI = sampleI = analogRead(inPinI);

By way of illustration, here is an emonTx V3.4 running with and without the problematical lines: With the "initialise filter values": Node: 10 Freq: 433Mhz Network: 210 13936 31168 13929 31189 13943 31146 13925 31120 14554 31733 14583 31756 14538 31723 (The first column is power, but the CT was not on a cable, the second column is Voltage in hundredths, and my supply is 240 V.) And here is the same without those lines in the library: Node: 10 Freq: 433Mhz Network: 210 7 23878 3 23928 5 23932 6 23945 4 23931 2 23928 3 23979 showing the correct power and voltage. (problem found by IngmarVerheij - http://openenergymonitor.org/emon/node/6387)

Paul Reed's picture

Re: EmonLib version 1a654efaca was BROKEN

For info Robert, I've created a 'git' pull request to revert the changes as per your post above, until a better fix is available for the other issue.

It's important that both issues are fixed eventually, but I think that these current errors outweigh the preceding problem.  

Paul

 

Robert Wall's picture

Re: EmonLib version 1a654efaca was BROKEN

I'm working on it. There's a fix in the sample sketches that's been working well for a long time: exercise the filters for about two hundred or so iterations during startup - throw the result away (but leave the "last" values in the filters).
But it was a bit naughty of Jack to submit an untested change, don't you think?

Paul Reed's picture

Re: EmonLib version 1a654efaca was BROKEN

But it was a bit naughty of Jack to submit an untested change, don't you think?

It was probably done in good faith, and unless the author is a seasoned programmer, it's very easy to cure one problem whilst creating another. I blame Glyn - he authorized it!

Paul

calypso_rae's picture

Re: EmonLib version 1a654efaca was BROKEN

I'm pleased to report that none of my sketches uses emonLib (other than RawSamplesTool.ino which has been replaced by the improved version, RawSamplesTool_4ss_2.ino, both on my Summary Page )

Happy New Year to all!

Robert Wall's picture

Re: EmonLib version 1a654efaca was BROKEN

As of 1300 UTC on 1 Jan 2015, Glyn advises that the earlier EmonLib (SHA: a3272aeb5e86ede0e9a1e41ba573d9d572fb2412) has been restored.

Robert Wall's picture

Re: EmonLib version 1a654efaca was BROKEN

The new library is available for testing at https://github.com/openenergymonitor/EmonLib/tree/Dev.

You should carefully test and verify the data produced before relying on the readings from any sketch that uses this library.

Using the library: Replace your existing EmonLib directory with this one. No changes to any sketch are necessary, however the section in some of the example sketches near the end of the setup( ) method, following the comment "Do some measurements to allow the software filter to settle - don't use the result" that calls calcVI( ) or calcIrms( ) a number of times is redundant, and can be removed with no ill effect. If these statements are not removed, the only difference that is the setup( ) method takes a little longer to complete.

Robert Wall's picture

Re: EmonLib version 1a654efaca was BROKEN

The change has now been incorporated into the main download of emonLib.

The change concerns how the d.c. offset of ½VCC, introduced by the hardware, is removed. In the original version of emonLib, this was done with a high pass filter that removed the offset directly by the action of the filter. At start-up, it took a few hundred iterations of the filter for the offset to be removed sufficiently for the output to settle, giving erroneous values until that happened.

The change has been to replace the high pass filter with a low pass filter, whose output is the d.c level introduced by the hardware. Given the correct resistor values, the value of this will be ½VCC, or 511, to within around 1% and the filter can be pre-loaded with this number at start-up, thus effectively removing - or at least dramatically reducing - the time taken to reach the final value. The offset can then be removed from the input signal by a simple subtraction. The principal benefit of the rapid start-up is that the output is available for use immediately, with little or no error. A side effect is the filter time constant can be increased significantly, thereby improving the performance of the filter.

As noted above, no change to the sketch is necessary, but a little time will be saved at start-up if the change described in the post immediately above this is implemented.

glyn.hudson's picture

Re: EmonLib version 1a654efaca was BROKEN

Can this thread by renamed now and unstickyed, since emonHub is now 'fixed'! Thanks for your help. 

Robert Wall's picture

Re: EmonLib version 1a654efaca was BROKEN

It's now past tense! - but how has it only just popped up in "Active Forum Topics"?

glyn.hudson's picture

Re: EmonLib version 1a654efaca was BROKEN

It was me, I edited it to make it 'un-sticky' as the problem has now been fixed. This has the side effect of brining it back to the top of the forum, however it will now gracefully descent hopefully to never be seen again! 

ukmoose's picture

Re: EmonLib version 1a654efaca was BROKEN

Yep, as does commenting on it.

Robert Wall's picture

Re: EmonLib version 1a654efaca was BROKEN

Yes, but it took from Saturday until Tuesday before it popped up!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.