Presentation is loading. Please wait.

Presentation is loading. Please wait.

8051 Timers Timers are the peripherals of the 8051 Microcontroller.

Similar presentations


Presentation on theme: "8051 Timers Timers are the peripherals of the 8051 Microcontroller."— Presentation transcript:

1 8051 Timers Timers are the peripherals of the 8051 Microcontroller.
Timers are peripherals in any of the controllers. This peripheral is mainly used in time based applications. A timer is a specialized type of clock. It can be used to control the sequence of an event or process. The 8051 comes equipped with two timers (Timer 0 and Timer 1). These timers are 16 bit registers.

2 General Functions of the Timer
Keeping time and/or calculating the amount of time between the events. Counting the Events themselves, or Generating baud rate for the serial port. Note: While generating delay this circuitry worked as Timer. While counting the number of events occurred at the particular time this circuitry worked as counter.

3 Baud Rate A number related to the speed of data transmission in a system. The rate indicates the number of electrical oscillations per second that occurs within a data transmission. The higher the baud rate, the more bits per second that are transferred.

4 For Timer: (Internal Pulses Working)
Crystal Oscillator / 12 Circuitry TIMER “X” MHz f = KHz Timer will get clock frequency from the crystal oscillator that is MHz. This frequency is given as input the circuitry that is called /12 (Divide by 12) circuitry. Because one machine cycle is nothing but 12 clock cycles.

5 For Counter : (External Pulses Working)
Timer 0 T1 Timer 1 T0 and T1 is the external input. So counter will get external input from the T0 and T1

6 SFRs relating to Timers
SFR Name Description SFR Address TH0 TIMER 0 Higher byte 8Ch TL0 TIMER 0 Lower byte 8Ah TH1 TIMER 1 Higher byte 8Dh TL1 TIMER 1 Lower byte 8Bh TCON TIMER Control 88h TMOD TIMER Mode 89h

7 TMOD Register If we program lower nibble, Timer 0 will get affected.
Gate C/T M1 M0 Timer 1 Timer 0 If we program lower nibble, Timer 0 will get affected. If we program higher nibble, Timer 1 will get affected.

8 Gate: 0 – Software Control 1 – H/W Control (Instruction with Interrupt Signal) C / T: 0 – Timer 1- Counter

9 Mode Bits Information M0 and M1
Description 13 bit Timer 1 16 bit Timer 8 bit Auto Load Split Timer

10 TCON Register LSB MSB Interrupts Timers TF1 TR1 TF0 TR0 IE1 IT1 IE0

11 External Interrupt 1 Edge Flag IT1 External Interrupt 1 Type Flag IE0
Bit Names Description TF1 Timer 1 Overflow Flag TR1 Timer Run Control bit TF0 Timer 0 Overflow Flag TR0 Timer 0 Run Control Bit IE1 External Interrupt 1 Edge Flag IT1 External Interrupt 1 Type Flag IE0 External Interrupt 0 Edge Flag IT0 External Interrupt 0 Type Flag

12 Hardware Configuration of Timers

13 Timer Mode Explanations
Mode 0 : TLX = 5 bit, THX = 8 bit Timer Address : 0000H to 1FFFH TLX THX TFX Interrupt

14 Timer Address : 0000H to FFFFH
Mode 1 : TLX = 8 bit, THX = 8 bit Timer Address : 0000H to FFFFH TLX THX TFX Interrupt

15 TLx = 8 bits THx = for storing Value, 00H to FFH
Mode 2 : Auto Reload (It is 8 – bit Mode), Because we can supposed to use only TLX 8 – bit only. TLx = 8 bits THx = for storing Value, 00H to FFH We have to initialize the TL register with some value. TH register is initialized with auto reload value. Interrupt TLX TFX Reload TLx

16 Mode 3 : TL0 = Timer 0 and TH0 = Timer 1 Timer 1 = 16 bit Timer
Interrupt TL0 TF0 Interrupt TH0 TF1

17 Time Delay Calculation
If we want to generate a time delay of 10 microseconds (or) 1 milliseconds. Step 1: Divide the required time delay by 1.085 Microseconds. Why Microseconds? MHz / 12 = 9.216KHz So, T = 1/f = 1/9.216KHz = 1.085Microseconds.

18 Time Delay Calculation
Step 2: (Maximum value of Timer + 1)10 – (n)10= (Z)10. Maximum value of timer is depending on the mode of a Timer. In case of Mode 0 : Maximum value is = 1FFF. In case of Mode 1 : Maximum Value is = FFFF. Note : FFFF + 1 =

19 Time Delay Calculation
Step 3: Convert (Z)10 to (YYXX)10 It will be loaded into TH and TL with YY & XX Respectively. TH = YY. TL = XX.

20 Example: Generate a time a time delay of 250microsecods. Assume Timer mode is 1. 1) (n)10 = 250microsecods/1.085microseconds = 230microseconds. 2) (z)10 = (FFFF+1) – (n)10 = – 230 = 3) Hexadecimal Value of is FF1AH. YY = FF XX = 1A TH = FFH and TL = 1AH


Download ppt "8051 Timers Timers are the peripherals of the 8051 Microcontroller."

Similar presentations


Ads by Google