-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added pulse width accumulate #4622
Open
patrick-kiwi
wants to merge
7
commits into
esphome:current
Choose a base branch
from
patrick-kiwi:pw-accumulate
base: current
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
931bf87
added pulse width accumulate
patrick-kiwi 575c5a0
smaller pic
patrick-kiwi a8faba2
changed text to reflect impoved accuracy from modified source code
patrick-kiwi 2923c75
added experimental detail
patrick-kiwi ad723bc
improvements
patrick-kiwi 0cc107c
implement suggested changes
patrick-kiwi ece4fb5
minor fix
patrick-kiwi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
Pulse Width Sensor | ||
================== | ||
|
||
.. seo:: | ||
:description: Instructions for setting up pulse width accumulation sensors | ||
in ESPHome to measure total on-time of GPIO inputs for MOSFETs and TRIACs | ||
|
||
|
||
The ``pulse_width_accumulate`` sensor allows you to sum the total on-time of | ||
a GPIO input. For example, this can be used to externally measure the on-time | ||
of a rapidly switched MOSFET or TRIAC. The sensor zeros itself every polling | ||
interval. Units of measurement are on-time seconds per update interval. | ||
An optional frequency sensor is also provided. | ||
|
||
.. Note:: | ||
|
||
Threshold stability values were experimentally determined for an ESP32 DevKit-v4: | ||
- Minimum pulse width: ≥ 25 µs | ||
- Minimum pulse width delay: ≥ 75 µs | ||
- Maximum implied frequency: ~10 kHz | ||
- Maximum polling window: 71.58 minutes (see text below) | ||
|
||
.. code-block:: yaml | ||
|
||
# Example configuration entry | ||
sensor: | ||
- platform: pulse_width_accumulate | ||
pin: GPIO32 | ||
name: Cumulative on-time sensor | ||
frequency: | ||
name: Average frequency sensor | ||
|
||
|
||
.. note:: | ||
|
||
Important implementation details: | ||
|
||
1. The polling function resets the microsecond counter to prevent overflow at 71.58 minutes | ||
2. Sensor accuracy is a function of the input signal frequency: | ||
- Test Condition #1 (25 µs pulses, 75 µs delay, 1 sec polling, 27380 samples): | ||
* Frequency. Expected 10 kHz. Observed mean 9980.5 Hz. Standard deviation=5.5 Hz | ||
* On-time. Expected based on time stamps 6846.75 s. Observed 6844.33 s | ||
- Test Condition #2 (300 µs pulses, 300 µs delay, 1 min polling, 289 samples): | ||
* Frequency, expected 1666.67 Hz, Observed mean 1666.57 Hz, standard deviation=0.08 Hz | ||
* On-time. Expected based on time stamps 8640 s. Observed 8639.98 s | ||
|
||
|
||
Configuration variables: | ||
------------------------ | ||
|
||
- **pin** (*Optional*, :ref:`Pin Schema <config-pin_schema>`): The pin to observe for the | ||
pulse width. | ||
- **update_interval** (*Optional*, :ref:`config-time`): The interval to check the sensor. | ||
Defaults to ``60s``. | ||
|
||
- **id** (*Optional*, :ref:`config-id`): Set the ID of this sensor for use in lambdas. | ||
- All other options from :ref:`Sensor <config-sensor>`. | ||
|
||
See Also | ||
-------- | ||
|
||
- :ref:`sensor-filters` | ||
- :apiref:`pulse_width_accumulate/pulse_width_accumulate.h` | ||
- :apiref:`pulse_width/pulse_width.h` | ||
- :apiref:`pulse_meter/pulse_meter_sensor.h` | ||
- :ghedit:`Edit` | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix note directive indentation.
The note directive must be indented with 4 spaces, not 2, to comply with RST formatting requirements.
📝 Committable suggestion
🧰 Tools
🪛 GitHub Check: build
[failure] 36-36:
Directive 'note' must be indented with 4 spaces, not 2. See components/sensor/pulse_width_accumulate.rst:36
🪛 GitHub Actions: Lint
[error] 36-36: Directive 'note' must be indented with 4 spaces, not 2