TIMER — Timer/counter

The TIMER peripheral is a general purpose timer allowing time intervals to be defined by user input.

The main features of TIMER are:

Figure 1. Block schematic for timer/counter
Block schematic

TIMER runs on the high-frequency clock source (HFCLK) and includes a four-bit (1/2X) prescaler that can divide the timer input clock (PCLK) from the HFCLK controller. The TIMER base frequency is always given as PCLK divided by the prescaler value.

The PPI system allows a TIMER event to trigger a task on another system peripheral on the device. The PPI system also enables the TIMER task/event feature to generate periodic output and PWM signals to any GPIO. The number of GPIO inputs or outputs used at the same time is limited by the number of GPIOTE channels.

TIMER can operate in two modes: Timer mode and Counter mode. In both modes, TIMER is started by triggering the START task, and stopped by triggering the STOP task. After TIMER stops, it can resume timing/counting by triggering the START task again. When timing/counting resumes, TIMER continues from the value it was on prior to stopping.

In Timer mode, TIMER's internal Counter register is incremented by one for every tick of the timer frequency fTIMER, as illustrated in Block schematic for timer/counter. The timer frequency is derived from PCLK as shown in the following example, using the values specified in the PRESCALER register.


    fTIMER = PCLK / (2PRESCALER)
  

For timers using PCLK16M as PCLK, when fTIMER ≤ 1 MHz, TIMER uses PCLK1M instead of PCLK for reduced power consumption. Clock source selection between PCLK and PCLK1M is automatic according to the TIMER base frequency set by the prescaler.

In Counter mode, the TIMER's internal Counter register is incremented by one each time the COUNT task is triggered, meaning the timer frequency and the prescaler are not utilized in Counter mode. Similarly, the COUNT task has no effect in Timer mode.

TIMER's maximum value is configured by changing the bit-width of the timer in register BITMODE.

PRESCALER and BITMODE must only be updated when TIMER is stopped. If these registers are updated while TIMER is started, unpredictable behavior may occur.

When TIMER is incremented beyond its maximum value, the Counter register will overflow and TIMER will automatically start over from zero.

The Counter register can be cleared by triggering the CLEAR task. This will explicitly set the internal value to zero.

TIMER implements multiple capture/compare registers.

Independent of prescaler settings, the accuracy of TIMER is equivalent to one tick of the timer frequency fTIMER as illustrated in Block schematic for timer/counter.

Capture

TIMER implements one capture task for every available capture/compare register.

Every time the CAPTURE[n] task is triggered, the counter value is copied to the CC[n] register.

Compare

TIMER implements one COMPARE event for every available capture/compare register.

When the counter value becomes equal to the value specified in a capture compare register CC[n], the corresponding compare event COMPARE[n] is generated.

BITMODE specifies how many Counter and capture/compare register bits are used when the comparison is performed. Other bits are ignored.

The COMPARE event can be configured to operate in one-shot mode by configuring the corresponding ONESHOTEN[n] register. After writing CC[n], a COMPARE[n] event is generated the first time the Counter matches CC[n].

Task delays

After TIMER is started, the CLEAR, COUNT, and STOP tasks are guaranteed to take effect within one clock cycle of the PCLK.

Task priority

If the START task and the STOP task are triggered at the same time, meaning within the same period of PCLK, the STOP task is prioritized.

If one or more of the CAPTURE tasks and the CLEAR task are triggered at the same time, that is, within the same period of PCLK, the CAPTURE tasks are prioritized. This means that the CC registers will capture the counter value before the CLEAR tasks are triggered.

Registers

Instances

InstanceDomainBase addressDescription
TIMER00GLOBAL0x40055000Timer TIMER00
TIMER10GLOBAL0x40085000Timer TIMER10
TIMER20GLOBAL0x400CA000Timer TIMER20

Configuration

InstanceDomainConfiguration
TIMER00GLOBAL

Peripheral clock frequency (PCLK) is 128 MHz

The system is able to configure the TIMER peripheral input clock frequency (PCLK) before it reaches TIMER, and calculations of PRESCALER value must take the actual PCLK frequency into account

6 capture compare channels implemented

TIMER10GLOBAL

Peripheral clock frequency (PCLK) is 32 MHz

8 capture compare channels implemented

TIMER20GLOBAL

Peripheral clock frequency (PCLK) is 16 MHz

6 capture compare channels implemented

Register overview

RegisterOffsetDescription
TASKS_START0x000Start Timer
TASKS_STOP0x004Stop Timer
TASKS_COUNT0x008Increment Timer (Counter mode only)
TASKS_CLEAR0x00CClear time
TASKS_CAPTURE[n]0x040Capture Timer value to CC[n] register
SUBSCRIBE_START0x080Subscribe configuration for task START
SUBSCRIBE_STOP0x084Subscribe configuration for task STOP
SUBSCRIBE_COUNT0x088Subscribe configuration for task COUNT
SUBSCRIBE_CLEAR0x08CSubscribe configuration for task CLEAR
SUBSCRIBE_CAPTURE[n]0x0C0Subscribe configuration for task CAPTURE[n]
EVENTS_COMPARE[n]0x140Compare event on CC[n] match
PUBLISH_COMPARE[n]0x1C0Publish configuration for event COMPARE[n]
SHORTS0x200Shortcuts between local events and tasks
INTEN0x300Enable or disable interrupt
INTENSET0x304Enable interrupt
INTENCLR0x308Disable interrupt
MODE0x504Timer mode selection
BITMODE0x508Configure the number of bits used by the TIMER
PRESCALER0x510Timer prescaler register
CC[n]0x540Capture/Compare register n
ONESHOTEN[n]0x580Enable one-shot operation for Capture/Compare channel n

