Presentation is loading. Please wait.

Presentation is loading. Please wait.

ENEE 440 Chapter 7 8254 Timer 8254 Register Select The 8254 timer is actually 3 timers in one. It is an upgraded version of the 8253 timer which was.

Similar presentations


Presentation on theme: "ENEE 440 Chapter 7 8254 Timer 8254 Register Select The 8254 timer is actually 3 timers in one. It is an upgraded version of the 8253 timer which was."— Presentation transcript:

1

2 ENEE 440 Chapter 7

3 8254 Timer

4 8254 Register Select The 8254 timer is actually 3 timers in one. It is an upgraded version of the 8253 timer which was used in the PC/XT. The PC/AT uses the 8254. The decoding scheme is shown below: -CS A1 A0 REGISTER 0 0 0 Counter 0 0 0 1 Counter 1 0 1 0 Counter 2 0 1 1 Control Register 1 X X8254 NOT SELECTED

5 8254 Timer Summary The counters are 16 bits wide. The count is loaded and read 8 bits at a time. The order is always LSB first and then MSB. CLK is the frequency of the input clock. OUT is the output which depends on the mode of operation. GATE disables the counter with 0V and enables it with 5V.

6 8254 Timer Modes... MODE 0Interrupt on terminal count: The output goes high when the counter decrements to zero(TC). This output can be connected to an external device to signal an interrupt. MODE 1Hardware retriggerable one-shot: Also called programmable one-shot. The output goes low when triggered by a 0-1 pulse applied to the gate input. The output goes high on TC (count down to zero). Retriggerable means that during the count-down another 0-1 pulse can retrigger the counter to reload the initial count and start the count-down again. Thus the width of the output (one-shot) can be increased.

7 8254 Timer Modes... MODE 2 Rate Generator: This gives a periodic output whose frequency depends on the number N loaded into the counter. This is a divide by N counter. The output stays high until the counter decrements to 1. The output then goes low for one clock cycle and the counter is reloaded with the initial count N. The cycle is repeated.

8 8254 Timer Modes... MODE 3 Square Wave Generator: If N is even, output is high for N/2 clock cycles and low for N/2 pulses. Thus the duty cycle is 50% and it is a divide by N counter. If N is odd then OUT is low for (N-1)/2 clock cycles and high for (N+1)/2 clock cycles. The duty cycle for odd N depends on N. MODE 4 Software triggered strobe: OUT stays high for N+1 clock pulses and then goes low for one clock pulse. The output is not periodic. To repeat the process, the counter must be reloaded.

9 8254 Timer Modes... MODE 5 Hardware triggered strobe: A 0-1 pulse on GATE will trigger the counter and the output will stay high for N+1 clock pulses and then go low for one clock pulse (cycle). If the gate is triggered during the countdown, the count will start all over again. The output is not periodic.

10 Time out....... for examples! The base address of an 8254 is 350H. CLK 2 is connected to a 200kHz clock. Write a program to generate a 40 kHz square wave. What is the duty cycle of this square wave?

11 8253/4 Control Word

12 Solution... Address of counter2 is 352H and that of the control register is 353H. We need N=5. Our square wave will be high for 3 clock cycles and low for 2 clock cycles. The duty cycle is 3/5 *100 = 60%. We need the control word. Looking at the chart for the control word, we have 10 for counter2, 01 for LSB,011 for mode 3 (square wave) and 1 for BCD The control word is 97

13 Program... Here is the program (finally!): mov dx, 353h; control register mov al, 97h; control word. out dx, al; counter2, mode 3, BCD counting dec dx; equals mov dx,352 mov al, 05h; N=5 out dx, al; No comments!

14 8253/4 Timer in the PC

15 Happy birthday to you..... and other loony tunes! The speaker will be turned off completely if bit 1 of port 61h is 0. Irrespective of the output at OUT2, the output of the NAND gate will stay high. The speaker can sound only if there is a frequency at the output of the NAND gate. If bit1 is 1 then OUT2 will sound the speaker if GATE 2 is enabled by bit 0 of port 61h also being high. Here is a recipe to generate music:

16 Happy birthday to you... 1. Program the 8254 counter 2 to generate square waves. 2. The frequency should be in the "music" range, say 100 to 1000 Hz. 3. Set bits 0 and 1 of port 61h to 1 without messing up the other bits. 4. Insert a delay for the length of time the music should continue. 5. Remember to turn the speaker off by restoring the original setting of port 61h. 6. If step 5 is messed up, the music will never stop!

17 A different tune! There is another method (not highly recommended but works for me!) to sound the speaker without using the 8254 timer! Set bit 0 of port 61h to 0. This disables the timer's output for ever. Now turn bit 1 of port 61h ON and OFF. This pulses the speaker! Make sure you have a software delay between ON and OFF and again between OFF and ON. The delay will determine the frequency of the speaker's output. You will need a different (much longer) delay to establish the time interval for which the tune will play.


Download ppt "ENEE 440 Chapter 7 8254 Timer 8254 Register Select The 8254 timer is actually 3 timers in one. It is an upgraded version of the 8253 timer which was."

Similar presentations


Ads by Google