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.

TMS320F28379S: Setting up ADC reference for f28379s

Part Number: TMS320F28379S
Other Parts Discussed in Thread: LAUNCHXL-F280025C, C2000WARE

Hi,

I trying to set up ADCs using a HAL_setupADCs() function. I am reusing this function originally written for f280025 examples. I getting compiler errors for the following two lines. The compiler is looking for the definition and declaration of ADC_setVREF(), which is missing n the adc.c of the f28379s driverlib. What is the function used for setting f28379s reference voltage.  

// LAUNCHXL-F280025C based kits
ADC_setVREF(obj->adcHandle[0], ADC_REFERENCE_INTERNAL, ADC_REFERENCE_3_3V);
ADC_setVREF(obj->adcHandle[1], ADC_REFERENCE_INTERNAL, ADC_REFERENCE_3_3V);

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

    SysCtl_delay(100U);

#if defined(BSXL8323RS_REVA) || defined(BSXL8323RH_REVB) || \
    defined(BSXL8353RS_REVA) || defined(BSXL3PHGAN_REVA) || \
    defined(BSXL8316RT_REVA) || defined(DRV8329AEVM_REVA)
    /* commented JS
    // LAUNCHXL-F280025C based kits
    ADC_setVREF(obj->adcHandle[0], ADC_REFERENCE_INTERNAL, ADC_REFERENCE_3_3V);
    ADC_setVREF(obj->adcHandle[1], ADC_REFERENCE_INTERNAL, ADC_REFERENCE_3_3V);
      */ // end commented JS
#elif defined(HVMTRPFC_REV1P1)
    // TMDSCNCD280025C based kits
    ADC_setVREF(obj->adcHandle[0], ADC_REFERENCE_INTERNAL, ADC_REFERENCE_3_3V);
    ADC_setVREF(obj->adcHandle[1], ADC_REFERENCE_INTERNAL, ADC_REFERENCE_3_3V);
#else
#error Select the right clock of PLL for the board
#endif  // ADC Reference

    SysCtl_delay(100U);

    // Set main clock scaling factor (50MHz max clock for the ADC module)
    ADC_setPrescaler(obj->adcHandle[0], ADC_CLK_DIV_2_0);
    ADC_setPrescaler(obj->adcHandle[1], ADC_CLK_DIV_2_0);

    // set the ADC interrupt pulse generation to end of conversion
    ADC_setInterruptPulseMode(obj->adcHandle[0], ADC_PULSE_END_OF_CONV);
    ADC_setInterruptPulseMode(obj->adcHandle[1], ADC_PULSE_END_OF_CONV);

    // set priority of SOCs
    ADC_setSOCPriority(obj->adcHandle[0], ADC_PRI_ALL_HIPRI);
    ADC_setSOCPriority(obj->adcHandle[1], ADC_PRI_ALL_HIPRI);

    // enable the ADCs
    ADC_enableConverter(obj->adcHandle[0]);
    ADC_enableConverter(obj->adcHandle[1]);

    // delay to allow ADCs to power up
    SysCtl_delay(1000U);

    //-------------------------------------------------------------------------
