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.
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.

Once you've calculated the ratio of the voltage divider, choose R1 and R2 so that:
1. little current is wasted in the voltage divider. This suggests to use high-value resistors but...
2. the input impedance seen by the ADC sets a limit.

Obviously there is not a unique solution, but stay in the kohms range.
 
Last edited:
As I said above if the ADC input impedance is known simply use it as part of the resistor calculation.

Use the resistors in parallel formula.

Where X is the required resistance of R2, R2 is the value of R2 actually required and Radc is the input resistance of the ADC.

[latex]R2 = \frac{1}{ \frac{1}{X} - \frac{1}{Radc} }[/latex]

For example:

The battery voltage range is 0 to 15V and needs scaling for an ADC input with a 5V reference and a resistance of 100k±5%.

Because the input's tolerance is so wide it wouldn't be good practice to rely on it being exactly 100k, yet its resistance is significantly low enough to affect the accuracy unless really a low value resistor is used.

Suppose R1 = 20k and R2 = 10k.

Using the formula above:
X = R2 = 10k
[latex]R2 = \frac{1}{ \frac{1}{10k} - \frac{1}{100k} }[/latex]= 11.11k

So use an 11k resistor with 110R in series.

If you use 0.5% tollerance resistors the 5% tolerance on the ADC's input impedance makes very little difference.
 
Last edited:
I think for an automotive application it is not advisable to just use the series resistor and internal pin diodes. The main reason being that the source might very likely be a simple switch to 12v, which is either at 12v or open circuit. The open circuit case would leave the PIC pin floating, and in a noisy automotive environment.
 
That's true, so perhaps the original poster hasn't been wasting resistors after all.
 
Going from A to B by way of X Y Z

nobody mentioned a very important point in this discussion
This is an automotive application and using a 7805 is not the best choice of regulators.
For an automotive environment, a low drop out regulator is desired.
If the opp is only wanting to sense when the voltage of 12v drops below say 5v then wouldn't a simple transistor switch be more efficient??
unless he wants to measure the actual voltage levels then the voltage divider is perhaps the best.
WOW 1kv input to a PIC??. never imagined.
 
For an automotive environment, a low drop out regulator is desired.
I wouldn't agree with that.

Under normal conditions the supply voltage shouldn't drop below about 10V, if it does the battery is likely to be bad.

An LM7805 leaves plenty of headroom, the regulation is garmented to 8V and won't be any worse than 250mV even at 7V. At lower currents than the 1A maximum rating it's even better.

The problem is that the LM7805 has a maximum input voltage of 35V so may be zapped by the 120V voltage spikes often present on an automotive power system. This can be fixed by adding a 15V zener and a series resistor (1R to 2R2) to limit the zener current.
 
there is alot of noise in automotive system

as well as unstable voltage levels.
This is why a low drop out regulator is used for automotive apps.
this subject has come up on numerious occasions in this forum as well as the general chat etc.
do a search and see what I am referring to.
sure a 7805 will work but how well??
 
This is why a low drop out regulator is used for automotive apps.
I understand the issues of overvoltage but using a LDO for a 5V in an 12V automotive application does seem like overkill. As I mentioned above, the LM7805 will work down to 9V and many automotive devices fail to work below 10.5V.

this subject has come up on numerious occasions in this forum as well as the general chat etc.
do a search and see what I am referring to.
sure a 7805 will work but how well??
I've done a quick search, I saw your thread but I've not seen anything about needing a LDO regulator for a 5V line when powered from a 12V system.

So are you telling me that all those inverters which specify a minimum working voltage of 10.5V are useless?:p

If this was an LM7809 then I'd agree 100%, you need an LDO but not for an LM7805, heck you'll probably get away with an LM7808 on a 12V system, providing the input is transient protected of course.
 
If you want electronics to keep going while the engine is cranking, a low drop regulator is a good idea. The minimum voltage needed to turn the engine depends on a lot of things, but I have seen reasonable cranking speeds and less than 5 V on the battery.

None of those inverters will work under those conditions.

Also, it is a really bad idea to detect 12 V with a PIC and just one resistor. The switching point is typically 1.5 V with a TTL type input on a PIC and 2.5 V on a Schmitt trigger type input. The problem is that you can easily get leakage to voltages like that. For instance, the voltage generated by an LED in sunlight will trigger an input. If 12 V is on and 0 V is off, you want a switching point much nearer the mid point.

You should add a pull-down resistor to make a potential divider so that the trigger point is above about 4 V.
 
If you want electronics to keep going while the engine is cranking, a low drop regulator is a good idea.

I have never seen any thing electronic stay on while cranking the engine why start now
 
I have never seen any thing electronic stay on while cranking the engine why start now

The clocks in my wife's car and in my daughter's car are digital with no moving parts. Strangely, neither of them need resetting to show the right time after I start the engine. I guess that the electronics in those clocks keeps on running while cranking.

My car has a clock with hands so I don't know if that stops briefly while cranking.

Come to think of it, the engine management computers in all the cars seem to run while cranking. I think that it would be difficult for the engine to start if the ignition / injection stopped when the starter motor was running.

My mother's older car does need a bit of skill to start, as the ignition doesn't really work when the engine is cranking. You have to spin the engine on the starter motor and then it fires when you let go. I guess that's why it's got a crank handle as well. However, I think things have moved on a bit since MG made the YB model.

I know that the car audio, AC, lights and windows stop on a lot of cars when cranking. That is done to reduce battery load and to stop strange behaviour on stuff than can be managed without. However, there is a lot of stuff that has to keep running, so it has been engineered to do so.
 
I new some one would say that sure the clock keeps time it was made for that sure the computer come out of sleep mode. But most gauges don't start working till the engine is running
Tell me something can you charge a battery with the engine off No
P.S solar cells not in use here lol

You don't need to test for charging till you have it up and running
 
The OP doesn't say what the application is, so I have no idea if it should keep on working when the engine is being started.

Even if the application doesn't have to work normally during cranking, if the power supply is poor, the application would shut down and do a cold reset each time the engine is started. If that happens, it will forget anything that isn't stored in EEPROM or as a mechanical switch position.

Now if what he is trying to do is decide if it's OK to power up a battery charger, that's fine.

However, if he has a system has any sort of settings stored in RAM, the RAM must be protected during cranking.

There are several settings like that in a modern car. Some settings are stored in EEPROM, but most things that can be set by the driver are in RAM. The settings stay when the engine is cranked but are forgotten when the battery is disconnected. These are on systems that don't actually work while the engine is cranking but they have to pick up where they left off when the battery voltage recovers.

The ones that spring to mind are:-
Audio setting like volume and operating mode (radio, tape, cd etc)
AC settings
locking status including rolling code settings
Lighting settings
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top