Friday PASM puzzle - Reading an input as a Ternary value
Beau Schwabe
Posts: 6,575
I was playing with an idea I had last night, and came up with this and thought it might be useful. But can you figure out what's going on that makes this work? :-)
0 = LOW
1 = MIDDLE
2 = HIGH
Please use at least a 47 Ohm resistor on the I/O you select.
0 = LOW
1 = MIDDLE
2 = HIGH
Please use at least a 47 Ohm resistor on the I/O you select.
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
Pin = 0
OBJ
PST : "Parallax Serial Terminal"
PUB start|AsmValue
PST.Start(19200{<- Baud})
cognew(@PASM, @AsmValue)
repeat
PST.dec(AsmValue)
DAT org 0
PASM
andn dira, PINmask 'Make pin an input
Ternary
mov t1, #2 'Set maximum counts to 2
mov t2, #0 'Clear accumulator
'------------------------------------------------------------------------------
loop muxz outa, PINmask 'preset pin to opposite state ; remember still an input
or dira, PINmask 'Make pin an output
andn dira, PINmask 'Make pin an input
and PINmask, ina nr,wz 'Read Pin
if_nz add t2, #1 'Increment accumulator if input reads 1
djnz t1, #loop 'If counts are still available read the pin again
'------------------------------------------------------------------------------
wrlong t2, par 'Write result so we can see it
jmp #Ternary 'Do it all over again
t1 long 0
t2 long 0
PINmask long |<Pin

Comments
-Phil
careerist, eager beaver, geek, grind, nerd, smug, striver, swot, swotter
Which of those would be most common in this case? ;o)
No offense! Just joking! (You have to explicitly say this in these days)
Can you detect the bouncing of a switch with that?
With a current limiting resistor on either end (47 Ohm) you get the tristate voltage levels when sending simultaneous data.
47 47 TX >----/\/\----o----------------//----------------o----/\/\----< TX | | 100 | | 100 RX <----/\/\----o o----/\/\----> RXIf Both TX's are in agreement, then the voltage at either RX follows the TX
If Both TX's are in disagreement then the voltage at either RX is VDD / 2
Using the Ternary code applied to the RX line, and only looking for a "1", you (the transmitter) know if you are in agreement or disagreement with the other guy (the receiver).
As for speed I'm not sure yet, or if you catch the data during a transition... but simple initial handshaking/syncing could correct these problems.
BTW) Phil you have the right idea in your PM ... the result is balanced creating somewhat of a hysteresis because it's working from both rails. .... A version of a Sigma Delta using only one I/O pin.