View previous topic :: View next topic |
Author |
Message |
pandu.ranganadh
Joined: 28 Apr 2008 Posts: 12 Location: hyd
|
Problem with Multiple ADC channels |
Posted: Wed May 07, 2008 8:13 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
densimitre
Joined: 21 Dec 2004 Posts: 45
|
|
Posted: Wed May 07, 2008 8:18 am |
|
|
setup_adc_ports (other ports)
Bye |
|
![](templates/subSilver/images/spacer.gif) |
pandu.ranganadh
Joined: 28 Apr 2008 Posts: 12 Location: hyd
|
Problem with Multiple ADC channels |
Posted: Wed May 07, 2008 8:23 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
densimitre
Joined: 21 Dec 2004 Posts: 45
|
|
Posted: Wed May 07, 2008 9:17 am |
|
|
First set_adc_channel, then read_adc()
to read other channel you mut set the correct channel and read it after..
Bye |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 07, 2008 11:37 am |
|
|
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
|
|
|
![](templates/subSilver/images/spacer.gif) |
|