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

Problem with Multiple ADC channels

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



Joined: 28 Apr 2008
Posts: 12
Location: hyd

View user's profile Send private message Visit poster's website AIM Address

Problem with Multiple ADC channels
PostPosted: Sat May 10, 2008 3:31 am     Reply with quote

Hi to all,

I am using the bellow details of version.

CCS C Compiler 6.0
PCM version 3.170b
PCH version 3.170b
IDE version 3.36

MPLAB IDE version v8.02

I have a problem with accessing multiple ADC Channels in PIC16F877,
and i am using PIC older version demo board.

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010072&part=DM163022


#include <16F877.H>
#device adc=10
//#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=16000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#include "flex_lcd.c"

//============================
void main()
{
int16 adc_value;
float volts,a=10.25;

lcd_init();


setup_adc_ports(RA0_ANALOG);

//setup_adc_ports(ALL_ANALOG);

setup_adc(ADC_CLOCK_INTERNAL);

set_adc_channel(5);
//set_adc_channel(0);

delay_us(20);


while(1)
{
adc_value = read_adc();

/***************************************************************************/
/* The formula for ADC conversion is */
/* ADC result = (ADC Digital output value * V.reff)/2^no.of ADC channels */
/* -> 1023.0 or 1024.0 represents the 10 bit ADC, in order to get accurate */
/* result that value should be maintain as float. */
/* -> 5 represents the V reference voltage for ADC is 5V */
/* -> " adc_value " represents the o/p of the ADC, initially is was binary */
/* but " read_adc(); " function converts that value in to integer. */
/* -> In order to get float result answer should be convert(Typecast) in to */
/* float. */
/***************************************************************************/

volts = (float)(adc_value * 5)/1023.0; // This is the fixed formula

//lcd_putc("\f Output \n");

printf(lcd_putc,"\f %3.4f Volts\n",volts);


delay_ms(500);

}


}

Its working for Channel-0 only,If i can give other channels 1-5, its not working.

you said pins A1, A2, and A3 for the LCD, and pin A4 is used for switch S2. Pin A0 is connected to a trimpot.

The only A/D pins that you can use are these:

pin channel
RA5 AN4
RE0 AN5
RE1 AN6
RE2 AN7

i have tried for " set_adc_channel(5) ( 5 for RA5); ", but its not working.

Please resolve my problem.
Please check and resend code, if u don't mine.

Thanking you.
Ttelmah
Guest







PostPosted: Sat May 10, 2008 6:52 am     Reply with quote

First, get your compiler version 'right'. CCS compiler versions are in the form x.xxx, with the highest value for the first digit, currently being '4'. There is no version 6....

Now, you need to perhaps understand the chips better. There is an analog input multiplexer, which allows you to select from the 'available' input channels. This is controlled by the 'set_adc_channel' function. What channels are available for this to use, is controlled by the 'setup_adc_ports' function, with the available values for this, being specified in the data sheet. Currently you are _only_ selecting channel 0, hence this is the only one available to use. The possible configurations, are given in 'register 11-2' in the data sheet, and the options to select these are in the include file for the processor.
Now, to select right up to E2, you would have to use the 'ALL_ANALOGS' setting in the setup_adc_ports function (or a similar one using another Vref source).

With this done set_adc_channel(5), will then select E0.

You can still use pins setup as analog inputs, as digital outputs for the LCD (or as digital inputs), but there are a couple of 'caveats'. First, if you put an analog voltage on a pin being read as a digital input, and this is in the 'transition' region of the logic input, then the chip will draw extra current. Secondly, using pins selected onto the multiplexer for logic levels, risks increasing the noise levels on the analog readings.

Best Wishes
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