Electronic – Choosing a transistor and resistor for PIC input pin protection from Car Power

automotivepicpullupvoltage divider

Further to my previous question,
Using a PIC to perform switch on and timed shutdowns in automotive environment

I've been pointed at zener diodes and voltage dividers, but I'm now confused by the PICs builtin weak pull-up resistors (and if I check the datasheet, values are TBD… I assume something like 10k?)

So the PIC input pin protection circuit I think I have understood is this:PIC input pin protection circuit

But using weak pullups, I think I could do this:

enter image description here

But all this does is swap a resistor to a transistor.

Update

Further to comment from @PJC50, I now think the circuit utilising the PIC's pullup resistors would look like this:
enter image description here
It's now clear why I should do this and how it reduces component count.

How do I choose a resistor and transistor that are suitable?

  • Is the voltage divider circuit correct?
  • Is the circuit that uses the weak pullups correct? (i think not)
  • Why would I use pullups over normal voltage divider?

So my new circuit looks like this:
enter image description here

Update 2:

I've tested the circuit with pull ups, and I think I'm getting closer to real solution, any further comment/critique welcome!

Best Answer

If you are using the NPN method as I described in #4 of my answer https://electronics.stackexchange.com/a/47250/4512, then you don't need a zener diode. The B-E diode of the transistor will limit the voltage by itself.

To clarify, here is how you can use two resistors and a zener diode to safely drive a 5 V PIC input from car power:

With 12 V in, the resistor dividers by themselves would drop the output to 6 V. However, the zener will clamp that to a bit below 5 V, which keeps the voltage safe for the PIC. Even if IN momentarily went to 50 V, for example, the zener will limit the voltage at OUT to a safe level.

The transistor method looks like this:

The B-E junction of the transistor will limit the voltage accross it to around 700 mV, so there is no need to protect the resistor. In this case I set the voltage divider so that it takes a few volts on IN to turn on the transistor. If the base is about 600 mV when the transistor first turns on, then there needs to be about 5 V on IN for that to happen. This gives you better noise immunity than just connecting a resistor to the base of a transistor without a pulldown there.

When IN is high, the transistor turns on, pulling OUT low. Since the transistor can only pull down or not pull at all, you need something to pull the line high when the transistor is off. This can either be the deliberate R3 as shown, or it can be a pullup resistor built into the PIC. In the latter case, you don't need R3 and you just tie the collector directly to the PIC input without any additional parts.