0% found this document useful (0 votes)
9 views5 pages

Unit 2 Timer - CIP51 - Calculations

The document outlines the functionalities and applications of timers in microcontroller systems, specifically focusing on the C8051F340 architecture. It details the operation modes of the timers, their configuration registers, and provides exercises for students to practice timer calculations. Additionally, it includes solved and unsolved examples to aid in understanding timer setup and delay calculations.

Uploaded by

Soham
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)
9 views5 pages

Unit 2 Timer - CIP51 - Calculations

The document outlines the functionalities and applications of timers in microcontroller systems, specifically focusing on the C8051F340 architecture. It details the operation modes of the timers, their configuration registers, and provides exercises for students to practice timer calculations. Additionally, it includes solved and unsolved examples to aid in understanding timer setup and delay calculations.

Uploaded by

Soham
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/ 5

Department of Electrical and Electronics Engineering

Academic Year: 2024-25


Course: Microcontroller and Applications (ECE2PM04A)
Unit 2: CIP51 Architecture
Self Study Topic for students: Week 7 Timers and Timer Calculations

TIMERS
Link: https://www.youtube.com/watch?v=kaCOTQwo7KY
• Timers are used for: interval timing, event counting or baud rate generation
• In interval timing applications, a timer is programmed to overflow at a regular interval
and the following:
• Set the timer overflow flag or
• Generate an interrupt
• This can also be used to generate waveforms at set frequencies
• Event counting is used to determine the number of occurrences of an event, rather than to
measure the elapsed time between events. In this case, the timer functions as a counter.
• An “event” is any external stimulus that provides a high-to-low transition at the
selected input pin
• The timers can also function as the baud rate generators for the C8051F340’s internal
serial ports (UART0 and UART1)
• “Baud rate” is the bit rate of the serial port
(the time period of a bit)
C8051F340 TIMERS
• C8051F340 has four counter/timers: Timer 0, Timer 1, Timer 2 and Timer 3
• Timer 0 and Timer 1 are nearly identical and have four primary modes of operation.
• Timer 2 and Timer 3 offer 16-bit and split 8-bit timer functionality with auto-reload.
Timer/ Counter Registers
Description Register Function
Name
Timer Control TCON Enables and disables Timer0 and Timer1, Also has overflow
Register flag and interrupt related bits

Timer Mode TMOD Selects the timer or counter operation with C/T0 and C/T1
Register bits, Also has mode selection for timer0 and timer1

Clock Control CKCON Controls clock supplied to timer0 and timer 1 if configured
to use prescaled clock inputs, or system clock

Timer 0 low byte TL0 Lower byte of timer0

Timer 0 high byte TH0 Higher byte of timer0


Timer 1 low byte TL1 Lower byte of timer1

Timer 1 high byte TH1 Higher byte of timer1

Timer 2 low byte TMR2L

Timer 2 High byte TMR2H

Timer 0 & 1 Mode 1: 16 bit Counter/Timer


• Mode 1 operation is the same as Mode 0, except that the counter/timer registers use all 16 bits
• The counter/timers are enabled and configured in Mode 1 in the same manner as for Mode 0.
• TH0 and TL0 holds the count. When the count in TH0 and TL0 overflows from all ones to
0x00, the timer overflow flag is set. The count in TH0 and TL0 should be loaded for next
iteration.
• If Timer 0 interrupts are enabled, an interrupt will occur when the TF0 flag is set. The count in
TH0 and TL0 should be loaded for next iteration.
SFR- CKCON: Clock Control

SFR TMOD: Timer Mode(First 4 bits bit 7 to bit 4 dedicated to timer 1)

SFR TCON: Timer Control


Exercise 1:
Solved: Configure TMOD register for Timer 0 in mode 1
Ans: TMOD=0x01H

Gate1 C/T1 T1M1 T1M0 Gate0 C/T0 T0M1 T0M0

0 0 0 0 0 0 0 1

Unsolved:Configure TMOD register for the following:


• Timer 1 in mode 1
• Timer 1 in mode 2
• Timer 0 in mode 1
• Timer 0 in mode 2
• Timer 1 in mode 2 and Timer 0 in mode 1
Exercise 2: Time Delay Calculations – For Mode 1
Note: Assume SystemClock = 12MHz
Time period of 1clock cycle = (1/SystemClock)
Count = (Required delay/Time period of 1 clock cycle)
Value to be loaded in timer register,
Value (in decimal)= 65536-Count
Convert Value from decimal to hex (YYXX)
Load YY in THx, and XX in TLx register
Solved Example: Calculation Mode 1
Find the value to be loaded into TMOD and timer register if required delay is 3msec (TIMER0
AND MODE 1)
Ans: TMOD=0x01 TH1=0x73 TL1=0x52
Unsolved examples:
 Find the value to be loaded into timer register if required delay is 4msec (timer1 and mode 1)
 Find the value to be loaded into timer register if required delay is 5msec (timer0 and mode 1)
 Find the value to be loaded into timer register if required delay is 1.5msec (timer0 and mode 1)

You might also like