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?
Question about PIC Voltmeter 0-30V
-
- 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
- Attachments
-
- Voltmeter_0-30V.fcfx
- (18.84 KiB) Downloaded 233 times
-
- 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
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:
As volt is an integer you can only multiply and divide by whole numbers only.
For example if 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 beas bytes and intergers are always rounded down and not up.
Try
martin
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
For example if
Code: Select all
volt = volt * 0.99
So if volt starts off with a value 250 then result will be
Code: Select all
250 * 0 = 0
Try
Code: Select all
volt = adc * 10 / 34
Martin
-
- 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
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.
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.