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.

Problem with ADC differential sampling with tm4c123gh6pm (Stellaris LaunchPad) in Keil

Hello. I'm working on an application that needs the differential ADC mode. My problem is that when my two inputs are at the same voltage (VIN + = VIN- = 1.65 V) get 0x79A when according to data sheet would have to get 0x800, and when my analog input is 3.3 V (VIN + = 3.3 V and VIN - = 0 V) I get about 0xF09 when he should get 0xFFF.  I do not know if this is normal or problem code. First of all, Thanks. Annex part of the code that configures the ADC.

Hola. Yo estoy trabajando en una aplicación que necesita el modo diferencial del ADC. Mi problema es que cuando mis dos entradas estan a la misma tension (VIN+=VIN-=1.65 V), obtengo 0x79A cuando segun la hoja de datos tendria que obtener 0x800, y cuando mi entrada analogica es 3.3 V (VIN+=3.3 V y VIN-=0 V) obtengo aproximadamente 0xF09 cuando tendria que obtener 0xFFF Yo no se si es normal o problema del codigo. De antemano gracias. Anexo la parte del codigo que configura el ADC.

#include "ADC.h"
#include "tm4c123gh6pm.h"

// This initialization function sets up the ADC 
void ADC0_Init(void){ volatile unsigned long delay;
  SYSCTL_RCGC2_R |= 0x00000010;  // 1) activate clock for Port E
  delay = SYSCTL_RCGC2_R;        //    allow time for clock to stabilize
  GPIO_PORTE_DIR_R &= ~0x0C;     // 2) make PE2 and PE3 input
  GPIO_PORTE_AFSEL_R |= 0x0C;    // 3) enable alternate function on PE2 and PE3
  GPIO_PORTE_DEN_R &= ~0x0C;     // 4) disable digital I/O on PE2 and PE3
  GPIO_PORTE_AMSEL_R |= 0x0C;    // 5) enable analog function on PE2 and PE3


  SYSCTL_RCGC0_R |= 0x00010000;  // 6) activate ADC0
  delay = SYSCTL_RCGC2_R;        //    allow time for clock to stabilize
  SYSCTL_RCGC0_R &= ~0x00000300; // 7) configure for 125K
  ADC0_SSPRI_R = 0x0123;         // 8) Sequencer 3 is highest priority
  ADC0_ACTSS_R &= ~0x0008;       // 9) disable sample sequencer 3
  ADC0_EMUX_R &= ~0xF000;        // 10) seq3 is software trigger
  ADC0_SSMUX3_R &= ~0x000F;      // 11) clear SS3 field
  ADC0_SSCTL3_R = 0x0007;        // 12) no TS0 D0, yes IE0 END0
  ADC0_ACTSS_R |= 0x0008;        // 13) enable sample sequencer 3
}


//------------ADC0_In------------
// Busy-wait Analog to digital conversion
// Input: none
// Output: 12-bit result of ADC conversion
unsigned long ADC0_In(void){ 
  unsigned long result;
  ADC0_PSSI_R = 0x0008;          // 1) initiate SS3
  while((ADC0_RIS_R&0x08)==0){}; // 2) wait for conversion done
  result = ADC0_SSFIFO3_R&0xFFF; // 3) read result
  ADC0_ISC_R = 0x0008;           // 4) acknowledge completion
  return result;
}

  • Hello Javier,

    I believe your code in the mid point region is very close to the expected behavior. On the other end it is still further away. Can you check that is value read by the ADC when the diff voltage is -3.3V

    There are some factors that affect the value
    1. The reference stability
    2. The input signal stability
    3. Non linearity of the ADC.

    You may need to weigh in 1 and 2 first by using fixed, temp compensated sources.

    Regards
    Amit
  • Thanks for the reply. Relative to the reference, I can not put external reference, since it is connected internally. At -3.3 V I get 0x000. My question is that in the data sheet offset mentioned is 30 LSB, and I get a much larger one.
  • Hello Javier,

    The data sheet reference is under lab test conditions where the input is in a noise reduced environment so that accurate measurements can be taken. These measurements when done with internal reference also are performed in a manner that there is a low noise on the VDDA supply.

    1. What is the differential voltage at which the reading becomes 0xFFF
    2. Is the test input the same as the VDDA supply?

    Regards
    Amit