View previous topic :: View next topic |
Author |
Message |
bowler32
Joined: 20 Apr 2007 Posts: 5
|
SINGLE PIN SWITCH/LED DRIVE |
Posted: Fri May 18, 2007 3:06 am |
|
|
Hello
I am trying to use a single pin to drive an led and read a switch on the 16F870 chip. I can get this to work on PORTB but no matter what I do I can't get it to work on either PORTA or C.
Any help please.
Ian |
|
|
TTelmah Guest
|
|
Posted: Fri May 18, 2007 5:08 am |
|
|
It'd help if you described the actual circuit involved....
I find it hard to visualise a circuit to perform both functions on a pin, without resulting in poatential harm to the PIC.
Big difference, when it comes to 'reading a switch', is that PORTB, has pull up resistors internally available, when none of the other ports have these.
Remember that RA4, has no internal pull up gate either. PortC, and PortD, have Schmitt trigger input buffers, which will switch at different points from the TTL buffers on PORTA, and PORTB.
Best Wishes |
|
|
bowler32
Joined: 20 Apr 2007 Posts: 5
|
|
Posted: Fri May 18, 2007 6:53 am |
|
|
Thanks for the reply.
I am driving the led through a 470R to 0ve and I have got a 4K7 pull up to 5volts for the switch.
I have tried different values for the pull up resistor for the differences between TTL and Schmit voltage levels.
I am polling the switch at 50ms intervals.
The internal pullups are disabled on portb.
Ian |
|
|
Ttelmah Guest
|
|
Posted: Fri May 18, 2007 8:16 am |
|
|
So, if the switch is made, while the PIC is driving the LED, the output gets shorted out, potentially overloading the output driver...
Though PICs are quite tough in this regard, it will result in nasty spikes of current on the supply rail, and could cause chip damage.
Double check that both Vss/Vdd connections are made to the chip. There can be some odditie like this if one is not properly made.
Best Wishes |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sat May 19, 2007 2:45 pm |
|
|
Quote: | I can get this to work on PORTB but no matter what I do I can't get it to work on either PORTA or C.
|
It is difficult to help you if you do not posted any code.
Anyway, be aware that PORTA by default is an Analog Input after power-up and
one of them (RA4) is an open drain type.
Regarding PORTC, some pins are shared with other internal modules like UART and
TIMER1 and some directive to use them will override your pin direction definitions.
Humberto |
|
|
|