pic18f4550 ADC

Discussion in 'Embedded Systems and Microcontrollers' started by Anjanav, Jul 3, 2010.

  1. Anjanav

    Thread Starter New Member

    Mar 2, 2010
    16
    0
    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,
     
  2. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    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.
     
  3. Tahmid

    Active Member

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

    Code ( (Unknown Language)):
    1. sub procedure ScanADCs(dim StartChannel as byte, dim ChannelNum as byte)
    2.        for Temp = 0 to 7
    3.            ADVal[Temp] = 0
    4.        next Temp
    5.        
    6.        for Temp = StartChannel to ChannelNum
    7.            ADVal[Temp] = ADC_Read(Temp)
    8.        next Temp
    9.  
    10.        Ch0 = ADVal[0]
    11.        Ch1 = ADVal[1]
    12.        Ch2 = ADVal[2]
    13.        Ch3 = ADVal[3]
    14.        Ch4 = ADVal[4]
    15.        Ch5 = ADVal[5]
    16.        Ch6 = ADVal[6]
    17.        Ch7 = ADVal[7]
    18.  
    19. end sub
    Call the subroutine like
    Code ( (Unknown Language)):
    1. ScanADCs(0,2)
    Hope this helps.
    Tahmid.
     
  4. Anjanav

    Thread Starter New Member

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

    here is my code...
    Code ( (Unknown Language)):
    1. void Get_Start_End(unsigned char a,unsigned char b)
    2. {
    3. int l,m,temp5;
    4. char a_buffer[3],c2[3][3],x;
    5. for(x = a, l=0; x<=a+b-1; x++,l++)
    6.  {
    7.    x = x & 0x07;
    8.    ADCON0bits.CHS0 = (x & 0b00000001);
    9.    ADCON0bits.CHS1 = ((x & 0b00000010)>>1);
    10.    ADCON0bits.CHS2 = ((x & 0b00000100)>>2);
    11.  
    12.   ADCON0bits.GO = 1;
    13.   while(ADCON0bits.NOT_DONE);
    14.    
    15.   temp5 = ReadADC();
    16.   itoa(temp5/2,a_buffer);
    17.     for(m=0; m<3; m++){
    18.       c2[l][m] = a_buffer[m];
    19.     }
    20.   }
    21.  
    22. putsUSBUSART(c2);
    23.    
    24. }
     
Loading...