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.

CCS/LAUNCHXL-F28027: ADC Conversion

Part Number: LAUNCHXL-F28027
Other Parts Discussed in Thread: CONTROLSUITE

Tool/software: Code Composer Studio

I am trying to use ADCINA0 for sensing position through potentiometer. I am using this code but am not getting some random number in ADCRESULT0 Register which remains constant even after sliding the pot. All the external functions used are the ones which were there in Examples folder of F2802x in controlsuite. Code which i am using is in the attached file. It will be helpful if anyone could point out the mistake which i am making and steps to rectify it.

/*
 * ADC.c
 *
 *  Created on: 27-Mar-2018
 *      Author: Nishant Sharma
 */


#include "DSP28x_Project.h" // DSP28x Headerfile
#include "F2802x_Device.h"

#define ADC_usDELAY  1000L

extern void InitAdc(void);
extern void InitSysCtrl(void);
extern void InitPieCtrl(void);
extern void InitPieVectTable(void);
extern void InitPeripheralClocks(void);
extern void InitGpio(void);
extern void DisableDog(void);
extern void InitFlash(void);
extern void AdcOffsetSelfCal(void);

Uint16 ConvertADC(void);

void main()
{
    Uint16 ACQPS_Value;
    Uint32 Value;
    DisableDog();
    InitFlash();
    InitSysCtrl();              // Basic Core Init from DSP2833x_SysCtrl.c
    InitGpio();
    InitPieCtrl();              // basic setup of PIE table; from DSP2833x_PieCtrl.c
    InitPieVectTable();         // default ISR's in PIE
    InitAdc();
    //AdcOffsetSelfCal();
    AdcRegs.ADCSOC0CTL.bit.CHSEL= 0;
    ACQPS_Value = 7;
    EALLOW;
    AdcRegs.SOCPRICTL.bit.SOCPRIORITY=01;
    EDIS;
    AdcRegs.ADCSOC0CTL.bit.ACQPS  = ACQPS_Value;
    AdcRegs.ADCSOC0CTL.bit.TRIGSEL= 00;
    AdcRegs.INTSEL1N2.bit.INT1E = 1;
    AdcRegs.INTSEL1N2.bit.INT1CONT = 0;
    AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1;    //ADCINTs trigger at end of conversion
    AdcRegs.INTSEL1N2.bit.INT1SEL = 0;      //EOC0 triggers ADCINT1
    AdcRegs.ADCINTSOCSEL1.all  = 00;
    AdcRegs.ADCINTSOCSEL2.all  = 00;
    DELAY_US(ADC_usDELAY);                  // Delay before converting ADC channels
    while(1)
    {
        Value=ConvertADC();
    }
    AdcRegs.INTSEL1N2.bit.INT1E = 0;
}


Uint16 ConvertADC(void)
{

    Uint32 Value;

    AdcRegs.ADCSOCFRC1.bit.SOC0 = 1;  // Force Start SOC0
    while (AdcRegs.ADCINTFLG.bit.ADCINT1 == 0){}
        AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;   //Must clear ADCINT1 flag since INT1CONT = 0
        Value= AdcResult.ADCRESULT0;
    return Value;                //return the value

}//end AdcConversion
/*
 * ADC.c
 *
 *  Created on: 27-Mar-2018
 *      Author: Nishant Sharma
 */


#include "DSP28x_Project.h" // DSP28x Headerfile
#include "F2802x_Device.h"

#define ADC_usDELAY  1000L

extern void InitAdc(void);
extern void InitSysCtrl(void);
extern void InitPieCtrl(void);
extern void InitPieVectTable(void);
extern void InitPeripheralClocks(void);
extern void InitGpio(void);
extern void DisableDog(void);
extern void InitFlash(void);
extern void AdcOffsetSelfCal(void);

Uint16 ConvertADC(void);

void main()
{
    Uint16 ACQPS_Value;
    Uint32 Value;
    DisableDog();
    InitFlash();
    InitSysCtrl();              // Basic Core Init from DSP2833x_SysCtrl.c
    InitGpio();
    InitPieCtrl();              // basic setup of PIE table; from DSP2833x_PieCtrl.c
    InitPieVectTable();         // default ISR's in PIE
    InitAdc();
    //AdcOffsetSelfCal();
    AdcRegs.ADCSOC0CTL.bit.CHSEL= 0;
    ACQPS_Value = 7;
    EALLOW;
    AdcRegs.SOCPRICTL.bit.SOCPRIORITY=01;
    EDIS;
    AdcRegs.ADCSOC0CTL.bit.ACQPS  = ACQPS_Value;
    AdcRegs.ADCSOC0CTL.bit.TRIGSEL= 00;
    AdcRegs.INTSEL1N2.bit.INT1E = 1;
    AdcRegs.INTSEL1N2.bit.INT1CONT = 0;
    AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1;    //ADCINTs trigger at end of conversion
    AdcRegs.INTSEL1N2.bit.INT1SEL = 0;      //EOC0 triggers ADCINT1
    AdcRegs.ADCINTSOCSEL1.all  = 00;
    AdcRegs.ADCINTSOCSEL2.all  = 00;
    DELAY_US(ADC_usDELAY);                  // Delay before converting ADC channels
    while(1)
    {
        Value=ConvertADC();
    }
    AdcRegs.INTSEL1N2.bit.INT1E = 0;
}


Uint16 ConvertADC(void)
{

    Uint32 Value;

    AdcRegs.ADCSOCFRC1.bit.SOC0 = 1;  // Force Start SOC0
    while (AdcRegs.ADCINTFLG.bit.ADCINT1 == 0){}
        AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;   //Must clear ADCINT1 flag since INT1CONT = 0
        Value= AdcResult.ADCRESULT0;
    return Value;                //return the value

}//end AdcConversion

  • Hi Nishant,

    Try this example code from controlSuite: C:\ti\controlSUITE\device_support\f2802x\v230\f2802x_examples_structs\adc_soc

    Regards,
    Gautam
  • Thanks a lot.

    I have one more query i am trying to convert ADC result value into displacement for my position sensor. I have been using Voltage1 variable as measured digital value and position as converted displacement. Both are declared volatile float global variables. But i am getting one constant value of both variables in watch expression window whereas result value is changing in ADCRESULT1 Register. Optimization is turned off. I am hereby attaching my ADC interrupt subroutine. Can you point out what might be the error.

    __interrupt void adc_isr(void)
    {
    Voltage1 = AdcResult.ADCRESULT1; //discard ADCRESULT0 as part of the workaround to the 1st sample errata for rev0
    //Voltage2[ConversionCount] = AdcResult.ADCRESULT2;

    // If 20 conversions have been logged, start over
    /* if(ConversionCount == 9)
    {
    ConversionCount = 0;
    }
    else
    {
    ConversionCount++;
    }*/
    position= (0.6*Voltage1)/4095;
    AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //Clear ADCINT1 flag reinitialize for next SOC
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE

    return;
    }

  • Nishant,

    Try setting a breakpoint in adc_isr() and single-step through the code execution to see where things are going wrong.

    -Tommy