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/TMS320F28335: how long does it take to use ADC?

Part Number: TMS320F28335

Tool/software: Code Composer Studio

Hello

I have used the example of ADC_SOC to read three A/D channels and I have used two functions "Start_Timer" and "Stop_Timer"  to measure the time it takes to read these channels. It takes almost 0.005 s to do this however in the data sheet of TMS320F28335 it is stated that the conversion time of ADC is 80ns. Could you please check my code and see why it takes this long?

void main(void)
{
    InitSysCtrl();




    EALLOW;
    #define ADC_MODCLK 0x3
    EDIS;


    EALLOW;
    SysCtrlRegs.HISPCP.all = ADC_MODCLK;
    EDIS;

    DINT;
    InitPieCtrl();

IER = 0x0000;
    IFR = 0x0000;

    
    InitPieVectTable();

    InitCpuTimers();   // For this example, only initialize the Cpu Timers

    EALLOW;  // This is needed to write to EALLOW protected register
    PieVectTable.ADCINT = &adc_isr;
    EDIS;    // This is needed to disable write to EALLOW protected registers


    StartTimer();



    InitAdc();  // For this example, init the ADC
    PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
    IER |= M_INT1;      // Enable CPU Interrupt 1
    EINT;               // Enable Global interrupt INTM
    ERTM;               // Enable Global realtime interrupt DBGM

    //
    
    LoopCount = 0;
    ConversionCount = 0;

    //
    // Configure ADC
    //
    AdcRegs.ADCMAXCONV.all = 0x0003;       // Setup 2 conv's on SEQ1
    AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x2; // Setup ADCINA2 as 1st SEQ1 conv.
    AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x3; // Setup ADCINA3 as 2nd SEQ1 conv.
    AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x4;
    //
    // Enable SOCA from ePWM to start SEQ1
    //
    AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;

    AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;  // Enable SEQ1 interrupt (every EOS)

    //
    // Assumes ePWM1 clock is already enabled in InitSysCtrl();
    //
    EPwm1Regs.ETSEL.bit.SOCAEN = 1;     // Enable SOC on A group
    EPwm1Regs.ETSEL.bit.SOCASEL = 4;    // Select SOC from from CPMA on upcount
    EPwm1Regs.ETPS.bit.SOCAPRD = 1;     // Generate pulse on 1st event
    EPwm1Regs.CMPA.half.CMPA = 0x0080;  // Set compare A value
    EPwm1Regs.TBPRD = 0xFFFF;           // Set period for ePWM1
    EPwm1Regs.TBCTL.bit.CTRMODE = 0;    // count up and start

     StopTimer();

     delta_time=cpuTime*6.66e-9;

void StartTimer(void)
{
   // cpuTime1 = 0;

    EALLOW;
    CpuTimer2Regs.TCR.bit.TRB = 1;        // Reset CPU timer to period value
    CpuTimer2Regs.TCR.bit.TSS = 0;        // Start or reset CPU timer 2
    cpuTime1 = CpuTimer2Regs.TIM.all;     // Get value of CPU Timer 2 before code
    EDIS;
}

void StopTimer(void)
{

    EALLOW;
    cpuTime2 = CpuTimer2Regs.TIM.all;    // Get value of CPU Timer 2 after code
    cpuTime = cpuTime1 - cpuTime2;     // Calculate time using cpuTimer2
    CpuTimer2Regs.TCR.bit.TSS = 1;        // Start or reset CPU timer 2
    EDIS;
}

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
__interrupt void
adc_isr(void)
{
    Voltage1 = AdcRegs.ADCRESULT0 >>4;
    Voltage2 = AdcRegs.ADCRESULT1 >>4;
    Voltage3 = AdcRegs.ADCRESULT2 >>4;
    current = Voltage1- Voltage2;
    voltage = Voltage2- Voltage3;

    //
    // If 40 conversions have been logged, start over
    //

    //
    // Reinitialize for next ADC sequence
    //
    AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1;         // Reset SEQ1
    AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;       // Clear INT SEQ1 bit
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;   // Acknowledge interrupt to PIE

    return;
}

  • Ata,

    Your StartTimer() and StopTimer() placements are not measuring the time for the ADC conversions; they are measuring the time to execute the hardware initialization code.

    The actual EPWM-ADC SOC trigger and conversion sequence takes place through hardware state machines in the background (asynchronously from code execution). I would recommend that you refer to the ADC and EPWM reference guides to see what each AdcRegs and EPwm1Regs instruction is doing in the examples.

    Coding with C on this platform will require prerequisite familiarity with digital design and assembly programming concepts.  An alternative would be to use a higher level development environment such as those from MathWorkssolidThinking, or PSIM.

    -Tommy

  • Thank you Tommy.
    So isn't it possible to measure the time it takes for ADC?
    I need to be able to do trigger my GPIO every 20 us, so I need to make sure that my ADC works less than 20us each time it gets analog signals. Is there a way that I can do it?
  • Ata Khiabani said:
    So isn't it possible to measure the time it takes for ADC?

    It's possible to indirectly measure the execution time by reading the EPWM TBCTR from the ADC ISR.

    Ata Khiabani said:
    I need to be able to do trigger my GPIO every 20 us, so I need to make sure that my ADC works less than 20us each time it gets analog signals. Is there a way that I can do it?

    According to the timing diagram in the datasheet, this should be possible. Module / Lab 6 from the F28335 Workshop looks similar to what you are describing.