![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
birumher
Joined: 28 Apr 2004 Posts: 10
|
18F452 ADC Stops |
Posted: Mon Nov 08, 2004 10:19 am |
|
|
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 ....
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Mon Nov 08, 2004 10:55 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
mvaraujo
Joined: 20 Feb 2004 Posts: 59 Location: Brazil
|
|
Posted: Mon Nov 08, 2004 1:20 pm |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
birumher
Joined: 28 Apr 2004 Posts: 10
|
|
Posted: Wed Nov 10, 2004 7:02 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|