View previous topic :: View next topic |
Author |
Message |
iso9001
Joined: 02 Dec 2003 Posts: 262
|
Possible to Output_high & check input in place of a pull |
Posted: Tue Jan 04, 2005 6:05 pm |
|
|
I have a switch that when pressed connects to ground.
Normally I would just add a pullup to 5V and check the state of the pin... high, the switch is not pressed, low and the switch is pressed. Easy.
But imagine if I had to do this w/o the pullup.... Can I output_high on that pin, and then check the inputstate... ? My guess is that maybe it would work the same way no ?
I know that Port B pins have pullups built in that can be enabled but you have to enable all of them right ? ie: not JUST the pullup on B1 ?
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jan 04, 2005 6:26 pm |
|
|
Quote: | But imagine if I had to do this w/o the pullup.... Can I output_high
on that pin, and then check the inputstate... ? My guess is that maybe it
would work the same way no ? |
You would be shorting the output driver to ground. Even if you put
a series resistor between the switch and ground, the resistor would
have to be a low value to load down the output driver enough to
make it go to a logic low level. Why can't you use a pull-up ?
I wouldn't recommend putting a heavy load on the PIC's output driver.
Quote: | I know that Port B pins have pullups built in that can be enabled
but you have to enable all of them right ? ie: not JUST the pullup on B1 ? |
Some PICs have the ability to turn individual pull-ups on or off.
If you forgot to put external pull-ups on your board, and you don't
have software controllable pull-ups on the PIC pins, AND you are not
putting this board into production (it's just a "one off" board), then
here is a way to read switches without pullups. This method does
short the output to ground for a very short time. This "fix" was just
for one board (I hope).
http://www.ccsinfo.com/forum/viewtopic.php?t=18121 |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
Re: Possible to Output_high & check input in place of a |
Posted: Tue Jan 04, 2005 6:28 pm |
|
|
iso9001 wrote: |
But imagine if I had to do this w/o the pullup.... Can I output_high on that pin, and then check the inputstate... ? My guess is that maybe it would work the same way no ?
|
This is not a good idea. You might be forcing the pin high when it is tied to the ground.
iso9001 wrote: |
I know that Port B pins have pullups built in that can be enabled but you have to enable all of them right ? ie: not JUST the pullup on B1 ?
|
The pull-up is on all the PORTB pins. Some chips allow you to enable/disable pull-ups on each pin individually, while some other only allow the pull-up to be enabled/disabled on all the pins at the same time. What PIC are you using? |
|
|
iso9001
Joined: 02 Dec 2003 Posts: 262
|
|
Posted: Tue Jan 04, 2005 6:34 pm |
|
|
Ah that makes sense about shorting the pin out.
I'm using a 16F872 and 76A series (they are very compatible for what my board is doing)
Its a sort of one off.
I'm bound to using the B0 pin b/c of its int_isr. So I'm not sure if charging the pin would work for me, but I do like that idea as a quick fix... gotta remember that.
I looked in the help for the port B pulls ups but the help doesnt show how to specify just one pin (am i wrong?). I'm not sure if the 16F87x series could either, I'm not sure where that would be in the datasheet. |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Tue Jan 04, 2005 7:29 pm |
|
|
You can't enable pull-ups only on one pin on the PIC16F87x series. It is all or none. |
|
|
Ttelmah Guest
|
|
Posted: Wed Jan 05, 2005 3:03 am |
|
|
There is a method that will do what you want, without any excessive loading. Have a resistor running from the PIC pin to a small capacitor. Have another smaller resistor from this junction to the switch. Pull the pin high. If the switch is open, the capacitor will charge via the resistor. Then switch the pin to input, and read the value. If the signal reads as high, the switch is open, if it reads as low, the switch is closed (assuming the switch pulls to ground).
If you are running really fast, and switch/read quickly, you can do this with just one resistor, and rely on the capacitance in the keyboard itself. If you are happy that your keyboard contacts wll not be harmed by directly connecting the charged capacitor across them, then you don't need the second capacitor (this just serves to lmit the current flow through the contacts in this case).
Best Wishes |
|
|
edi
Joined: 22 Dec 2003 Posts: 82
|
|
Posted: Wed Mar 05, 2014 6:33 am |
|
|
Thanks a lot.
PU will be added... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Wed Mar 05, 2014 6:55 am |
|
|
There is a way to read if the a is high,low, or hi-Z but I can't quickly find the Microchip app for that....I like loking at real databooks not online.
I did find Mark Sullivan's 'software switch pull-ups' in the quickcode section of the 'designing for dollars' book circa 1998. That you might be able to use for your project.While code is assembler, it is dead simple to translate.
I have to agree though real pullups are 'simpler'.
hth
jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19536
|
|
Posted: Wed Mar 05, 2014 8:28 am |
|
|
It's tip 3 in the "compiled tips 'n tricks" guide.
Requires a resistor _and_ capacitor.....
Best Wishes |
|
|
|