Page 1 of 1
15V Voltmeter at 3v3 mcu (SOLED)
Posted: Thu Apr 07, 2022 6:47 am
by bercioiu
Hi guys! I need your help again!
I want to make a voltmeter for my car and I can't handle with math ...
Mcu I use is 18F26K20, powered at 3.3 v, powered by the car's electrical installation through a stabilizer ld111733.
1) What values should the divider resistors have (R1, R2) ?
2) What should the adc reading calculation look like?
I've attached the FC8 file I want to work on.
Thank you!
+15V
|
R1
|
---- ADC
|
R2
|
--- Gnd
Thank you!
Re: 15V Voltmeter at 3v3 mcu
Posted: Thu Apr 07, 2022 10:51 pm
by medelec35
Hello
I have moved your post from Programming Tips & Tricks as that section is for sharing tips and not starting with a question.
I have calculated R1 to be 33K & R2 to be 8K2
This is handy as they are common preferred values.
Then if the voltage goes above 15V,the ADC of the PIC will be protected.
As for your flowchart just place * 5.0 at the end of your fomula so you will have
Code: Select all
MeasuredVoltage = 3.3 / 1024.0 * IntADC * 5.0
Note 15V in the top or R1 = 3V on the ADC pin.
This gives you a bit of leeway in voltage tolerance.
Re: 15V Voltmeter at 3v3 mcu (SOLED)
Posted: Fri Apr 08, 2022 6:57 am
by bercioiu
Thanks again for your help, Martin!
I put the resistors as you said and everything goes very well, everything is linear! There are no differences in different voltages.
When you have some free time, can you explain to me why " * 5 " ?
Later edit: I think I understand, 5 is the ratio between the input voltage and the adc voltage, after the divider.
Re: 15V Voltmeter at 3v3 mcu
Posted: Fri Apr 08, 2022 7:59 am
by medelec35
You're welcome, I'm glad the values worked for you as it was only theory.
bercioiu wrote: ↑Fri Apr 08, 2022 6:57 am
I think I understand, 5 is the ratio between the input voltage and the adc voltage, after the divider.
Yes, that is correct.
As the voltage going into the top of the R1 is five times higher than the voltage going into the ADC, the display has to show five times ADC voltage.
The ratio is five as you correctly stated.
If you want the precise ratio the maths are
That is why the display voltage values match (or very near to) the actual voltage values.
Re: 15V Voltmeter at 3v3 mcu
Posted: Fri Apr 08, 2022 4:41 pm
by bercioiu
For fine tuning, I formed R1 from 10k adjustable and 27k fixed, and I adjusted the potentiometer until I read the measured value with a reliable voltmeter.
Re: 15V Voltmeter at 3v3 mcu
Posted: Fri Apr 08, 2022 4:55 pm
by medelec35
Yes, that is a good way.
The alternative is to measure the two resistances, then plug the values in the above formula since resistors do have tolerances.
Then you can use that for that * value at the end of your formula.