#if defined(MOTOR1_ISBLDC)
    // configure the interrupt sources
    // Interrupt for motor 1
    ADC_setInterruptSource(MTR1_ADC_INT_BASE,
                           MTR1_ADC_INT_NUM, MTR1_ADC_INT_SOC);

    // Idc 1st
    ADC_setupSOC(MTR1_IDC1_ADC_BASE, MTR1_IDC1_ADC_SOC_NUM, MTR1_IDC_TRIGGER_SOC,
                 MTR1_IDC1_ADC_CH_NUM, MTR1_ADC_I_SAMPLEWINDOW);

    // Configure PPB to eliminate subtraction related calculation
    // PPB is associated with ADCA_SOC0
    ADC_setupPPB(MTR1_IDC1_ADC_BASE, MTR1_IDC1_ADC_PPB_NUM, MTR1_IDC1_ADC_SOC_NUM);

    // Write zero to this for now till offset calibration complete
    ADC_setPPBCalibrationOffset(MTR1_IDC1_ADC_BASE, MTR1_IDC1_ADC_PPB_NUM, 0);

    // Idc 2nd
    ADC_setupSOC(MTR1_IDC2_ADC_BASE, MTR1_IDC2_ADC_SOC_NUM, MTR1_IDC_TRIGGER_SOC,
                 MTR1_IDC2_ADC_CH_NUM, MTR1_ADC_I_SAMPLEWINDOW);

    // Configure PPB to eliminate subtraction related calculation
    // PPB is associated with ADCC_SOC0
    ADC_setupPPB(MTR1_IDC2_ADC_BASE, MTR1_IDC2_ADC_PPB_NUM, MTR1_IDC2_ADC_SOC_NUM);

    // Write zero to this for now till offset calibration complete
    ADC_setPPBCalibrationOffset(MTR1_IDC2_ADC_BASE, MTR1_IDC2_ADC_PPB_NUM, 0);

    // VSEN_A_M1
    ADC_setupSOC(MTR1_VU_ADC_BASE, MTR1_VU_ADC_SOC_NUM, MTR1_ADC_TRIGGER_SOC,
                 MTR1_VU_ADC_CH_NUM, MTR1_ADC_I_SAMPLEWINDOW);

    // VSEN_B_M1
    ADC_setupSOC(MTR1_VV_ADC_BASE, MTR1_VV_ADC_SOC_NUM, MTR1_ADC_TRIGGER_SOC,
                 MTR1_VV_ADC_CH_NUM, MTR1_ADC_I_SAMPLEWINDOW);

    // VSEN_C_M1
    ADC_setupSOC(MTR1_VW_ADC_BASE, MTR1_VW_ADC_SOC_NUM, MTR1_ADC_TRIGGER_SOC,
                 MTR1_VW_ADC_CH_NUM, MTR1_ADC_I_SAMPLEWINDOW);

    // VSEN_DCBUS_M1-->Trig Interrupt
    ADC_setupSOC(MTR1_VDC_ADC_BASE, MTR1_VDC_ADC_SOC_NUM, MTR1_ADC_TRIGGER_SOC,
                 MTR1_VDC_ADC_CH_NUM, MTR1_ADC_I_SAMPLEWINDOW);

#if defined(CMD_POT_EN) || defined(DRV8329AEVM_REVA)
    // POT_M1
    ADC_setupSOC(MTR1_POT_ADC_BASE, MTR1_POT_ADC_SOC_NUM, MTR1_ADC_TRIGGER_SOC,
                 MTR1_POT_ADC_CH_NUM, MTR1_ADC_I_SAMPLEWINDOW);
#endif  // CMD_POT_EN | DRV8329AEVM_REVA

#else // !MOTOR1_ISBLDC
    // configure the SOCs for M1
#if defined(MOTOR1_DCLINKSS)
    // configure the interrupt sources
    // Interrupt for motor 1
    ADC_setInterruptSource(MTR1_ADC_INT_BASE,
                           MTR1_ADC_INT_NUM, MTR1_ADC_INT_SOC);

    // Idc 1st
    ADC_setupSOC(MTR1_IDC1_ADC_BASE, MTR1_IDC1_ADC_SOC_NUM, MTR1_IDC1_TRIGGER_SOC,
                 MTR1_IDC1_ADC_CH_NUM, MTR1_ADC_I_SAMPLEWINDOW);

    // Configure PPB to eliminate subtraction related calculation
    // PPB is associated with ADCA_SOC0
    ADC_setupPPB(MTR1_IDC1_ADC_BASE, MTR1_IDC1_ADC_PPB_NUM, MTR1_IDC1_ADC_SOC_NUM);

    // Write zero to this for now till offset calibration complete
    ADC_setPPBCalibrationOffset(MTR1_IDC1_ADC_BASE, MTR1_IDC1_ADC_PPB_NUM, 0);

    // Idc 2nd
    ADC_setupSOC(MTR1_IDC2_ADC_BASE, MTR1_IDC2_ADC_SOC_NUM, MTR1_IDC2_TRIGGER_SOC,
                 MTR1_IDC2_ADC_CH_NUM, MTR1_ADC_I_SAMPLEWINDOW);

    // Configure PPB to eliminate subtraction related calculation
    // PPB is associated with ADCC_SOC0
    ADC_setupPPB(MTR1_IDC2_ADC_BASE, MTR1_IDC2_ADC_PPB_NUM, MTR1_IDC2_ADC_SOC_NUM);

    // Write zero to this for now till offset calibration complete
    ADC_setPPBCalibrationOffset(MTR1_IDC2_ADC_BASE, MTR1_IDC2_ADC_PPB_NUM, 0);

    // Idc 3rd
    ADC_setupSOC(MTR1_IDC3_ADC_BASE, MTR1_IDC3_ADC_SOC_NUM, MTR1_IDC3_TRIGGER_SOC,
                 MTR1_IDC3_ADC_CH_NUM, MTR1_ADC_I_SAMPLEWINDOW);

    // Configure PPB to eliminate subtraction related calculation
    // PPB is associated with ADCA_SOC0
    ADC_setupPPB(MTR1_IDC3_ADC_BASE, MTR1_IDC3_ADC_PPB_NUM, MTR1_IDC3_ADC_SOC_NUM);

    // Write zero to this for now till offset calibration complete
    ADC_setPPBCalibrationOffset(MTR1_IDC3_ADC_BASE, MTR1_IDC3_ADC_PPB_NUM, 0);

    // Idc 4th
    ADC_setupSOC(MTR1_IDC4_ADC_BASE, MTR1_IDC4_ADC_SOC_NUM, MTR1_IDC4_TRIGGER_SOC,
                 MTR1_IDC4_ADC_CH_NUM, MTR1_ADC_I_SAMPLEWINDOW);

    // Configure PPB to eliminate subtraction related calculation
    // PPB is associated with ADCC_SOC0
    ADC_setupPPB(MTR1_IDC4_ADC_BASE, MTR1_IDC4_ADC_PPB_NUM, MTR1_IDC4_ADC_SOC_NUM);

    // Write zero to this for now till offset calibration complete
    ADC_setPPBCalibrationOffset(MTR1_IDC4_ADC_BASE, MTR1_IDC4_ADC_PPB_NUM, 0);


