I am using pic18F4580 to acquire samples from 8 adc channels. For AN0 I connected to +5V and AN0 connected to +0V. I make a simple code to acquire from all channels and when conversions completed at all channels the coded will send a termination charater 'A'.
- CODE: SELECT_ALL_CODE
#include <18F4580.h>
#device ADC=8
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define button (PIN_B0)
void main()
{
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_8);
const int8 channel1[]=0,1,2,3,4,5,6,7;
int16 ADC_value[sizeof(channel1)];
int8 value;
int z;
char char1;
SETUP_ADC_PORTS(ALL_ANALOG); //all analogue
output_low(PIN_B6);
output_low(PIN_B7);
while(TRUE) //loop forever
{
while (TRUE)
{
if(input(button) == 0) //RB0 when pressed o/p will be 0
break;
else
output_high(PIN_B6);
}
//get here when 'S' is pressed
for (z=0;z<1;z++) //1x=8 samples data for 1 frame image
{
output_low(PIN_B6);
for (value=0;value<sizeof(channel1);value++)
// read from 9 adc channels
{
output_low(PIN_B7);
set_adc_channel(channel1[value]);
ADC_value[value]=read_adc(); //ADC readings
printf("%4.3w\r\n", ADC_value[value]); //4 digit adc value and new line between value
//putc(read_adc());
output_high(PIN_B7);
}
printf("A\r\n");
}
}
}
From the hyper terminal I am getting this value:
- CODE: SELECT_ALL_CODE
0.255
0.232
0.114
0.099
0.050
0.031
0.035
0.000
A
0.255
0.226
0.134
0.083
0.043
0.056
0.021
0.000
A
My questions are:
a) I am getting value of 255 (8-bit) instead of 5 from AN0. How to change the samples to real floating point value?
b) Instead of sending each data from each channels when conversion is completed, how to send one-time data from all channels when all samples are available?
Thank you.