This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Switching between two ADC channel



Hi,

I had written a simple code to use the ADC channel 4 and 5 in a timer ISR.I first convert channel 5 and then channel 4.
Voltage in channel 5 is getting converted properly. Then, I switch to Channel 4. But, its been observed that
ADCmux is not getting set to channel 4 !!! What is the exact procedure, if you want to switch between channels?
Is there amyu issue, if I do inside a ISR ?? I have posted the ISR code. Please help me out.

interrupt void TINT_isr(void)
{
    Int32 SAVE_ME             = 0;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Clearing Timer Interrupt Flags and Timer0 Bit
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    *CPU_TIM0_IER             = 0x0001;               /* clear Timer0 interrupt flag */
    *CPU_TIMINT_AGGR     |= 0x0001;              /* clear Timer0 bit */
    

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//This section of the code selected Channel 5
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     *SARCTRL                   |= (1 << 14);            
     *SARCTRL                  &= ~(1 << 13);          
    *SARCTRL                   |= (1 << 12);                

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//ADC is working on Single Conversion mode.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    *SARDATA               |= (1<<15);                //ADC_BUSY Made high
    *SARCTRL               |= (1<<15);                //Start ADC Conversion
    while ((*SARDATA & 0x8000)==0x8000);        //Wait for ADC conversion
    *SARCTRL               &= ~(1<<15);                //Stop ADC Conversion
    Input_Signal_1[ptr]    = *SARDATA & 0x3FF;    

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//SAVE_ME variable is watched in debug mode to ensure tht channel 5 is being converted
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    SAVE_ME = *SARDATA;
     

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Here I switch to Channel 4
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    *SARCTRL               |= (1 << 14);            //
       *SARCTRL               &= ~(1 << 13);            //
    *SARCTRL               &= ~(1 << 12);            //     
      
    *SARDATA               |= (1<<15);                //ADC_BUSY Made high
    *SARCTRL               |= (1<<15);                //Start ADC Conversion
    while ((*SARDATA & 0x8000)==0x8000);        //Wait for ADC conversion
    *SARCTRL               &= ~(1<<15);                //Stop ADC Conversion
    Input_Signal[ptr]     = *SARDATA & 0x3FF;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//SAVE_ME variable is watched in debug mode to ensure tht channel 5 is being converted
//BUT here, evn after setting channel 4, in SAVE_ME varibale it shown tht Channel 0 is being selected
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    SAVE_ME = *SARDATA;  
}

  • One more observation..

    If i am converting Channel 5 @ first and then Channel 4, then only Channel 5 is being converted !!!!

    If i am converting Channel 4 @ first and then Channel 5, then only Channel 4 is being converted !!!!

    In nutshell : Whtever I am converting @ first is being converted ....

  • Hello Anand,

    Try using a SAVE_ME2 = * SARDATA and see if you get the proper result.  I don't see we're you are doing anything to save the data to a different location.  Your are just overwriting it.  Also, double check your SARCTRL configuration for the channels.

    Thanks,

  • Hi,

    I have saved the signal to the variables Input_signal and Input_Signal_1. Infact, SAVE_ME is just a dummy variable to see whts happening

  • Take a look at this post, it should resolve your problem.

    http://e2e.ti.com/support/dsp/c5000/f/109/p/89547/326102.aspx

    Thanks,

  • I got the issue...its becaz i had made a small mistakein setting the bit.

    posting the correct code for others with same problem .

    interrupt void TINT_isr(void)
    {
        *CPU_TIM0_IER         = 0x0001;                 /* clear Timer0 interrupt flag */
        *CPU_TIMINT_AGGR     |= 0x0001;              /* clear Timer0 bit */

        *SARCTRL               &= ~(1 << 12);            //Channel 4 Selected           
        *SARCTRL               |= (1<<15);                //Start ADC Conversion
        while ((*SARDATA & 0x8000)==0x0000);        //Wait for ADC_BUSY to 1
        while ((*SARDATA & 0x8000)==0x8000);        //Wait for ADC_BUSY to 0
        *SARCTRL               &= ~(1<<15);            //Stop ADC Conversion
        Input_Signal[ptr]     = *SARDATA & 0x3FF;

        *SARCTRL               |= (1 << 12);            //Channel 5 selected    
        *SARCTRL               |= (1<<15);                //Start ADC Conversion
        while ((*SARDATA & 0x8000)==0x0000);        //Wait for ADC_BUSY to 1
        while ((*SARDATA & 0x8000)==0x8000);        //Wait for ADC_BUSY to 0
        *SARCTRL               &= ~(1<<15);            //Stop ADC Conversion
        Input_Signal_1[ptr]    = *SARDATA & 0x3FF;       

    }