pvol
Joined: 10 Oct 2008 Posts: 46 Location: GREECE
|
adc problem 18f4620 |
Posted: Thu Jan 01, 2009 12:42 pm |
|
|
happy new year everyone
I made a program to plot on labview
6 different channels
channel 0,1 POT 1K
channel 2,3,4,5 sensor
I begin from 2 channel then 3 ,4,5..
at the end i put and the POTS
now starts the problem...
when i plot 2,3,4,5 everything ok
when i plot all of them
channel 0 and 2 confuses and show same thing!!! value of 0 goes to 2
I made a attempt to take off "duty" POT 0
and result was channel 1 and 2 confuses again!! value of 1 goes to 2
here is code:
Code: |
#include <18F4620.h>
#device ADC=10
#fuses H4,NOWDT,NOPROTECT,NOLVP
#use delay(clock=40000000)
#byte porta=0xF80
#byte portb=0xF81
#byte portc=0xF82
//#byte portd=0xF83
//#byte porte=0xF84
#use RS232(baud=115200, xmit=PIN_C6, rcv=PIN_C7)
int count=0;
int16 cha1a[25];
int16 cha2a[25];
int16 cha3a[25];
int16 cha4a[25];
int16 cha1b[25];
int16 cha2b[25];
int16 cha3b[25];
int16 cha4b[25];
int16 cha1c[25];
int16 cha2c[25];
int16 cha3c[25];
int16 cha4c[25];
int16 cha1d[25];
int16 cha2d[25];
int16 cha3d[25];
int16 cha4d[25];
int16 cha1e[25];
int16 cha2e[25];
int16 cha3e[25];
int16 cha4e[25];
int16 cha1f[25];
int16 cha2f[25];
int16 cha3f[25];
int16 cha4f[25];
int flag=1;
int i=0;
int p=0;
#int_timer1
void t1mer(){
set_timer1(0xE0C0);
if(count<=25){
set_adc_channel(2);
delay_us(5);
cha1a[i] = read_ADC();
set_adc_channel(3);
delay_us(5);
cha1b[i] = read_ADC();
set_adc_channel(4);
delay_us(5);
cha1c[i] = read_ADC();
set_adc_channel(5);
delay_us(5);
cha1d[i] = read_ADC();
set_adc_channel(1);
delay_us(5);
cha1f[i] = read_ADC();
set_adc_channel(0);
delay_us(5);
cha1e[i] = read_ADC();
count++;
i++;
if(i>=25){
i=0; }
}
if((count>25)&&(count<=50)){
set_adc_channel(2);
delay_us(5);
cha2a[i] = read_ADC();
set_adc_channel(3);
delay_us(5);
cha2b[i] = read_ADC();
set_adc_channel(4);
delay_us(5);
cha2c[i] = read_ADC();
set_adc_channel(5);
delay_us(5);
cha2d[i] = read_ADC();
set_adc_channel(0);
delay_us(5);
cha2e[i] = read_ADC();
set_adc_channel(1);
delay_us(5);
cha2f[i] = read_ADC();
count++;
i++;
if(i>=25){i=0;
}
}
if((count>50)&&(count<=75)){
set_adc_channel(2);
delay_us(5);
cha3a[i] = read_ADC();
set_adc_channel(3);
delay_us(5);
cha3b[i] = read_ADC();
set_adc_channel(4);
delay_us(5);
cha3c[i] = read_ADC();
set_adc_channel(5);
delay_us(5);
cha3d[i] = read_ADC();
set_adc_channel(0);
delay_us(5);
cha3e[i] = read_ADC();
set_adc_channel(1);
delay_us(5);
cha3f[i] = read_ADC();
count++;
i++;
if(i>=25){i=0;
}
}
if((count>75)&&(count<=100)){
set_adc_channel(2);
delay_us(5);
cha4a[i] = read_ADC();
set_adc_channel(3);
delay_us(5);
cha4b[i] = read_ADC();
set_adc_channel(4);
delay_us(5);
cha4c[i] = read_ADC();
set_adc_channel(5);
delay_us(5);
cha4d[i] = read_ADC();
set_adc_channel(0);
delay_us(5);
cha4e[i] = read_ADC();
set_adc_channel(1);
delay_us(5);
cha4f[i] = read_ADC();
count++;
i++;
if(i>=25){i=0;
i=0;
flag=0;
count=0;
}
}
return; }
void main (void){
// set_tris_a(0xff);
// set_tris_b(0x00);
setup_adc_ports( AN0_TO_AN5 );
setup_adc(ADC_CLOCK_DIV_32);
set_timer1(0xE0C0); //interrupt every 0.8ms
setup_timer_1(T1_internal|T1_DIV_BY_1);
enable_interrupts(INT_TIMER1);
enable_interrupts(global);
while(TRUE){
while(flag);
disable_interrupts(INT_TIMER1);
for(p=0;p<=24;p++){
printf ("A %ld\n",cha1a[p]);
printf ("B %ld\n",cha1b[p]);
printf ("C %ld\n",cha1c[p]);
printf ("D %ld\n",cha1d[p]);
printf ("E %ld\n",cha1e[p]);
printf ("F %ld\n",cha1f[p]);}
for(p=0;p<=24;p++){
printf ("A %ld\n",cha2a[p]);
printf ("B %ld\n",cha2b[p]);
printf ("C %ld\n",cha2c[p]);
printf ("D %ld\n",cha2d[p]);
printf ("E %ld\n",cha2e[p]);
printf ("F %ld\n",cha2f[p]);}
for(p=0;p<=24;p++){
printf ("A %ld\n",cha3a[p]);
printf ("B %ld\n",cha3b[p]);
printf ("C %ld\n",cha3c[p]);
printf ("D %ld\n",cha3d[p]);
printf ("E %ld\n",cha3e[p]);
printf ("F %ld\n",cha3f[p]);}
for(p=0;p<=24;p++){
printf ("A %ld\n",cha4a[p]);
printf ("B %ld\n",cha4b[p]);
printf ("C %ld\n",cha4c[p]);
printf ("D %ld\n",cha4d[p]);
printf ("E %ld\n",cha4e[p]);
printf ("F %ld\n",cha4f[p]);}
enable_interrupts(INT_TIMER1);
set_timer1(0xE0C0);
flag=1;}} |
where do you think is the problem?
thanks for any answer |
|