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.

ADC Offset

Other Parts Discussed in Thread: TM4C123BH6ZRB

Hi,

I'm having issue with the ADC on tiva C series

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/timer.h"
#include "driverlib/rom.h"

uint32_t ADC0ValueS0[5];

// The interrupt handler for the ADC interrupt.
void ADC0IntHandlerS0(void)
{
	// Read ADC Values.
	ROM_ADCSequenceDataGet(ADC0_BASE, 0, ADC0ValueS0);
	
	// Clear the ADC interrupt flag.
	ROM_ADCIntClear(ADC0_BASE, 0);
}

void ConfigADC0S0(void)
{
    //
    // The ADC0 peripheral must be enabled for use.
    //
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_FULL, 1);

    //
    // Enable the ports
    //
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);

	//
	// Set reference to the internal 3.3V reference
	//
	ROM_ADCReferenceSet(ADC0_BASE, ADC_REF_INT);

    //
    // Select the analog ADC function for these pins.
	// SIG1, SIG2, SIG3, SIG4, SIG5
	//
	ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_0);
	ROM_GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_1);
	ROM_GPIOPinTypeADC(GPIO_PORTK_BASE, GPIO_PIN_2);

	//
	// Enable sample sequence 0 with a processor signal trigger
	//
	ROM_ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);

	ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH1);
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH2);
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH3);
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH14);
	ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_CH18 | ADC_CTL_IE | ADC_CTL_END);

	//
	// Register the ADC interrupt for sequencer 0
	//
	ADCIntRegister(ADC0_BASE, 0, ADC0IntHandlerS0);

	//
	// Enable ADC Seq 0 interrupt
	//
	ROM_ADCIntEnable(ADC0_BASE, 0);

	//
	// Since sample sequence 0 is now configured, it must be enabled.
	//
	ROM_ADCSequenceEnable(ADC0_BASE, 0);

	//
	// Clear the interrupt status flag
	//
	ROM_ADCIntClear(ADC0_BASE, 0);
}

void TriggerADC(void)
{
	ROM_ADCProcessorTrigger(ADC0_BASE, 0);
}
micro-controller. I.m using TM4c123BH6ZRB. Please find my code for ADC configurations attached. Actually I'm getting offset on one of the ADC channel. Kindly explain me what I'm doing wring in the code. Thanks

Regards,

Mohsin

  • Hello Mohsin

    Which channel you are seeing an issue and how much is the offset? Also are you ensuring that the total source impedance on the channel is below the 500Ohm as required by the TM4C123x device?

    Regards,
    Amit
  • Hi Amit,

    Thanks for your reply. I'm getting offset on CHAN 1 & CHAN 2 (SIG1 & SIG2). I will get back to you while we consider this. Thanks
    Mohsin
  • Hello Mohsin

    For a configuration perspective, it is OK. There has to be something electrical on the path which is causing the offset. Can you check if the VREF voltage is correct as well besides the impedance?

    Regards
    Amit
  • I suggest to make a simple test. Connect the ADC input pin directly to GND, and check the conversion results. Then connect it to VREF (or Vcc), and again check the conversion results.

    Both results should be close to the limits (zero and max, allow for a few bits off). If so, you might need to improve your coupler/amplifier circuitry.

    If the results are significantly off, you seem to have a hardware design problem - probably a PCB issue related to voltage supply or VREF.

  • Amit Ashara said:
    how much is the offset?

    An absolutely key question.  All A/Ds have known error ranges, chasing errors that fall within those ranges is, at best, minimally productive and potentially misleading.

    Robert

  • Robert Adsett said:
    ...known error ranges, chasing errors that fall therein - (proves) minimally productive and potentially misleading.

    And - is endlessly repeated here - due to the complexity of the ADC, the utter lack of highly visible & enforced, Poster Guidelines, and (too often) poster's failure to perform the required, basic MCU manual reading.   (And - when we "jump" to "answer" - do we not encourage & reward those, "effort-lite" posters?   Is that good?

    Not every poster is as skilled & experienced as the forum would like.   ("pretending" that "posters" are (as an "unguided" forum suggests) - leads to incomplete postings - forum bloat - general inefficiency...)

    Excelsior (or not)...

  • Hello All,

    Hasn't it been an ADC week where all of a sudden ADC has been showing offset but no clear information on its connectivity and signal chain is being presented

    Regards
    Amit
  • May we vote for, "ADC Year?"