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: Wed May 07, 2008 8:13 am     Reply with quote

Hi to all,

I am using the bellow details of version.

CCS C Compiller 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(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
//set_adc_channel(1);
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, inorder to get acurate */
/* 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, inetially is was binary */
/* but " read_adc(); " function converts that value in to integer. */
/* -> Inoder ot 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. How to use remaining channels.
Please check and resend code.

Bye
Thanking you.
densimitre



Joined: 21 Dec 2004
Posts: 45

View user's profile Send private message

PostPosted: Wed May 07, 2008 8:18 am     Reply with quote

setup_adc_ports (other ports)

Bye
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: Wed May 07, 2008 8:23 am     Reply with quote

Hi,

Thank you for sending reply,
I have done that job as

setup_adc_ports(ALL_ANALOG); or any of other, then its not working, There is no display on LCD.


Bye
Thanking you.
densimitre



Joined: 21 Dec 2004
Posts: 45

View user's profile Send private message

PostPosted: Wed May 07, 2008 9:17 am     Reply with quote

First set_adc_channel, then read_adc()

to read other channel you mut set the correct channel and read it after..

Bye
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 07, 2008 11:37 am     Reply with quote

Quote:
Its working for Channel-0 only. How to use remaining channels.

Most of the A/D pins are already used for other purposes on your board.
It uses 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:
Code:

pin   channel
RA5   AN4
RE0   AN5
RE1   AN6
RE2   AN7
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