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 support@ccsinfo.com

18F452 ADC Stops

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



Joined: 28 Apr 2004
Posts: 10

View user's profile Send private message Send e-mail

18F452 ADC Stops
PostPosted: Mon Nov 08, 2004 10:19 am     Reply with quote

I am trying to make 8 channel ADC with USB support.
in every 100 us with timer0 interrupt program starts channel 1 conversion and send the value USB chip after channel 2 conversion starts etc..
The system woks fine. but for test puposes I have connected potentiometers to analog-digital converters and when I connect 0 volt to ADC pin the conversion stops.
As you see in the code , I set the GODONE bit in order to start the conversion and wait for GODONE. The problem is here when I connect 0 V to ADC pin GODONE never becomes 0 and the conversion stops. Is it normal ?

Code:


void timer0_isr()

{
      for(i=0;i<ChannelCount;++i) {
         ChannelNo = i;
         ChannelNo = ChannelNo << 3;
         ADCON0 |= ChannelNo; 
         GODONE = 1; // start the conversion
         while (GODONE != 0) ;// wait for GODONE         
         value1 = ADRESL;
         value2 = ADRESH;


//write value1 and  value 2 to USB ....

      }
}
 



Ttelmah
Guest







PostPosted: Mon Nov 08, 2004 10:55 am     Reply with quote

Ignoring your actual problem for a moment, you seem to be doing a lot in the timer ISR. This is not a good idea, nor is waiting for things in the ISR. As it stands, you are selecting the AD channel, and immediately sampling. This will give appalling results. The ADC input, is internally connected to a capacitor, and requires _time_ to charge to the voltage on the input. This is why you need to wait for typically 10uSec, after selecting a channel, before reading the channel. Physically, you cannot sample 8 channels in 100uSec. The charging time required is typically 10uSec/channel, and the sampling time is at minimum about the same.
You should be sequencing the operations.
So on the first call you select the first channel.
On the second call you trigger the ADC
On the third call you read the ADC, and select the next channel.
On the next call you behave like call 2 and trigger the ADC
You then keep looping.
This way the ISR, never waits (so long as the interval of the ISR, is greater than the sample time and charge time of the ADC).
You would then need 16* the interrupt interval (or a minimum of 8* the charge interval, and 8* the sampling interval), to take eight readings.

Now the Go/Done bit, should have no difference on a value of zero, however I have seen exactly this behaviour on an early stepping of the 18F252, so it is possible that there is a silicon fault that causes this. Generally, it is better to scale the input to avoid zero though, since otherwise there is no way to tell that your input is not 'beyond' what you want as a zero 'point'.

However even without this, you need to redesign your code, if you are to get accurate readings.

Best Wishes
mvaraujo



Joined: 20 Feb 2004
Posts: 59
Location: Brazil

View user's profile Send private message

PostPosted: Mon Nov 08, 2004 1:20 pm     Reply with quote

Yep, Ttelmah is right!

Consider using timer interrupt only to set a flag informing that it's time to convert and keep the AD state machine on the main loop.

Respect the time to charge internal capacitor, even if you're not seeing problems now, you will have in the future. Do you really need to sample these channels so fast?
birumher



Joined: 28 Apr 2004
Posts: 10

View user's profile Send private message Send e-mail

PostPosted: Wed Nov 10, 2004 7:02 am     Reply with quote

Thank you for your replies mvaraujo , Ttelmah.

I am changing the code . In every interrupt routine it will only sample 1 channel, and 1 sample for 20 us is enough for me. But there is a point that is not clear for me.
Where do I make a delay for ADC. After setting ADCON0 register or after setting GODONE bit or both?
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