0% found this document useful (0 votes)
99 views

lpc2148 Timers

The document describes the timers module of a microcontroller, including the pin descriptions for capture and match signals, the purpose and function of various timer registers like the timer control, counter, prescale, match, and capture registers, and how to configure and initialize the timers, set prescale values, enable matching and interrupts, and use one of the timers to generate delays.

Uploaded by

Smruti Pore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

lpc2148 Timers

The document describes the timers module of a microcontroller, including the pin descriptions for capture and match signals, the purpose and function of various timer registers like the timer control, counter, prescale, match, and capture registers, and how to configure and initialize the timers, set prescale values, enable matching and interrupts, and use one of the timers to generate delays.

Uploaded by

Smruti Pore
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Timers

Pin Description
• CAP0.3..0(Capture Signals)-
– A transition on a capture pin can be configured to
load one of the Capture Registers with the value in the
Timer Counter and optionally generate an interrupt.
• MAT0.3..0(External Match Output)-
– When a match register (MR3:0) equals the timer
counter (TC) this output can either toggle, go low, go
high, or do nothing. The External Match Register
(EMR) controls the functionality of this output.
Registers
• TCR Timer Control Register.
– The TCR is used to control the Timer Counter
functions. The Timer Counter can be disabled or
reset through the TCR.
• TC Timer Counter.
– The 32-bit TC is incremented every PR+1 cycles of
PCLK. The TC is controlled through the TCR
Registers
• PR Prescale Register.
– The Prescale Counter (below) is equal to this
value, the next clock increments the TC and clears
the PC.
• PC Prescale Counter.
– The 32-bit PC is a counter which is incremented to
the value stored in PR. When the value in PR is
reached, the TC is incremented and the PC is
cleared. The PC is observable and controllable
through the bus interface
Registers
• MCR Match Control Register.
– The MCR is used to control if an interrupt is
generated and if the TC is reset when a Match
occurs.
• MRX Match Register .
– MRX can be enabled through the MCR to reset the
TC, stop both the TC and PC, and/or generate an
interrupt every time MRX matches the TC.
Registers
• CCR Capture Control Register.
– The CCR controls which edges of the capture
inputs are used to load the Capture Registers and
whether or not an interrupt is generated when a
capture takes place.
• CRx Capture Register CRx
– CRx is loaded with the value of TC when there is
an event on the CAPn.0(CAP0.0 or CAP1.0
respectively)
Registers
• EMR External Match Register.
– The EMR controls the external match pins
MATn.0-3 (MAT0.0-3 and MAT1.0-3 respectively).
• CTCR Count Control Register.
– The CTCR selects between Timer and Counter
mode, and in Counter mode selects the signal and
edge(s) for counting.
Setting up & configuring Timers
• Set appropriate value in TxCTCR
• Define the Prescale value in TxPR
• Set Value(s) in Match Register(s) if required
• Set appropriate value in TxMCR if using Match
registers / Interrupts
• Reset Timer – Which resets PR and TC
• Set TxTCR to 0x01 to Enable the Timer when
required
• Reset TxTCR to 0x00 to Disable the Timer when
required
Timer Initialization
void initTimer0(void) { /*Assuming that PLL0 has
been setup with CCLK = 60Mhz and PCLK also
= 60Mhz.*/
T0CTCR = 0x0;
T0PR = PRESCALE-1; //(Value in Decimal!) -
Increment T0TC at every 60000 clock cycles
//Count begins from zero hence subtracting 1
//60000 clock cycles @60Mhz = 1 mS
T0TCR = 0x02; //Reset Timer }
void delayMS(unsigned int milliseconds) //Using
Timer0
{
T0TCR = 0x02; //Reset Timer
T0TCR = 0x01; //Enable timer
while(T0TC < milliseconds); //wait until timer
counter reaches the desired delay T0TCR =
0x00; //Disable timer }
Output

You might also like