Hlw8012/Bl0937 averages pulses over 200ms (#1)

* Hlw8012/Bl0937 averages pulses over 200ms

* Hlw8012/Bl0937 averages pulses over 200ms
This commit is contained in:
Alex 2021-04-14 09:57:23 +01:00 committed by GitHub
parent 2f5c20a42f
commit cfebce9b09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -47,7 +47,9 @@ struct HLW {
uint32_t debug[HLW_SAMPLE_COUNT]; uint32_t debug[HLW_SAMPLE_COUNT];
#endif #endif
volatile uint32_t cf_pulse_length = 0; volatile uint32_t cf_pulse_length = 0;
volatile uint32_t cf_summed_pulse_length = 0;
volatile uint32_t cf_pulse_last_time = 0; volatile uint32_t cf_pulse_last_time = 0;
volatile uint32_t cf_pulse_counter = 0;
uint32_t cf_power_pulse_length = 0; uint32_t cf_power_pulse_length = 0;
volatile uint32_t cf1_pulse_length = 0; volatile uint32_t cf1_pulse_length = 0;
@ -86,7 +88,9 @@ void HlwCfInterrupt(void) // Service Power
Hlw.load_off = false; Hlw.load_off = false;
} else { } else {
Hlw.cf_pulse_length = us - Hlw.cf_pulse_last_time; Hlw.cf_pulse_length = us - Hlw.cf_pulse_last_time;
Hlw.cf_summed_pulse_length += Hlw.cf_pulse_length;
Hlw.cf_pulse_last_time = us; Hlw.cf_pulse_last_time = us;
Hlw.cf_pulse_counter++;
Hlw.energy_period_counter++; Hlw.energy_period_counter++;
} }
Energy.data_valid[0] = 0; Energy.data_valid[0] = 0;
@ -124,7 +128,14 @@ void HlwEvery200ms(void)
Hlw.cf_pulse_length = 0; // No load for some time Hlw.cf_pulse_length = 0; // No load for some time
Hlw.load_off = true; Hlw.load_off = true;
} }
Hlw.cf_power_pulse_length = Hlw.cf_pulse_length;
if(Hlw.cf_pulse_counter){
Hlw.cf_power_pulse_length = Hlw.cf_summed_pulse_length/Hlw.cf_pulse_counter;
Hlw.cf_summed_pulse_length=0;
Hlw.cf_pulse_counter=0;
} else {
Hlw.cf_power_pulse_length=0;
}
if (Hlw.cf_power_pulse_length && Energy.power_on && !Hlw.load_off) { 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 ; // W *10 hlw_w = (Hlw.power_ratio * Settings.energy_power_calibration) / Hlw.cf_power_pulse_length ; // W *10