diff --git a/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp b/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp index 0e7ff85d99..1d07385ac3 100644 --- a/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp +++ b/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp @@ -65,6 +65,7 @@ bool UlpPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) { * Note that the ULP reads only the lower 16 bits of these variables. */ ulp_edge_count = 0; + ulp_run_count = 0; ulp_debounce_counter = 3; ulp_debounce_max_count = 3; ulp_next_edge = 0; diff --git a/esphome/components/pulse_counter_ulp/ulp/pulse_cnt.S b/esphome/components/pulse_counter_ulp/ulp/pulse_cnt.S index b6625a8db4..578d77d314 100644 --- a/esphome/components/pulse_counter_ulp/ulp/pulse_cnt.S +++ b/esphome/components/pulse_counter_ulp/ulp/pulse_cnt.S @@ -55,6 +55,11 @@ debounce_max_count: edge_count: .long 0 + /* Number of times program run since last read */ + .global run_count +run_count: + .long 0 + /* Total number of signal edges acquired */ .global edge_count_total edge_count_total: @@ -70,6 +75,12 @@ io_number: .text .global entry entry: + /* Increment run_count */ + move r3, run_count + ld r2, r3, 0 + add r2, r2, 1 + st r2, r3, 0 + /* Load io_number */ move r3, io_number ld r3, r3, 0