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.

LM3S1607: ADC in differential mode in LM3S1607

Part Number: LM3S1607

Hello TI.

Do not work ADC in differential mode in LM3S1607.

Please, help undestand my mistaik. My code bellow:

setup:

//***************************************************************************
/*------ port D -----------------------------------------------------------
*/
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
/*------ port E -----------------------------------------------------------
*/
SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

//***************************************************************************
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC);
// 
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
//
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);
//
ADCSequenceStepConfigure(ADC0_BASE, 2, 2, ADC_CTL_D | ADC_CTL_CH4 );
ADCSequenceStepConfigure(ADC0_BASE, 2, 3, ADC_CTL_D | ADC_CTL_IE | ADC_CTL_END);
//
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END);
//
ADCSequenceEnable(ADC0_BASE, 1);
ADCSequenceEnable(ADC0_BASE, 2);
ADCSequenceEnable(ADC0_BASE, 3);
//
ADCIntClear(ADC0_BASE, 1);
ADCIntClear(ADC0_BASE, 2);
ADCIntClear(ADC0_BASE, 3);
//
ADCIntEnable(ADC0_BASE, 1); // 
ADCIntEnable(ADC0_BASE, 2); // 
ADCIntEnable(ADC0_BASE, 3); // 
IntEnable(INT_ADC0SS1); // 
IntEnable(INT_ADC0SS2); // 
IntEnable(INT_ADC0SS3); // 

ADCProcessorTrigger(ADC0_BASE, 1);
ADCProcessorTrigger(ADC0_BASE, 2);
ADCProcessorTrigger(ADC0_BASE, 3);

interrupt:

//*************************************************
void ADCIntHandler(void) __irq 
{
  if(ADCIntStatus(ADC0_BASE, 1, true)){

    ADCIntClear(ADC0_BASE, 1);
    __nop();__nop();__nop();__nop();__nop();
    // 
    ADCSequenceDataGet(ADC0_BASE, 1, &ulADC0_Value[0]);
		//
    if(count_accum < 2){
        if (start_transmit < 1){ 
          accumulation_4 += ulADC0_Value[0];
          accumulation_5 += ulADC0_Value[1];
          accumulation_6 += ulADC0_Value[2];
          accumulation_7 += ulADC0_Value[3];
          count_accum++;
        }
    ADCProcessorTrigger(ADC0_BASE, 1);
    }
    else{
        if (start_transmit < 1){ 
          ra.sec.two.sens[4].data = accumulation_4 / count_accum;
          ra.sec.two.sens[5].data = accumulation_5 / count_accum;
          ra.sec.two.sens[6].data = accumulation_6 / count_accum;
          ra.sec.two.sens[7].data = accumulation_7 / count_accum;
          
          accumulation_4 = 0;
          accumulation_5 = 0;
          accumulation_6 = 0;
          accumulation_7 = 0;
          count_accum = 0;
        Update = 1;
        }
    }
  }
  if(ADCIntStatus(ADC0_BASE, 2, true)){
    //
    ADCIntClear(ADC0_BASE, 2);
    // 
    ADCSequenceDataGet(ADC0_BASE, 2, &ADC0_ValueDiff[0]);

    if(count_tok < 1){
          accumulation_tok1 += ADC0_ValueDiff[2];
          accumulation_tok2 += ADC0_ValueDiff[3];
          count_tok++;
      //ADCSequenceDisable(ADC0_BASE, 2);
      //ADCSequenceEnable(ADC0_BASE, 2);
      ADCProcessorTrigger(ADC0_BASE, 2);
    }
    else{
          ADCSequenceDisable(ADC0_BASE, 2);
          adc_result_tok1 = accumulation_tok1 / count_tok;
          adc_result_tok2 = accumulation_tok2 / count_tok;
          ra.sec.two.sens[0].data = adc_result_tok1;
          ra.sec.two.sens[2].data = adc_result_tok2;
          accumulation_tok1 = 0;
          accumulation_tok2 = 0;
          count_tok = 0;
          Update2 = 1;
    }
  }
  if(ADCIntStatus(ADC0_BASE, 3, true)){
    // 
    ADCIntClear(ADC0_BASE, 3);
    __nop();__nop();__nop();__nop();__nop();
    // 
    ADCSequenceDataGet(ADC0_BASE, 3, &accumulation_tmp);

    if(count_ts < 200){
          accumulation_ts += accumulation_tmp;
          count_ts++;
      ADCSequenceDisable(ADC0_BASE, 3);
      ADCSequenceEnable(ADC0_BASE, 3);
      ADCProcessorTrigger(ADC0_BASE, 3);
    }
    else{
          ADCSequenceDisable(ADC0_BASE, 3);
          adc_result_ts = accumulation_ts / count_ts;
          ra.sec.two.sens[16].data = adc_result_ts;/////////////////
          accumulation_ts = 0;
          count_ts = 0;
          ADC_Update = 1;
    }
//    ADCProcessorTrigger(ADC0_BASE, 3);
  }
    
}

  • in real code sequences config:

    ...

    ADCSequenceStepConfigure(ADC0_BASE, 2, 2, ADC_CTL_D | ADC_CTL_CH4 );
    ADCSequenceStepConfigure(ADC0_BASE, 2, 3, ADC_CTL_D | ADC_CTL_CH6 | ADC_CTL_IE | ADC_CTL_END);

    ...

  • First, this part is no longer recommended for new designs.

    Have you been able to do single ended conversions on channels 4 and 5 (the two channels you want the differential measurement for)?
  • Hello, Bob.

    I know the recommendations for these parts. We are upgrading old controllers.

    Actually, the problem is solved. I found the following text with a string:

    ..."Differential mode only works with adjacent channel pairs (for example, 0 and 1). The channel select

    must be the number of the channel pair to sample (for example, ADC_CTL_CH0 for 0 and 1, or

    ADC_CTL_CH1 for 2 and 3) or undefined results are returned by the ADC. Additionally, if differential

    mode is selected when the temperature sensor is being sampled, undefined results are returned

    by the ADC."

    Therefore, corrected config strings:

      ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_D  | ADC_CTL_CH2 );
      ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_D  | ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);

    Differential mode has earned.

    P.S. It was not a bad thing to include such details in the descriptions