Timer 0¶
Description¶
Execution timing and event counting, for use within task iterations
This resource provides access to AUX Timer 0 for use within task code blocks.
AUX Timer 0 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 0 hardware module. The following procedures cannot be called while AUX Timer 0 is in use by this resource (started by timer0Start()
, stopped by timeout in single mode or by timer0Stop()
):
evhSetupTimer0Trigger()
uartEmulator()
Examples¶
Single Event¶
// Generate timer event after 100 us
timer0Start(TIMER0_MODE_SINGLE, 2400, 0);
gpioSetOutput(AUXIO_O_LED);
// Wait for the timeout
timer0Wait();
gpioClearOutput(AUXIO_O_LED);
Periodical Events¶
// Generate timer events at every 100 us
timer0Start(TIMER0_MODE_PERIODICAL, 2400, 0);
// 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
timer0Wait();
gpioSetOutput(AUXIO_O_LED);
gpioClearOutput(AUXIO_O_LED);
}
// Stop the timer
timer0Stop();
Timeout¶
// Start an 8 ms timeout
timer0Start(TIMER0_MODE_SINGLE, 24000, 3);
// Wait for sensor interrupt or timeout, whichever comes first
U16 interrupt;
do {
// Check whether the timeout has occured
U16 timer0IsRunning;
timer0CheckState(timer0IsRunning);
U16 timeout = timer0IsRunning ^ 0x0001;
// Check whether the interrupt has occurred
gpioGetInputValue(AUXIO_I_INTERRUPT; interrupt);
U16 done = interrupt | timeout;
} while (done == 0);
// Stop the timer
timer0Stop();
Procedures Overview¶
Name | Brief description |
timer0CheckState() |
Checks whether AUX Timer 0 is currently running. More … |
timer0GetValue() |
Returns the current AUX Timer 0 counter value. More … |
timer0Start() |
Sets up AUX Timer 0 to generate events, either one-shot after the specified delay or repeatedly at the specified interval. More … |
timer0StartWithTickSrc() |
Sets up AUX Timer 0 to generate events, either one-shot after the specified delay or repeatedly at the specified interval. More … |
timer0Stop() |
Stops AUX Timer 0. More … |
timer0Wait() |
Waits for the next AUX Timer 0 event. More … |
Constants¶
Name | Description |
TIMER0_MODE_PERIODICAL |
Timer 0 mode: Periodical events at the specified interval |
TIMER0_MODE_SINGLE |
Timer 0 mode: Single event after the specified delay |
TIMER0_TICKSRC_AUXIO_BASE |
Timer 0 tick source: AUXIO (base + index) |
TIMER0_TICKSRC_AUX_ADC_DONE |
Timer 0 tick source: ADC done |
TIMER0_TICKSRC_AUX_COMPA |
Timer 0 tick source: COMPA output |
TIMER0_TICKSRC_AUX_COMPB |
Timer 0 tick source: COMPB output |
TIMER0_TICKSRC_AUX_TIMER1_EV |
Timer 0 tick source: Timer 1 event |
TIMER0_TICKSRC_AUX_TIMER2_EV0 |
Timer 0 tick source: Timer 2 event 0 |
TIMER0_TICKSRC_AUX_TIMER2_EV1 |
Timer 0 tick source: Timer 2 event 1 |
TIMER0_TICKSRC_AUX_TIMER2_EV2 |
Timer 0 tick source: Timer 2 event 2 |
TIMER0_TICKSRC_AUX_TIMER2_EV3 |
Timer 0 tick source: Timer 2 event 3 |
TIMER0_TICKSRC_SCLK_LF |
Timer 0 tick source: SCLK_LF (32 kHz) |
TIMER0_TICKSRC_SYS_ACTIVE |
Timer 0 tick source: High while any part of the system (MCU domain, AUX domain and/or JTAG) is in active mode |
TIMER0_TICKSRC_VDDR_RECHARGE |
Timer 0 tick source: VDDR recharge |
Global Variables¶
None.
Procedures¶
timer0CheckState¶
Prototype: timer0CheckState(isRunning)
Checks whether AUX Timer 0 is currently running.
After task code calls timer0Start()
, this procedure returns 1 until task code calls timer0Stop()
or the delay expires in single event mode.
Return value(s)¶
- isRunning : 1 if AUX Timer 0 is running, otherwise 0
timer0GetValue¶
Prototype: timer0GetValue(value)
Returns the current AUX Timer 0 counter value.
The timer counts from 0 to the specified delay/interval mantissa value minus 1.
Return value(s)¶
- value : Timer 0 counter value
timer0Start¶
Prototype: timer0Start(#mode, mant, #exp)
Sets up AUX Timer 0 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 (TIMER0_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].
timer0StartWithTickSrc¶
Prototype: timer0StartWithTickSrc(#tickSrc, #edge, #mode, mant, #exp)
Sets up AUX Timer 0 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 (TIMER0_TICKSRC_XYZ)
- #edge : The event signal edge that shall increment the Timer 0 counter (1 = rising, 0 = falling)
- #mode : Select single event or periodical events (TIMER0_MODE_XYZ)
- mant : Timer 0 event delay/interval mantissa value (2-65535). Resulting delay/interval is mant * 2^exp [tick source edges].
- #exp : Timer 0 event delay/interval exponent value (0-15). Resulting delay/interval is mant * 2^exp [tick source edges].
timer0Wait¶
Prototype: timer0Wait()
Waits for the next AUX Timer 0 event.
The event occurs each time the specified timeout is reached, and also whenever the timer is idle.