|
|
View previous topic :: View next topic |
Author |
Message |
ADC_18F458 Guest
|
Problem with adc in 18F458 |
Posted: Mon May 23, 2005 9:15 pm |
|
|
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
|
|
Posted: Mon May 23, 2005 10:01 pm |
|
|
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);
}
} |
|
|
|
|
|
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
|