This is the multi-page printable view of this section. Click here to print...

Return to the regular view of this page

As of 2025-07-24

PulseCounter

Pulse Counter (mwx::periph_pulse_counter)
    The pulse counter is a circuit that counts pulses even when the microcontroller’s CPU is not operating.

    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.

    SettingConsecutive SamplesMax Detection Frequency
    0-100kHz
    123.7kHz
    242.2kHz
    381.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.