CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

A/D problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mojsa2000



Joined: 18 May 2010
Posts: 78

View user's profile Send private message

A/D problem
PostPosted: Tue Sep 07, 2010 2:26 pm     Reply with quote

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: 19540

View user's profile Send private message

PostPosted: Tue Sep 07, 2010 2:39 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Sep 07, 2010 7:07 pm     Reply with quote

Thank you Ttelmah.
I'll try it and report result as soon as possible.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group