|
muwerk mupplet Core Library
muwerk applets; mupplets: functional units that support specific hardware or reusable applications
|
#include <mup_frequency_counter.h>
Public Types | |
| enum | InterruptMode { IM_RISING , IM_FALLING , IM_CHANGE } |
| enum | MeasureMode { LOWFREQUENCY_FAST , LOWFREQUENCY_MEDIUM , LOWFREQUENCY_LONGTERM , HIGHFREQUENCY_FAST , HIGHFREQUENCY_MEDIUM , HIGHFREQUENCY_LONGTERM } |
Public Member Functions | |
| FrequencyCounter (String name, uint8_t pin_input, int8_t interruptIndex_input, MeasureMode measureMode=HIGHFREQUENCY_MEDIUM, InterruptMode irqMode=InterruptMode::IM_FALLING) | |
| void | setMeasureMode (MeasureMode mode, bool silent=false) |
| bool | begin (Scheduler *_pSched, uint32_t scheduleUs=2000000L) |
Interrupt driven frequency counter.
On an ESP32, measurement of frequencies at a GPIO are possible in ranges of 0-250kHz. There are six measurement modes: LOWFREQUENCY_FAST (good for measurements <50Hz, not much filtering) LOWFREQUENCY_MEDIUM (good for sub-Hertz enabled measurements, e.g. Geiger-counters) LOWFREQUENCY_LONGTERM (good for <50Hz, little deviation, high precision)
The HIGHFREQUENCY modes automatically reset the filter, if the input signal drops to 0Hz. HIGHFREQUENCY_FAST (no filtering) HIGHFREQUENCY_MEDIUM (some filtering) HIGHFREQUENCY_LONGTERM (strong filtering, good for precision measurement of signals with little deviation)
Precision <80kHz is better than 0.0005%. Interrupt load > 80kHz impacts the performance of the ESP32 severely and error goes up to 2-5%.
| topic | message body | comment |
|---|---|---|
<mupplet-name>/sensor/frequency | 53.001 | Frequency in Hz encoded as String |
<mupplet-name>/sensor/mode | [LOW,HIGH]FREQUENCY_[FAST,MEDIUM,LONGTERM] | Sample mode, e.g. LOWFREQUENCY_MEDIUM as string |
| topic | message body | comment |
|---|---|---|
<mupplet-name>/mode/set | [LOW,HIGH]FREQUENCY_[FAST,MEDIUM,LONGTERM] | Set the sample mode, e.g. LOWFREQUENCY_FAST, string encoded |
<mupplet-name>/state/get | Causes current frequency to be sent with topic <mupplet-name>/sensor/frequency | |
<mupplet-name>/frequency/get | Causes current frequency to be sent with topic <mupplet-name>/sensor/frequency | |
<mupplet-name>/mode/get | Causes current sample mode to be sent with topic <mupplet-name>/sensor/mode |
Sampling mode
|
inline |
Create a frequency counter
| name | Name of mupplet, used in message topics |
| pin_input | GPIO of input signal |
| interruptIndex_input | a system wide unique index for the interrupt to be used [0...9] |
| measureMode | MeasureMode, e.g. LOWFREQUENCY_MEDIUM. |
| irqMode | InterruptMode, e.g. IM_RISING. |
|
inline |
Enable interrupts and start counter
| _pSched | Pointer to scheduler |
| scheduleUs | Measurement schedule in microseconds |
|
inline |
Change sample mode
| mode | MeasureMode, e.g. LOWFREQUENCY_MEDIUM. |
| silent | on true, no message is sent. |