Pouria
Pouria

Reputation: 49

x86 timer2 of 8254/8253: creates always 1s instead of wave

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.

Upvotes: 0

Views: 104

Answers (1)

rcgldr
rcgldr

Reputation: 28826

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

Upvotes: 1

Related Questions