Pulse Counter

Description

Counts rising edges on a digital input pin or the COMPA output

This resource uses the TDC prescaler as counter. The counter value is 16-bit.

The prescaler is independent of the TDC and can be used in parallel with other TDC usage (that does not utilize the prescaler).

The pulse counter can be used while the Sensor Controller is in standby mode, for example for a sensor that reports its value as a number of pulses. During such use, other Sensor Controller tasks must not use the Pulse Counter resource or the prescaler option in the TDC resource.

The following operations are possible:

  • Select input source and enable the pulse counter
  • Read the pulse counter
  • Reset and disable the pulse counter

Limitations

The input signal should be stable while calling pcntEnable() . Any rising edges that occur during this call may or may not be included in the reported pulse count.

The pulse counter can not measure less than 3 pulses. For 0, 1 or 2 pulses, the reported pulse count is 3.

Examples

Digital Input Pin Pulse Counting

// At this point the digital input pin should be static

// Enable pulse counter with digital input pin as source
pcntEnable(PCNT_INPUT_AUXIO_BASE + AUXIO_I_PULSE_CNT_INPUT);

// Generate a pulse train on AUXIO_O_PULSE_OUTPUT, which is looped back
// to AUXIO_I_PULSE_CNT_INPUT
gpioGenPulseTrain(AUXIO_O_PULSE_OUTPUT, 0, 24, 24, cfg.pulseCount);

// Get the number of pulses in the pulse train
pcntGetValue(output.measuredPulseCount);

// Disable the pulse counter
pcntDisable();

COMPA Output Pulse Counting

// Enable COMPA
compaSelectGpioInput(AUXIO_A_COMPA_INPUT);
compaSelectIntRef(COMPA_REF_DCOUPL);
compaEnable();

// At this point the COMPA output should be static

// Enable pulse counter with COMPA output as source
pcntEnable(PCNT_INPUT_COMPA);

// Generate a pulse train on AUXIO_O_PULSE_OUTPUT, which is looped back
// to AUXIO_A_COMPA_INPUT
gpioGenPulseTrain(AUXIO_O_PULSE_OUTPUT, 0, 24, 24, cfg.pulseCount);

// Read the pulse train counter
pcntGetValue(output.measuredPulseCount);

// Disable the pulse counter
pcntDisable();

// Disable COMPA
compaDisable();

Procedures Overview

Name Brief description
pcntDisable() Disables the pulse counter and resets the counter value. More …
pcntEnable() Selects input source and enables the pulse counter. More …
pcntGetValue() Returns the current pulse counter value. More …

Constants

Name Description
PCNT_INPUT_AUXIO_BASE Input source: AUXIO (base + index)
PCNT_INPUT_COMPA Input source: COMPA output

Global Variables

None.

Procedures

pcntDisable

Prototype: pcntDisable()

Disables the pulse counter and resets the counter value.

pcntEnable

Prototype: pcntEnable(input)

Selects input source and enables the pulse counter.

Parameter value(s)

  • input : Counter input source (PCNT_INPUT_XYZ)

pcntGetValue

Prototype: pcntGetValue(value)

Returns the current pulse counter value.

Return value(s)

  • value : The current pulse counter value