There are two pulse counter systems. PC0 is assigned to PulseCounter0
, and PC1 is assigned to PulseCounter1
. The alias PulseCounter
refers to PulseCounter1
.
Methods
begin()
void begin(uint16_t refct = 0,
E_PIN_INT_MODE edge = PIN_INT_MODE::FALLING,
uint8_t debounce = 0)
Initializes the object and starts counting. The first parameter, refct
, is the reference count used to determine whether an interrupt or availability condition is met. When the count exceeds this number, it is reported to the application. A value of 0 may also be specified, in which case it will not trigger a wake-up from sleep.
The second parameter, edge
, specifies whether the interrupt is on the rising (PIN_INT_MODE::RISING
) or falling (PIN_INT_MODE::FALLING
) edge.
The third parameter, debounce
, accepts values 0, 1, 2, or 3. Settings 1 through 3 reduce the effect of noise by requiring consecutive identical values for detection.
Setting | Consecutive Samples | Max Detection Frequency |
---|---|---|
0 | - | 100kHz |
1 | 2 | 3.7kHz |
2 | 4 | 2.2kHz |
3 | 8 | 1.2kHz |
end()
void end()
Stops pulse detection.
available()
inline bool available()
If the specified count (refct
in begin()
) is 0, returns true
when the count is 1 or more.
If the specified count (refct
in begin()
) is 1 or more, returns true
when the count exceeds the specified threshold.
read()
uint16_t read()
Reads the count value. The value is reset to 0 after reading.