#else   // !(MOTOR1_DCLINKSS)
    // configure the interrupt sources
    // Interrupt for motor 1
    ADC_setInterruptSource(MTR1_ADC_INT_BASE,
                           MTR1_ADC_INT_NUM, MTR1_ADC_INT_SOC);
    // ISEN_A_M1
    ADC_setupSOC(MTR1_IU_ADC_BASE, MTR1_IU_ADC_SOC_NUM, MTR1_ADC_TRIGGER_SOC,
                 MTR1_IU_ADC_CH_NUM, MTR1_ADC_I_SAMPLEWINDOW);

    // Configure PPB to eliminate subtraction related calculation
    // PPB is associated with ADCA_SOC0
    ADC_setupPPB(MTR1_IU_ADC_BASE, MTR1_IU_ADC_PPB_NUM, MTR1_IU_ADC_SOC_NUM);

    // Write zero to this for now till offset calibration complete
    ADC_setPPBCalibrationOffset(MTR1_IU_ADC_BASE, MTR1_IU_ADC_PPB_NUM, 0);

    // ISEN_B_M1
    ADC_setupSOC(MTR1_IV_ADC_BASE, MTR1_IV_ADC_SOC_NUM, MTR1_ADC_TRIGGER_SOC,
                 MTR1_IV_ADC_CH_NUM, MTR1_ADC_I_SAMPLEWINDOW);

    // Configure PPB to eliminate subtraction related calculation
    // PPB is associated with ADCC_SOC0
    ADC_setupPPB(MTR1_IV_ADC_BASE, MTR1_IV_ADC_PPB_NUM, MTR1_IV_ADC_SOC_NUM);

    // Write zero to this for now till offset calibration complete
    ADC_setPPBCalibrationOffset(MTR1_IV_ADC_BASE, MTR1_IV_ADC_PPB_NUM, 0);

    // ISEN_C_M1
    ADC_setupSOC(MTR1_IW_ADC_BASE, MTR1_IW_ADC_SOC_NUM, MTR1_ADC_TRIGGER_SOC,
                 MTR1_IW_ADC_CH_NUM, MTR1_ADC_I_SAMPLEWINDOW);

    // Configure PPB to eliminate subtraction related calculation
    // PPB is associated with ADCA_SOC0
    ADC_setupPPB(MTR1_IW_ADC_BASE, MTR1_IW_ADC_PPB_NUM, MTR1_IW_ADC_SOC_NUM);

    // Write zero to this for now till offset calibration complete
    ADC_setPPBCalibrationOffset(MTR1_IW_ADC_BASE, MTR1_IW_ADC_PPB_NUM, 0);
#endif   // !(MOTOR1_DCLINKSS)

