Searching \ for 'Pin hi to low change time question' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/timers.htm?key=time
Search entire site for: 'Pin hi to low change time question'.

Truncated match.
PICList Thread
'Pin hi to low change time question'
1997\06\10@014557 by Glen Benson

flavicon
face
Hi,

  Im fairly new to pics, so if this is a dumb question please ignore it.
I am using basic until i learn asm, and I noticed that if I close a
momentary switch to bring an input pin high, it stays high for some time
(approx. 15 seconds) then it will go low. I can set the pin low just after
the pin goes high, but that doesnt alow me to see if the button is being
held down. Below is some sample code. Is there a way to keep the pin from
latching high for so long?

Any help appreciated.

16c84

'---------- begin code -------------
       input pin0                   ' make pin 0 an input
start:  if pin0=0 then start         ' loop until button pressed

action: high 7                       ' turn on an led (or whatever)

wait:   if pin0=1 then wait          ' wait for pin 0 to go low
       goto start                   ' go back and wait for button again
'--------------- end code ---------------

The above code will loop on the wait label for about 8 seconds ( I didnt
time it, But it was too long to be useful. If force pin0 low at the first
line of the action label, it works but I cant tell if the button is held down.

Thanks

Glen Benson

1997\06\10@195309 by Mike Keitz

picon face
On Mon, 9 Jun 1997 22:46:55 EST Glen Benson <spam_OUTbensonTakeThisOuTspamBENSONASSOC.COM>
writes:
>Hi,
>
>   Im fairly new to pics, so if this is a dumb question please ignore
>it.
>I am using basic until i learn asm, and I noticed that if I close a
>momentary switch to bring an input pin high, it stays high for some
>time
>(approx. 15 seconds) then it will go low. I can set the pin low just
>after
>the pin goes high, but that doesnt alow me to see if the button is
>being
>held down. Below is some sample code. Is there a way to keep the pin
>from
>latching high for so long?

The PIC16C84 inputs are CMOS, so they look like small capacitors to the
external circuit.  There is no (intentional) DC path inside the PIC from
an input pin to ground or Vdd, except the Port B pull-ups which your
BASIC may or may not support.  So leaving a pin open causes it to assume
an indeterminate state.  What is happening in your case is the pin is
holding the charge placed on it when the switch is closed and eventually
drifting back toward ground several seconds after the switch opens.

To fix the problem, connect a resistor from the pin to ground.  The size
of the resistor is a tradeoff between many factors favoring a small
resistance (faster pull-down, more tolerance for leaky switch, more
tolerance for induced EMI) and the power drawn from the supply while the
switch is closed.  With BASIC software and a manual switch, speed is not
a problem so a large resistor of 100K to 1M will work.  The supply
current "wasted" by the resistor while the switch is closed will be on
the order of 50uA which will be insignificant in most cases.

1997\06\12@001814 by Richard Adamec

flavicon
face
On Mon, 9 Jun 1997, Glen Benson wrote:

{Quote hidden}

The problem you may be facing is with the circuitry itself,  you mention a
momentary switch but no tie down or pull up resistors.

If you have a switch pulling the input to high, make sure you also have a
resistor pull the input to low.  This way you wont have to wait for the
charge to "leak out" of the input pin.  This works the opposite as well,
ie. if you have a switch to pull the input lo, have a resistor pulling the
pin high.

this will also eliminate possible false switching due to the pin floating
while the switch is open,

another alternative is to use the internal weak pull up option if using
port B.

             |
            ---
   pin o----0 0----o +5v
          |
          /
          \  approx             example of pull down resistor
          /   5-10k
          |
          o
       ground

More... (looser matching)
- Last day of these posts
- In 1997 , 1998 only
- Today
- New search...