0

I'm trying to make a hardware delay using the counter2 of 8254 IC by creating a square wave and counting the number of times the square wave value got 1:


mov al, 10101110B
out 43H, al
        
mov al, 33h
out 42H, al
mov al, 05h
out 42H, al
        
;;enable the port
in AL, 61H
push ax
OR AL, 00000011B ;;enable PB0 and PB1
out 61h, al
        
mov cx, 200
;;make delay
        
waitf1:
        in al, 62H ;; Reads from 62H The result is always 20h
        and al, 20h 
        cmp al, ah
        je waitf1
            
        mov ah, al
        loop waitf1
            
        
        

pop ax
out 61h, al

the program stocks in a loop as the value read from port 62h is alwas 20h (PC5 is always 1) while I expected it to be a square wave.

Pouria
  • 49
  • 8

1 Answers1

1

I'm wondering if it matters if the timer is in mode 2 or not. Here old assembly code I used to get an accurate time from timer0 with MSDOS. The jmp short $+2 delays were needed, perhaps because the cpu was running a bit faster than the ISA bus. Since this code gets gets a 16 bit count from the timer, bit 15 could be used for a square wave pattern. The interrupt count read into dx in this code is not needed for the original question.

TMR     equ     040h
Tmrgt0: cli
        mov     dx,IntCnt               ;get current int count
        mov     al,0c2h                 ;output read channel 0 cmd
        out     TMR+3,al
        jmp     short $+2
        in      al,TMR                  ;get bit  (15  )
        test    al,2                    ;br if in mode 2
        jz      Tmrgt1
        shl     al,1
        jmp     short $+2
        in      al,TMR                  ;get bits ( 7-0) << 1
        mov     ah,al
        jmp     short $+2
        in      al,TMR                  ;get bits (14-8) << 1
        sti
        xchg    al,ah                   ;ax = bits 15-0
        rcr     ax,1
        test    ax,07fffh               ;if bits (14-0) == 0 re-get
        jz      Tmrgt0
        cmp     dx,IntCnt               ;if int occured re-get
        jne     Tmrgt0
        neg     ax                      ;make count positive
        ret

Tmrgt1: in      al,TMR                  ;get bits ( 7-0)
        mov     ah,al
        jmp     short $+2
        in      al,TMR                  ;get bits (15-8)
        sti
        xchg    al,ah                   ;ax = bits 15-0
        cmp     dx,IntCnt               ;if int occured re-get
        jne     Tmrgt0
        neg     ax                      ;make count positive
        ret
rcgldr
  • 27,407
  • 3
  • 36
  • 61
  • It's not working with mode 3 too. I also changes to frequency to lowest possible (the value in 42H to 0xFFFF ) but no change. It seems that no square wave is generated but the output is always 1 – Pouria Jun 03 '21 at 15:06
  • @Pouria - I recommend using one of the bits of the count as retrieved in the above code for a square wave. For timer0, in one of the modes you get a square wave, in the other mode, you just get a pulse, and it's one of the transitions that is connected to the edge driven interrupt pin normally used for the 18.2hz ticker. What are you initializing the reload value for the counter to? – rcgldr Jun 03 '21 at 21:14