#if defined(MOTOR1_FAST) || defined(MOTOR1_ISBLDC)
    // VSEN_A_M1
    ADC_setupSOC(MTR1_VU_ADC_BASE, MTR1_VU_ADC_SOC_NUM, MTR1_ADC_TRIGGER_SOC,
                 MTR1_VU_ADC_CH_NUM, MTR1_ADC_V_SAMPLEWINDOW);

    // VSEN_B_M1
    ADC_setupSOC(MTR1_VV_ADC_BASE, MTR1_VV_ADC_SOC_NUM, MTR1_ADC_TRIGGER_SOC,
                 MTR1_VV_ADC_CH_NUM, MTR1_ADC_V_SAMPLEWINDOW);

    // VSEN_C_M1
    ADC_setupSOC(MTR1_VW_ADC_BASE, MTR1_VW_ADC_SOC_NUM, MTR1_ADC_TRIGGER_SOC,
                 MTR1_VW_ADC_CH_NUM, MTR1_ADC_V_SAMPLEWINDOW);
#endif  // MOTOR1_FAST || MOTOR1_ISBLDC

    // VSEN_DCBUS_M1-->Trig Interrupt
    ADC_setupSOC(MTR1_VDC_ADC_BASE, MTR1_VDC_ADC_SOC_NUM, MTR1_ADC_TRIGGER_SOC,
                 MTR1_VDC_ADC_CH_NUM, MTR1_ADC_V_SAMPLEWINDOW);


#if defined(CMD_POT_EN) || defined(DRV8329AEVM_REVA)
    // POT_M1
    ADC_setupSOC(MTR1_POT_ADC_BASE, MTR1_POT_ADC_SOC_NUM, MTR1_ADC_TRIGGER_SOC,
                 MTR1_POT_ADC_CH_NUM, MTR1_ADC_V_SAMPLEWINDOW);
