-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Random readings when no load\relay off #11
Comments
Same problem for me. |
Same problem here |
I just did some tests with readings of power as fast as possible. To do this I set a boolean in the ISR and every time this is triggered (as this is an edge on the CF line) I print out the power. |
I also noticed these spurious readings with the HLW8012 but couldn't remove them. My approach in ESPurna is the same as yours, @erniberni. I'm not reading so often but I apply a median filter every 3 readings. |
Do you have some example code of your method @erniberni ? |
@chinswain
In the main loop, every time when trigd is set I check the power. When the measured power is within a limit bigger or smaller (half or doubled) then the previous value then I trust this value, if not, the value will be ignored. The first trigd set must be ignored. Here is a part of my test sketch.
The debug messages are printed on a tcp client. |
Did you try using my code above? |
I am going to implemented your idea as part of the library, test it and share the results. |
It seems that the new filter performs good compared to the original libray code. In the image, to the left it was the original library code, to the right it is the new filter functionality: I also checked the CF signal with an oscilloscope and there were not signal spikes or noise (while there is no load connected), but the software reported this strange and random values. Perhaps the noise it is related to the manufacturer PCB design. In my case, everthing has been tested on a Delock 11827 smart plug metter. The filter functionalities are implemented in the ISR for the CF line, therefore this will work only using interrupts. void ICACHE_RAM_ATTR HLW8012::cf_interrupt() {
unsigned long now = micros();
_power_pulse_width = now - _last_cf_interrupt;
_last_cf_interrupt = now;
// Check if timeout event ocurred
if (_power_pulse_width > _pulse_timeout){
_notimeout_cf_cntr = 0;
_timeout_interrupt = now;
_power_pulse_width = 0;
_power = 0;
}
// Ignore any values during the PULSE_TIMEOUT microsec after first timeout event
if( (now - _timeout_interrupt) < PULSE_TIMEOUT ){
_power_pulse_width = 0;
_power = 0;
}else{
// Wait for valid measurements, meantime ignore measurements
if(_notimeout_cf_cntr <= TIMEOUT_VALID_PULSES){
_notimeout_cf_cntr++;
_power_pulse_width = 0;
_power = 0;
}
}
// Increment energy values only on valid signal
if (_notimeout_cf_cntr >= TIMEOUT_VALID_PULSES)
_pulse_count++;
} The full source code can be find on the following fork repository https://github.com/javier-fg/hlw8012 If someone could also test it on their hardware, I could request a push to the original repository. |
I've just uploaded the interrupts example to a Sonoff POW, once or twice a minute I get random readings - is that to be expected? (I want to use the POW to determine if a device is switched on and for how long so was triggering on if current > x).
Most of the time with no load:
Randomly with relay off:
1 Hour history:
The text was updated successfully, but these errors were encountered: