#include <30F6014A.h>
#device ADC=12
#include <float.h>
#include <string.h>
#fuses FRC_PLL16, NOWDT, NOPROTECT, PUT64, BORV27 //7.37MHz x16
#use delay(clock=117920000,internal)
#use rs232(baud=9600,UART1,ERRORS)
void main()
{
set_TRIS_C(0x0000);
set_TRIS_D(0x0000);
SETUP_ADC(adc_OFF);
setup_adc_ports(ALL_ANALOG);
setup_adc_ports(sAN0 |sAN1|sAN2|sAN3|sAN4|sAN5|sAN6|sAN7|sAN8|sAN9|sAN10|sAN11|sAN12|sAN13|sAN14|sAN15, VSS_VDD);
setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_2);
setup_adc(ADC_CLOCK_INTERNAL);
// Built-in A/D setup function
//setup_adc_ports(ALL_ANALOG);
// Build-in A/D setup function
signed int32 ert_adc_value_5;
signed int32 ert_adc_value_6;
signed int32 ert_adc_value_7;
signed int32 ert_adc_value_8;
signed int32 ert_adc_value_9;
signed int32 ert_adc_value_10;
signed int32 ert_adc_value_11;
signed int32 ert_adc_value_12;
signed int32 ert_adc_value_13;
signed int32 ert_voltages_5;
signed int32 ert_voltages_6;
signed int32 ert_voltages_7;
signed int32 ert_voltages_8;
signed int32 ert_voltages_9;
signed int32 ert_voltages_10;
signed int32 ert_voltages_11;
signed int32 ert_voltages_12;
signed int32 ert_voltages_13;
while(TRUE)
{
//sample at TR5
set_adc_channel(4); //read from channel 0
delay_us(10); //delay is required after setting channel and bef.read
ert_adc_value_5=read_adc(); //starts conversion & store it in value
ert_voltages_5=(ert_adc_value_5)*5000/4096;// last result of last conversion
printf("Ch05=%u\r\n",ert_voltages_5);
//sample at TR6
set_adc_channel(5); //read from channel 0
delay_us(10); //delay is required after setting channel and bef.read
ert_adc_value_6=read_adc(); //starts conversion & store it in value
ert_voltages_6=(ert_adc_value_6)*5000/4096;// last result of last conversion
printf("Ch06=%u\r\n",ert_voltages_6);
//sample at TR7
set_adc_channel(6); //read from channel 0
delay_us(10); //delay is required after setting channel and bef.read
ert_adc_value_7=read_adc(); //starts conversion & store it in value
ert_voltages_7=(ert_adc_value_7)*5000/4096;// last result of last conversion
printf("Ch07=%u\r\n",ert_voltages_7);
//sample at TR8
set_adc_channel(7); //read from channel 0
delay_us(10); //delay is required after setting channel and bef.read
ert_adc_value_8=read_adc(); //starts conversion & store it in value
ert_voltages_8=(ert_adc_value_8)*5000/4096;// last result of last conversion
printf("Ch08=%u\r\n",ert_voltages_8);
//sample at TR9
set_adc_channel(8); //read from channel 0
delay_us(10); //delay is required after setting channel and bef.read
ert_adc_value_9=read_adc(); //starts conversion & store it in value
ert_voltages_9=(ert_adc_value_9)*5000/4096;// last result of last conversion
printf("Ch09=%u\r\n",ert_voltages_9);
//sample at TR10
set_adc_channel(9); //read from channel 0
delay_us(10); //delay is required after setting channel and bef.read
ert_adc_value_10=read_adc(); //starts conversion & store it in value
ert_voltages_10=(ert_adc_value_10)*5000/4096;// last result of last conversion
printf("Ch10=%u\r\n",ert_voltages_10);
//sample at TR11
set_adc_channel(10); //read from channel 0
delay_us(10); //delay is required after setting channel and bef.read
ert_adc_value_11=read_adc(); //starts conversion & store it in value
ert_voltages_11=(ert_adc_value_11)*5000/4096;// last result of last conversion
printf("Ch11=%u\r\n",ert_voltages_11);
//sample at TR12
set_adc_channel(11); //read from channel 0
delay_us(10); //delay is required after setting channel and bef.read
ert_adc_value_12=read_adc(); //starts conversion & store it in value
ert_voltages_12=(ert_adc_value_12)*5000/4096;// last result of last conversion
printf("Ch12=%u\r\n",ert_voltages_12);
//sample at TR13
set_adc_channel(12); //read from channel 0
delay_us(10); //delay is required after setting channel and bef.read
ert_adc_value_13=read_adc(); //starts conversion & store it in value
ert_voltages_13=(ert_adc_value_13)*5000/4096;// last result of last conversion
printf("Ch13=%u\r\n",ert_voltages_13);
}
}//end main
how to change to 1 sample for every channels?
#include <30F6014A.h>
#device ADC=12
#include <float.h>
#include <string.h>
#fuses FRC_PLL8,NOWDT, NOPROTECT, PUT64, BORV27,
#use delay(clock=58960000,internal)
#use rs232(baud=9600,UART1,ERRORS)
void main()
{
set_TRIS_C(0x0000);
set_TRIS_D(0x0000);
SETUP_ADC(adc_OFF);
setup_adc_ports(ALL_ANALOG);
setup_adc_ports(sAN0 |sAN1|sAN2|sAN3|sAN4|sAN5|sAN6|sAN7|sAN8|sAN9|sAN10|sAN11|sAN12|sAN13|sAN14|sAN15, VSS_VDD);
setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_16);
signed int32 ert_adc_value_5;
signed int32 ert_adc_value_6;
signed int32 ert_adc_value_7;
signed int32 ert_voltages_5;
signed int32 ert_voltages_6;
signed int32 ert_voltages_7;
while(TRUE)
{
output_high(PIN_D4);
delay_us(1);
output_low(PIN_D4);
delay_us(2);
output_high(PIN_D4);
delay_us(1);
output_low(PIN_D4);
delay_us(2);
//sample at TR5
set_adc_channel(4); //read from channel 4
delay_us(20); //delay is required after setting channel and bef.read
//read_adc(ADC_START_ONLY);
ert_adc_value_5=read_adc(); //starts conversion & store it in value
ert_voltages_5=(ert_adc_value_5)*5000/4096;// last result of last conversion
printf("Ch05=%u\n\r",ert_voltages_5);
output_high(PIN_C2);
//sample at TR6
set_adc_channel(5); //read from channel 5
delay_us(20); //delay is required after setting channel and bef.read
//read_adc(ADC_START_ONLY);
ert_adc_value_6=read_adc(); //starts conversion & store it in value
ert_voltages_6=(ert_adc_value_6)*5000/4096;// last result of last conversion
printf("Ch06=%u\r\n",ert_voltages_6);
output_high(PIN_C3);
//sample at TR7
set_adc_channel(6); //read from channel 6
delay_us(20); //delay is required after setting channel and bef.read
//read_adc(ADC_START_ONLY);
ert_adc_value_7=read_adc(); //starts conversion & store it in value
ert_voltages_7=(ert_adc_value_7)*5000/4096;// last result of last conversion
printf("Ch07=%u\r\n",ert_voltages_7);
}
//}//end kbhit
//}//end while
}//end main
#include <30F6014A.h>
#device ADC=12
#include <float.h>
#include <string.h>
#fuses NOWDT, NOPROTECT, PUT64, BORV27
#use delay (clock=58982400, xtal=7372800)
#use rs232(baud=9600,UART1,ERRORS)
char adc_value_5[20];
char adc_value_6[20];
unsigned char ert_adc_value_5;
unsigned char ert_adc_value_6;
unsigned char ert_voltages_5;
unsigned char ert_voltages_6;
void task1()
{
set_adc_channel(4); //read from channel 0
delay_us(10); //delay is required after setting channel and bef.read
//read_adc(ADC_START_ONLY);
ert_adc_value_5=read_adc(); //starts conversion & store it in value
ert_voltages_5=(ert_adc_value_5)*5000/4096;// last result of last conversion
//printf("Ch04=%u\n\r",ert_voltages_5);
sprintf(adc_value_5,"Ch05=<%u\r\n>",ert_voltages_5);
}
void task2()
{
set_adc_channel(5); //read from channel 0
delay_us(10); //delay is required after setting channel and bef.read
//read_adc(ADC_START_ONLY);
ert_adc_value_6=read_adc(); //starts conversion & store it in value
ert_voltages_6=(ert_adc_value_6)*5000/4096;// last result of last conversion
//printf("Ch05=%u\r\n",ert_voltages_6);
sprintf(adc_value_6,"Ch05=<%u\r\n>",ert_voltages_6);
}
void main(void) //void=nothing, no return value
{
set_TRIS_D(0x0000);
SETUP_ADC(adc_OFF);
setup_adc_ports(ALL_ANALOG);
setup_adc_ports(sAN0 |sAN1|sAN2|sAN3|sAN4|sAN5|sAN6|sAN7|sAN8|sAN9|sAN10|sAN11|sAN12|sAN13|sAN14|sAN15, VSS_VDD);
setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_2);
//setup_adc(ADC_CLOCK_INTERNAL);
while(TRUE)
{
task1();
task2();
}//end while
}//end main
puts(adc_value_5);
putc('\n');
puts(adc_value_6);
putc('\n');
unsigned int ert_adc_value[8];
unsigned int ert_voltages[8];
char adc_value[8][20];
void do_adc(int chan)
{
set_adc_channel(chan); //read from channel
delay_us(10); //delay is required after setting channel and bef.read
ert_adc_value[chan]=read_adc(); //starts conversion & store it in value
ert_voltages[chan]=(ert_adc_value[chan])*5000/4096;// last result of last conversion
sprintf(adc_value[chan],"Ch%02d=<%u\r\n>",chan, ert_voltages[chan]);
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?