#endif  // CMD_POT_EN | DRV8329AEVM_REVA
#endif  // !MOTOR1_ISBLDC

    return;
} // end of HAL_setupADCs() function

  • Hello Jagbir,

    The reason that the function is missing is because the F2837xS device does not have the option for internal/external VREFHI, only external VREFHI is allowed (you can verify this by comparing the Analog Peripherals section of the datasheets for both devices).

    Best regards,

    Omer Amir

  • Thanks, Omer.

    Another question: is the main clock scaling factor work in the same way as 280025.

  • Hi Jagbir,

    Are you talking about the ADC clock? The clock requirements and prescalers should be the same for both devices.

    Best regards,

    Omer Amir

  • Hi Omer,

    I have kept the clocks the same for the f28379s.

    Now, I am trying to read the ADCIND1 pin on the ADC D port. However, the measured value by the ADCIND1(37.27V) is incorrect. The correct value is 48V. 

    The voltage measured at the pin is 2.16V, consistent with my resistor divider on 48V.

    Two questions:

    1. Why is the measured value by ADC incorrect.

    2. What adc register stores the ADCIND1 value for f2839s devices. Is it ADCresult6 register .

          

  • Hello Jagbir,

    1. What is the VREF configuration you are using? Using this we can figure out how much your reading is off by
    2. The ADC used in C2000 devices are SOC-based, meaning configurations are set up per SOC. If you configure an SOC to read from a certain channel, the result should show up with that same SOC number. The ADC results do not get stored according to the channel/pin they are read from.

    Best regards,

    Omer Amir

  • 1. I am using the 3.3V, as shown in the schematics above. 

    2. Here are my SOC and PPB configurations. Can you check if I have configured ADC properly.

    #define MTR1_IU_ADC_BASE        ADCA_BASE               // ADCA-A3
    #define MTR1_IV_ADC_BASE        ADCA_BASE               // ADCA-A4
    #define MTR1_IW_ADC_BASE        ADCA_BASE               // ADCA-A5
    
    #define MTR1_IU_ADCRES_BASE     ADCARESULT_BASE         // ADCA-A3
    #define MTR1_IV_ADCRES_BASE     ADCARESULT_BASE         // ADCC-A4
    #define MTR1_IW_ADCRES_BASE     ADCARESULT_BASE         // ADCC-A5
    
    #define MTR1_IU_ADC_CH_NUM      ADC_CH_ADCIN3          // ADCA-A3
    #define MTR1_IV_ADC_CH_NUM      ADC_CH_ADCIN4           // ADCA-A4
    #define MTR1_IW_ADC_CH_NUM      ADC_CH_ADCIN5           // ADCA-A5
    
    #define MTR1_IU_ADC_SOC_NUM     ADC_SOC_NUMBER1         // ADCA-A3-SOC1-PPB1
    #define MTR1_IV_ADC_SOC_NUM     ADC_SOC_NUMBER2         // ADCA-A4-SOC2-PPB2
    #define MTR1_IW_ADC_SOC_NUM     ADC_SOC_NUMBER3         // ADCA-A5-SOC3-PPB3
    
    #define MTR1_IU_ADC_PPB_NUM     ADC_PPB_NUMBER1         // ADCA-A3-SOC1-PPB1
    #define MTR1_IV_ADC_PPB_NUM     ADC_PPB_NUMBER2         // ADCA-A4 -SOC2-PPB2
    #define MTR1_IW_ADC_PPB_NUM     ADC_PPB_NUMBER3         // ADCA-A5- SOC3-PPB3
    
    
    // ADC - Voltage, Phase and dc-bus
    #define MTR1_VU_ADC_BASE        ADCB_BASE               // ADCB-B3
    #define MTR1_VV_ADC_BASE        ADCB_BASE               // ADCB-B4
    #define MTR1_VW_ADC_BASE        ADCB_BASE               // ADCB-B5
    #define MTR1_VDC_ADC_BASE       ADCD_BASE               // ADCD1-D1
    #define MTR1_POT_ADC_BASE       ADCD_BASE               // NC
    
    #define MTR1_VU_ADCRES_BASE     ADCBRESULT_BASE         // ADCB3-B3
    #define MTR1_VV_ADCRES_BASE     ADCBRESULT_BASE         // ADCB4-B4
    #define MTR1_VW_ADCRES_BASE     ADCBRESULT_BASE         // ADCB5-B5
    #define MTR1_VDC_ADCRES_BASE    ADCDRESULT_BASE         // ADCD1-D1
    #define MTR1_POT_ADCRES_BASE    ADCDRESULT_BASE         // NC
    
    #define MTR1_VU_ADC_CH_NUM      ADC_CH_ADCIN4           // ADCB3-B3
    #define MTR1_VV_ADC_CH_NUM      ADC_CH_ADCIN5           // ADCB4-B4
    #define MTR1_VW_ADC_CH_NUM      ADC_CH_ADCIN6           // ADCB5-B5
    #define MTR1_VDC_ADC_CH_NUM     ADC_CH_ADCIN7           // ADCD1-D1
    #define MTR1_POT_ADC_CH_NUM     ADC_CH_ADCIN8          // NC
    
    #define MTR1_VU_ADC_SOC_NUM     ADC_SOC_NUMBER4         // ADCB-B3   -SOC4
    #define MTR1_VV_ADC_SOC_NUM     ADC_SOC_NUMBER5         // ADCB-B4   -SOC5
    #define MTR1_VW_ADC_SOC_NUM     ADC_SOC_NUMBER6         // ADCB-B5   -SOC6
    #define MTR1_VDC_ADC_SOC_NUM    ADC_SOC_NUMBER7         // ADCD-D1   -SOC7
    #define MTR1_POT_ADC_SOC_NUM    ADC_SOC_NUMBER8         // NC
    

  • Hello Jagbir,

    What ADC resolution are you using for this? Your expected value is 2681 for 2.16V, but your results register has 2651. Depending on the ADC resolution you are using (12-bit or 16-bit), this may be within the margin of error.

    Best regards,

    Omer Amir

  • I am using a 12 bit ADC. How is the ADC channel selected. For example, the ADC input is connected on D1 pin. Shall I assign it channel 1 or I can assign it some other channel channel.

    #define MTR1_VDC_ADC_CH_NUM     ADC_CH_ADCIN7           // ADCD1-D1

  • Hello Jagbir,

    The ADC channel is typically selected by using " ADC_setupSOC(uint32_t base, ADC_SOCNumber socNumber, ADC_Trigger trigger, ADC_Channel channel, uint32_t sampleWindow)" function. You choose an ADC, an SOC within that ADC, the trigger, the channel, and the sample window. You are using the correct function within your initial code; to check what channels are available for an ADC (the specific SOC does not matter), you can check the Analog Subsystem chapter of the technical reference manual. If you want further clarification on how to set up an ADC for the F2837xS device, you can look at the provided examples in C2000Ware (C2000Ware_4_XX_XX_XX\driverlib\f2837xs\examples\cpu1\adc).

    The result you received does seem to be outside the datasheet values; are you just reading a DC value? Is the input buffered at all? Are any of the other ADCs being used simultaneously?

    Best regards,

    Omer Amir

  • Thanks Amir.

    All my ADC are on channel A. Can I assigna single SoC for all.

  • No, each SOC can only sample 1 channel at a time; to assign multiple to it, you would need to change the channel each time before you sampled/triggered the SOC.