Hi all,
I want to measure voltage of a car battery... say between 9v and 16v
with and ADC in the ESP32, can you recommend the input circuit to the pin?
would it be a voltage divider then a Zener to make sure it does not exceed 3.3v?
so like 39k + 10k then a 3.3v zener
or maybe 2 diodes as a voltage clamp
one to 3.3v other to gnd
just looking for a suggestion
thanks
mitch
measure 9v to 18v
Re: measure 9v to 18v
You are right to be concerned about protecting the ADC input. It is said that there can be substantial voltage spikes on car battery voltages but I have not seen any information about what voltages can be expected. Don't forget to also protect the power supply to your ESP32.
The voltage-current characteristics of low voltage zener diodes, such as 3.3V, are poor. They have a significant 'knee', quite high dynamic resistance and relatively poor accuracy of zener voltage. I therefore suggest this circuit with a zener of about 6.8V which will have significantly better characteristics . . . . However you should bear in mind the tolerance of the voltage value. A 6.8V zener may not conduct until say 7.2V and then only 5mA. Conversely, due to the knee and tolerance of zener voltage, a 6.8V zener may start conducting at roughly 6.0V. You need to choose resistor values accordingly.
There are three more things you can do to further improve protection. Firstly use high value resistors. The ESP32 datasheet does not specify a maximum input current for an ADC. I expect you can use resistors above 1MΩ but one ought to consider if there is any significant leakage in the zener below the voltage at which it nominally starts to conduct. Secondly, you can use a low value of ADC attenuation. So for example if you set the ADC attenuation within the ESP32 to 0dB, the ADC will operate over the input voltage range of about 0.1V to 1.1V. That would allow you to divide the voltage by a greater amount so leasening the chance of a really big spike causing the voltage to exceed 3.3V. Thirdly, consider adding a capacitor across the ADC input or across the zener. That will filter out short spikes; it may have the added advantage of filtering out short-term changes of battery voltage and electrical noise.
I guess we ought to consider protection against negative voltage spikes. A zener diode will start to conduct as a normal silicon diode when it's voltage exceeds about -0.65V. The ESP32 is supposed to tolerate input voltages to -0.3V maximum. This means your proposal to put a zener diode across the ADC input would be insufficient. However by using three resistors as shown in my circuit diagram above, the ADC input would not go below -0.3V (with appropriate choice of resistors).
I wonder whether you could simply use two very high-value resistors as a voltage divider without a zener. You would then be relying on the input protection built into the ESP32 (but poor documented!).
Please be aware that the ESP32 ADCs have very poor noise performance. See 'Minimising Noise' here.
The voltage-current characteristics of low voltage zener diodes, such as 3.3V, are poor. They have a significant 'knee', quite high dynamic resistance and relatively poor accuracy of zener voltage. I therefore suggest this circuit with a zener of about 6.8V which will have significantly better characteristics . . . . However you should bear in mind the tolerance of the voltage value. A 6.8V zener may not conduct until say 7.2V and then only 5mA. Conversely, due to the knee and tolerance of zener voltage, a 6.8V zener may start conducting at roughly 6.0V. You need to choose resistor values accordingly.
There are three more things you can do to further improve protection. Firstly use high value resistors. The ESP32 datasheet does not specify a maximum input current for an ADC. I expect you can use resistors above 1MΩ but one ought to consider if there is any significant leakage in the zener below the voltage at which it nominally starts to conduct. Secondly, you can use a low value of ADC attenuation. So for example if you set the ADC attenuation within the ESP32 to 0dB, the ADC will operate over the input voltage range of about 0.1V to 1.1V. That would allow you to divide the voltage by a greater amount so leasening the chance of a really big spike causing the voltage to exceed 3.3V. Thirdly, consider adding a capacitor across the ADC input or across the zener. That will filter out short spikes; it may have the added advantage of filtering out short-term changes of battery voltage and electrical noise.
I guess we ought to consider protection against negative voltage spikes. A zener diode will start to conduct as a normal silicon diode when it's voltage exceeds about -0.65V. The ESP32 is supposed to tolerate input voltages to -0.3V maximum. This means your proposal to put a zener diode across the ADC input would be insufficient. However by using three resistors as shown in my circuit diagram above, the ADC input would not go below -0.3V (with appropriate choice of resistors).
I wonder whether you could simply use two very high-value resistors as a voltage divider without a zener. You would then be relying on the input protection built into the ESP32 (but poor documented!).
Please be aware that the ESP32 ADCs have very poor noise performance. See 'Minimising Noise' here.
Re: measure 9v to 18v
To complement the answers above, you may want to add a 100n cap between input and gnd to filter the ignition spikes and other noise, and do your ADC measurements as running average.
Re: measure 9v to 18v
thanks for all the input... I wasn't aware of the issues with low voltage zeners
would I calculate the voltage divider as 6.8v input?
other thought:
what do you think of the diode clamp?
one of my thoughts was to do this
for sure i will average the value... what do you think is a good read count, 10? 25? 100? to get the average
i got time, how this works, its a ble characteristic to read voltage, im gonna just keep voltage up to date in a task
thanks!
mitch
would I calculate the voltage divider as 6.8v input?
other thought:
what do you think of the diode clamp?
one of my thoughts was to do this
for sure i will average the value... what do you think is a good read count, 10? 25? 100? to get the average
i got time, how this works, its a ble characteristic to read voltage, im gonna just keep voltage up to date in a task
thanks!
mitch
Re: measure 9v to 18v
As you wish to measure up to 18V, you don't want the zener to be conducting when you have 18V input. A datasheet I'm looking at for a particular 6.8V zener gives a tolerance of 6.4V to 7.2V at 5mA. A graph on the datasheet clearly shows the 'knee' but there is no detailed information about the knee. I think you would need to assume that the zener may start conducting at roughly 5.4V, especially as we are proposing to used quite high value resistors so need to consider small currents. I therefore suggest resistors should be chosen such that when the input is 18V, the voltage across the zener is about 5.4V and the ADC input is 1.0V (max). You would then need to check how well the circuit performs in practice, especially with regard to linearity.mitchjs wrote:. . . would I calculate the voltage divider as 6.8v input?
The reason I've said the ADC input should be 1.0V (max) is because it is stated that the ADC reference voltage "can range from 1000mV to 1200mV" (just above the second graph here). I understand that means with ADC attenuation set to 0dB, it's just possible that maximum digital value could be reached with 1.0V input.
We can get some appreciation of the protection afforded by the zener (ignoring any capacitor). My datasheet shows the dynamic resistance is maximum 8Ω at 5mA. So if we consider a zener at the top end of the voltage tolerance range (7.2V at 5mA) and increase its current to (say) 100mA, we would expect the voltage to increase by only 0.76V (strictly, the dynamic resistance may not be constant above 5mA). The resistors dropping the voltage from about 5.4V to 1.0V will also drop the voltage from about -0.7V to -0.13V if a negative spike occurs.
Your proposed diode clamp looks OK but I have a few comments. With regard to the ADC reference voltage range mentioned above, in order to be sure to be able to measure up to 18V, you may wish to increase R11 to 180kΩ (or decrease R13). I am a little concerned that the leakage current of those Schottky diodes can be up to 10µA at 5V. In comparison, the zener diode datasheet I've been looking at shows leakage current up to 0.1µA at 3V. I therefore again suggest you check how well the circuit performs in practice, especially with regard to linearity. What's the purpose of R12?
I assume you are going to calibrate against a digital voltmeter, editing a numeric value in your code accordingly.
Protecting your voltage regulator may be more problematic.
Is this a one-off or will it go into production?
I suggest you experiment!mitchjs wrote:... what do you think is a good read count, 10? 25? 100? to get the average
Re: measure 9v to 18v
Hi Mitch, my friends from HW will comment about the clamping diodes, I think you can rely on the ones on the ESP32 IO but better double check. As far as averaging, you can try with 20 samples and optimize accordingly. Have fun.
Re: measure 9v to 18v
still researching...
R12 limits current into ADC so that if there is a turn on off the pins internal diodes (assuming it already has small clamping diodes)
its very low current... course with 150k R11 the current flowing should be tiny
mitch
R12 limits current into ADC so that if there is a turn on off the pins internal diodes (assuming it already has small clamping diodes)
its very low current... course with 150k R11 the current flowing should be tiny
mitch
Re: measure 9v to 18v
The ESP32 datasheet says that a digital input voltage should be between -0.3V and VDD+0.3V. A graph on the BAT760-7 datasheet indicates that the diode at 0°C will drop 0.3V at about 25mA. Assuming the input voltage range also applies to ADC inputs and ignoring tolerances, 25mA through 150K would require 3.75kV. I don't think R12 helps at all .
Re: measure 9v to 18v
A few years ago I read about voltage spikes in car power lines.
As far as I remember, those spikes come from devices which have an inductance.
They can have peak voltages of more than 100V.
Make sure not only to protect the ADC input but also use a proper power supply for the chip.
As far as I remember, those spikes come from devices which have an inductance.
They can have peak voltages of more than 100V.
Make sure not only to protect the ADC input but also use a proper power supply for the chip.
my page: http://www.barth-dev.de/
Who is online
Users browsing this forum: Bing [Bot] and 89 guests