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.

TMS320F28379D: Reading 16 Bit Data

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE

Hi,

I am a little bit confused with the reading 16-bit data in 16 bit ADC mode.  

I wanna do a 16 bit read on the MCU. As I can see that, Both ADCINxP and ADCINxN can swing between VREFHI and VSS. 

My analogue signal is ranging from0 to 3V and is single-ended. I have connected this signal to ADCINA1 and ADCINA0 is grounded. Now I am using the given example in driverlib for 16 bot mode. I am not able to interpret the results.

Please find the Captures below. My input signal is 1.5V.

Single Ended.

Differential

Whatever I am doing is correct? Do I need any change in the given example for 16-bit mode (other than changing the resolution to 16 bit)? or I need to convert my the signal to differential?

Do I need to add adcAresult0 and adcResult1 in 16-bit mode to get the result?

Comparing above, I am getting the correct value in single-ended mode.

Regards

Vishal Kakade

  • Hi Vishal,

    Grounding the negative input will not work.  

    Take a look at this training on the different ADC types:

    https://training.ti.com/ti-precision-labs-adcs-sar-adc-input-types?context=1139747-1128375-1139103-1128659

    The differential inputs on this device are 'fully differential' not 'true differential' so you will need to provide a pair of signals that are complementary about the common mode voltage (Vcm needs to be within +/-50mV from VREFHI/2).

  • Hi Devin,

    Thanks for your response.

    As I see from the datasheet, ADCINxP, and ADCINx can swing between VREFHI and VSSA. 

     

    What is this "-VREFHI?

    If its a Fully differential ADC, then Both inputs can swing between VREFHI and VSS then effective voltage is double of VREFHI?

    If My input signal is single-ended and is ranging from 0 to 3V. Then after converting it to the differential, what is the swing of P and N?

    Can I use the circuit from the below link?

    http://www.ti.com/lit/an/sbaa265/sbaa265.pdf

    Regards

    Vishal

  • Hi Vishal,

    Yes, the effective range for the effective fully differential signal is VREFHI*2.  In the upper waveform this has been scaled to +VREFHI to -VREFHI instead of 0 to 2*VREFHI.  

    Once you convert to differential, ADCINxP will be between 0 to 3.0V. ADCINxN will also be between 0 to 3.0V and will always be the complement of ADCINxP about the common mode voltage (so if ADCINxP is 2.9V ADCINxN will be 0.1V, if ADCINxP is 0.5V then ADCINxN will be 2.5V).  Because of this, the range of ADCINxP - ADCINxN will be 3.0V to -3.0V (ADCINxP = 3.0V and ADCINxN = 0V, to ADCINxP = 0V and ADCINxN = 3.0V).

    Yes, that topology should work.  Note that Vcm = 1.5V instead of 2.5V and you may want to use an op-amp supply voltage of 3.3V. Be careful if the op-amp supplies are 5V since this could result in an over-voltage condition if the op-amp output rails for some reason.

     

  • Hi Devin,

    Thanks for your response.

    I will take care of the hardware as per your suggestion. One more doubt, If the resulting signal is swinging from +VREF to -VREF, how is controller supporting this. as I don't see any negating supply to the controller?

    Now coming to software, Does software needs any change? How to calculate the resulting ADC value in 16-bit mode?

    Should I read both P and N read independently? Or Need to use some other API's?

    Regards

    Vishal

  • Hi Vishal,

    The ADC is differential throughout its full architecture, so the effective voltage never literally exists as say -VREFHI, instead it is always two voltages that are being compared, subtracted, amplified, etc. in order to determine the digital result.  

    For the other questions, have a read through the TRM chapter on the ADC (http://www.ti.com/lit/ug/spruhm8i/spruhm8i.pdf): 

    • "Expected Conversion Results" and "Interpreting Conversion Results" will tell you how the digital results relate to the analog inputs
    • "Channel Selection" and "SOC Principle of Operation" should tell you about how channel selection works in differential mode

    And then depending on if you are using bitfields or driverlibs you'll want to have a read through either the ADC register descriptions in the TRM or the driverlib documentation for the ADC functions (in C2000ware in \device_support\f2837xd\docs\) to see which register or function contains the results.  Looking at the SW examples in c2000ware will also be helpful here.  

     

  • Hi Devin,

    Thanks for your response.

    As Discussed, I constructed a single-ended to fully differential converter.

    Here are the connection details

    ADCINB2 is my +ve input

    ADCINB3 is my -ve input

    I am Using DACOUTA to generate my input signal which is then fed to Single to diff converter and its outputs are fed to ADC.(VCM=1.5V)

    1. If my Input is 1V (Single-ended input signal) and I am getting Below results on ADC read.

    ADCINB2 =21739

    ADCINB3=21715

    2. If my Input is 2V (Single-ended input signal) and I am getting Below results on ADC read.

    ADCINB2 =43670

    ADCINB3=43673

    Now I wanna know how will I calculate my input signal from these ADC values. As the notations used in the Technical reference manual are a bit confusing. like

    ADCRESULTx , ADCRESULTy ? (Why only one ADC value is used as we get both P and N )

    Am I suppose to average the values or consider any one? 

    Regards

    Vishal

  • Hi Vishal,

    When you sample a differential channel, both channels are sampled simultaneously and the ADC takes care of turning the differential signal into a single digital output.  In the channel selection table, you can see that the results are the same regardless of setting CHSEL = 2 or CHSEL = 3.  Either way, B2 and B3 will be used for sampling: 

    Then if you look at the conversion formulas, the formula takes two inputs (Positive, Negative) and produces a single digital output.

    So in your first example:

    ADCINP = 1V

    ADCINN = 2V (assuming the SE to DE conversion circuit is functioning as intended)

    VREFHI = 3V

    So ADCRESULT = 65536*(((1 - 2) + 3)/(2*3)) = 21845

    (assuming the voltages are exact)

    And your second run when sampling B3 instead of B2 does exactly the same thing so the difference is sample-to-sample variation due to noise. 

    In your second example:

    ADCINP = 2V

    ADCINN = 1V 

    VREFHI = 3V

    So ADCRESULT = 65536*(((2 - 1) + 3)/(2*3)) = 43691

    (again, assuming the voltages were exact)

  • Hi Devin,

    Thanks for your response. I understood this part. But If I am getting 

    ADCINB2 =21739

    ADCINB3=21715

    then, Which one should I consider for converting it back to my analog value? I declared ADCINB2  and ADCINB3 as uint16_t. and I want my analog value to be a float. Can you use my examples and ADC reading and show me how to get my input singnal value?

    Regards

    Vishal

  • Hi Vishal,

    There is no difference between selecting CHSEL = B2 or CHSEL = B3 in differential mode.  The difference you observed is strictly due to noise; you would see the same thing if you convert say B2 multiple times in a row.  

    To go from a conversion result to an analog value use this table:

    So 

    ADCRESULT = 21739

    VREFHI = 3.0V

    So (ADCINP - ADCINN) = 3.0*(2*21739/65536 - 1) = -1.00097V 

  • Hi Devin,

    So is it necessary to convert both the channels? or Can I convert any one channel? If so then Can I directly map 0 to 3V as 0 to 65535?

    So my input signal which is from  0 to 3V is mapped between -3V to +3V?

    Also, I have some double regarding the compiler. Let's say x is declared as float and if I am doing x=3/2, My output is 1 but If I do x=3/2.0 then its 1.5V. So is this the right way to do it or should I use (float) Result (typecasting)?

    Regards

    Vishal.

  • HI Devin,

    I used the formula given in the reference manual. But for any input, I am getting output as -3.0V.

    Find my Code below.

    //#############################################################################
    //
    // FILE:   adc_ex1_soc_software.c
    //
    // TITLE:  ADC Software Triggering
    //
    //! \addtogroup driver_example_list
    //! <h1>ADC Software Triggering</h1>
    //!
    //! This example converts some voltages on ADCA and ADCB based on a software
    //! trigger.
    //!
    //! The software triggers for the two ADCs happen sequentially, so the
    //! two ADCs will run asynchronously.
    //!
    //! \b External \b Connections \n
    //!  - A0, A1, B0, and B1 should be connected to signals to convert
    //!
    //! \b Watch \b Variables \n
    //! - \b adcAResult0 - Digital representation of the voltage on pin A0
    //! - \b adcAResult1 - Digital representation of the voltage on pin A1
    //! - \b ADCB_2 - Digital representation of the voltage on pin B0
    //! - \b ADCB_3 - Digital representation of the voltage on pin B1
    //!
    //
    //#############################################################################
    // $TI Release: F2837xS Support Library v3.08.00.00 $
    // $Release Date: Mon Dec 23 17:37:14 IST 2019 $
    // $Copyright:
    // Copyright (C) 2014-2019 Texas Instruments Incorporated - http://www.ti.com/
    //
    // Redistribution and use in source and binary forms, with or without
    // modification, are permitted provided that the following conditions
    // are met:
    //
    //   Redistributions of source code must retain the above copyright
    //   notice, this list of conditions and the following disclaimer.
    //
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the
    //   documentation and/or other materials provided with the
    //   distribution.
    //
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    //
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // $
    //#############################################################################
    
    //
    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    
    //
    // Defines
    //
    #define RESULTS_BUFFER_SIZE     256
    #define EX_ADC_RESOLUTION       16
    
    //
    // Globals
    //
    uint16_t ADCB_2 = 0;
    uint16_t ADCB_3 = 0;
    float voltage = 0.0;
    uint16_t dac_val = 0;
    
    float BB_SIGNAL_DIFFF = 0.0;
    float AN_ADCB_2 = 0.0;
    float AN_ADCB_3 = 0.0;
    //
    // Function Prototypes
    //
    void initADCs(void);
    void initADCSOCs(void);
    void Config_DACA(void);
    
    //
    // Main
    //
    void main(void)
    
    {
        //
        // Initialize device clock and peripherals
        //
        Device_init();
    
        //
        // Disable pin locks and enable internal pullups.
        //
        Device_initGPIO();
    
        //
        // Initialize PIE and clear PIE registers. Disables CPU interrupts.
        //
        Interrupt_initModule();
    
        //
        // Initialize the PIE vector table with pointers to the shell Interrupt
        // Service Routines (ISR).
        //
        Interrupt_initVectorTable();
    
        //
        // Set up ADCs, initializing the SOCs to be triggered by software
        //
        initADCs();
        initADCSOCs();
        Config_DACA();
    
        //
        // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
        //
        EINT;
        ERTM;
    
        //
        // Loop indefinitely
    
        //
        while(1)
        {
            //
            // Convert, wait for completion, and store results
            //
    
            ADC_forceSOC(ADCB_BASE, ADC_SOC_NUMBER2);
            ADC_forceSOC(ADCB_BASE, ADC_SOC_NUMBER3);
    
            //
            // Wait for ADCA to complete, then acknowledge flag
            //
    
    
            //
            // Wait for ADCB to complete, then acknowledge flag
            //
            while(ADC_getInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1) == false)
            {
            }
            ADC_clearInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1);
    
            //
            // Store results
            //
    
            ADCB_2 = ADC_readResult(ADCBRESULT_BASE, ADC_SOC_NUMBER2);
            ADCB_3 = ADC_readResult(ADCBRESULT_BASE, ADC_SOC_NUMBER3);
    
            dac_val = voltage * 4096 / 3;
            DAC_setShadowValue(DACA_BASE, dac_val);
    
            BB_SIGNAL_DIFFF = 3.0 * ((2 * ADCB_2 / 65536) - 1);
            //
            // Software breakpoint. At this point, conversion results are stored in
            // adcAResult0, adcAResult1, ADCB_2, and ADCB_3.
            //
            // Hit run again to get updated conversions.
            //
            // ESTOP0;
        }
    }
    
    //
    // Function to configure and power up ADCs A and B.
    //
    void initADCs(void)
    {
        //
        // Set ADCCLK divider to /4
        //
    
        ADC_setPrescaler(ADCB_BASE, ADC_CLK_DIV_4_0);
    
        //
        // Set resolution and signal mode (see #defines above) and load
        // corresponding trims.
        //
    #if(EX_ADC_RESOLUTION == 12)
    
        ADC_setMode(ADCB_BASE, ADC_RESOLUTION_12BIT, ADC_MODE_SINGLE_ENDED);
    #elif(EX_ADC_RESOLUTION == 16)
        ADC_setMode(ADCA_BASE, ADC_RESOLUTION_16BIT, ADC_MODE_DIFFERENTIAL);
        ADC_setMode(ADCB_BASE, ADC_RESOLUTION_16BIT, ADC_MODE_DIFFERENTIAL);
    #endif
    
        //
        // Set pulse positions to late
        //
    
        ADC_setInterruptPulseMode(ADCB_BASE, ADC_PULSE_END_OF_CONV);
    
        //
        // Power up the ADCs and then delay for 1 ms
        //
    
        ADC_enableConverter(ADCB_BASE);
    
        DEVICE_DELAY_US(1000);
    }
    
    //
    // Function to configure SOCs 0 and 1 of ADCs A and B.
    //
    void initADCSOCs(void)
    {
    
        //
        // Configure SOCs of ADCB
        // - SOC0 will convert pin B0.
        // - SOC1 will convert pin B1.
        // - Both will be triggered by software only.
        // - For 12-bit resolution, a sampling window of 15 (75 ns at a 200MHz
        //   SYSCLK rate) will be used.  For 16-bit resolution, a sampling window
        //   of 64 (320 ns at a 200MHz SYSCLK rate) will be used.
        //
    #if(EX_ADC_RESOLUTION == 12)
        ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_SW_ONLY,
                     ADC_CH_ADCIN0, 15);
        ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER1, ADC_TRIGGER_SW_ONLY,
                     ADC_CH_ADCIN1, 15);
    #elif(EX_ADC_RESOLUTION == 16)
        ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER2, ADC_TRIGGER_SW_ONLY, ADC_CH_ADCIN2,
                     64);
        ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER3, ADC_TRIGGER_SW_ONLY, ADC_CH_ADCIN3,
                     64);
    #endif
    
        //
        // Set SOC1 to set the interrupt 1 flag. Enable the interrupt and make
        // sure its flag is cleared.
        //
        ADC_setInterruptSource(ADCB_BASE, ADC_INT_NUMBER1, ADC_SOC_NUMBER3);
        ADC_enableInterrupt(ADCB_BASE, ADC_INT_NUMBER1);
        ADC_clearInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1);
    }
    
    void Config_DACA(void)
    {
        //
        // Set VDAC as the DAC reference voltage.
        // Edit here to use ADC VREF as the reference voltage.
        //
        DAC_setReferenceVoltage(DACA_BASE, DAC_REF_ADC_VREFHI);
    
        //
        // Enable the DAC output
        //
        DAC_enableOutput(DACA_BASE);
    
        //
        // Set the DAC shadow output to 0
        //
        DAC_setShadowValue(DACA_BASE, 0);
    
        //
        // Delay for buffered DAC to power up
        //
        DEVICE_DELAY_US(1);
    }
    
    

    Regards

    Vishal

  • Hi Devin,

    I am getting some compiler errors. After using the formulas.

    For a single statement execution, My output id always -3.0V. But after doing step by step execution, I am getting correct results.

    For an input of 1V, My output should be -1.0V.

    I am getting BB_SIGNAL_DIFFF=-1.0V and diff1=-3.0

    For an input of 2V. My output should be 1V.

    I am getting BB_SIGNAL_DIFFF=-2.0V and diff1=-3.0. Why? After declaring My ADC reads as uint32_t, I am getting correct results on BB_SIGNAL_DIFFF but diff is still at -3.0V

    Please find code below.

    //#############################################################################
    //
    // FILE:   adc_ex1_soc_software.c
    //
    // TITLE:  ADC Software Triggering
    //
    //! \addtogroup driver_example_list
    //! <h1>ADC Software Triggering</h1>
    //!
    //! This example converts some voltages on ADCA and ADCB based on a software
    //! trigger.
    //!
    //! The software triggers for the two ADCs happen sequentially, so the
    //! two ADCs will run asynchronously.
    //!
    //! \b External \b Connections \n
    //!  - A0, A1, B0, and B1 should be connected to signals to convert
    //!
    //! \b Watch \b Variables \n
    //! - \b adcAResult0 - Digital representation of the voltage on pin A0
    //! - \b adcAResult1 - Digital representation of the voltage on pin A1
    //! - \b ADCB_2 - Digital representation of the voltage on pin B0
    //! - \b ADCB_3 - Digital representation of the voltage on pin B1
    //!
    //
    //#############################################################################
    // $TI Release: F2837xS Support Library v3.08.00.00 $
    // $Release Date: Mon Dec 23 17:37:14 IST 2019 $
    // $Copyright:
    // Copyright (C) 2014-2019 Texas Instruments Incorporated - http://www.ti.com/
    //
    // Redistribution and use in source and binary forms, with or without
    // modification, are permitted provided that the following conditions
    // are met:
    //
    //   Redistributions of source code must retain the above copyright
    //   notice, this list of conditions and the following disclaimer.
    //
    //   Redistributions in binary form must reproduce the above copyright
    //   notice, this list of conditions and the following disclaimer in the
    //   documentation and/or other materials provided with the
    //   distribution.
    //
    //   Neither the name of Texas Instruments Incorporated nor the names of
    //   its contributors may be used to endorse or promote products derived
    //   from this software without specific prior written permission.
    //
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // $
    //#############################################################################
    
    //
    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    
    //
    // Defines
    //
    #define RESULTS_BUFFER_SIZE     256
    #define EX_ADC_RESOLUTION       16
    
    //
    // Globals
    //
    uint16_t ADCB_2 = 0;
    uint16_t ADCB_3 = 0;
    float voltage = 2.0;
    uint16_t dac_val = 0;
    
    float BB_SIGNAL_DIFFF = 0.0;
    float diff1 = 0.0;
    float AN_ADCB_2 = 0.0;
    float AN_ADCB_3 = 0.0;
    //
    // Function Prototypes
    //
    void initADCs(void);
    void initADCSOCs(void);
    void Config_DACA(void);
    
    //
    // Main
    //
    void main(void)
    
    {
        float x = 0, y = 0, z = 0;
        //
        // Initialize device clock and peripherals
        //
        Device_init();
    
        //
        // Disable pin locks and enable internal pullups.
        //
        Device_initGPIO();
    
        //
        // Initialize PIE and clear PIE registers. Disables CPU interrupts.
        //
        Interrupt_initModule();
    
        //
        // Initialize the PIE vector table with pointers to the shell Interrupt
        // Service Routines (ISR).
        //
        Interrupt_initVectorTable();
    
        //
        // Set up ADCs, initializing the SOCs to be triggered by software
        //
        initADCs();
        initADCSOCs();
        Config_DACA();
    
        //
        // Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
        //
        EINT;
        ERTM;
    
        //
        // Loop indefinitely
    
        //
        while(1)
        {
            //
            // Convert, wait for completion, and store results
            //
    
            ADC_forceSOC(ADCB_BASE, ADC_SOC_NUMBER2);
            ADC_forceSOC(ADCB_BASE, ADC_SOC_NUMBER3);
    
            //
            // Wait for ADCA to complete, then acknowledge flag
            //
    
    
            //
            // Wait for ADCB to complete, then acknowledge flag
            //
            while(ADC_getInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1) == false)
            {
            }
            ADC_clearInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1);
    
            //
            // Store results
            //
    
            ADCB_2 = ADC_readResult(ADCBRESULT_BASE, ADC_SOC_NUMBER2);
            ADCB_3 = ADC_readResult(ADCBRESULT_BASE, ADC_SOC_NUMBER3);
    
            dac_val = voltage * 4096 / 3;
            DAC_setShadowValue(DACA_BASE, dac_val);
    
            x = 2 * ADCB_2;
            y = x / 65536;
            z = y - 1;
            BB_SIGNAL_DIFFF = 3.0 * z;
            diff1 = ((3.0) * (((2 * ADCB_2) / 65536) - 1));
            //
            // Software breakpoint. At this point, conversion results are stored in
            // adcAResult0, adcAResult1, ADCB_2, and ADCB_3.
            //
            // Hit run again to get updated conversions.
            //
            // ESTOP0;
        }
    }
    
    //
    // Function to configure and power up ADCs A and B.
    //
    void initADCs(void)
    {
        //
        // Set ADCCLK divider to /4
        //
    
        ADC_setPrescaler(ADCB_BASE, ADC_CLK_DIV_4_0);
    
        //
        // Set resolution and signal mode (see #defines above) and load
        // corresponding trims.
        //
    #if(EX_ADC_RESOLUTION == 12)
    
        ADC_setMode(ADCB_BASE, ADC_RESOLUTION_12BIT, ADC_MODE_SINGLE_ENDED);
    #elif(EX_ADC_RESOLUTION == 16)
        ADC_setMode(ADCA_BASE, ADC_RESOLUTION_16BIT, ADC_MODE_DIFFERENTIAL);
        ADC_setMode(ADCB_BASE, ADC_RESOLUTION_16BIT, ADC_MODE_DIFFERENTIAL);
    #endif
    
        //
        // Set pulse positions to late
        //
    
        ADC_setInterruptPulseMode(ADCB_BASE, ADC_PULSE_END_OF_CONV);
    
        //
        // Power up the ADCs and then delay for 1 ms
        //
    
        ADC_enableConverter(ADCB_BASE);
    
        DEVICE_DELAY_US(1000);
    }
    
    //
    // Function to configure SOCs 0 and 1 of ADCs A and B.
    //
    void initADCSOCs(void)
    {
    
        //
        // Configure SOCs of ADCB
        // - SOC0 will convert pin B0.
        // - SOC1 will convert pin B1.
        // - Both will be triggered by software only.
        // - For 12-bit resolution, a sampling window of 15 (75 ns at a 200MHz
        //   SYSCLK rate) will be used.  For 16-bit resolution, a sampling window
        //   of 64 (320 ns at a 200MHz SYSCLK rate) will be used.
        //
    #if(EX_ADC_RESOLUTION == 12)
        ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_SW_ONLY,
                     ADC_CH_ADCIN0, 15);
        ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER1, ADC_TRIGGER_SW_ONLY,
                     ADC_CH_ADCIN1, 15);
    #elif(EX_ADC_RESOLUTION == 16)
        ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER2, ADC_TRIGGER_SW_ONLY, ADC_CH_ADCIN2,
                     64);
        ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER3, ADC_TRIGGER_SW_ONLY, ADC_CH_ADCIN3,
                     64);
    #endif
    
        //
        // Set SOC1 to set the interrupt 1 flag. Enable the interrupt and make
        // sure its flag is cleared.
        //
        ADC_setInterruptSource(ADCB_BASE, ADC_INT_NUMBER1, ADC_SOC_NUMBER3);
        ADC_enableInterrupt(ADCB_BASE, ADC_INT_NUMBER1);
        ADC_clearInterruptStatus(ADCB_BASE, ADC_INT_NUMBER1);
    }
    
    void Config_DACA(void)
    {
        //
        // Set VDAC as the DAC reference voltage.
        // Edit here to use ADC VREF as the reference voltage.
        //
        DAC_setReferenceVoltage(DACA_BASE, DAC_REF_ADC_VREFHI);
    
        //
        // Enable the DAC output
        //
        DAC_enableOutput(DACA_BASE);
    
        //
        // Set the DAC shadow output to 0
        //
        DAC_setShadowValue(DACA_BASE, 0);
    
        //
        // Delay for buffered DAC to power up
        //
        DEVICE_DELAY_US(1);
    }
    
    

  • Hi Vishal,

    Yes, you only need to read one or the other of ADCB2 or ADCB3 in differential mode; they will produce the same result.  

    Yes, at the end of the day your DAC code of 0 to 4095 will correspond to an ADC conversion result of 0 to 65535. 

    0 to 4095 --> 0 to 3.0V --> P = 0 to 3.0V, N = 3.0V to 0 --> ADCIN = -3V to 3V --> 0 to 65535 

    I think you should break your calculations up step-by-step so you can check the results at each point.  For instance, 2*ADCB_2 could be larger than 65535, resulting in an overflow of your unsigned 16-bit value, but it won't be clear why the end result is incorrect if you only look at the end result.

    I'm pretty sure you are always getting -3V (except when using a breakpoint) because you aren't allowing time for the analog processes to occur/complete.  You are

    (1) Converting the ADC first, then changing the DAC value

    You'll wan to change the DAC output first, then sample with the ADC if you want your results to correspond

    (2) Not waiting for the DAC to settle

    Refer to the device datasheet for the DAC settling time, then add an appropriate delay after updating the DAC value