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.

TMS320F28027: Basic ADC problem

Part Number: TMS320F28027
Other Parts Discussed in Thread: CONTROLSUITE, C2000WARE

Hello, 

I am trying to use the ADC to read a particular voltage. The ADCs that have been set up are the follows:

void HAL_setupAdcs(HAL_Handle handle)
{
  HAL_Obj *obj = (HAL_Obj *)handle;


  // disable the ADCs
  ADC_disable(obj->adcHandle);


  // power up the bandgap circuit
  ADC_enableBandGap(obj->adcHandle);


  // set the ADC voltage reference source to internal 
  ADC_setVoltRefSrc(obj->adcHandle,ADC_VoltageRefSrc_Int);


  // enable the ADC reference buffers
  ADC_enableRefBuffers(obj->adcHandle);


  // power up the ADCs
  ADC_powerUp(obj->adcHandle);


  // enable the ADCs
  ADC_enable(obj->adcHandle);


  // set the ADC interrupt pulse generation to prior
  ADC_setIntPulseGenMode(obj->adcHandle,ADC_IntPulseGenMode_Prior);


  // set the temperature sensor source to external
  ADC_setTempSensorSrc(obj->adcHandle,ADC_TempSensorSrc_Ext);


  // configure the interrupt sources
  ADC_disableInt(obj->adcHandle,ADC_IntNumber_1);
  ADC_setIntMode(obj->adcHandle,ADC_IntNumber_1,ADC_IntMode_ClearFlag);
  ADC_setIntSrc(obj->adcHandle,ADC_IntNumber_1,ADC_IntSrc_EOC7);


  //configure the SOCs for boostxldrv8305evm_revA
  // sample the first sample twice due to errata sprz342f

  // ISEN_A
  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_0,ADC_SocChanNumber_B1);
  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_0,ADC_SocTrigSrc_EPWM1_ADCSOCA);
  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_0,ADC_SocSampleDelay_7_cycles);

  // ISEN_A
  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_1,ADC_SocChanNumber_B1);
  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_1,ADC_SocTrigSrc_EPWM1_ADCSOCA);
  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_1,ADC_SocSampleDelay_7_cycles);

  // ISEN_B
  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_2,ADC_SocChanNumber_B3);
  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_2,ADC_SocTrigSrc_EPWM1_ADCSOCA);
  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_2,ADC_SocSampleDelay_7_cycles);

  // ISEN_C
  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_3,ADC_SocChanNumber_B7);
  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_3,ADC_SocTrigSrc_EPWM1_ADCSOCA);
  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_3,ADC_SocSampleDelay_7_cycles);

  // VSEN_A
  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_4,ADC_SocChanNumber_A7);
  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_4,ADC_SocTrigSrc_EPWM1_ADCSOCA);
  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_4,ADC_SocSampleDelay_7_cycles);

  // VSEN_B
  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_5,ADC_SocChanNumber_A3);
  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_5,ADC_SocTrigSrc_EPWM1_ADCSOCA);
  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_5,ADC_SocSampleDelay_7_cycles);

  // VSEN_C
  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_6,ADC_SocChanNumber_A1);
  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_6,ADC_SocTrigSrc_EPWM1_ADCSOCA);
  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_6,ADC_SocSampleDelay_7_cycles);

  // V_PVDD
  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_7,ADC_SocChanNumber_A0);
  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_7,ADC_SocTrigSrc_EPWM1_ADCSOCA);
  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_7,ADC_SocSampleDelay_7_cycles);


  //ADC for switch
  ADC_setSocChanNumber (obj->adcHandle, ADC_SocNumber_8, ADC_SocChanNumber_A4);    //set SOC0 channel select to ADCINA4
  ADC_setSocChanNumber (obj->adcHandle, ADC_SocNumber_9, ADC_SocChanNumber_A4);
  ADC_setSocTrigSrc(obj->adcHandle, ADC_SocNumber_8, ADC_SocTrigSrc_EPWM1_ADCSOCA);    //set SOC0 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1
  ADC_setSocTrigSrc(obj->adcHandle, ADC_SocNumber_9, ADC_SocTrigSrc_EPWM1_ADCSOCA);    //set SOC1 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1
  ADC_setSocSampleDelay(obj->adcHandle, ADC_SocNumber_8, ADC_SocSampleDelay_7_cycles);   //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
  ADC_setSocSampleDelay(obj->adcHandle, ADC_SocNumber_9, ADC_SocSampleDelay_7_cycles);   //set SOC1 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)


  //  //SWITCH
//  ADC_setSocChanNumber(obj->adcHandle,ADC_SocNumber_8,ADC_SocChanNumber_A2);
//  ADC_setSocTrigSrc(obj->adcHandle,ADC_SocNumber_8,ADC_SocTrigSrc_EPWM1_ADCSOCA);
//  ADC_setSocSampleDelay(obj->adcHandle,ADC_SocNumber_8,ADC_SocSampleDelay_7_cycles);

  return;
} // end of HAL_setupAdcs() function

In my main I have created an interrupt to get the voltage counts at the ADC using the following function achieved from the ADC example:

__interrupt void adc_isr(void)
{
    //discard ADCRESULT0 as part of the workaround to the 1st sample errata for rev0
    Voltage1[ConversionCount] = ADC_readResult(myAdc, ADC_ResultNumber_8);
    Voltage2[ConversionCount] = ADC_readResult(myAdc, ADC_ResultNumber_9);

    // If 10 conversions have been logged, start over
    if(ConversionCount == 9)
    {
        ConversionCount = 0;
    }
    else
    {
        ConversionCount++;
    }

    // Clear ADCINT1 flag reinitialize for next SOC
    ADC_clearIntFlag(myAdc, ADC_IntNumber_1);
    // Acknowledge interrupt to PIE
    PIE_clearInt(myPie, PIE_GroupNumber_10);

    return;
}

I am getting some random values which are above 4096 which is supposed to be between 0-3.3 V. The voltage at my ADC pin is almost 1 V .

I have a motor driver 8305 with the 28027 as the controller. 

I am not sure if this is the right way of setting up an ADC but if possible can someone refer me to a document if there is on setting up an ADC. 

Regards, 

Rajan Joshi

  • Hi Rajan,

    I would suggest you to have a structured approach instead of driver based. Check this example code:
    C:\ti\controlSUITE\device_support\f2802x\v230\f2802x_examples_structs\adc_soc

    Regards,
    Gautam
  • Hello Gautam, 

    I am not sure if I understand correctly, but do you mean to say that I should not modify the hal.c and just try to structure it as the example that you pointed me to?

    I had another quick question:

    I was able to get it to run just using the example, but when I was injecting the 3.3 V from the board directly to the ADC, i was not getting a steady value but it was fluctuating from 4096 and 4095. Should it not be exactly 4095?

    Regards,

    Rajan  

  • Rajan Joshi said:
    I was able to get it to run just using the example, but when I was injecting the 3.3 V from the board directly to the ADC, i was not getting a steady value but it was fluctuating from 4096 and 4095. Should it not be exactly 4095?

    Nope, the digital value would fluctuate. You can further implement a moving average filter when the noise level in your system increases.

    Rajan Joshi said:
    I am not sure if I understand correctly, but do you mean to say that I should not modify the hal.c and just try to structure it as the example that you pointed me to?

    Nope, for F28027 the code can be written in 2 formats: 1. Structured 2. Driver based. If you navigate to this folder you'll understand:

    C:\ti\c2000\C2000Ware_1_00_00_00\device_support\f2802x\examples

    Regards,

    Gautam