flat assembler
Message board for the users of flat assembler.

Index > Main > play with lpt IRQ7

Author
Thread Post new topic Reply to topic
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
hey hey hey!

since i want to test the usefullness of what i've writen in my book, i play with lpt irq7, and the main problem i meet is the irq firing with the switch.
up to 15 interrupts can be fired with just one push on the switch...
why?

simply because when you push a button, there are many many little edges before to have the definitive state of the button.

on MCU, the problem is solved with a little delay, but on a computer.
the CPU is so fast that the delay can be very limitative (mov ecx,0FFFFFh, loop $) and can become a problem.

in this code:
Code:
        org 100h
        push 0b800h
        pop es
        mov di,0
;activer irq7 sur ack
        mov dx,37Ah
        in al,dx
        or al,10h
;et positionner /strobe à 5 volts
        and al,not 1
        out dx,al
;initialiser le port
        mov dx,378h
        mov al,0ffh
        out dx,al
;désactiver les irq
        cli
;installer le vecteur
        mov ax,0
        mov fs,ax
        mov word[fs:15*4],irq7
        mov ax,cs
        mov word[fs:15*4+2],ax
;activer irq7
        in al,21h
        and al,not 80h
        out 21h,al
;activer les irq
        sti
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;boucle
@@:
        mov al,byte[ticks]
        call b2h
        rol eax,8
        ror ax,8
        and eax,00ff00ffh
        or eax,4f004f00h
        mov [es:di],eax
        cmp [ticks],150
        jb @b
;quitter
        ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
irq7:
        push ds cs
        pop ds
        inc [ticks]
        ror [value],1
        mov dx,378h
        mov al,[value]
        out dx,al
;eoi
        mov al,20h
        out 20h,al
        pop ds
        iret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;données
value   db 1
ticks   db 0
include 'b2h.inc'
    

ACK (pin 10 of LPT connector) is pulled at 2.5 volts.
to fire an IRQ, should pull down this pin to gnd.


the IRQ rotates a value, outputs it on the lpt data port (to display on leds), and increment a tick.
the tick count is displayed on the screen.
and when it reaches 150, it will exit.

then, as i don't want to do a delay inside the LPT IRQ7 routine, i plan on something besed on PIT IRQ0.

but... it is a little complex because, even if IRQ7 is fired many times, only one IRQ should be effective in a short time (approximatelly 100ms).
then, it lets you fire 10 IRQ7 by hand with the switch.

i will find a way to do that. but before, go to sleep because the sleep state is the best way to find the evident solutions.


Description:
Filesize: 1.86 KB
Viewed: 4956 Time(s)

04EP10.png


Post 16 Mar 2011, 00:46
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
shoorick
theoretically, you can use flip-flop, monostable multivibrator(?) or at least capacitor to avoid chatter of button's contacts. i never played with interrupts, but thought interrupt has to disable hardware interrupts and interrupt processing subroutine must enable it again, maybe i'm wrong. under what OS you are testing that?

i mean if you run it under windows it may enable it by itself so single process will not be able to disable hardware interrupts for whole system. it may be just partially compatible to let printers print normally and protect system from hanging.
Post 16 Mar 2011, 10:52
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
i test under win98 (that is the best for low level asm).

i just have a simple thoery, based on the flipflop.
but as i don't wnat to overcomplicate the montage, i will do a software flipflop, using pit ticks counter from bios.

when irq7 is fired for the first time (after the last irq7), the routine will set some flag somewhere.

if after one tick T of 18.2 Hz pit (i think it is enough) the ack line is down, means it is an interrupt. else, it is not an interrupt, and then, the routine should not be executed.

but how to do that.

i have all the day to find a way, without modification of irq0, and with the less code inside mainloop.
Code:
ACK up  IRQ7      action         IRQ7        no action
        v   v   v v ack=0        v           v  ack=1
         ----T-----               -----T-----.
--------|         .            /-\ /---------°
        V /-\ /-\ .            | V |
        | | V | V .            | | |
        \-/ \-/ \-°------------/ \-/                           
    
