Timer 1

Description

Execution timing and event counting, for use within task iterations

This resource provides access to AUX Timer 1 for use within task code blocks.

AUX Timer 1 is a 16-bit timer with a 2^N prescaler, where N is between 0 and 15.

The timer can either increment on each clock cycle, or on each edge of a selected tick source.

The timer counts up to the specified delay value, pulses an event output signal, and either stops or restarts from 0. The event signal can either be waited for in task code, or it can be used as a trigger signal, for example for the ADC.

The following operations are supported:

  • Start the timer in single or periodical event mode
    • Without tick source: The timer increments at the Sensor Controller clock rate used in the current power mode
    • With tick source: The timer increments at the selected edge of the selected tick source event signal
  • Read the timer counter value
  • Wait for the timer event
  • Check whether the timer is running (the single event has not yet occurred)
  • Stop the timer

The timer must be stopped before exiting the task code block where it has been used.

Note: This resource uses the AUX Timer 1 hardware module. The following procedures cannot be called while AUX Timer 1 is in use by this resource (started by timer1Start() , stopped by timeout in single mode or by timer1Stop() ):

  • evhSetupTimer1Trigger()
  • rtcmecCheckCaptEv()
  • rtcmecClearCapt()
  • rtcmecInit()
  • rtcmecSetPeriod()

Examples

Single Event

// Generate timer event after 100 us
timer1Start(TIMER1_MODE_SINGLE, 150, 4);
gpioSetOutput(AUXIO_O_LED);

// Wait for the timeout
timer1Wait();
gpioClearOutput(AUXIO_O_LED);

Periodical Events

// Generate timer events at every 100 us
timer1Start(TIMER1_MODE_PERIODICAL, 150, 4);

// Generate one pulse right away
gpioSetOutput(AUXIO_O_LED);
gpioClearOutput(AUXIO_O_LED);

// Generate another 3 pulses
for (U16 n = 0; n < 3; n++) {

    // Wait for timer event before generating each pulse
    timer1Wait();
    gpioSetOutput(AUXIO_O_LED);
    gpioClearOutput(AUXIO_O_LED);
}

// Stop the timer
timer1Stop();

Timeout

// Start an 4.8 ms timeout
timer1Start(TIMER1_MODE_SINGLE, 225, 9);

// Wait for sensor interrupt or timeout, whichever comes first
U16 interrupt;
do {

    // Check whether the timeout has occured
    U16 timer1IsRunning;
    timer1CheckState(timer1IsRunning);
    U16 timeout = timer1IsRunning ^ 0x0001;

    // Check whether the interrupt has occurred
    gpioGetInputValue(AUXIO_I_INTERRUPT; interrupt);

    U16 done = interrupt | timeout;
} while (done == 0);

// Stop the timer
timer1Stop();

Procedures Overview

Name Brief description
timer1CheckState() Checks whether AUX Timer 1 is currently running. More …
timer1GetValue() Returns the current AUX Timer 1 counter value. More …
timer1Start() Sets up AUX Timer 1 to generate events, either one-shot after the specified delay or repeatedly at the specified interval. More …
timer1StartWithTickSrc() Sets up AUX Timer 1 to generate events, either one-shot after the specified delay or repeatedly at the specified interval. More …
timer1Stop() Stops AUX Timer 1 event generation. More …
timer1Wait() Waits for the next AUX Timer 1 event. More …

Constants

Name Description
TIMER1_MODE_PERIODICAL Timer 1 mode: Periodical events at the specified interval
TIMER1_MODE_SINGLE Timer 1 mode: Single event after the specified delay
TIMER1_TICKSRC_AUXIO_BASE Timer 1 tick source: AUXIO (base + index)
TIMER1_TICKSRC_AUX_ADC_DONE Timer 1 tick source: ADC done
TIMER1_TICKSRC_AUX_COMPA Timer 1 tick source: COMPA output
TIMER1_TICKSRC_AUX_COMPB Timer 1 tick source: COMPB output
TIMER1_TICKSRC_AUX_TIMER0_EV Timer 1 tick source: Timer 0 event
TIMER1_TICKSRC_AUX_TIMER2_EV0 Timer 1 tick source: Timer 2 event 0
TIMER1_TICKSRC_AUX_TIMER2_EV1 Timer 1 tick source: Timer 2 event 1
TIMER1_TICKSRC_AUX_TIMER2_EV2 Timer 1 tick source: Timer 2 event 2
TIMER1_TICKSRC_AUX_TIMER2_EV3 Timer 1 tick source: Timer 2 event 3
TIMER1_TICKSRC_SCLK_LF Timer 1 tick source: SCLK_LF (32 kHz)
TIMER1_TICKSRC_SYS_ACTIVE Timer 1 tick source: High while any part of the system (MCU domain, AUX domain and/or JTAG) is in active mode
TIMER1_TICKSRC_VDDR_RECHARGE Timer 1 tick source: VDDR recharge

Global Variables

None.

Procedures

timer1CheckState

Prototype: timer1CheckState(isRunning)

Checks whether AUX Timer 1 is currently running.

After task code calls timer1Start() , this procedure returns 1 until task code calls timer1Stop() or the delay expires in single event mode.

Return value(s)

  • isRunning : 1 if AUX Timer 1 is running, otherwise 0

timer1GetValue

Prototype: timer1GetValue(value)

Returns the current AUX Timer 1 counter value.

The timer counts from 0 to the specified delay/interval mantissa value minus 1.

Return value(s)

  • value : Timer 1 counter value

timer1Start

Prototype: timer1Start(#mode, mant, #exp)

Sets up AUX Timer 1 to generate events, either one-shot after the specified delay or repeatedly at the specified interval.

The timer counts from 0 to the specified delay/interval mantissa value minus 1.

Parameter value(s)

  • #mode : Select single event or periodical events (TIMER1_MODE_XYZ)
  • mant : Delay/interval mantissa value (2-65535). Resulting delay/interval is mant * 2^exp [Sensor Controller clock periods].
  • #exp : Delay/interval exponent value (0-15). Resulting delay/interval is mant * 2^exp [Sensor Controller clock periods].

timer1StartWithTickSrc

Prototype: timer1StartWithTickSrc(#tickSrc, #edge, #mode, mant, #exp)

Sets up AUX Timer 1 to generate events, either one-shot after the specified delay or repeatedly at the specified interval.

The timer increments when the selected edge occurs on the selected tick source event signal.

The timer counts from 0 to the specified delay/interval mantissa value minus 1.

Parameter value(s)

  • #tickSrc : Select the event signal to count periodical events (TIMER1_TICKSRC_XYZ)
  • #edge : The event signal edge that shall increment the Timer 1 counter (1 = rising, 0 = falling)
  • #mode : Select single event or periodical events (TIMER1_MODE_XYZ)
  • mant : Timer 1 event delay/interval mantissa value (2-65535). Resulting delay/interval is mant * 2^exp [tick source edges].
  • #exp : Timer 1 event delay/interval exponent value (0-15). Resulting delay/interval is mant * 2^exp [tick source edges].

timer1Stop

Prototype: timer1Stop()

Stops AUX Timer 1 event generation.

timer1Wait

Prototype: timer1Wait()

Waits for the next AUX Timer 1 event.

The event occurs each time the specified timeout is reached, and also whenever the timer is idle.