esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

[pulse_meter] fails reading higher frequencies #4479

Open pkejval opened 1 year ago

pkejval commented 1 year ago

The problem

I found out that pulse_meter is unable to read more than 120 Hz of pulses (7500 RPM). With increasing frequency it then shows only these values - 8600 RPM, 10 000 RPM and 20 000 RPM - completely off values. pulse_counter sensor is working fine even with much higher frequencies.

It can be easily tested with YAML posted here. Just connect GPIO2 with GPIO22. I made ledc output where you can set frequency at runtime. RPMs are limited in both cases if set to PULSE or EDGE mode.

Which version of ESPHome has the issue?

2023.4.2

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

No response

What platform are you using?

ESP32

Board

wemos_d1_mini32

Component causing the issue

pulse_meter

Example YAML snippet

number:
  - platform: template
    id: freq
    name: Frequency
    mode: BOX
    min_value: 0
    max_value: 10000
    initial_value: 100
    step: 1
    optimistic: true
    set_action:
      - lambda: 'id(pin_out).update_frequency(x);'

output:
  - platform: ledc
    pin: GPIO2
    id: pin_out

 sensor:
   - platform: pulse_meter
     id: RPM
     name: "Engine"
     pin: 
       number: GPIO22
       inverted: false
       mode:
         input: true
         pulldown: true
     unit_of_measurement: 'RPM'
     accuracy_decimals: 0
     timeout: 1.5s          
     filters:
       - lambda: 'return 100 * round(x / 100);'

Anything in the logs that might be useful for us?

Additional information

When I use pulse_counter I can measure RPM for hundreds, thousands of Hz without problem.


sensor:
  - platform: pulse_counter
    id: RPM
    name: "Engine"
    pin: 
      number: GPIO22
      inverted: false
      mode:
        input: true
        pulldown: true
    unit_of_measurement: 'RPM'
    accuracy_decimals: 0
    filters:
      - lambda: 'return 100 * round(x / 100);'
    update_interval: 500ms
github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

TrentHouliston commented 1 year ago

This might be better now that https://github.com/esphome/esphome/pull/4231 has merged. I had a similar problem with high pulse rates so I refactored the pulse_meter to handle them better