Post 16 Mar 2011, 11:48
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
shoorick
on the first IRQ save current ticks count into var. on the next time compare ticks with that var - the differense is small, then ignore it, otherwise it is the new interrupt - save new ticks count and process IRQ.
Post 16 Mar 2011, 13:29
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
the problem is with the switch release, as it will launch the same process as switch hold, i think i will be forced to use IRQ0 as a IRQ7 tester.

if IRQ7 is fired, it pass a function pointer to IRQ0.
IRQ0 will wait a little time before to test the ack line, and if the ack line is clear, it is a IRQ7, ifg the ack line is set, it is not a IRQ7.

but it will limit the action to one or two instruction (set or increment a flag), in order to don't use a lot of irq0 time.

ones i will have a good technique for switch handling, i will be able to do it on PIC12F675, using timer.
Post 16 Mar 2011, 14:07
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
shoorick
isn't 7400 enough? Wink


Description:
Filesize: 3.06 KB
Viewed: 4894 Time(s)

rs.png



_________________
UNICODE forever!
Post 16 Mar 2011, 14:31
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
no hardware.
just software.

the hardware should be the less possible.
just the switch as shown in the original post, due to some economicotechnical constraint.
and then, it is done.
very easy in fact.

Code:
        org 100h
        push 0b800h
        pop es
        mov di,0

        mov dx,37Ah
        in al,dx
        or al,10h
        and al,not 1
        out dx,al

        cli
        mov ax,0
        mov fs,ax
        mov eax,[fs:8*4]
        mov [irq0.old],eax
        mov word[fs:15*4],irq7
        mov word[fs:8*4],irq0
        mov ax,cs
        mov word[fs:15*4+2],ax
        mov word[fs:8*4+2],ax
        in al,21h
        and al,not 81h
        out 21h,al
        sti
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@:
        mov al,byte[ticks]
        call b2h
        mov [es:di],al
        mov [es:di+2],ah
        cmp [ticks],100
        jb @b
        mov al,0ffh
        mov dx,378h
        out dx,al
        ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
irq0:
        inc [.ticks]
        cmp [.func],0
        je @f
        call near word[.func]
@@:
        jmp far dword[.old]
align 4
.ticks  dd 0
.old    dd 0
.func   dw 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
irq7:
        cmp [irq0.func],.fire
        je @f
        mov [.ticks],1
        mov [irq0.func],.fire
@@:
        mov al,20h
        out 20h,al
        iret
.value   db 1
.ticks   db 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.fire:
        dec [.ticks]
        je @f
        ret
@@:
        mov dx,379h
        in al,dx
        test al,40h
        jne @f
        inc [ticks]
        mov dx,378h
        mov al,[.value]
        out dx,al
        rol [.value],1
@@:
        mov [irq0.func],0
        ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ticks    db 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
include 'b2h.inc'
    


the old IRQ0 handler is still called (jmp) and then, no problem with BIOS compatibility.

i like this way to do because it is something like... simple and efficient.

just wait one tick of the 18.2Hz pit, and then, read back the value of ACK bit on LPT port.

if this bit is clear, IRQ7, if not, noting.
and it works fine now.

i've tryed with a frequency reprog.. and it don't bring any benefit, just takes more instructions to program the pit frequency.

then, i adopt this code. sorry for the useage of IRQ0... but, it is there, not only for the bios, but to be used by applications.

about the 7400 shematic, it is cool, but in what application i want to do, it is too much, i should do something with the les components as possible.

i still should put a quartz clock because for the application, i need a precise timing (motor cycle shift light), and for the button, i need something really simple, just to program the shiftlight to a given rotation speed/2. or do it manually by a sequence of clicks.

for example:
1 long click (1 or 2 second), put the device in programming mode, led on
5 fast clicks means shift light at 5000rpm, each click makes the led blink one or 2 times.
1 long click means programming done
led blinking 5 times to show it is well programmed.
and lets go for the circuit session.

on the pic, there are some input schmit triggered, then, just a pull up resistor would be enough..
Post 16 Mar 2011, 18:34
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
shoorick
well, let's what it will be than Wink
Post 17 Mar 2011, 05:50
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.