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!
15V Voltmeter at 3v3 mcu (SOLED)
Moderator: Benj
-
- Posts: 161
- Joined: Sun Feb 25, 2007 10:56 am
- Location: bucharest, romania
- Has thanked: 90 times
- Been thanked: 34 times
- Contact:
15V Voltmeter at 3v3 mcu (SOLED)
- Attachments
-
- WhatsApp Image 2022-04-07 at 7.44.34 AM.jpeg (63.01 KiB) Viewed 8547 times
-
- Voltmeter_3v3.fcfx
- (10.9 KiB) Downloaded 114 times
Last edited by bercioiu on Tue May 10, 2022 5:51 am, edited 1 time in total.
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: 15V Voltmeter at 3v3 mcu
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
Note 15V in the top or R1 = 3V on the ADC pin.
This gives you a bit of leeway in voltage tolerance.
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
This gives you a bit of leeway in voltage tolerance.
Martin
-
- Posts: 161
- Joined: Sun Feb 25, 2007 10:56 am
- Location: bucharest, romania
- Has thanked: 90 times
- Been thanked: 34 times
- Contact:
Re: 15V Voltmeter at 3v3 mcu (SOLED)
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.
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.
Last edited by bercioiu on Tue May 10, 2022 5:51 am, edited 1 time in total.
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: 15V Voltmeter at 3v3 mcu
You're welcome, I'm glad the values worked for you as it was only theory.
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.
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
Code: Select all
1/(R2/(R1 + R2))
= 5.024
Martin
-
- Posts: 161
- Joined: Sun Feb 25, 2007 10:56 am
- Location: bucharest, romania
- Has thanked: 90 times
- Been thanked: 34 times
- Contact:
Re: 15V Voltmeter at 3v3 mcu
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.
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: 15V Voltmeter at 3v3 mcu
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.
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.
Martin