TASKS_START

Address offset: 0x000

Start Timer

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWTASKS_STARTStart Timer
Trigger1Trigger task

TASKS_STOP

Address offset: 0x004

Stop Timer

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWTASKS_STOPStop Timer
Trigger1Trigger task

TASKS_COUNT

Address offset: 0x008

Increment Timer (Counter mode only)

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWTASKS_COUNTIncrement Timer (Counter mode only)
Trigger1Trigger task

TASKS_CLEAR

Address offset: 0x00C

Clear time

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWTASKS_CLEARClear time
Trigger1Trigger task

TASKS_CAPTURE[n]

Address offset: 0x040 + (n × 0x4)

Capture Timer value to CC[n] register

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWTASKS_CAPTURECapture Timer value to CC[n] register
Trigger1Trigger task

SUBSCRIBE_START

Address offset: 0x080

Subscribe configuration for task START

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCHIDX[0..255]DPPI channel that task START will subscribe to
BRWEN
Disabled0Disable subscription
Enabled1Enable subscription

SUBSCRIBE_STOP

Address offset: 0x084

Subscribe configuration for task STOP

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCHIDX[0..255]DPPI channel that task STOP will subscribe to
BRWEN
Disabled0Disable subscription
Enabled1Enable subscription

SUBSCRIBE_COUNT

Address offset: 0x088

Subscribe configuration for task COUNT

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCHIDX[0..255]DPPI channel that task COUNT will subscribe to
BRWEN
Disabled0Disable subscription
Enabled1Enable subscription

SUBSCRIBE_CLEAR

Address offset: 0x08C

Subscribe configuration for task CLEAR

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCHIDX[0..255]DPPI channel that task CLEAR will subscribe to
BRWEN
Disabled0Disable subscription
Enabled1Enable subscription

SUBSCRIBE_CAPTURE[n]

Address offset: 0x0C0 + (n × 0x4)

Subscribe configuration for task CAPTURE[n]

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCHIDX[0..255]DPPI channel that task CAPTURE[n] will subscribe to
BRWEN
Disabled0Disable subscription
Enabled1Enable subscription

EVENTS_COMPARE[n]

Address offset: 0x140 + (n × 0x4)

Compare event on CC[n] match

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWEVENTS_COMPARECompare event on CC[n] match
NotGenerated0Event not generated
Generated1Event generated

PUBLISH_COMPARE[n]

Address offset: 0x1C0 + (n × 0x4)

Publish configuration for event COMPARE[n]

Bit number313029282726252423222120191817161514131211109876543210
IDBAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCHIDX[0..255]DPPI channel that event COMPARE[n] will publish to
BRWEN
Disabled0Disable publishing
Enabled1Enable publishing

SHORTS

Address offset: 0x200

Shortcuts between local events and tasks

Bit number313029282726252423222120191817161514131211109876543210
IDPONMLKJIHGFEDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A-HRWCOMPARE[i]_CLEAR (i=0..7)Shortcut between event COMPARE[i] and task CLEAR
Disabled0Disable shortcut
Enabled1Enable shortcut
I-PRWCOMPARE[i]_STOP (i=0..7)Shortcut between event COMPARE[i] and task STOP
Disabled0Disable shortcut
Enabled1Enable shortcut

INTEN

Address offset: 0x300

Enable or disable interrupt

Bit number313029282726252423222120191817161514131211109876543210
IDHGFEDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A-HRWCOMPARE[i] (i=0..7)Enable or disable interrupt for event COMPARE[i]
Disabled0Disable
Enabled1Enable

INTENSET

Address offset: 0x304

Enable interrupt

Bit number313029282726252423222120191817161514131211109876543210
IDHGFEDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A-HRW
W1S
COMPARE[i] (i=0..7)Write '1' to enable interrupt for event COMPARE[i]
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled

INTENCLR

Address offset: 0x308

Disable interrupt

Bit number313029282726252423222120191817161514131211109876543210
IDHGFEDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
A-HRW
W1C
COMPARE[i] (i=0..7)Write '1' to disable interrupt for event COMPARE[i]
Clear1Disable
Disabled0Read: Disabled
Enabled1Read: Enabled

MODE

Address offset: 0x504

Timer mode selection

Bit number313029282726252423222120191817161514131211109876543210
IDAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWMODETimer mode
Timer0Select Timer mode
Counter1

Select Counter mode

This enumerator is deprecated.

LowPowerCounter2Select Low Power Counter mode

BITMODE

Address offset: 0x508

Configure the number of bits used by the TIMER

Bit number313029282726252423222120191817161514131211109876543210
IDAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWBITMODETimer bit width
16Bit016 bit timer bit width
08Bit18 bit timer bit width
24Bit224 bit timer bit width
32Bit332 bit timer bit width

PRESCALER

Address offset: 0x510

Timer prescaler register

Bit number313029282726252423222120191817161514131211109876543210
IDAAAA
Reset 0x0000000400000000000000000000000000000100
IDR/WFieldValue IDValueDescription
ARWPRESCALER[0..9]Prescaler value

CC[n]

Address offset: 0x540 + (n × 0x4)

Capture/Compare register n

Bit number313029282726252423222120191817161514131211109876543210
IDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCC

Capture/Compare value

Only the number of bits indicated by BITMODE will be used by the TIMER.

ONESHOTEN[n]

Address offset: 0x580 + (n × 0x4)

Enable one-shot operation for Capture/Compare channel n

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWONESHOTEN

Enable one-shot operation

Configures the corresponding compare-channel for one-shot operation

Disable0

Disable one-shot operation

Compare event is generated every time the Counter matches CC[n]

Enable1

Enable one-shot operation

Compare event is generated the first time the Counter matches CC[n] after CC[n] has been written