Frequency Measurement of a Square Wave in 8085 Assembly

Frequency Measurement of a Square Wave in 8085 Assembly

Published by Arun Isaac on

Tags: 8085, assembly

This code snippet continuously reads a square wave from Port A of the 8255 (programmable peripheral interface) and thus measures its time period.

This code snippet continuously reads a square wave from Port A of the 8255 (programmable peripheral interface) and thus measures its time period. The code is organized into four subroutines - counton (to measure the ON time), countoff (to measure the OFF time), initports (to initialize the 8255 with the appropriate control word), and the main subroutine.

Basically, this code continuously reads the square wave signal from Port A. As long as it is reading an ON state, it loops around in the 'counton' subroutine incrementing a counter for each iteration of the loop. As soon as it detects an OFF state, it stores the ON count value in memory and jumps to the 'countoff' subroutine. In the 'countoff' subroutine, the time in the OFF state is measured by incrementing a counter. As soon as an ON state is detected, the OFF count value is stored in memory and the execution jumps back to the 'counton' subroutine.

Based on delay calculations, one 'count' of this code corresponds to 33 T states or 11us (assuming 3 MHz clock). So, 11us can be thought of as the sampling period.

In the code below, PPICNT is the 8 bit address of the control port of the 8255. The input square wave must be connected to bit 0 of Port A.

main:           CALL initports
                JMP counton

initports:      MVI A, 90h
                OUT PPICNT
                RET

counton:        LXI H, 0000h
loopon:         INX H
                IN PORTA
                CPI 00h
                JNZ loopon
                SHLD 4300h
                JMP countoff

countoff:       LXI H, 0000h
loopoff:        INX H

                IN PORTA
                CPI 01h
                JNZ loopoff
                SHLD 4302h
                JMP counton