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.

Implementation of internal ADC in differential mode tiva

Hi All,

Please let me know how to use TIVA internal ADC in differential mode.

I will be using 2 i/p from my load cell.

  • Hello Utpal,

    To configure the ADC in differential mode two consecutive channels needs to be configured as Differential inputs. The pairs are always an even-odd channel, i.e. AIN0-AIN1 and never AIN1-AIN2 (odd-even). The next thing is to configure the sequencer step by adding the parameter ADC_CTL_D to ADCSequenceStepConfigure when configuring the channel.

    From a physical point of view, do make sure that the diff paths are balanced in terms of impedance or you may end up seeing an altogether different value.

    Regards
    Amit
  • utpal kumar said:

    ADC...differential mode...will be using 2 i/p from my load cell. 

    You may do well to consider the "output, signal range" of your load cell and the (expected) applied load.

    Three items - from the above - deserve attention:

    a) that output signal range must remain w/in the ADC's input signal spec.

    b) that output signal range may be too small/slight - thus require boost/amplification - and it's that boosted signal that would be applied to your ADC.

    c) should the applied load enable a "bi-polar" load cell output - you must insure that your (base) load cell output is centered at the ADC's "half-max" value.  This enables the ADC to track those differential signals - both above & below - the load cell's (base) output.

    Should your load cell require signal boost - it may be possible to achieve the desired amplification via a, "differential to single-ended" amp application. This then "escapes" the requirement for your use of the ADC in differential mode.  (and enables your harvest of yet another ADC channel...)

  • Dear Amit Sir,

    Thanks for your valuable reply.

    As advised i had done the changes ,but still facing problems.

    Kindly have a look on below code & let me know ,if any changes required.

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    unsigned long INTERNAL_ADC(void)
    {

    unsigned long ulValue;//,retval;


    ROM_SysCtlClockSet(SYSCTL_SYSDIV_12 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
    SYSCTL_XTAL_16MHZ); // ADC REQUIRED 16 MHz


    // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
    // SYSCTL_XTAL_16MHZ); // ADC REQUIRED 16 MHz
    //

    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    SysCtlPeripheralEnable(SYSCTL_RCGC0_ADC);
    SysCtlPeripheralEnable(SYSCTL_RCGCGPIO);
    SysCtlPeripheralEnable(SYSCTL_RCGCGPIO_R4);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    GPIODirModeSet(GPIO_PORTE_BASE,GPIO_PIN_4 | GPIO_PIN_5,GPIO_DIR_MODE_HW);
    GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_4 | GPIO_PIN_5); // USE DIFFERENTIAL MODE AIN8 AND AIN9
    // SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS);

    //SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP0);

    ADCReferenceSet(ADC0_BASE,ADC_REF_INT); //


    ADCSequenceDisable(ADC0_BASE, 0);

    ADCResolutionSet(ADC0_BASE,ADC_RES_12BIT);


    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
    // ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_COMP0, 0);

    // ADCSequenceStepConfigure(ADC0_BASE, 0, 0,ADC_CTL_IE | ADC_CTL_END | ADC_CTL_CMP0 | ADC_CTL_D |ADC_CTL_CH8);

    ADCSequenceStepConfigure(ADC0_BASE, 0, 0,ADC_CTL_IE | ADC_CTL_END | ADC_CTL_D |ADC_CTL_CH4);
    // ADCSoftwareOversampleConfigure(ADC0_BASE,0,8);
    // ADCSoftwareOversampleStepConfigure(ADC0_BASE,0,8,ADC_CTL_IE | ADC_CTL_END | ADC_CTL_D |ADC_CTL_CH8);

    // ComparatorRefSet(COMP_BASE, COMP_REF_2_371875V);//COMP_REF_1_65V);

    // ComparatorConfigure(COMP_BASE, 0,(COMP_TRIG_NONE | COMP_INT_BOTH |COMP_ASRCP_REF | COMP_OUTPUT_NORMAL));

    // SysCtlDelay(SysCtlClockGet() / 12);

    // ulValue = ComparatorValueGet(COMP_BASE,0);
    // return(ulValue);


    ADCSequenceEnable(ADC0_BASE, 0);

    ADCIntClear(ADC0_BASE, 0);


    // ADCComparatorConfigure(ADC0_BASE,0,ADC_COMP_TRIG_HIGH_ALWAYS | ADC_COMP_INT_HIGH_ALWAYS);
    // ADCComparatorRegionSet(ADC0_BASE,0,);
    //buz_on();buz_on();buz_on();
    // buz_on();buz_on();buz_on();
    // ADCComparatorIntEnable(ADC0_BASE,0);
    // buz_on();buz_on();buz_on();
    // ComparatorRefSet(COMP_BASE, COMP_REF_1_65V);
    // ComparatorConfigure(COMP_BASE, 0,(COMP_TRIG_NONE | COMP_INT_BOTH |COMP_ASRCP_REF | COMP_OUTPUT_NORMAL));


    //
    // Trigger the sample sequence.
    //
    ADCProcessorTrigger(ADC0_BASE, 0);
    //
    // Wait until the sample sequence has completed.
    //
    while(!ADCIntStatus(ADC0_BASE, 0, false))
    // while(!ADCComparatorIntStatus(ADC0_BASE))

    {
    // buz_on();
    }

    ADCIntClear(ADC0_BASE, 0);
    //
    // Read the value from the ADC.
    //
    // ADCSoftwareOversampleDataGet(ADC0_BASE,0,&ulValue,1);
    ADCSequenceDataGet(ADC0_BASE, 0, &ulValue);

    SysCtlDelay(SysCtlClockGet() / 12);


    // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
    // SYSCTL_XTAL_16MHZ);

    return(ulValue);

    }

     

  • Hello Utpal,

    Lot of coding mistakes.... What is this and how did you arrive to enabling the clocks?

    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC);
    SysCtlPeripheralEnable(SYSCTL_RCGC0_ADC);
    SysCtlPeripheralEnable(SYSCTL_RCGCGPIO);
    SysCtlPeripheralEnable(SYSCTL_RCGCGPIO_R4);

    Why configure the ADC this way?

    GPIODirModeSet(GPIO_PORTE_BASE,GPIO_PIN_4 | GPIO_PIN_5,GPIO_DIR_MODE_HW);
    GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_4 | GPIO_PIN_5); // USE DIFFERENTIAL MODE AIN8 AND AIN9

    I could go on, then I realized that there is a differential example code in TivaWare...

    C:\ti\TivaWare_C_Series-2.1.0.12573\examples\peripherals\adc\differential.c

    Regards

    Amit

  • Dear Amit Sir,

    Thanks for your inputs.

    Now i am able to do it.

    Thanks for your quick response.

  • @ interested others - seeking to read & process the output of, "balanced-bridge type" sensors

    Our firm has found that (often) the direct connection of such sensor to (most) MCU ADC inputs may "unbalance and/or distort" the sensor's bridge.

    Further - it's rare that the sensor's voltage span will fully overlap the ADC's input signal range.

    As suggested (earlier here) the insertion of an op-amp between the sensor & ADC input(s) has proved an effective remedy for both (potential) ills - listed above...