What is the best method to connect 12V inputs to a pic.

Beta Testing discussion on mikroC PRO for PIC.
Post Reply
Author
Message
nayantha88
Posts: 33
Joined: 26 May 2012 14:36

What is the best method to connect 12V inputs to a pic.

#1 Post by nayantha88 » 21 Feb 2014 18:28

What is the best method to connect 12V inputs to a pic.
I used a pc123 and a bc327 transistor. But sometimes it wont work and I don't know why.
Attached document is my circuit. It may be not working i found it from google

Now I'm trying to use 4n35. But I don't have a schematic
Cant use voltage divider because the Input voltage may change from 9 to 24Vdc

Can anyone Guide me?

lejeff
Posts: 218
Joined: 04 Dec 2011 16:10
Location: France

Re: What is the best method to connect 12V inputs to a pic.

#2 Post by lejeff » 22 Feb 2014 08:27

For a digital input with 4n35, datasheet is here : http://measure.feld.cvut.cz/groups/edu/osv/4n35.pdf
diode forward voltage is 1.4V at Imax forward current 60 mA (at 25°C)
at 24V the resistor value is (24-1.4)/60 10exp-3 = 380 ohm
at 9V with 380 ohm the diode forward current is about 20mA (within the limits)
so you put a 380 ohm resistor in serial at the input, a 10k resistor between collector and +5V or between emiter and 0V, depending of your need
that's all
schematic is here
http://www.befriendwe.com/wp-content/up ... iption.png
You can choose a lowest forward current to calculate the resistor at 24V but consider the forward current at 9V with the same resistor (too low it doesn't works)

nayantha88
Posts: 33
Joined: 26 May 2012 14:36

Re: What is the best method to connect 12V inputs to a pic.

#3 Post by nayantha88 » 23 Feb 2014 13:48

How to use separate grounds??

cgengineer
Posts: 18
Joined: 11 Apr 2017 06:17
Location: Italy

Re: What is the best method to connect 12V inputs to a pic.

#4 Post by cgengineer » 11 Apr 2017 08:42

Hi

you can use a series resistor with a clamping zener

Input impedance of PIC input is very high so you can use a high value series resistor and a little zener. This simplify debouncing because you can place a capacitor in parallel with zener to realise a first order low-pass filter

The suggested optocoupler solution is good but has a low input impedance that maybe not good for who's feeding that input: but i saw that you are in a trouble about grounds, so don't worry, simply calculate the resistor for the input diode, place the collector of the output transistor at uC Vdd, place the emitter at the input pin and pull down it to ground with a resistor of at least 10k (the value is based on the frequency needed for the input)

Best

Post Reply

Return to “mikroC PRO for PIC Beta Testing”