TIMER — Timer/counter

This peripheral is a general purpose timer designed to keep track of time in user-selective time intervals, it can operate in two modes: timer and counter.

Figure 1. Block schematic for timer/counter

The timer/counter runs on the high-frequency clock source (HFCLK) and includes a four-bit (1/2X) prescaler that can divide the timer input clock from the HFCLK controller. Clock source selection between PCLK16M and PCLK1M is automatic according to TIMER base frequency set by the prescaler. The TIMER base frequency is always given as 16 MHz divided by the prescaler value.

The PPI system allows a TIMER event to trigger a task of any other system peripheral of the device. The PPI system also enables the TIMER task/event features to generate periodic output and PWM signals to any GPIO. The number of input/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 the timer is stopped the timer can resume timing/counting by triggering the START task again. When timing/counting is resumed, the timer will continue from the value it had prior to being stopped.

In Timer mode, the 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 PCLK16M as shown in the following example, using the values specified in the PRESCALER register.


    fTIMER = 16 MHz / (2PRESCALER)
    

When fTIMER ≤ 1 MHz, TIMER will use PCLK1M instead of PCLK16M for reduced power consumption.

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.

The 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 the timer is stopped. If these registers are updated while the timer is started, unpredictable behavior may occur.

When the timer is incremented beyond its maximum value, the Counter register will overflow and the 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 setting, 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.

A COMPARE event is generated when the Counter is incremented and then becomes equal to the value specified in one of the capture compare registers. 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 bits of the Counter register and the capture/compare register that are used when the comparison is performed. Other bits will be ignored.

Task delays

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

Task priority

If the START task and the STOP task are triggered at the same time, meaning within the same period of PCLK16M, the STOP task will be prioritized.

Registers

Instances

InstanceBase addressDescription
TIMER00x40008000Timer 0
TIMER10x40009000Timer 1
TIMER20x4000A000Timer 2
TIMER30x4001A000Timer 3
TIMER40x4001B000Timer 4

Configuration

InstanceConfiguration
TIMER0This timer instance has 4 CC registers (CC[0..3])
TIMER1This timer instance has 4 CC registers (CC[0..3])
TIMER2This timer instance has 4 CC registers (CC[0..3])
TIMER3This timer instance has 6 CC registers (CC[0..5])
TIMER4This timer instance has 6 CC registers (CC[0..5])

Register overview

RegisterOffsetDescription
TASKS_START0x000Start Timer
TASKS_STOP0x004Stop Timer
TASKS_COUNT0x008Increment Timer (Counter mode only)
TASKS_CLEAR0x00CClear time
TASKS_SHUTDOWN0x010

Shut down timer

This register is deprecated.

TASKS_CAPTURE[0]0x040Capture Timer value to CC[0] register
TASKS_CAPTURE[1]0x044Capture Timer value to CC[1] register
TASKS_CAPTURE[2]0x048Capture Timer value to CC[2] register
TASKS_CAPTURE[3]0x04CCapture Timer value to CC[3] register
TASKS_CAPTURE[4]0x050Capture Timer value to CC[4] register
TASKS_CAPTURE[5]0x054Capture Timer value to CC[5] register
EVENTS_COMPARE[0]0x140Compare event on CC[0] match
EVENTS_COMPARE[1]0x144Compare event on CC[1] match
EVENTS_COMPARE[2]0x148Compare event on CC[2] match
EVENTS_COMPARE[3]0x14CCompare event on CC[3] match
EVENTS_COMPARE[4]0x150Compare event on CC[4] match
EVENTS_COMPARE[5]0x154Compare event on CC[5] match
SHORTS0x200Shortcuts between local events and tasks
INTENSET0x304Enable interrupt
INTENCLR0x308Disable interrupt
MODE0x504Timer mode selection
BITMODE0x508Configure the number of bits used by the TIMER
PRESCALER0x510Timer prescaler register
CC[0]0x540Capture/Compare register 0
CC[1]0x544Capture/Compare register 1
CC[2]0x548Capture/Compare register 2
CC[3]0x54CCapture/Compare register 3
CC[4]0x550Capture/Compare register 4
CC[5]0x554Capture/Compare register 5

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_SHUTDOWN (Deprecated)

Address offset: 0x010

Shut down timer

This register is deprecated.

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWTASKS_SHUTDOWN

Shut down timer

This field is deprecated.

Trigger1Trigger task

TASKS_CAPTURE[0]

Address offset: 0x040

Capture Timer value to CC[0] register

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

TASKS_CAPTURE[1]

Address offset: 0x044

Capture Timer value to CC[1] register

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

TASKS_CAPTURE[2]

Address offset: 0x048

Capture Timer value to CC[2] register

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

TASKS_CAPTURE[3]

Address offset: 0x04C

Capture Timer value to CC[3] register

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

TASKS_CAPTURE[4]

Address offset: 0x050

Capture Timer value to CC[4] register

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

TASKS_CAPTURE[5]

Address offset: 0x054

