Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

TIMER LPC 23 xx

features
a timers Counters
La y channels per timer
To to 73
2s Co toCz
Total channels 16

not all can


generate external exp
or take external lip
Be can do so per timer Code
only 2

Co Can generate external op or

a
3 take external Yp

C2
used for generating internal
timing functions
C Cannot generate external timing
and cannot take external
fun
Yp

Every Gplo pin can be programmed to have


alternate
an
Say you want fun
ilp to your timer or want Olp
from your timer you can
program any one
Gplo Pin
of your the time to function as the alternate
fan for Yp or the timer op
32 bit timer
or counter with programmable 32 bit prescaler
used
Timer
operations
can be
both for counting Timing

A Difference bw timing and counting open


Timer open
ÉÉ É
to be counted
gtghip Something internal which
triggers the counter this
External objects to is Called timing open
be counted Counting

a Timer
2
ways to use Kp't capture
D Outputmatch
Counter output
compare

INPUT CAPTURE
Used for finding time Intervals
Ton
Say q
yp I V
Ip capture can find time interval as
interval b w 2 rising edges
interval bw 2 falling edges
interval btw rising edge and the
falling edges Ton
Interval btw falling edge and the
rising edges TOFF
Channels in TIMER
can be used for ext up or entyp
tinchanwels
early
3
This case is Similar
for Timers Timer 2 Timea 3

INPUT CAPTURE PROCESS


These 2 Gits are
PeripheralClock available for choosing

my The edges of measurement


orRising falling edges
toRising Rising edges
or falling as falling edges
or falling as Rising edges
Ipcw
External yp is to be
connected to PT

flow Rising edge to Rising edge


measurement

Calculating the freest rising edge


d Say we are measuring for rising edges
whenever this est lip has rising edge the
working value of 32 Git counter is moved to
of capture evey
and at same time an Interrupt is raised
capture provided if it is enabled
now the user can read the value of
Capture rely or store it in nm location
2s Say 0005m
Calculating the next Rising edges
Again when not rising edge arrives whatever is
the count valve is
And an interrupt isagain
captured
again raised
The captured valve is transferred to the capture reg
say valve I 000AM
Time b w 2 edges 000AM 0005 0005
in
G time b w 2
this
This is
edges
valve
no
of elk cycles
here 5 elk cycles the
peripheral aw
of
Peripheral Cik
Frey 2MHz day
time period ins
So time elapsed btw 2 rising edges 5ps

Programming LPC 2378 for Yp Capture


turn on the Timer
steps By default To T are ON T2873 are OFF
Turn on this is done by Power Control Peripheral reg

Prey is
ThisPeon
IT used
In Sema Gatedelk
Igg is used to provide
on OFF control

Step2 Pinselect
veg Rinser is used to select the alternate
set functions
PINSELMeg LPC2378 1 PIN has 4 alternate functions Huttis 9 0
STM32 I PIN has 16 alternate functions
The pin select registers in LPC2378
There are 5 ports in LPC2378
POR o
PORT1 Ps3
ji
PORT2 Ps's
WYTV
Md PORT3 386
Ps
got
wed Each port has 32 bits
PORT4
each PINSEL veg is 32 bits But 2 bits are neg to
selectaltern fun of each Port So Single PINSEL reg can
handle 16 PINS
In 2bits

Default is Oo Gro
2 PINSEL
beg for each port
leg in total
D 10 PINSEL

Programming the Pins El reg


To Co op Timer O Channel0
y
To Ci
PortsPin18 alternate Fxn 3 is used

First do alternate functions


then do apio on leftover
PINS

do if using a pin for timer then ensure that to not reuse it as


GPIO later
to program Ports Pin 26 for Yp capture PINSEL Ps3 veg
is to be programmed
Here Peck is to be decided By default
eyed
qffep3
select your select Clk for Timer 0 12 3

Similar to PINSEL there are Polk set beg also


Pan selection Register o
Bit 2 3 PCIK TIMERO
Bit 4 5 PCLK TIMERI it
Polk Selection register 1
B is
Steph Prescaler Cia source selection Peck can be scaledfurther

00
Peck is scaled by 5 1

Op Peakscaled by 571
I Two sources
of CIA
pp PCLK
external signal thou CAP
Greene
this ext Signal is usedfor
the Ilp capture only and not
for counting process
only Pak is selected here It is done using CTCR beg
here functioning as a Counter i e counting eat pulses

CTCR Counter Control Reg for Timer 01 2 3

yhis selects the Clk for


all n channels of a timer
CMI CMO
Eat selects the Risingfalling edge

X Ent
of the Polk ext clock
Ese for Ilp capture
em Cmo 00
x Ent
CISI CisO
It using the Pe you can have external trigger for CIA
capture
Cist Ciso
O O O
O 1

Ips
setup the Capture
Capture Reg for Timer 0123

veg TxCCR
plutempt

