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

DIRS question

ArchiverArchiver Posts: 46,084
edited 2003-09-02 17:41 in General Discussion
I am looking over a program a co-worker wrote a while back trying to
understand they why and how he did what he did.

At the first of the program he declares the inputs and outputs correctly
with the DIRL and DIRH commands

DIRL=%00000000 'Pin 7-0 (low byte); Initial INPUT or OUTPUT
state
DIRH=%11111111 'Pin 15-8; 1=out, 0=in

OUTL=%00000000 'Pin 7-0, initial value; 1 = 5 volts
OUTH=%10010111 'Pin 15-0

but later he uses one of the pins to generate a pulse on pin 14 (Dith_Pin)
like the following:

PulsOut DITH_PIN,DITH_AMP 'Send Dither Pulse on output line
dir14=0 'Return output line to high impedance

Its the DIR14 I have never seen before and also why would he be calling it
'high' impedence. He has made the pin and input, correct? There is a 1k
series resistor from the pin to 5V, but couldnt this cause a problem?

Why wouldnt you just leave the pin an output and not change it? Also, is
the DIR'x' command a legal one? I couldnt find it in the documentation.

Thanks,

Mark





[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-09-02 17:41
    Very nice example.

    What's going on is that Stamp pins have three states,
    basically. These are OUTPUT HIGH, OUTPUT LOW, and
    INPUT. HIGH means it's outputting a 5 volt signal.
    LOW means it's 'forcing' a pin to ground -- basically
    connecting the pin to a low-impedance path to ground
    inside the chip. 'INPUT' means that the output drivers
    are disconnected from the pin, so whatever chip is
    outside the Stamp can put the pin in whatever state
    it wants to.

    This last state is also called 'high-impedance'.
    Since the 'low-impedance' drivers to +5 and ground are
    both disconnected in 'Input' mode, the 'outside'
    chip's signal 'sees' a high-impedance (10 Megohms
    or so). (This 'high-impedance' is the resistance
    from the Stamp's receiver circuitry to ground,
    inside the chip.) Thus the outside chip does not
    have to drive very much current to get the
    Stamp to 'see' its HIGH, nor sink very much
    current to get the Stamp to 'see' its LOW.

    When you do a 'PULSOUT', the Stamp sets the pin
    as an OUTPUT, and does its thing with it. It
    leaves the pin as an OUTPUT at the end of the
    'PULSOUT'. This can lead to some drive currents
    being active on the line -- so your co-worker did
    an explicit DIR14 = 0 (ie, put pin 14 in INPUT mode)
    to disconnect the OUTPUT drivers, and leave the
    pin in high-impedance INPUT mode.

    This is a very good thing to do at times. It
    reduces 'idle' currents from the Stamp, and also
    allows other devices to now drive the line.

    --- In basicstamps@yahoogroups.com, "Mark Adams" <madams@a...> wrote:
    > I am looking over a program a co-worker wrote a while back trying to
    > understand they why and how he did what he did.
    >
    > At the first of the program he declares the inputs and outputs
    correctly
    > with the DIRL and DIRH commands
    >
    > DIRL=%00000000 'Pin 7-0 (low byte); Initial INPUT or
    OUTPUT
    > state
    > DIRH=%11111111 'Pin 15-8; 1=out, 0=in
    >
    > OUTL=%00000000 'Pin 7-0, initial value; 1 = 5 volts
    > OUTH=%10010111 'Pin 15-0
    >
    > but later he uses one of the pins to generate a pulse on pin 14
    (Dith_Pin)
    > like the following:
    >
    > PulsOut DITH_PIN,DITH_AMP 'Send Dither Pulse on output line
    > dir14=0 'Return output line to high impedance
    >
    > Its the DIR14 I have never seen before and also why would he be
    calling it
    > 'high' impedence. He has made the pin and input, correct? There
    is a 1k
    > series resistor from the pin to 5V, but couldnt this cause a
    problem?
    >
    > Why wouldnt you just leave the pin an output and not change it?
    Also, is
    > the DIR'x' command a legal one? I couldnt find it in the
    documentation.
    >
    > Thanks,
    >
    > Mark
    >
    >
    >
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
Sign In or Register to comment.