The Timer Counter blocks of Arduino Due's AT91SAM3X8E

July 24, 2015 · View on GitHub

The AT91SAM3X8E embedds nine general-purpose 32-bit timers/counters. They are organized in three blocks (TC0, TC1, TC2) each containing three channels (0, 1, 2). Each block and channel has input lines for their clock and input/output lines which can be used in different ways, such as PWM pins etc.

Resources

Information on the Timer Counter and its I/O signals pins can be found here:

The Timer Counter Signals / Pins

Many of the I/O lines of the Timer Counter are directly accessible on pin headers of the Arduino Due board. This section helps you to find out which of them are and which are not.

In order to actually connect those signals (TCLKx, TIOAx and TIOBx) to the pins on the Arduino Due, you must tell the Parallel I/O Controllers (PIOA, PIOB, PIOC or PIOD) to set up their mux (multiplexer) accordingly.
A useful resource to find out how to set the PIOs is Arduino's const array of PinDescriptions and the definition of PinDescription, the data type of its entries.

Overview of the I/O lines of the Timer Counter

Here is a table of the Timer Counter channels and their TCLKx (external clock input), TIOAx (I/O Line A) and TIOBx (I/O Line B) signals:

InstanceTCChannelExternal Clock InputI/O Line AI/O Line B
T0TC00TCLK0TIOA0TIOB0
T1TC01TCLK1TIOA1TIOB1
T2TC02TCLK2TIOA2TIOB2
T3TC10TCLK3TIOA3TIOB3
T4TC11TCLK4TIOA4TIOB4
T5TC12TCLK5TIOA5TIOB5
T6TC20TCLK6TIOA6TIOB6
T7TC21TCLK7TIOA7TIOB7
T8TC22TCLK8TIOA8TIOB8
TCLKx

Here is how the external clock inputs are routed to pins on the Arduino Due board:

Clock InputPort Pin of µCPin on Arduino Due Board
TCLK0PB 26Digital Pin 22
TCLK1PA 4Analog In 5
TCLK2PA 7Digital Pin 31
TCLK3PA 22Analog In 3
TCLK4PA 23Analog In 2
TCLK5PB 16DAC1
TCLK6PC 27/
TCLK7PC 30LED "RX"
TCLK8PD 9Digital Pin 30
TIOAx

Here is how the I/O Lines A are routed to pins on the Arduino Due board:

I/O Line APort Pin of µCPin on Arduino Due Board
TIOA0PB 25Digital Pin 2
TIOA1PA 2Analog In 7
TIOA2PA 5/
TIOA3PE 9/
TIOA4PE 11/
TIOA5PE 13/
TIOA6PC 25Digital Pin 5
TIOA7PC 28Digital Pin 3
TIOA8PD 7Digital Pin 11
TIOBx

Here is how the I/O Lines B are routed to pins on the Arduino Due board:

I/O Line BPort Pin of µCPin on Arduino Due Board
TIOB0PB 27Digital Pin 13 / Amber LED "L"
TIOB1PA 3Analog In 6
TIOB2PA 6Analog In 4
TIOB3PE 10/
TIOB4PE 12/
TIOB5PE 14/
TIOB6PC 26Digital Pin 4 (also connected to PA29)
TIOB7PC 29Digital Pin 10 (also connected to PA28)
TIOB8PD 8Digital Pin 12

TC Clock Source Selection

The clock of the counters can be set very flexibly to internal or external signals. To use the channel as a timer, it makes sense to connect its clock input to an internal timer clock. Here are the options:

NameDefinition
TIMER_CLOCK1MCK / 2
TIMER_CLOCK2MCK / 8
TIMER_CLOCK3MCK / 32
TIMER_CLOCK4MCK / 128
TIMER_CLOCK5SLCK

Where MCK is the master clock (84 MHz for the Arduino Due) and SLCK is the slow clock (which can be clocked at 32.768 kHz by Y2 on the Arduino Due).