Shop OBEX P1 Docs P2 Docs Learn Events
dira question — Parallax Forums

dira question

LuckyLucky Posts: 98
edited 2010-04-04 00:21 in Propeller 1
When you code "dira[noparse][[/noparse]pin]~", the pin is at high impedance(input). Now when its NOT'ed (!dira[noparse][[/noparse]pin), which sets it to an output, does the prop automatically have the pin connected to ground, or do you also have to write outa[noparse][[/noparse]pin]~ to pull the pin low. The reason I'm asking is because the ps/2 protocol has both the data and clock lines pulled up to·+5V. So when I want to transmit something to the keyboard, such as the states of the Caplock,NumLock, and ScrLock LEDS, I have the Data·line (connected to P19) go Dira[noparse][[/noparse]DatPin]~ to transmit a 1 and·dira[noparse][[/noparse]DatPin]~~ to transmit a 0. Is this okay or not? I'm not seeing any of the three LEDS flash and nothing is happening on the data line·when I monitor it on a oscilloscope.

······································································································································································· -Thanks

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"You do not really understand something unless you can explain it to your grandmother."


-Lucky[size=-1][/size]

Comments

  • TheGrueTheGrue Posts: 114
    edited 2010-04-03 05:22
    Dira just sets the direction. You would need to the Outa[noparse][[/noparse]pin]~~ to set it to high. The PE Kit book shows in Chapter 6 that you can set the outa high first and then set the dira to toggle from high to low/input like:

    outa[noparse][[/noparse]pin]~~ ' sets to high but pin is not output yet
    dira[noparse][[/noparse]pin]~~ ' the high is now transmitted
    dira[noparse][[/noparse]pin]~ ' the pin is now low and an input

    You can also do it in one line like

    dira[noparse][[/noparse]pin] := outa[noparse][[/noparse]pin] := 1 'sets pin output and a high
  • kwinnkwinn Posts: 8,697
    edited 2010-04-03 13:14
    It is always a good practice to set an output pin to the state you want it to be in before you set it as an output. If the pin is controlling hardware it is a good idea to use a pull up or pull down resistor to put the pin in a known safe state even when it is an input.


    PS - Granny ( and others ) may not understand your explanation no matter how well you know your stuff or how clear and concise your explanation.

    Post Edited (kwinn) : 4/3/2010 1:20:29 PM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-04-03 15:11
    outa is set to zero when the cog is started, so you don't need to do anything to set the pin low when its direction changes to output the first time.

    -Phil
  • LuckyLucky Posts: 98
    edited 2010-04-03 17:48
    I don't think you guys answered my question completely as I was hoping for. The Data and Clock Lines are pulled up to five volts by an external 10k resistor. Therefore if you want to transmit a one on the Data line, you leave the prop pin at high impedance(input) and if you desire to transmit a 0, you set the prop pin to an output, which brings the Data line low by connecting it to ground through the prop pin. If the outa for that pin has not been disturbed, it is always a zero, so by just going dira[noparse][[/noparse]pin]~~, i'm assuming the line is taken low. Is there anything wrong with this line of thinking?

    @PhiPi: Thanks for clearing up that part of the question.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "You do not really understand something unless you can explain it to your grandmother."


    -Lucky[size=-1][/size]
  • SapiehaSapieha Posts: 2,964
    edited 2010-04-03 17:58
    Hi Lucky

    To emulate OPEN Colector output.

    1.Have first Pin as INPUT
    2.OUT pin=0
    3.DIR pin=1 - Required time to have that pin as 0-GND
    4.DIR pin=0 - Reset Dir to INPUT (Open Colector simulation) - External resistor drives that pin now HIGH-1
    NEXT PULSE -
    Points 4-3 agin
    Regards
    Christoffer J

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer.
    Don't guess - ask instead.
    If you don't ask you won't know.
    If your gonna construct something, make it·as simple as·possible yet as versatile as posible.


    Sapieha
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-04-04 00:21
    Lucky,

    To simulate an open-drain output, you've got exactly the right idea. You don't need to touch outa at all; just modulate dira. The caveat, of course, is that the bit polarity is reversed, as compared with modulating outa.

    -Phil
Sign In or Register to comment.