pic18f4550 ADC

Thread Starter

Anjanav

Joined Mar 2, 2010
16
Hi...

for acquiring 4 analog inputs of PIC18F4550 am using a condition like(if i give 1 & 2 as input channel 1 and channel 2 value should get displayed)
where 1 starting channel number and 2 end of channel number
I tried this using for loop but am not getting any proper values...

correct me whether am correct...
awaiting for ur replies...

thanks,
 

retched

Joined Dec 5, 2009
5,207
You might want to post your code, as I cant make any sense of what you have said in regard to the conditions you placed.

Remember to use the [C0DE] and [/C0DE] tags to surround your code when posting it.
Click on go advanced (Next to the 'Post Quick Reply' button)

At the top of the editor, you will see a '#' button. Clicking that will add the CODE tags.
 

Tahmid

Joined Jul 2, 2008
343
Hi,
Here's what I would do in mikroBASIC. You can get the idea from here and convert to your own code.

Rich (BB code):
sub procedure ScanADCs(dim StartChannel as byte, dim ChannelNum as byte)
       for Temp = 0 to 7
           ADVal[Temp] = 0
       next Temp
       
       for Temp = StartChannel to ChannelNum
           ADVal[Temp] = ADC_Read(Temp)
       next Temp

       Ch0 = ADVal[0]
       Ch1 = ADVal[1]
       Ch2 = ADVal[2]
       Ch3 = ADVal[3]
       Ch4 = ADVal[4]
       Ch5 = ADVal[5]
       Ch6 = ADVal[6]
       Ch7 = ADVal[7]

end sub
Call the subroutine like
Rich (BB code):
ScanADCs(0,2)
Hope this helps.
Tahmid.
 

Thread Starter

Anjanav

Joined Mar 2, 2010
16
thanks for your replies retched and Tahmid...

here is my code...
Rich (BB code):
void Get_Start_End(unsigned char a,unsigned char b)
{
int l,m,temp5;
char a_buffer[3],c2[3][3],x;
for(x = a, l=0; x<=a+b-1; x++,l++)
 {
   x = x & 0x07;
   ADCON0bits.CHS0 = (x & 0b00000001);
   ADCON0bits.CHS1 = ((x & 0b00000010)>>1);
   ADCON0bits.CHS2 = ((x & 0b00000100)>>2);

  ADCON0bits.GO = 1;
  while(ADCON0bits.NOT_DONE);
   
  temp5 = ReadADC();
  itoa(temp5/2,a_buffer);
    for(m=0; m<3; m++){
      c2[l][m] = a_buffer[m];
    }
  }

putsUSBUSART(c2);
    
}
 
Top