'Pin hi to low change time question'
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.
'---------- 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.
|On Mon, 9 Jun 1997 22:46:55 EST Glen Benson <BENSONASSOC.COM> benson
> Im fairly new to pics, so if this is a dumb question please ignore
>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
>(approx. 15 seconds) then it will go low. I can set the pin low just
>the pin goes high, but that doesnt alow me to see if the button is
>held down. Below is some sample code. Is there a way to keep the pin
>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.
On Mon, 9 Jun 1997, Glen Benson wrote:
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
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
pin o----0 0----o +5v
\ approx example of pull down resistor
More... (looser matching)
- Last day of these posts
- In 1997
, 1998 only
- New search...