How to invert low input to high output using interrupts

Flint10

New Member
I am using an hardware interrupt to read the state of 8 input pins on PinsC.

Whilst in the Interrupt routine is it possible to then invert that state and put that into 8 out pins on pinsD?

Cheers,
 

Flint10

New Member
Thanks Hippy.

Seems to work in a fashion.

But the outputs are not staying 'latched on' when more than one input is high. One output may stay on but the other(s) stay on fleetingly. This isn't correct is it?

My code is :

mainloop:
if b2 = %11111110 then goto glockset
if b2 = %11111101 then goto violinset
if b2 = %11111100 then goto gv
if b2 = %11111010 then goto gb
if b2 = %11110110 then goto gf
if b2 = %11101110 then goto gc
goto mainloop

glockset:
outpinsD = pinsC ^ $FF
goto mainloop

violinset:
outpinsD = pinsC ^ $FF
goto mainloop

gv:
outpinsD = pinsC ^ $FF
goto mainloop

gb:
outpinsD = pinsC ^ $FF
goto mainloop

gf:
outpinsD = pinsC ^ $FF
goto mainloop

gc:
outpinsD = pinsC ^ $FF
goto mainloop
 

MartinM57

Moderator
Some questions first...
- where is b2 assigned a value(s)?
- why do you do all the 'if' tests and do the same code on each 'goto' target?
- where is the interrupt code you initially referred to?
 

Flint10

New Member
Because of the problems with the outputs not staying on until the next interrupt I put the results of the if statements into the sub-routines to introduce a pause but this didn't help. I realise that normally the contents of the sub routines as they are can be left at the relevent line in the mainloop part.

Sorry for the omissions, here is the interrupt code along with the previous. Hope this is of help


init:
setfreq em40

let dirsB = %11111110
let dirsD = %11111111
hintsetup %00010001 ;set up B.0 as INT0 on bit 4 in rising edge interrupt
setintflags %00000001, %00000001 ;set hardware INT0 to interrupt on any event

goto mainloop


interrupt: ;check to see if any input is selected


let b2 = pinsC 'Get inputs 7 to 0
hint0flag = 0
hintsetup %00010001
setintflags %00000001, %00000001
return

mainloop:
if b2 = %11111110 then goto glockset
if b2 = %11111101 then goto violinset
if b2 = %11111100 then goto gv
if b2 = %11111010 then goto gb
if b2 = %11110110 then goto gf
if b2 = %11101110 then goto gc
goto mainloop

glockset:
outpinsD = pinsC ^ $FF
goto mainloop

violinset:
outpinsD = pinsC ^ $FF
goto mainloop

gv:
outpinsD = pinsC ^ $FF
goto mainloop

gb:
outpinsD = pinsC ^ $FF
goto mainloop

gf:
outpinsD = pinsC ^ $FF
goto mainloop

gc:
outpinsD = pinsC ^ $FF
goto mainloop
 

hippy

Ex-Staff (retired)
If you have the inputs you want to output inverted in 'b2' then the code possibly has to be changed to -

outpinsD = b2 ^$FF

But I'm not really sure what you want. A more detailed description and what your hardware actually is may help.
 

Flint10

New Member
If you have the inputs you want to output inverted in 'b2' then the code possibly has to be changed to -

outpinsD = b2 ^$FF

But I'm not really sure what you want. A more detailed description and what your hardware actually is may help.
Actually, I've been having trouble with the outputs not 'latching' for some time.

Please see attached schematic for the setup. The interrupt part is missing as this was going to be my next attempt...
The setup as shown works with the code shown below with the following problems:-

1) When a single input is present the relevent output goes high as expected. Condition acceptable.
2) When 2 simultaneous inputs are present both the relevent outputs do not stay high as expected. One stays high but the other stays high just fleetingly.
3) I can get both outputs to stay high if I put a pause into the sub-routine as in gosub routine cv: This is not the answer though because as soon as the pause times-out one of the outputs goes low. I need both outputs to stay high until a different input state is present.

Hippy, the reason I was asking about the inverse of the input pin states was because I thought that a hard interrupt might be the answer and I was going to incorporate that into the interrupt routine to save code space.

Am I missing something here, guys. My understanding is that as soon as an output is set high it should stay high until the program decides otherwise..... or is it that something external may be influencing the behaviour.... I'm at a loss...

Code

init:
setfreq em40

let dirsB = %11111110
let dirsD = %11111111

goto mainloop

mainloop:
b2 = pinsC
if b2 = %11111110 then gosub glockset
if b2 = %11111101 then gosub violinset
if b2 = %11111011 then gosub bourdonset
if b2 = %11110111 then gosub fluteset
if b2 = %11101111 then gosub cmelset

if b2 = %11111100 then gosub gv
if b2 = %11111010 then gosub gb
if b2 = %11110110 then gosub gf
if b2 = %11101110 then gosub gc
if b2 = %11111001 then gosub vb
if b2 = %11110101 then gosub vf
if b2 = %11101101 then gosub vc
if b2 = %11110011 then gosub bf
if b2 = %11101011 then gosub bc
if b2 = %11100111 then gosub fc

goto mainloop


glockset:
let pinsD = %00000001
return
violinset:
let pinsD = %00000010
return
bourdonset:
let pinsD = %00000100
return
fluteset:
let pinsD = %00001000
return
cmelset:
let pinsD = %00010000
return
gv:
let pinsD= %00000011
pause 1000
return
gb:
let pinsD= %00000101
return
gf:
let pinsD= %00001001
return
gc:
let pinsD= %00010001
return
vb:
let pinsD= %00000110
return
vf:
let pinsD= %00001010
return
vc:
let pinsD= %00010010
return
bf:
let pinsD =%0001100
return
bc:
let pinsD =%00010100
return
fc:
let pinsD =%00011000
return
 

Attachments

Top