diff --git a/sonoff/xsns_01_counter.ino b/sonoff/xsns_01_counter.ino index d1cb5da5b..4ae01d4a0 100644 --- a/sonoff/xsns_01_counter.ino +++ b/sonoff/xsns_01_counter.ino @@ -21,13 +21,13 @@ * Counter sensors (water meters, electricity meters etc.) \*********************************************************************************************/ -unsigned long last_counter_timer[MAX_COUNTERS]; // Last counter time in milli seconds +unsigned long last_counter_timer[MAX_COUNTERS]; // Last counter time in micro seconds void CounterUpdate(byte index) { - unsigned long counter_debounce_time = millis() - last_counter_timer[index -1]; - if (counter_debounce_time > Settings.pulse_counter_debounce) { - last_counter_timer[index -1] = millis(); + unsigned long counter_debounce_time = micros() - last_counter_timer[index -1]; + if (counter_debounce_time > Settings.pulse_counter_debounce * 1000) { + last_counter_timer[index -1] = micros(); if (bitRead(Settings.pulse_counter_type, index -1)) { RtcSettings.pulse_counter[index -1] = counter_debounce_time; } else { @@ -98,7 +98,7 @@ void CounterShow(boolean json) for (byte i = 0; i < MAX_COUNTERS; i++) { if (pin[GPIO_CNTR1 +i] < 99) { if (bitRead(Settings.pulse_counter_type, i)) { - dtostrfd((double)RtcSettings.pulse_counter[i] / 1000, 3, counter); + dtostrfd((double)RtcSettings.pulse_counter[i] / 1000000, 6, counter); } else { dsxflg++; dtostrfd(RtcSettings.pulse_counter[i], 0, counter); @@ -124,6 +124,7 @@ void CounterShow(boolean json) #endif // USE_WEBSERVER } } + if(bitRead(Settings.pulse_counter_type, i)) RtcSettings.pulse_counter[i]=0xFFFFFFFF; // Set Timer to max in case of no more interrupts due to stall of measured device } if (json) { if (header) {