title: Tiva ADC Sequencer with different step sources
body: <p>I'm trying to measure some ADC channels with the same sequencer. I took a base on the Chapter 5 of <a href="http://software-dl.ti.com/trainingTTO/trainingTTO_public_sw/GSW-TM4C123G-LaunchPad/TM4C123G_LaunchPad_Workshop_Workbook.pdf" rel="nofollow">Texas Tiva's ARM Cortex-M4 Workshop</a>. So, my (interrupted) original code is working perfectly:</p>
  
  <pre><code>#include &lt;stdint.h&gt;
  #include &lt;stdbool.h&gt;
  #include "inc/hw_memmap.h"
  #include "inc/hw_types.h"
  #include "inc/hw_ints.h"
  #include "driverlib/sysctl.h"
  #include "driverlib/adc.h"
  #include "driverlib/interrupt.h"
  #include "driverlib/gpio.h"
  #include "driverlib/pin_map.h"
  
  uint32_t ui32ADC0Value[4];
  
  volatile uint32_t ui32TempAvg;
  volatile uint32_t ui32TempValueC;
  
  int main(void) {
  
      SysCtlClockSet(
      SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_SYSDIV_5);
  
      SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
      SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0);
  
      ADCSequenceDisable(ADC0_BASE, 1);
      ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
  
      SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
      GPIOPinTypeADC(GPIO_PORTD_BASE,
      GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2);
  
      ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
      ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
      ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
      ADCSequenceStepConfigure(ADC0_BASE, 1, 3,
      ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END);
  
      IntEnable(INT_ADC0SS1);
      ADCIntEnable(ADC0_BASE, 1);
      ADCSequenceEnable(ADC0_BASE, 1);
  
      IntMasterEnable();
  
      while (1) {
          ADCProcessorTrigger(ADC0_BASE, 1);
      }
  
  }
  
  void ISRHandler(void) {
  
      while (!ADCIntStatus(ADC0_BASE, 1, false)){};
  
      ADCIntClear(ADC0_BASE, 1);
      ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
  
      ui32TempAvg = ui32ADC0Value[3];
  
      ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096) / 10;
  
  }
  </code></pre>
  
  <p>However if I change this part</p>
  
  <pre><code>ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
  ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
  ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
  ADCSequenceStepConfigure(ADC0_BASE, 1, 3,
          ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END);
  </code></pre>
  
  <p>by this part (so the steps 0 to 2 read other channels, instead of ADC_CTL_TS), where my analog pin channels are <em>grounded</em> (so the measurement would read near zero):</p>
  
  <pre><code>ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH7);
  ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH6);
  ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH5);
  ADCSequenceStepConfigure(ADC0_BASE, 1, 3,
          ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END);
  </code></pre>
  
  <p>the step 3 (where I measure ADC_CTL_TS) goes crazy, ranging values totally incoherent. Also, looking into debug, the measurement of TS looks like "walking" throught the other steps, because when 3 of them are near 0, the other "moving one" is far bigger. It looks like a temporal misalignment. </p>
  
  <p>Why, and how to fix it? Thanks.</p>