Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Detecting 12V on a PIC input running at 5V off a 7805

Status
Not open for further replies.

Yobortsa

Member
Hi all,

I'm limited in my electronics knowledge. I have a simple 5V circuit running a PIC12F675 and I want to use several of the inputs to detect the presence of a 12V supply in an automotive application.

What sort of circuit can I use to send a 12V signal from the car into one of the PIC inputs?

Thanks in advance,

David :)
 
The easiest way to do this in my oppinion especially as you know the input is 12v is to use a Voltage Divider and ADC. There are constraints dependant upon the PIC for current and maybe resistance, you will have to check the datasheet for your micro.

Hope this helps.
 
You don't need a voltage divider, simply stick a high value resistor (about 100k) in series with the input.

If the signal is from a switch, add a pull down resistor to the PIC input but then it'll be a voltage divider as suggested above.:D
 
Will that not just limit the current by putting a series resistor in?

I always thought you need a divider to reduce the voltage.
 
PICs have internal protection diodes connecting each input to Vdd, therefore clamping each input to the supply voltage. All you need is a current limiting resistor to protect the diode from overcurrent.
 
Ah, I didn't know that, but what is the max before you will blow the internal diode?
I was also thinking of something like a transorb.
 
It looks like this electronically:
**broken link removed**
The resistor in the schematic above will have quite a low value and won't be enough to protect it from overcurrent.

According to Nigles site the maximum rating of the diodes is 20mA but there's no point in having any more than 100µA or so because it's a high impedance input.
**broken link removed**A useful feature of the PIC inputs are the 'protection diodes', these clamp the input to the +VE supply and GND, preventing the input going above +VE or below GND. This means you can feed a higher voltage into the input, with just a simple current limiting resistor, MicroChip have an application note for a light dimmer, where the incoming mains is fed via such a limiting resistor straight into a PIC input pin - used to detect the zero-crossing point of the mains. The 16F628 datasheets quotes the maximum 'clamp current' through the diodes as 20mA, but I would suggest keeping it far lower than that, it's a high impedance input so we don't require much current through the limiting resistor.
 
Last edited:
You can clamp up to 240volts Ac is the max it microchips apnote an521
 
Wow, amazing, I didn't know that it had protective diodes which could take that much.

So if 12v was fed to an A/D it would see 12v as 5v max still right? and until I got below 5v it would still read 5v as it's input?

What i'm trying to say is that the PIC cant measure above or below it's reference voltage of ~5v?
 
It's not voltage but current that matters, you could connect it to 1kV using a suitably high powered high voltage resistor.

You're right that a PIC can only measure voltages with its power rails.
 
Hero999 I don't think I'll try 1Kv. I'm sure it would work with a bunch of resistors in series
Sure not try one LOl
 
If you want to measure the voltage (say to detect a low battery condition on a 12V battery), you'll need to use a voltage divider so that the maximum battery voltage divides down to the 5V max the A/D can measure.

But if you only need to sense the presence/absence of the voltage (e.g. a digital input), or only care if it drops below 5V for measuring purposes, then you can get by with just a current-limiting resistor and the internal clamp diode.
 
Yes, that was my original response, to use a VD, but I wasn't aware you could put above 5v to the pin, to measure 12v you need a VD, as it will only ever see a max of 5v due to it's internal Voltage Ref, however, question, if I was to use a PIC18F for ex which supports an external voltage reference, could I put 12v into VREF and measure the ADC via the external Voltage Reference instead of having to use a VD does anybody know (putting a limiting resistor in series).
 
Yes, that was my original response, to use a VD, but I wasn't aware you could put above 5v to the pin, to measure 12v you need a VD, as it will only ever see a max of 5v due to it's internal Voltage Ref, however, question, if I was to use a PIC18F for ex which supports an external voltage reference, could I put 12v into VREF and measure the ADC via the external Voltage Reference instead of having to use a VD does anybody know (putting a limiting resistor in series).

No, the reference voltage can't be higher than Vdd + 0.3 V (typ). Check section 'Electrical characteristics' in the PIC datasheets.
If you use the ADC to measure the voltage, as you said, you use a voltage divider.
Detecting the presence of the external voltage might be done using the pins as digital inputs.
 
Last edited:
eng1 you just throned apnote an521 out the door LOL
Electrical characteristics said not to go higher then .3Vdd
But the apnote tells you that it clamp higher voltages just limited it to less then 20mA
I would use a voltage divider for this application.
If I just wanted to see if it was hot I would use the emf diodes to clamp it with a current limiting resistor.
 
I also would go with the voltage divider. For accurate voltage measurements the source resistance needs to be kept low. A VD will help with this.
 
Voltage Divider calculations - how many ohms for R1?

Thanks all for your valuable suggestions.

The voltage divider appears to be a more robust and safe solution and here is a sample schematic I found.

**broken link removed**

Source: http://letsmakerobots.com/node/3050

How do i choose the resistors?

There is a calculator online at **broken link removed**

Perhaps R1 could be 60 ohm and R2 could be 40 ohm to end up with 4.8V from 12V.

If the car battery was charging and the voltage of the system went up to 16V, perhaps I should adjust the values a bit. So, say the worst case scenario is 18V, presumably I'd run the resister calculation at 18V in which case I'd get R1 60 ohm and R2 23 ohm and end up with 4.988 V output. But at 12V input I'd only end up with 3.325 V output. Will the GPIO on the PIC still work at 3.325 V? How low can you go with the voltage?

The other question is, how do you know what size to make R1? According to the PICAXE schematic above, R1 is 3300 ohm and R2 is 1000 ohm. You'd end up with between 2.791V from 12V and 4.186V from 18V. But I could end up with exactly the same voltage divider with any value for R1. Is 3K3 an appropriate value for the PIC?

I presume the size of R1 has to do with how much current you want to make available to the PIC GPIO pin and probably has to do with R=V/I.

Clearly I am a newbie to this, thanks again for all your help.

David :)
 
If you know the input impedance of the ADC, then you can take it into account when calculating the resistor values.
 
If you know the input impedance of the ADC, then you can take it into account when calculating the resistor values.


If it's a 16fxxx 10k or less is idea
The maximum recommended impedance for analog sources is 10 kΩ. This is required to meet the pin leakage
specification.

If it's a 18fxxx 5k or less is idea
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top