View previous topic :: View next topic |
Author |
Message |
mojsa2000
Joined: 18 May 2010 Posts: 78
|
A/D problem |
Posted: Tue Sep 07, 2010 2:26 pm |
|
|
In my program that uses PIC16f877a I've used 2 inputs as 2 A/D channel.
With timer2 it makes a 4ms overflow that in its interrupt reads the analog inputs. First the channel 0 and then channel1. In simulating by Proteus everything is ok and analog inputs are converted as well as I want, but on the board there is a strange problem. When both analog inputs values (channel 0,1) have a same value, converting is correct but when increases the channel 0 value and decreases channel 1 it makes error in converting.
That error is a voltage decrease on channel 1. For example the value on channel 1 was 3v but the lcd display 1.8v. This error is fixed with changing in other input value (channel0).
Best regards |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Tue Sep 07, 2010 2:39 pm |
|
|
Almost certainly you are not allowing time for the internal capacitor to charge between selecting the channel, and reading it. Hence the actual reading reflects the voltage stored in the capacitor before you changed channels.
Proteus, like all simulators, does not match real hardware exactly.
So, in your interrupt do something like:
Code: |
static int8 chan;
val[chan]=read_adc();
chan++;
if (chan==2) chan=0;
set_adc_channel(chan);
|
So you select the _next_ ADC channel before you leave the interrupt, allowing the 4mSec between interrupts for the ADC capacitor to charge.
Best Wishes |
|
|
mojsa2000
Joined: 18 May 2010 Posts: 78
|
|
Posted: Tue Sep 07, 2010 7:07 pm |
|
|
Thank you Ttelmah.
I'll try it and report result as soon as possible. |
|
|
|