Shop OBEX P1 Docs P2 Docs Learn Events
Friday PASM puzzle - Reading an input as a Ternary value — Parallax Forums

Friday PASM puzzle - Reading an input as a Ternary value

Beau SchwabeBeau Schwabe Posts: 6,568
edited 2011-02-04 21:02 in Propeller 1
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.
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 Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-02-04 13:22
    I've emailed my solution.

    -Phil
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-02-04 13:46
    @Phil: The translator says
    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?
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-02-04 21:02
    The idea is to allow for simultaneous Full Duplex serial communication over a single wire between two Propellers.

    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----/\/\----> RX
    
    

    If 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.
Sign In or Register to comment.