PDA

View Full Version : PIC16F886 Pulldown inputs



pescador
- 9th January 2024, 19:53
I'm using a 16f886 to detect digital inputs. I set RA5 for example to be a digital input. No analogs for this project.

ANSEL = 0 ' Make AN0-AN7 digital
ANSELH= 0 ' Make AN8-AN13 digital

I'm using opto isolators to accept 12V and convert the 12V to 5v (VCC).
That output is connected to pin 7 (RA5).

I'm observing that it thinks its high all the time because I made the mistake of leaving that input floating instead of tying it to GND thru a high ohm resistor as a default. When I touch my probe on the pin it works - telling me it needs a pull down.

I then put a thru hole resistor on the opto isolator output (1.5M because thats what I had) and it works, that fixed it. But now I have to modify my prototype.

My question is there a way to configure the 886 to have pulldown capability on portA. I'm reading and reading and can't seem to find that solution. Prob not possible.

And last - the PIC886 is a fairly old IC - is there a newer version which might incorporate pull down functionality? I'll hang up and ask Micrchip for that answer...

Any ideas that might solve this rather than redoing my proto to have the pull down resisitor fix?

Ioannis
- 9th January 2024, 21:31
No. The chip has internal pull-up resistors not pull-down.

Normally you would connect the optocouplers to ground and the input of the chip. Then enable the internal pullup.

What exactly you did?

Ioannis

pescador
- 9th January 2024, 22:41
I didnt do that - as you can see PARK for example - pin 15 - is the output of pin 16 when pin 1 is high. 15 is basically floating when not activated - I want the pin on the PIC to be active high - not low. I think adding a high ohm resistor to ground will take care of it. Unless you have another idea?

I could have used a simple voltage divider as the input - but the input voltages could exceed the divider output (<5V) and I thought the opto would do the trick passing 5V(VCC) which is regulated.

Any way to paste a screen shot instead of a pdf?

https://optoelectronics.liteon.com/upload/download/DS70-2009-0014/LTV-2X7%20sereis%20Mar17.PDF - opto pinout

Ioannis
- 10th January 2024, 09:55
I am sorry but this is not correct as you designed it.

Now the only way is to add the resistors to ground from all the relative PIC inputs. And do add 10K resistors. Not more than that because of noise that can distrurb the input. Better change the 2K to 100 ohms too.

The usual practice is to have Pull Ups and then the opto drive to ground the input. If you want the input high then just reverse the byte your read from the port in software. Easy task.

Also note that in 886, there are Pull-Ups only on Port B and not on Port A.

Ioannis

pescador
- 10th January 2024, 20:17
Ok thanks - I'll connect the opto collector tied high to the PIC and drive the Opto to GND - easy - no need then for ground resistors...

Thanks for R values..9547

Ioannis
- 10th January 2024, 20:24
Maybe I was not very clear.

With your original design, you would change the 2K to 100 ohms.

But with the new design, the pullup will be around 10K. NOT 100 ohms. I am pretty sure you will destroy the optos.

Ioannis

pescador
- 10th January 2024, 20:33
- So just to be clear - I'm driving the optos using the 2k to the anode, the output is the "collector" tied hi to a resistor - to the PIC w 5V. I'm not sure 100 ohms to the PIC would damage the PIC, but I dont think the opto would care?

In any case - I'll use 10K like you suggest.. no real reason to use 100.

Ioannis
- 10th January 2024, 21:15
With 100 ohms from +5 to the collector of opto, you will force 50mA through opto. This is the absolute max according to the data sheet. It will lead sooner or later to the destruction of the opto.

Please do use 10K from +5 to the collector of the opto and drive from the collector the PIC port. The emitter of the opto will be earthed.

Everytime you feed current to the LED of the opto, the PIC port will be low and when the LED is off, port will be high.

Ioannis