capture for channels capture for channelo

Though there are u channels but bits for Yp Capture


and op compare are only present for 2 Channels
Co C

Because
only 2 channels are available
for this
ont

wait next interrupt and


Iss
Branch to ISR and read

when it happens
the
an

for
then the difference b w 2 Captures can be
calculated

step 6 Enable the timer every timer has a control


Program register Txer semeans which timer
Interrupt
my

doEnable the
I forresetting the timer
timer

I
Bring value to zero
to check which of the yp has Caused the
Yp Capture
check from TxIR evey

Dubming
EYE
After acknowledging what has caused the
interrupt
read the capture registers
b
Uchannels Sofourcapture registers

ta to
though u registers are available
me for Yp Capture
ACRO
But only channelO's channels's Capture
evey is available for reading

Because
only channel0 channel I support
Input capture
OutputCompare Output match
1 4 32 bit match registers are available
for this
Optional interrupt generation on match
Stops the timer every time there is a match
resets the timer everytime there is match
2
up to a external signals are there associated
to match veg
4 types of narration you can set with
these external signals
Set low high Toggle Do nothing on match

example changing the ops when there is


a match
value in match obey 0005
12345
reset everytime when there
is a match
when value in 32 bit Counter
0005 becomes 0005

32 bit comparator generates


an interrupt
If
enabled
Say if every match toggles
an op high is set Then
pe is set to high
Again the counter Valve is reset
If toggle is set for Opp then

aerated because of
EY
toggling
En En j

Pin set neg and Alternate functions

when using for Olp compare


the matelved ofp are available
on alternate functions

Timeros chano
chant
Timers chan O
Chand
exceptionally channel2 has
4 01ps
God
But in case Ilpcapture it
allows only 2of4ps
Programming for Op compare
for op compare there would be different pins
as compared to Yp Capture

Steps to program
ON the timer Program the pin select

Program timer counter select Peck freq


reg TCR
to as Gallows to select
ext capture cap
from Internal Yp Pans or
pyroptore
to can be capture Rising edge
can be capture falling edge
can be capture Rising falling
edge
West stop
This step is different from Yp Capture
match registers for timer 0 1 213

for all 4 Timer channels 3 bits are available


CHI CHI CHO

Mdgftd
TxMRO TXMP3
Tx MCR É
gInterruptshould
raised
reset count
toggled
stop count when
match is detected
External match timer GXEMCR
register for
01 2 3

for any Internal operation

Emos value l If you want to have any external


External to take
match bit operation place
for CHO
which edge
risingedge
falling edge 9,8 forchannelo
toggle
same can be done for CMI using Em bits
Emet
though EMB EMC 2 are available but can't be
used because there is no external match

signal available n so set bevern to 0


Example
Program LPC 23 xx to count the no of Objects
Crossing a particular point with a period of
I see Also
find the time interval b w two
Objects
count of falling edges Centennial edges

I use timer as counter

Generating interrupt after I see

Is Olp match stop


time interval in between 2 falling edges
Zs
up capture
Parts Count Objects use counter Option

CAP 1 O Pint 18 Altfunz Timers Creo


Pin select
Pin1.18 Altfun3
register3 2 for CAP 1.0
00000
PinselectReg 3
ftp.ggpinio No weed to torn
on timers as
C it is already on

É
PI Select the eat Ur
Use the counter control evegister
Sas
for timers

Int P CLA 0 O O
Risingedge on O 1
as no Ga fully edge y o
crossing point bothlubing 0 I 1
Is to be counted falling edge
so use falling
edge here
Parts
To Reset and enable the timer

reset the timer so that it starts


from zero Treon
I part
ofdues Party generating a I see delay
using
Olp match
for 1sec delay use match leg Timoteo
no Otp is leg
48 MHz I CCLN
Peak Selection 0
beg
Bit 2 3 PCLK TIMER OO
Bit 9 5 ALLA TIMERS
48mn34 12MHz 7 PCLA

TIP R
122 timer preseaber Valve 11
To 12MHz
12 1MHz
Parts
Interrupt weep every I see
Imm freq is feed into the Counter
BEBER

Expert selected
Mimms
Using matchregister

Is

once
Laafterdone
I
see
and timer is
not reset
timer is stopped
after I see
Parts No op is req value stored in matchReg

All the ent 01ps are set to zero

To MRO 14106 1 7999999


Ts timer o
o 93193 tomtit agamas

Interrupt
Raised
tower stopped

To for finding the interval b w the Objects


using Yp Capture
Pants
a Timer2 PIN0.4 Altfine3
000 selects attune3
9,999
9 an selection

Il in prescaber

final Cik frey 1MHz


Pat
selecting the pan as Yp to counter for
Timer2
CCIR

un
G Peck

bag
Interrupt
Edocapture
capture to falling edge
deveninterrupt
coves
beset enable

You might also like