RTC Multi-Event Capture

Description

RTC capture of every N’th rising edge on a GPIO pin

This resource uses AUX Timer 1 to count rising edges on a single GPIO pin. For every N’th rising edge, a capture is triggered in RTC channel 1. The task code gets an indicator when the capture occurs, so that data matching the RTC timestamp can be tagged and matched when processed by the System CPU.

This can be used to timestamp interrupts from an external circuit that are generated at a fixed, but imprecise rate, for example an accelerometer running off an uncalibrated RC oscillator. By only capturing every N’th interrupt, individual timestamps can be approximated by the System CPU, avoiding frequent wake-ups and need to store timestamps in the AUX RAM.

When enabling this resource, RTC channel 1 will be configured automatically for AUX Timer 1 event capture. The Sensor Controller task code should tag the output data (for example by setting a single bit) so that RTC captures can be correlated with the interrupts/data from the sensor. This is done in the example below.

Note the following:

  • Only one resource per project can use AUX Timer 1.
  • Enabling this resource will cause the AUX domain to run at 32 kHz (instead of having no clock) when the Sensor Controller and System CPU are in standby mode. Since the AUX domain needs to run at 24 MHz while the System CPU is active, the switch increases the time for exit from and reentry into standby mode.

Examples

Initialization Code

// Capture interrupt pin rising edge, starting with an RTC capture on the first interrupt
rtcmecInit(AUXIO_I_INT);

Execution Code

// If a capture occurred in the last iteration of the Execution code ...
if (state.captEv != 0) {

    // Clear the stretched AUX Timer 1 event going to the RTC
    rtcmecClearCaptEv();
    state.captEv = 0;

    ... Hand off tagged sensor data from the last iteration ...
}

// If an interrupt is pending ...
U16 irqPending;
gpioGetInputValue(AUXIO_I_INT; irqPending);
if (irqPending != 0) {

    ... Handle the interrupt ...

    // Set the number of interrupts per RTC capture now that the first capture is done
    rtcmecSetPeriod(10);

    // Record whether an RTC capture took place now. The AUX Timer 1 event to the RTC must be
    // held active for at least one 32 kHz clock period, so clearing is postponed until the
    // next iteration of the Execution Code.
    U16 captEv;
    rtcmecCheckCaptEv(captEv);
    if (captEv != 0) {
        ... Tag the sensor data from this interrupt, delaying the data hand-off until the RTC capture has occurred ...
    } else {
        ... Hand off untagged sensor data right away ...
    }
    state.captEv = captEv;
}

Procedures Overview

Name Brief description
rtcmecCheckCaptEv() Checks whether the latest GPIO event triggers an RTC capture. More …
rtcmecClearCaptEv() Clears the capture event going from AUX Timer 1 to RTC channel 1. More …
rtcmecInit() Initializes RTC multi-event capture, where AUX Timer 1 counts rising edges on a GPIO input. More …
rtcmecSetPeriod() Sets the number of GPIO events per RTC time capture. More …

Constants

None.

Global Variables

None.

Procedures

rtcmecCheckCaptEv

Prototype: rtcmecCheckCaptEv(status)

Checks whether the latest GPIO event triggers an RTC capture. If it does, rtcmecClearCaptEv() must be called after 32 us. The delay allows the AUX Timer 1 event signal to propagate to the RTC for capture.

Return value(s)

  • status : Indicates whether capture is triggered by the latest GPIO event (1) or not (0)

rtcmecClearCaptEv

Prototype: rtcmecClearCaptEv()

Clears the capture event going from AUX Timer 1 to RTC channel 1. The event signal must be held active for at least 32 us to allow it to propagate.

rtcmecInit

Prototype: rtcmecInit(#auxio)

Initializes RTC multi-event capture, where AUX Timer 1 counts rising edges on a GPIO input. The first RTC capture occurs on the first rising edge of the GPIO. When this capture occurs, rtcmecSetPeriod() must be called to switch to the desired interval.

Parameter value(s)

  • #auxio : AUX I/O index

rtcmecSetPeriod

Prototype: rtcmecSetPeriod(period)

Sets the number of GPIO events per RTC time capture.

Parameter value(s)

  • period : Number of events per capture (2-65535)