Docsity

Slides on Microcontroller Timing Functions | ELEC 5260, Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download Slides on Microcontroller Timing Functions | ELEC 5260 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Microcontroller Timing

Functions

Reference:

LPC 2292 User Manual

Timers and counters

 Very similar:

 a timer is incremented by a periodic signal;

 a counter is incremented by an asynchronous, occasional

signal.

 Rollover causes interrupt or sets a testable flag”

 Programmable counter, prescaler, operating mode

binary counter

detect

rollover

interrupt flag

interrupt mask

prescale

clock

or

async signal

SW testable

external pin

Watchdog timer

 Watchdog timer is periodically reset by

system software.

 If watchdog is not reset, it generates an

interrupt to reset the host.

 Use to detect problems with host

host CPU

watchdog

timer

interrupt
reset

General purpose timer

32-bit Prescaler

(PC)

32-bit Timer

Counter (TC)

Pclk

Timer Control

(TCR)

Prescaler

Register (PR)

  • Prescaler increments on Pclk
  • Counter increments on Prescaler rollover
VLSI
Peripheral
Clock

Counter increments when prescaler matches prescaler

register (prescaler resets to 0)

Capture

Registers (4)

Match

Registers (4)

Pin

Pin

IRQ
IRQ
IRQ

reset (^) match

CR3-CR
MR3-MR

Main Timer/Counter Registers

 Timer Count (TC) : T0TC, T1TC

 32-bit count

 Prescale Counter (PC) : T0PC, T1PC

 32-bit prescale counter, increments on Pclk

 Resets and increment TC when PC = PR

 Prescale Register (PR): T0PR, T1PR

 Maximum 32-bit prescale count

 Timer Control Reg. (TCR): T0TCR, T1TCR

 Bit0=TC/PC enable, Bit1=TC/PC reset

Timer Control Register

Enable timer counter and prescale counter

1 = enable, 0 = disable

Timer0: T0TCR, Timer1: T1TCR

Reset timer counter and prescale counter

(remain reset until this bit = 0)

Capture Control Register (CCR)

Timer0: T0CCR, Timer1: T1CCR

Interrupt on CAP0.n “event”
Load CR0 with TC on CAP0.n falling edge
Load CR0 with TC on CAP0.n rising edge
CR3 CR2 CR

Capture example

 Measure period of a waveform

 Capture time at each rising edge

st

edge = time T

nd

edge = time T

 Waveform period T = T2-T

T1 T
T

Match registers

 Program match register with desired time to trigger

an “event”

 Trigger when match register = TC

 Interrupt on match event (if enabled)

 TC can be continuous, reset, or stopped on event

 Can force state of an output pin (low,high,toggle)

 Match registers MR0,MR1,MR2,MR

 Output pins:

 MAT0.0, MAT0.1, MAT0.2, MAT0.

MAT1.0, MAT1.1, MAT1.2, MAT1.

 Configure in External Match Register (EMR)

External Match Control Register

Timer0: T0EMR, Timer1: T1EMR

External match 0:

state of pin MAT0.

on match of MR

Control and status of external match pins

MR3 MR2 MR

Control MAT0.0 on match

00 – nothing

01 – reset

10 – set

11 - toggle

MR3 MR2 MR

Match example

Match example

Real time clock

 Set of counters to measure time

 Maintains calendar and clock

 Seconds, minutes, hours, day of month, month,

year (to 2099), day of week, day of year

 Alarm registers trigger events at designated times

 Low power mode

 Battery operation while CPU idle

Real time clock structore