Skip to content

Commit

Permalink
6.4.1.7 Fix regression energy sensors
Browse files Browse the repository at this point in the history
6.4.1.7 20190106
 * Fix HLW8012, HJL01 and BL0937 based energy sensors low Power (below 10W) measurement regression from 6.4.1.6
  • Loading branch information
arendst committed Jan 6, 2019
1 parent de996cb commit cb8963a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
5 changes: 4 additions & 1 deletion sonoff/_changelog.ino
@@ -1,4 +1,7 @@
/* 6.4.1.6 20190105
/* 6.4.1.7 20190106
* Fix HLW8012, HJL01 and BL0937 based energy sensors low Power (below 10W) measurement regression from 6.4.1.6
*
* 6.4.1.6 20190105
* Add commands PowerCal, VoltageCal and CurrentCal for HLW8012, HJL01 and BL0937 based energy sensors
*
* 6.4.1.5 20190103
Expand Down
2 changes: 1 addition & 1 deletion sonoff/sonoff_version.h
Expand Up @@ -20,7 +20,7 @@
#ifndef _SONOFF_VERSION_H_
#define _SONOFF_VERSION_H_

#define VERSION 0x06040106
#define VERSION 0x06040107

#define D_PROGRAMNAME "Sonoff-Tasmota"
#define D_AUTHOR "Theo Arends"
Expand Down
16 changes: 5 additions & 11 deletions sonoff/xnrg_01_hlw8012.ino
Expand Up @@ -47,8 +47,6 @@ byte hlw_load_off;
byte hlw_cf1_timer;
unsigned long hlw_cf_pulse_length;
unsigned long hlw_cf_pulse_last_time;
unsigned long hlw_cf_summed_pulse_length;
unsigned long hlw_cf_pulse_counter;
unsigned long hlw_cf_power_pulse_length;

unsigned long hlw_cf1_pulse_length;
Expand Down Expand Up @@ -84,10 +82,6 @@ void HlwCfInterrupt(void) // Service Power
} else {
hlw_cf_pulse_length = us - hlw_cf_pulse_last_time;
hlw_cf_pulse_last_time = us;

hlw_cf_summed_pulse_length += hlw_cf_pulse_length;
hlw_cf_pulse_counter++;

hlw_energy_period_counter++;
}
}
Expand Down Expand Up @@ -119,20 +113,19 @@ void HlwEvery200ms(void)
unsigned long hlw_u = 0;
unsigned long hlw_i = 0;


if (micros() - hlw_cf_pulse_last_time > (HLW_POWER_PROBE_TIME * 1000000)) {
hlw_cf_pulse_counter = 0; // No load for some time
hlw_cf_pulse_length = 0; // No load for some time
hlw_load_off = 1;
}
hlw_cf_power_pulse_length = hlw_cf_pulse_length;

if (hlw_cf_pulse_counter && energy_power_on && !hlw_load_off) {
hlw_cf_power_pulse_length = hlw_cf_summed_pulse_length / hlw_cf_pulse_counter;
if (hlw_cf_power_pulse_length && energy_power_on && !hlw_load_off) {
hlw_w = (hlw_power_ratio * Settings.energy_power_calibration) / hlw_cf_power_pulse_length;
energy_active_power = (float)hlw_w / 10;
} else {
energy_active_power = 0;
}
hlw_cf_summed_pulse_length = 0;
hlw_cf_pulse_counter = 0;

hlw_cf1_timer++;
if (hlw_cf1_timer >= 8) {
Expand Down Expand Up @@ -224,6 +217,7 @@ void HlwSnsInit(void)
hlw_current_ratio = HLW_IREF;
}

hlw_cf_pulse_length = 0;
hlw_cf_pulse_last_time = 0;
hlw_cf_power_pulse_length = 0;
hlw_cf1_pulse_length = 0;
Expand Down

0 comments on commit cb8963a

Please sign in to comment.