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

ADC

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







ADC
PostPosted: Tue May 17, 2005 3:51 pm     Reply with quote

Hello, im trying to read several analogue inputs from some sensors and using PIC16C765. However, sometimes the readings do not match the input that is coming into the ADC channel. The sample code to display all values on all ADC channels is :
#include <16C765.h>
#device *=16
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=24000000) //maybe we change that to 6 MHz instead of 24MHz

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, bits=8, parity=N)



void main() {
int8 out_data[4];
unsigned int8 temp;

setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_32);

temp=0;
delay_ms(2000);

while (TRUE)
{
out_data[0]=0;

// printf("%U\t",counter);

//X
set_adc_channel(0);
delay_ms(1);

temp=read_adc();
delay_ms(1);

printf("%U ",temp);


set_adc_channel(1);
delay_ms(1);

temp=read_adc();
delay_ms(1);

printf("%U ",temp);


set_adc_channel(2);
delay_ms(1);

temp=read_adc();
delay_ms(1);

printf("%U ",temp);


set_adc_channel(3);
delay_ms(1);

temp=read_adc();
delay_ms(1);

printf("%U ",temp);


set_adc_channel(4);
delay_ms(1);

temp=read_adc();
delay_ms(1);

printf("%U ",temp);


set_adc_channel(5);
delay_ms(1);

temp=read_adc();
delay_ms(1);

printf("%U ",temp);


set_adc_channel(6);
delay_ms(1);

temp=read_adc();
delay_ms(1);

printf("%U ",temp);


set_adc_channel(7);
delay_ms(1);

temp=read_adc();
delay_ms(1);

printf("%U\n\r",temp);


delay_ms(4);
}
}

I also have to mention that when i read only 1 adc channel it outputs 0 but when reading all of them i get some sort of garbage values. Could someone please explain this behaviour. I set All channels ADC.
Thank You
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 17, 2005 3:56 pm     Reply with quote

What is your version of the compiler ?

I need to compile your code and look at the .LST file to see
what your version is doing.
MOHSEN
Guest







ADC
PostPosted: Tue May 17, 2005 4:07 pm     Reply with quote

I'm not sure how to get the exact version of the CCS C compiler im using. Any help in how i can get it
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 17, 2005 4:08 pm     Reply with quote

There are at least three ways to find the compiler version.

1. Compile a test file, and look at the top of the .LST file.
It will show the version.

2. Click on Start/ Programs, and then find the entry for CCS.
It might be called "PIC-C". Then click on the icon for "Compiler Version".

2. Open a DOS window and go to c:\Program Files\Picc
and run this command line: CCSC +v
MOHSEN
Guest







ADC
PostPosted: Tue May 17, 2005 4:16 pm     Reply with quote

It says:
PCB version 3.168
PCM Version 3.168
PCH version 3.168
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 17, 2005 4:32 pm     Reply with quote

I didn't see any problems with the compiled code.

What is the output impedance of the sensors that are connected
to the A/D pins ? The data sheet says the maximum permitted
impedance is 10K ohms.
MOHSEN
Guest







A/D
PostPosted: Tue May 17, 2005 5:40 pm     Reply with quote

I dont think i have an impedance problem. Here is the situation:
I have two working sensors on A/D channels 0 and 1. they read correctly. the sensor that is causing a problem is on A/D channel 3. When i read_adc() on channel 3 only it outputs 0. It doesnt read anything. However when i read_adc() on channels 3 (the problem) plus channel 1 (working) it outputs garbage data. I dont know what could cause such a behaviour. Could it be that the A/D did not get rid of the values stored from the first conversion and so it affects the second conversion. This is a wild guess.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 17, 2005 5:54 pm     Reply with quote

To test whether the problem is in the sensor or the wiring,
try moving the cable for Sensor 3 to A/D channel 0.
Then read ch. 0 and see if it's OK. If it fails, then
the problem is in Sensor 3 or its cable.
MOHSEN
Guest







A/D
PostPosted: Tue May 17, 2005 7:49 pm     Reply with quote

Thank you so much, you have been a great help.
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