Timer 2 Event Trigger

Description

Use Timer 2 to trigger Event Handler Code

This resource uses an AUX Timer 2 event output to trigger an Event Handler Code task code block.

This can typically be used to:

  • Sequence startup of external circuitry, followed by Sensor Controller wake-up and sensor polling.
  • Run a Sensor Controller task at irregular intervals, without unnecessary wake-ups from the RTC.
  • Follow up on actions performed by the Execution Code , for reading results from and powering down an external sensor device after a period of time.

The Timer 2 peripheral must be enabled separately using the Timer 2 resource.

The trigger can be set up from within the Initialization Code , Execution Code or Event Handler Code task code blocks.

The trigger is one-shot.

Event Trigger Mapping

The CC13x2/CC26x2 and CC13x4/CC26x4 chip families support up to 3 event triggers in total per project. The Code Generator Panel displays an error message if this number is exceeded.

Access the Task Panel to map event trigger(s) to Event Handler Code task code blocks:

  • Ensure that one or more event trigger resources are enabled
  • Below these resources, select the number of simultaneous event triggers for the task
  • Map the event index(es) to Event Handler Code task code blocks. The event indexes start at 0 for each task.

While the number of event triggers and mapping of event indexes to task code blocks are static, the event indexes can be reused for different types of event triggers. For example, it is possible to alternate between a timer trigger and a GPIO trigger for one event index.

If a new event trigger is set up using an already active event index, the previously set up event trigger is cancelled.

The Termination Code must call evhCancelTrigger() for each used event index, so that the last set up event triggers do not occur after the task has been stopped.

Trigger Timing

Typical startup delays, from the Timer 2 event trigger to execution of the Event Handler Code task code block, are shown in the tables below.

For startup to low-power mode:

Scenario No clock in standby mode SCLK_LF in standby mode*
From standby mode, SCLK_MF clock not running 32 us 47 - 77 us
From standby mode, SCLK_MF clock already running 30 us 45 - 75 us
Trigger occurs while Sensor Controller runs other code 24 us or more (already running code must finish)

For startup to active mode:

Scenario No clock in standby mode SCLK_LF in standby mode*
From standby mode, SCLK_HF clock not running 145 - 200 us 145 - 215 us
From standby mode, SCLK_HF clock already running 7 us 24 - 54 us
Trigger occurs while Sensor Controller runs other code 4 us or more (already running code must finish)

* SCLK_LF is used in standby mode when one or more of these resources are enabled:

  • Reference DAC
  • RTC Multi-Event Capture
  • Timer 0 Event Trigger
  • Timer 1 Event Trigger

Examples

Power-Up Sequencing Using Timer 2 (Initialization Code)

// Select SCLK_HFDIV2 temporarily as clock source to speed up Timer 2 register
// configuration. All register accesses occur at the selected clock rate.
timer2SetClockSource(TIMER2_CLOCKSRC_HFDIV2);
timer2WaitForClockSource();

// Configure the Timer 2 channel that powers up the sensor.
// 32 LF periods = ~1 ms from now
timer2CfgCcChannel(0, TIMER2_CCMODE_SET_ON_CMP, 1 << TIMER2_EV_ID0);
timer2ConnectEventToGpio(TIMER2_EV_ID0, AUXIO_O_ALS_POWER);
timer2SetInitCmpValue(0, 32);

// Configure the Timer 2 channel that wakes up the Sensor Controller.
// +32 LF periods = ~1 ms after sensor power-up
timer2CfgCcChannel(1, TIMER2_CCMODE_PULSE_ON_CMP, 1 << TIMER2_EV_ID1);
timer2SetInitCmpValue(1, 32 + 32);

// Perform measurement at ~10 Hz
timer2SetInitCounterTarget(32768 / 10);

// Switch Timer 2 to LF clock and start it
timer2SetClockSource(TIMER2_CLOCKSRC_LF);
timer2WaitForClockSource();
timer2StartWithTarget(TIMER2_CNTRMODE_UP_REP);

// Setup the first wake-up trigger
evhSetupTimer2Trigger(0, TIMER2_EV_ID1, 1, EVH_TIMER2_TRIG_ON_EDGE);

Power-Up Sequencing Using Timer 2 (Event Handler Code)

... Sample the sensor ...

// Power down the sensor
timer2ClearEvent(TIMER2_EV_ID0);

... Process the sensor value ...

// Setup the next wake-up trigger
evhSetupTimer2Trigger(0, TIMER2_EV_ID1, 1, EVH_TIMER2_TRIG_ON_EDGE);

Power-Up Sequencing Using Timer 2 (Termination Code)

// Cancel the Timer 2 event trigger
evhCancelTrigger(0);

// Stop Timer 2, and reset all used functionality
timer2Stop();
timer2ResetCcChannel(0);
timer2ResetCcChannel(1);
timer2ClearEvent(0);
timer2ClearEvent(1);
timer2SetClockSource(TIMER2_CLOCKSRC_NONE);
timer2WaitForClockSource();

Procedures Overview

Name Brief description
evhCancelTrigger() Cancels a previous call to an event trigger setup procedure (for example evhSetupGpioTrigger() ) with matching event index, including any pending Event Handler Code execution if the trigger already has occurred. More …
evhGetActiveTrigger() This procedure can be called from event handler code to determine which event index triggered the event handler code. More …
evhSetupTimer2Trigger() Sets up an AUX Timer 2 capture/compare channel to trigger execution of an Event Handler Code task code block. More …

Constants

Name Description
EVH_TIMER2_TRIG_ON_EDGE Timer 2 event trigger type: Generated on transition, edge from inverse level is required
EVH_TIMER2_TRIG_ON_MATCH Timer 2 event trigger type: Generated on match, edge from inverse level is not required

Global Variables

None.

Procedures

evhCancelTrigger

Prototype: evhCancelTrigger(#evIndex)

Cancels a previous call to an event trigger setup procedure (for example evhSetupGpioTrigger() ) with matching event index, including any pending Event Handler Code execution if the trigger already has occurred.

This procedure should be called from the Termination Code if the task can be stopped by the application while an event trigger is enabled.

Parameter value(s)

  • #evIndex : Event index to be cancelled

evhGetActiveTrigger

Prototype: evhGetActiveTrigger(bvEvent)

This procedure can be called from event handler code to determine which event index triggered the event handler code.

Return value(s)

  • bvEvent : Bit-vector indicating the event index that triggered the event handler code

evhSetupTimer2Trigger

Prototype: evhSetupTimer2Trigger(#evIndex, #timer2EvId, #level, #type)

Sets up an AUX Timer 2 capture/compare channel to trigger execution of an Event Handler Code task code block.

The timer must be started separately, and may run continuously in the background.

The trigger occurs as soon as the specified event output matches or transitions to the specified level. The specified Event Handler Code then starts when the Sensor Controller is idle or in standby.

Parameter value(s)

  • #evIndex : Event index to be triggered
  • #timer2EvId : Timer 2 event signal output (0-3)
  • #level : The event signal level that shall generate the trigger (1 = high, 0 = low)
  • #type : Timer 2 event trigger type (EVH_TIMER2_TRIG_ON_MATCH to trigger immediately on match, or EVH_TIMER2_TRIG_ON_EDGE to wait for a transition to the level)