How would you do this?


Closed Thread
Results 1 to 24 of 24
  1. #1
    Join Date
    Jan 2010
    Posts
    88

    Default How would you do this?

    Hi Guys,

    I am trying to trigger an input on a PIC16F687 using an external 12 volt source. The circuit will be using this same supply. Would you have the 12 volt source control a transistor which the transistor will be connected to the input of the pin (either pull up or down, haven't decided yet) or have the 12 volt source go to the input pin via resistors?

    I thought about doing it via directly to the pin using resistors, such as in a voltage divider setup, but wasn't sure if that was the best way. Your thoughts?

    Thanks,
    Tony

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    A voltage divider on the input will work fine. How about 5K from the input pin to GND and 7.5K from the input pin to your 12V source. If you need a little noise
    immunity, you can add a .1uF cap across the 5K resistor.
    Charles Linquist

  3. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    I would suggest optocoupler as TLP504 or similar.

    Al.
    All progress began with an idea

  4. #4
    Join Date
    Jan 2010
    Posts
    88


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    Quote Originally Posted by aratti View Post
    I would suggest optocoupler as TLP504 or similar.

    Al.
    Hi Al,

    Just out of curiosity, why would you use the optocoupler?

    Tony

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    With optocoupler you will obtain Total isolation from the 5 volts rail and total immunity to noise.

    Cheers

    Al.
    All progress began with an idea

  6. #6
    Join Date
    Feb 2011
    Location
    Michigan, USA
    Posts
    33


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    Actually the picbasic pro manual shows under the serin command, you
    can input 12 volts directly through a current limiting resistor. (22k in example)

    But if you truly need a reliable trigger, without false triggers, I agree with aratti
    and use optocoupler and caps.

  7. #7
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    If the grounds are not isolated, can someone explain to me why an optocoupler is more reliable?
    Charles Linquist

  8. #8


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    If some kind of voltage spike comes along the circuits other than ground, less paths of that spike to the uP reduces chance of frying.


    Don
    Amgen

  9. #9
    Join Date
    Feb 2011
    Location
    Michigan, USA
    Posts
    33


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    Quote Originally Posted by Charles Linquis View Post
    If the grounds are not isolated, can someone explain to me why an optocoupler is more reliable?
    I agree Charles. Isolated grounds would be best. But if thats not practical, than keeping circuit neighborhoods isolated would be next best. At least thats the way I understand it and have seen in practice.

    Meaning of neighborhood. If you already know this than I apologize. One neighborhood would be the analog section. Another would be the digital. All neighborhoods should have their own ground that leads back to the point where power ground comes into the circuit. This point will have the lowest impeadance to power/earth ground. In other words, all neighborhoods share their ground at only one point. Doing this keeps noise created in one neighborhood from effecting another.

    This does not work for all applications but using an optocoupler will keep this idea in place.

    Also this idea relies on the use of the right capacitors in the right place. I still don't fully understand how caps fixed certain high speed trigger problems i had.
    ...maybe it was inductance or quantum interactions ... i don't know ???
    Last edited by MikeWinston; - 13th September 2011 at 18:51.

  10. #10
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    Isolation is usually the best policy. But sometimes isolation is not possible, or cost effective or...

    In this case, ERMEGM (I hope that is an acronym for something!), has the grounds connected. In this case, if you added an opto, you would have both the Emitter and the LED Cathode connected to the processor GND. You would have some sort of resistor in series with the LED anode. The collector would be connected to VCC through a resistor.

    Now, apply 12V to the LED through the resistor. The transistor will conduct, and the PIC pin will go to GND. Take away the 12V, and the PIC pin will go to Vcc - no higher. So far, so good.
    If there is noise on the input, the opto (because it is slow), will not respond to really narrow 'glitches'. That is good, too.
    A downside is that the LED has virtually no hysteresis. There will be very little noise immunity if the signal sits around some value
    above the LED threshold (exact value determined by the resistor value).
    If you apply a narrow 20KV spike to the Anode of the opto, you might probably blow everything - because most optos don't have an isolation voltage of greater than 5KV.
    If you should accidently apply 50V continuously, you might burn the resistor in series with the LED, since the value of the resistor will have to be low enough to give it a few mA of drive at 12V.

    On the other hand, if you use a divider you have the hysteresis of the PIC input pin. If you add a capacitor across the "lower" resistor, you block any narrow spikes, and you have noise immunity. Amazingly enough, this will also protect the PIC from those narrow
    20KV spikes. How do I know? I have tested them. And if you should accidentally apply 50V continuously across the resistor network (7.5K/5K like I suggested), then you would have 44.5V across the "top" resistor (because the PIC would clamp at Vcc + 1 diode drop). I = E/R, so the current through the resistor would be ~7mA (6mA into the PIC pin and 1mA through the "bottom" resistor. Will the PIC care? The datasheet says it won't. A PIC input is good for at least 25mA in the "clamp" mode. No damage would result.

    I'd say that this is a case where a divider is probably as good as anything.
    Charles Linquist

  11. #11
    Join Date
    Jan 2010
    Posts
    88


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    Thank you for your responses. As for my name, the name I wanted was already taken, so I used my kid's initials.

    My original thought was to use a voltage divider setup with a filtering cap and a 5 volt zener in parallel with the cap going to ground. This way, the cap would filter out the ripple effects and the zener would protect the pic by regulating the input to 5 volts. As this is 12 volts from a vehicle, I'd like to protect the circuit as best as I can. This part of the circuit will not be detecting a momentary input. It's setup so that when it receives its input, it is constant, like a light switch. When the pic sees this, it goes into another routine until the input is removed.

    With the optocoupler, if you have your resistor in place for the LED, any voltage spike would kill the LED. You could setup the same cap and zener across the LED portion of it, and this should provide the same protection, right? The zener would have to be a 12 volt zener though.

    Tony

  12. #12
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    You can just feed the 12V into a small, 78L05-type regulator, and the output to the PIC.
    Charles Linquist

  13. #13
    Join Date
    Jan 2010
    Posts
    88


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    I'm looking at 4 inputs though. Two for a positive trigger and two for a negative trigger.

    My thought was to pull the positive ones low and the negative ones high to give a distinct change.

  14. #14
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    I give up.
    Charles Linquist

  15. #15
    Join Date
    Jan 2010
    Posts
    88


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    Here are two circuits I've put together. One is a voltage divider and the other is an optocoupler setup. The positive inputs on the VD setup has a cap and zener for debouncing and has pulldown resistors. The negative inputs have a pullup resistor. The VD setup allows for only one input to trigger a new routine. The opto setup requires the LED circuit to be completed in order to trigger a new routine, so the setup has to work as a pair instead of individually.

    In this case, is the VD setup the better setup to use? Disregard the resistor values and they were just thrown in there.

    Thanks,
    Tony
    Name:  vd.gif
Views: 3099
Size:  7.7 KB

    Name:  opto.gif
Views: 3990
Size:  31.8 KB

  16. #16


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    Charles,
    Good point about clamp ability in pins (a few pins don't have that clamp diode), but why are you using such low val resisters ? Voltage dividers with 50, 100-200K value resisters make any voltage/power dissipation insignificant. I tried a touch sensor to a/d pin through a 10 MEG ohm R (and diode) which instantly brought a/d val to full, (5 volt).
    Don

  17. #17
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    Quote Originally Posted by Charles Linquis View Post
    You can just feed the 12V into a small, 78L05-type regulator, and the output to the PIC.

    If I may, Charles means something like this:




    (for some reason, on-site attachments don't seem to work)

    Robert

  18. #18
    Join Date
    Jan 2010
    Posts
    88


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    Hi Guys,

    Yes, I know what Charles is saying. What I'm asking though is another thing. This will be a production item, so adding a 7805 and caps to every board increases the board size and cost. My diagram from above I thought was pretty straight forward. Does it seem plausible? I think the diodes may be redundant.

    Thanks,
    Tony

  19. #19
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    The only comment I can make is "do you have experience with automotive electrical systems?"

    Newer cars might be different, but the voltage used to vary a lot. I'd just make sure to have a circuit that can withstand up to 25V without breaking a sweat.

    Oh yeah, I read a while back about some manufacturers wanting to use 24V and up, just a thought.

    As for your circuit VS Charles divider or any other design, I'm not qualified to comment.

    Robert

  20. #20
    Join Date
    Jan 2010
    Posts
    88


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    Actually, I am very familiar with vehicle systems, voltage ranges and the spikes that can occur. However, when studying how other manufacturers have created their product to be installed in such a vehicle using the same features, I don't see much protection being used. Probably because the cost of the board and the likelihood of the malfunction and repair is not cost prohibitive. It almost seems like the opto circuit would be best in isolating one circuit from the other and maybe a 12 volt zener across the LED terminals would prevent damage to the opto. Any thoughts?

  21. #21
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    You don't need to protect the opto led! Assume you will use TLP504a it will need a forward current of 16mA, current that can be easily obtained with a resistor of 600 ohms @ 12 V. The device can resist up to 1 A of forward peak current for 100 micro seconds, which means spikes of 600 volts.

    Cheers

    Al.
    All progress began with an idea

  22. #22
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    I said I would remain silent, but I can't now.

    A couple of things:

    Lower value resistors increase noise immunity. Others may use dividers with 50K Thevenin equivalents, but it is generally better to have somewhat lower impedance unless you have really high voltages, or are powered with a battery. A 10K (total) resistance across 12V will dissipate 14mW and will draw 1.2mA. No big deal.

    PIC *INPUT* pins are good for 20mA (at least that is what my 18F8723 datasheet says). That means that you can connect a 1K resistor from 12V directly to a PIC input pin with no damage. The input will clamp at 5.5V. 12V - 5.5V = 6.5V/1K = 6.5mA = NO DAMAGE. You don't need zeners, diodes, anything. You should, however put a cap (.1 or so) across the input pin to GND. An extremely fast high voltage (spark) can drive the input above the breakdown voltage before the input clamp diode has a chance to conduct. The capacitor slows down the risetime to a safe value.

    That 1K resistor directly to the input pin will be fine unless the applied voltage is sustained for more than a few mSec at 25V or higher. Change that resistor to 10K and you will be able to tolerate 200V continuously (of course, the resistor would need to be a 5W type).


    This is not "chip abuse". This is according to the datasheet.

    Some other things (probably more important in your case) are whether or not inputs will be present when the PIC has no Vcc. A 1K resistor to 12V will be able to supply enough current to power the PIC through its body diodes. In fact, if there is very little load on Vcc, that 1K resistor to 12V will drive Vcc to above 10V, since the current will flow from 12V through the resistor through the body diode and into Vcc. A lot of people (me included) have found that their circuits did not RESET properly on startup only to find that when shut off, the PIC still had significant voltage on it. The PIC was being powered through its input pins by a circuit that still had power when the PIC was supposedly shut off.

    If the inputs will have power when the PIC does not, use optos or transistors on the inputs, otherwise, resistors will work fine.
    Charles Linquist

  23. #23
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    I said I would remain silent
    We would have all lost if you had. Thank you for this post
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  24. #24
    Join Date
    Jan 2010
    Posts
    88


    Did you find this post helpful? Yes | No

    Default Re: How would you do this?

    I want to thank everyone for their help on explaining a few things. There are a lot of things to consider when putting circuits in these types of environments and some of us have more experience than others, so I'm sure I speak for most of us when I say that I appreciate everyone's input especially when someone is sharing their trial and errors with the rest of us. I hope Charles didn't take my questions as questioning his formulation. I am merely trying to understand and also make sure that I am clearly describing what I am trying to do.

    With that said, I'd like to share what I have found myself about what I was asking to do. This setup can obviously be modified to do what you need it to do, but this is something that works for my application, so I'd like to share it with you.

    The red input is what activates the routine. The pic is already running and pin 5 is pulled low. Pin 5 sees 5 volts through the zener when 12 volts is applied to the red input. When the positive input goes high with 12 volts, the transistor is turned on and diverts the 12 volts from the red wire to ground so pin 5 sees nothing and is pulled low again.

    The circuit on the right is a negative trigger. Pin 4 sees 12 volts through the two resistors above. When ground is applied to the negative input, pin 4 is pulled low to trigger another routine on the pic.

    My question is this though, why the RC parallel filter? I know I can simply use the same setup, but I'd like to understand what value this has. I know the cap is for smoothing out the input to prevent the pic from seeing multiple inputs when there is only one (debouncing), but what's the parallel resistor for? I see how it's part of a voltage divider on the right side circuit, but what about on the left side? Is that just to discharge the cap?

    Thanks,
    Tony

    Name:  triggers.gif
Views: 3110
Size:  8.9 KB
    Last edited by ERMEGM; - 8th October 2011 at 03:10.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts