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.

Reading the Pulse Counter

For CC13x0/CC26x0 devices, the pulse counter value must only be read while the input source is static. Otherwise a random value might be returned.

Do the following to force the input source low:

  • For a digital input pin: Call gpioDisableInputBuf() before reading the pulse counter value.
  • For COMPA output: Call compaDisable() before reading the pulse counter value.

If you need to read the pulse count during a measurement, do not force the input source low and then reenable it, as this causes an extra pulse if done while the input source is high.

Instead, if the input source is a slow signal, it is possible to read the pulse count twice until both the read values are identical. See the example below for details, and how to determine the maximum pulse frequency.

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);

// If the digital input pin could be unstable at this point, the input buffer must
// be disabled before we call pcntGetValue()
gpioDisableInputBuf(AUXIO_I_PULSE_CNT_INPUT);

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

// Reenable the input buffer
gpioEnableInputBuf(AUXIO_I_PULSE_CNT_INPUT);

// 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);

// If the COMPA output could be unstable at this point, COMPA must be disabled
// before we call pcntGetValue()
compaDisable();

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

// Disable the pulse counter
pcntDisable();

Reading Pulse Count during Measurement (Slow Input Signal Only!)

// Read the pulse count twice until both the read values are equal.
// IMPORTANT: The pulse interval must be longer than one iteration of this
// loop. The following code has 12 instructions per loop iteration, so in
// this case the pulse interval must be greater than 1 microsecond.
U16 a;
U16 b;
do {
    pcntGetValue(a);
    pcntGetValue(b);
} while (a != b);
output.measuredPulseCount = a;

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.

This procedure must only be called when the pulse counter input source is static.

Return value(s)

  • value : The current pulse counter value