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 adc in 18F458

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







Problem with adc in 18F458
PostPosted: Mon May 23, 2005 9:15 pm     Reply with quote

I am using five adc channels in a pic18F458 and I use for testing ANO and the others connected to ground (AN1, AN2, AN3, AN4) and I get a lot of garbage in Hyperterminal:

Code:

  0,  0,  0, 64,  0
  0,  0,  0,  0, 64
  0,  0, 64,  0,  0
  0,  0,  0,  0,  0
  0,  0,  0,  0, 64
  0,  0, 64,  0,  0
 64,  0, 64,  0,  0
  0,  0, 64,  0,  0
  0,  0,  0,  0,  0
 64,  0, 64,  0,  0
  0,  0,  0,  0,  0
 64,  0,  0,  0,  0
  0,  0,  0,  0,  0
 64,  0, 64,  0,  0
 64,  0,  0,  0, 64
 64,  0, 64, 64,  0
 64,  0, 64, 64,  0
128,  0,  0,  0,  0
 64,  0, 64, 64,  0
  0, 64, 64, 64,  0
 64,  0, 64, 64,  0
128, 64,  0,  0, 64
  0,  0,  0,  0,  0
  0,  0,  0, 64,  0
 64,  0,  0,  0,  0


Here is only working AN0, and the others are connected to ground

Code:

#if defined(__PCH__)
#include <18F458.h>
#device ADC=16
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#endif

void main() {

   int ch0,ch1,ch2,ch3,ch4;
   char coma;

   setup_port_a( ALL_ANALOG );
   setup_adc( ADC_CLOCK_INTERNAL );
   coma = ',';
   

   while (TRUE)
       {
         set_adc_channel(0);
         delay_us(10);
         ch0 = Read_ADC();
         printf("%3U%C",ch0,coma);
         delay_ms(10);
         set_adc_channel(1);
         delay_us(10);
         ch1 = Read_ADC();
         printf("%3U%C",ch1,coma);
         delay_ms(10);
         set_adc_channel(2);
         delay_us(10);
         ch2 = Read_ADC();
         printf("%3U%C",ch2,coma);
         delay_ms(10);
         set_adc_channel(3);
         delay_us(10);
         ch3 = Read_ADC();
         printf("%3U%C",ch3,coma);
         delay_ms(10);
         set_adc_channel(4);
         delay_us(10);
         ch4 = Read_ADC();
         printf("%3U\r\n",ch4);
         delay_ms(10);
       }
}


Thanks for your help!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 23, 2005 10:01 pm     Reply with quote

Make the changes shown in bold below:
Quote:
#include <18F458.h>
#device ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#endif

void main() {

int16 ch0,ch1,ch2,ch3,ch4;
char coma;

setup_port_a( ALL_ANALOG );
setup_adc(ADC_CLOCK_DIV_16);
coma = ',';


while (TRUE)
{
set_adc_channel(0);
delay_us(10);
ch0 = Read_ADC();
printf("%LU%C",ch0,coma);
delay_ms(10);
set_adc_channel(1);
delay_us(10);
ch1 = Read_ADC();
printf("%LU%C",ch1,coma);
delay_ms(10);
set_adc_channel(2);
delay_us(10);
ch2 = Read_ADC();
printf("%LU%C",ch2,coma);
delay_ms(10);
set_adc_channel(3);
delay_us(10);
ch3 = Read_ADC();
printf("%LU%C",ch3,coma);
delay_ms(10);
set_adc_channel(4);
delay_us(10);
ch4 = Read_ADC();
printf("%LU\r\n",ch4);
delay_ms(10);
}
}
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