Question about PIC Voltmeter 0-30V

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
maharadga
Posts: 71
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Has thanked: 17 times
Been thanked: 12 times
Contact:

Question about PIC Voltmeter 0-30V

Post by maharadga »

Hello.
I maked Voltmeter with PIC16F876A in range 0-30V.
But in range 0-~20V , voltage, displayng on LCD is about ~0,1 V less that real value. In range ~20-30V is Ok.
It's error on ADC or it's my mistake?
Attachments
Voltmeter_0-30V.fcfx
(18.84 KiB) Downloaded 233 times

medelec35
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: Question about PIC Voltmeter 0-30V

Post by medelec35 »

Hi maharadga,
Have you tried on real hardware?
I would not have thought it would work at all.
Reason being, for calculations you're using INT variables.
You have got a calculation:

Code: Select all

volt = 0.293255 * adc
As volt is an integer you can only multiply and divide by whole numbers only.
For example if

Code: Select all

volt = volt * 0.99
then whatever the volt variable starts at, the result will always be 0
So if volt starts off with a value 250 then result will be

Code: Select all

250 * 0 = 0
as bytes and intergers are always rounded down and not up.
Try

Code: Select all

volt = adc * 10 / 34
martin
Martin

maharadga
Posts: 71
Joined: Mon Dec 01, 2014 1:38 pm
Location: Bulgaria
Has thanked: 17 times
Been thanked: 12 times
Contact:

Re: Question about PIC Voltmeter 0-30V

Post by maharadga »

Hi, medelec35.
Yes, of course I tryed in hardware. Exactly in hardware I see difference 0,1V bellow ~20V.
In your formula " volt = adc * 10 / 34" difference is 0,2V over measured voltage.
Better result is with formula "volt = 0.0300097 * adc" where "volt" is floating point and "adc" is integer.

Post Reply