I have searched for schematics -- usually you find a few common approaches,that vary slightly.
When I searched for "voltage clamp schematic" it came up with tons of different ones -- and after spending time checking them, I realize that it's seems pretty system specific.
In an automotive environment, were nominal voltage is 13.8 with spikes to 20+. I want to measure the volts using a voltage divider, the problem is those spikes, increasing the voltage divider to account for 20 loose some resolution, and still stands the chance of a 25v spike....
I read a few posts that mostly said "that won't work" or "use an op amp" but didn't elaborate much.
Since i want to read the voltage, is there a simple/reliable/fast clamping method to cut off anything higher than "X" volts? (specifically for me I would like to clamp at 16 or so).
I'm not an engineer, but, I read grump mike's site on protection & power -- but it didn't clue me in as to how to calculate resistors for the protection circuit...
One "pre made" solution I contemplated was to use a dc-dc buck/boost dialed in for 12v but that seems a spendy alternative...
any suggestions for a good method to go? While the system does have a generator/charge, it does not necessarily mean it is being charged, so (and why I don't like the dc-dc b/b converter) I would like to keep power consumption down as much as possible. When "not being charged" the power will never spike anyway...
If you use e.g a 1:3 divider with 10k/30k resistors, you can measure to 20volt.
And you are protected to ~50volt.
Add a 100n cap between analogue pin and ground, and you also kill fast spikes.
Another (better) way is to use a ~1:15 divider, and use the internal 1.1volt Aref.
A read range of 0-16volt (with full resolution), and protection to >200volt.
Here is a sample sketch. I also have an LCD shield version.
Leo..
/*
0 - ~17volt voltmeter
works with 3.3volt and 5volt Arduinos
uses the internal 1.1volt reference
10k resistor from A1 to ground, and 150k resistor from A1 to +batt
(1k8:27k or 2k2:33k are also valid 1:15 ratios)
100n capacitor from A1 to ground for stable readings
*/
float Aref = 1.063; // change this to the actual Aref voltage of ---YOUR--- Arduino (1.000 - 1.200), or adjust to get accurate voltage reading
unsigned int total; // A/D output
float voltage; // converted to volt
//
void setup() {
analogReference(INTERNAL); // use the internal ~1.1volt reference, change (INTERNAL) to (INTERNAL1V1) for a Mega
Serial.begin(9600); // ---set serial monitor to this value---
}
//
void loop() {
analogRead(1); // one unused reading to clear old sh#t
for (int x = 0; x < 16; x++) { // 16 analogue readings and 1/16 voltage divider = no additional maths
total = total + analogRead(1); // add each value
}
voltage = total * Aref / 1024; // convert readings to volt
// print to serial monitor
Serial.print("The battery is ");
Serial.print(voltage);
Serial.println(" volt");
total = 0; // reset value
delay(1000); // readout delay
}
A most people quite rightly do not use that because it is only an internal static protection device and is not rated to take any specified current. It is a very "hacky" thing to do and is not guaranteed to add to the reliability of the device. An engineere in industry would be sacked for doing such a thing.
My understanding of the proper way is to start with a good idea of what you are protecting against. If you are expecting your device to be hit by lightning and still work then you have a totally different protection to the device that only needs to be protected against the battery being plugged in backwards. Usually you would say that lightning strikes are expected to damage your device but the 15KV ESD human body model (static electricity from your fingers touching the device) should be absorbed without disrupting the operation of the device.
The automotive environment is particularly harsh as the battery can be connected backwards or you can get big inductive spikes of 16v or more. One common method alluded to above is to put diodes between the inputs and the Arduino power rails so that if the input is less than 0V then one diode will conduct to the ground of the Arduino or if it's greater than 5V the other diode will conduct to the 5V rail. The BAT54S (the "S" is important) is a good way to put pairs of these diodes on the board.
However, the spikes you expect to get in a car have a lot of power behind them. In EE terms, they are "low impedance" which means that it can deliver a lot of current to a protection diode. Easily enough to burn it out. Or, if it's a high voltage spike, it can push enough current into the 5V rail to bring it up to 10V and smoke your Arduino. So you need to add a high impedance between the input and the protection diodes. This is a simple resistor. It might be a 1000 ohm resistor or it might be a 1 ohm resistor, depending on what you are trying to protect.
Zener diodes and other types of avalanche devices can be used to apply voltage limits but they all need a resistor in front of them to protect them too. The basic BAT54S is usually better and it uses the same resistor in the same way.
I normally use a larger series resistor (maybe 1K). Since you're using a voltage divider, those resistors will limit the current through the diode(s) so you don't need to add another one.
I think we are over reacting here.
Internal protection diodes are just what they are. Protection diodes.
As long as you're well within the current limits, I see no harm in using them. Short term.
Designers will get fired if they use them?
What about reset caps, or the Aref cap, RC oscillators, or any cap on a pin.
Big chance that they get discharged through the protection diode when you turn your Arduino on or off.
The first option I gave, the 1:3 divider, does NOT use the diodes under 21.2volt. And diode current is less than 500uA @35volt.
The second option, the 1:15 divider, does NOT use the diodes under 84.4volt.
If a 12volt battery has that on it, everything in the car will get fried.
Any spike can't get through with a 150k/100n RC filter that has a cut-off frequency of ~10hz.
Low forward voltage diodes lke the BAT54 are ok to use, but I would avoid zeners when in measuring setups, because of the leakage and non-linearity.
I see NO need for adding diodes in this case.
Leo..
Wawa:
I think we are over reacting here.
Internal protection diodes are just what they are. Protection diodes.
As long as you're well within the current limits, I see no harm in using them. Short term.
Designers will get fired if they use them?
What about reset caps, or the Aref cap, RC oscillators, or any cap on a pin.
Big chance that they get discharged through the protection diode when you turn your Arduino on or off.
.....
I see NO need for adding diodes in this case.
Leo..
I am glad you weren't on my team with an attitude like that.
As long as you're well within the current limits, I see no harm in using them. Short term.
Hedging bets here. What is the current limit on these diodes? What does the data sheet say about them?
The answer is nothing at all. The 1mA "rating" comes from an application note where a very high resistor is in series ( many meg ohms ) with a pin.
These diodes were designed for static discharge protection, and as such if rated for anything they are expected to be used very intermittently.
Your big mistake was saying that:-
Most people are forgetting one thing.
An Arduino has 1mA input protection diodes.
No we do not forget it, we know more about it and know why not to rely on it.
Hmmm, the Atmel guys that wrote this document should get fired then.
They use a 1Megohm resistor between mains 230volt AC and an input pin, to detect zero crossing.
They say to keep it under 1000volt, so the diode current stays under 1mA.
The real reason they should be sacked is using a single 1M resistor insteads of two or more high voltage resistors
in series - you don't want a single point of failure between you and the mains. Imagine an ant crawling
over the circuit board, walks over the single 1M resistor and starts a high voltage flashover. Its obvious
adding a second resistor is a sensible mitigating measure for this kind of risk.
Thanks -- while I find it distasteful to "hit and run" (your idea sucks, but don't give any good alternatives); I have a few things to try now. It would see this would be a regular task. Time to sign up for some electronics elective courses & hope the instructor knows his stuff ;-)... (I am not an EE major).
I think I explained all of it, and I even have written the code for you.
Just follow the voltage divider instruction, and upload the code.
A 1:15 divider protects to 16x the Arduino supply voltage, and beyond.
With a 10k:150k voltage divider, theoretical survival voltage is 238volt.
A divider with these values uses ~75uA from the battery.
If drain current is not an issue, then you could also use the other 1:15 values listed in the code.
The code also uses pre-reading of the pin, and 16x sampling.
16x sampling and a 1:15 divider (1/16) also means no extra maths.
The internal 1.1volt analogue reference is used to make the reading independent of Arduino supply fluctuations.
The measuring range is ~17volt, so almost the whole range of the A/D is used when measuring a 12volt car battery.
(0 - ~1.1volt = 0 - 1023)
Let me know if you want the LCD shield version.
Leo..
ItsInterior:
An Arduino has 1mA input protection diodes.
Sigh - there is no telling people.
Use this diode at your own risk. It is not OFFICIALLY supported. A mention in an application note does not constitute official support.
@wawa -- thank you for your examples. I am using one of them now, only reason I said I needed to sign up for a class was so I could better understand the relationships -- I'm just learning electronics & even tho something might be blindingly obvious to one, it isn't to another... (I had one response to another question that basically said "leave arduino behind if you want to do real work" which didn't help)
I do appreciate your code, time, explanations, etc. Thank you.