Capture Timer value to CC[5] register

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

EVENTS_COMPARE[0]

Address offset: 0x140

Compare event on CC[0] match

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

EVENTS_COMPARE[1]

Address offset: 0x144

Compare event on CC[1] match

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

EVENTS_COMPARE[2]

Address offset: 0x148

Compare event on CC[2] match

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

EVENTS_COMPARE[3]

Address offset: 0x14C

Compare event on CC[3] match

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

EVENTS_COMPARE[4]

Address offset: 0x150

Compare event on CC[4] match

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

EVENTS_COMPARE[5]

Address offset: 0x154

Compare event on CC[5] match

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

SHORTS

Address offset: 0x200

Shortcuts between local events and tasks

Bit number313029282726252423222120191817161514131211109876543210
IDLKJIHGFEDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCOMPARE0_CLEARShortcut between event COMPARE[0] and task CLEAR
Disabled0Disable shortcut
Enabled1Enable shortcut
BRWCOMPARE1_CLEARShortcut between event COMPARE[1] and task CLEAR
Disabled0Disable shortcut
Enabled1Enable shortcut
CRWCOMPARE2_CLEARShortcut between event COMPARE[2] and task CLEAR
Disabled0Disable shortcut
Enabled1Enable shortcut
DRWCOMPARE3_CLEARShortcut between event COMPARE[3] and task CLEAR
Disabled0Disable shortcut
Enabled1Enable shortcut
ERWCOMPARE4_CLEARShortcut between event COMPARE[4] and task CLEAR
Disabled0Disable shortcut
Enabled1Enable shortcut
FRWCOMPARE5_CLEARShortcut between event COMPARE[5] and task CLEAR
Disabled0Disable shortcut
Enabled1Enable shortcut
GRWCOMPARE0_STOPShortcut between event COMPARE[0] and task STOP
Disabled0Disable shortcut
Enabled1Enable shortcut
HRWCOMPARE1_STOPShortcut between event COMPARE[1] and task STOP
Disabled0Disable shortcut
Enabled1Enable shortcut
IRWCOMPARE2_STOPShortcut between event COMPARE[2] and task STOP
Disabled0Disable shortcut
Enabled1Enable shortcut
JRWCOMPARE3_STOPShortcut between event COMPARE[3] and task STOP
Disabled0Disable shortcut
Enabled1Enable shortcut
KRWCOMPARE4_STOPShortcut between event COMPARE[4] and task STOP
Disabled0Disable shortcut
Enabled1Enable shortcut
LRWCOMPARE5_STOPShortcut between event COMPARE[5] and task STOP
Disabled0Disable shortcut
Enabled1Enable shortcut

INTENSET

Address offset: 0x304

Enable interrupt

Bit number313029282726252423222120191817161514131211109876543210
IDFEDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCOMPARE[0]Write '1' to enable interrupt for event COMPARE[0]
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled
BRWCOMPARE[1]Write '1' to enable interrupt for event COMPARE[1]
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled
CRWCOMPARE[2]Write '1' to enable interrupt for event COMPARE[2]
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled
DRWCOMPARE[3]Write '1' to enable interrupt for event COMPARE[3]
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled
ERWCOMPARE[4]Write '1' to enable interrupt for event COMPARE[4]
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled
FRWCOMPARE[5]Write '1' to enable interrupt for event COMPARE[5]
Set1Enable
Disabled0Read: Disabled
Enabled1Read: Enabled

INTENCLR

Address offset: 0x308

Disable interrupt

Bit number313029282726252423222120191817161514131211109876543210
IDFEDCBA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWCOMPARE[0]Write '1' to disable interrupt for event COMPARE[0]
Clear1Disable
Disabled0Read: Disabled
Enabled1Read: Enabled
BRWCOMPARE[1]Write '1' to disable interrupt for event COMPARE[1]
Clear1Disable
Disabled0Read: Disabled
Enabled1Read: Enabled
CRWCOMPARE[2]Write '1' to disable interrupt for event COMPARE[2]
Clear1Disable
Disabled0Read: Disabled
Enabled1Read: Enabled
DRWCOMPARE[3]Write '1' to disable interrupt for event COMPARE[3]
Clear1Disable
Disabled0Read: Disabled
Enabled1Read: Enabled
ERWCOMPARE[4]Write '1' to disable interrupt for event COMPARE[4]
Clear1Disable
Disabled0Read: Disabled
Enabled1Read: Enabled
FRWCOMPARE[5]Write '1' to disable interrupt for event COMPARE[5]
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[0]

Address offset: 0x540

Capture/Compare register 0

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.

CC[1]

Address offset: 0x544

Capture/Compare register 1

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.

CC[2]

Address offset: 0x548

Capture/Compare register 2

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.

CC[3]

Address offset: 0x54C

Capture/Compare register 3

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.

CC[4]

Address offset: 0x550

Capture/Compare register 4

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.

CC[5]

Address offset: 0x554

Capture/Compare register 5

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.