Experiment-6: Generating Square wave with 8254 PIT 8086 Programming by Ravinder Nath Rajotiya - April 15, 2021May 6, 20220 Share on Facebook Share Send email Mail Print Print AIM: Write a Program to generate a square wave using 8254. Write an assembly language program in 8085 microprocessor which generates 1 KHz square waveform by using counter 2 as a binary counter if clock frequency of 8254 is 2 MHz. Table of Contents Toggle Objective:Assumption –Modes of Operation:Mode-3 is used for square wave generation. So it is explained in detail.Programming the 8254 for Square wave generationAlgorithm Steps:Program: Objective: To understand the mode of operation of 8254 To understnd the calculation of count value To develop the program for generating a square wave pulse using 8254 Assumption – Assume the port addresses are 8C01 H, 8C03 H, 8C05 H, 8C07 H for Counter-0, Counter-1, Counter-2, Control Register. Modes of Operation: 8254 can operate in six mode of operations. These are: Mode-0: Interrupt on Terminal Count –Mode 0 is typically used for event counting Mode-1: Hardware Retriggreable One Shot Mode-2: Rate Generator) –Initially value of OUT is low. When counting is enabled, it becomes high and this process repeats periodically. Mode-3: Square Wave Generator Mode-4: Software Triggered Strobe Mode-5: Hardware Triggered Strobe –OUT will initially be high. Counting is triggered by a rising edge of GATE. When the initial count has expired, OUT will go low for one clock pulse and then go high again Mode-3 is used for square wave generation. So it is explained in detail. Mode 3 (Square Wave Generator) – Counting is enabled when GATE = 1 and disabled when GATE = 0. This mode is used to generate square waveform and time period (equal to count) is generated. Control Word Format: If N is count and is even then ontime of wave = N/2 and offtime = N/2 If N is odd the on time = (N + 1) / 2 and offtime = (N – 1) / 2 For the above problem, 8254 must work in Mode 3 which is the square wave generator. Count for register is given as clock frequency / square wave frequency count = 2 MHz / 1 KHz = 2000 decimal to hex: 16 | 2000 16 | 125 -→0 16 | 7 → 13 → D 16 | 0 → 7 2000 = (07C0) H Now the data is 16 bit so value of RL1 = 1 and RL0 = 1 in Control Register. As we want to select C2 (Counter 2) the value of SC1 = 0 and SC0 = 1 in Control Register. Value of M2 = 0, M1 = 1 and M2 = 1 for Mode 3 in Control Register. For binary counter value of LSB in CR is 0. Hence the Control Register (CR) is given by, D7 D6 D5 D4 D3 D2 D1 D0 1 0 1 1 0 1 1 0 Control Word FORMAT; Counter-1 in Mode-3, and Binary COUNT For Counter-0 CW =36h For Counter-1 CW = 76h For Counter-2 CW = B6h Programming the 8254 for Square wave generation Algorithm Steps: Step-1: Set CWR address in DX Step-2: Transfer the CW value (B6 for counter-2 ) at CWR address Step-3: Set the counter address for counter-2 Step-4: Set the count value in counter 2, with LS Byte first then the MS Byte Program: Address Opcode and Operands Mnemonic Comments 1000: 0200 BA 07 8C MOV DX, 8C07h ; CWR Address 1000:0203 B0 B6 MOV AL, B6H 1000:0205 EE OUT DX AL LOAD CWR 1000:0206 BA 05 8C MOV DX, 8C05H COUNTER 2 ADDRESS 1000:0209 B0 D0 MOV AL, 0D0H 1000:020B EE OUT DX, AL Load counter-2 LS Byte 1000:020C B0 07 MOV AL, 07 1000:020E EE OUT DX, AL Load counter-2 MS Byte 1000:020F EB F8 JMP 0209 LOOP Before executing the program, you have to provide the clock input to the CLK2 of the 8253(timer-2). This can be done by shorting the jumper (out of the black of two) located below 8253 IC (U-22) * * ViVa Questions: Q1. name the different modes of operations of 8254 Ans:8254 can operate in six mode of operations. These are: Mode-0: Interrupt on Terminal Count –Mode 0 is typically used for event counting Mode-1: Hardware Retriggreable One Shot Mode-2: Rate Generator) –Initially value of OUT is low. When counting is enabled, it becomes high and this process repeats periodically. Mode-3: Square Wave Generator Mode-4: Software Triggered Strobe Mode-5: Hardware Triggered Strobe –OUT will initially be high. Counting is triggered by a rising edge of GATE. When the initial count has expired, OUT will go low for one clock pulse and then go high again Q2. Write the control word for generating a square wave pulse using counter-0 binary count.Ans: D7 D6 D5 D4 D3 D2 D1 D0 0 0 1 1 0 1 1 0 Counter-0 LSB first then MSB Mode-3 Binary Q3. What will be the value of the count if the clock frequency top 8254 is 1MHz and it is required to get a pulse of 1KHz square wave. Ans: count = 2 MHz / 1 KHz = 2000 decimal to hex: 16 | 1000 16 | 65 -→4 16 | 4 → 1 16 | 0 → 4 1000 = (0414) H Thus the count to be loaded in the counter is 0414h Share on Facebook Share Send email Mail Print Print