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.

CCS/TM4C1294NCPDT: ADC + uDMA reading error

Part Number: TM4C1294NCPDT

Tool/software: Code Composer Studio

Hello,

I am currently trying to implement the reading of 8 analog inputs per uDMA, but I am having inaccurate readings on all inputs.

The same hardware has already been tested with other firmware, without the use of uDMA and obtained more reliable results.

For example, an AD connected to GND without DMA, gives me a result between (0~10) / 4096, using DMA I have a result between (190~200) / 4096.

At all tension levels I have inaccurate results...

Could you help me with this problem?

#pragma DATA_ALIGN(pui8ControlTable, 1024)
uint8_t pui8ControlTable[1024];

void Config_uDMA(void)
{
    ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_UDMA);
    ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_UDMA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
    while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_UDMA)){}


    ROM_IntEnable(INT_UDMAERR);

    ROM_uDMAEnable();

    ROM_uDMAControlBaseSet(pui8ControlTable);
}

#define NUMBER_OF_STEPSADC     8       //Number of conversions in ADC0 Sequence 0
#define NUMBER_OF_SETSADC      30      //Number of sets of conversions which are stored in buffer

Buffers for storing ADC convertion results
volatile static int32_t g_ADCui8RxBufA[NUMBER_OF_SETSADC][NUMBER_OF_STEPSADC];
volatile static int32_t g_ADCui8RxBufB[NUMBER_OF_SETSADC][NUMBER_OF_STEPSADC];

void Config_ADC0_uDMA(void)
{
    ROM_uDMAChannelAttributeDisable(UDMA_CH14_ADC0_0, UDMA_ATTR_ALL);

    ROM_uDMAChannelAttributeEnable(UDMA_CH14_ADC0_0, UDMA_ATTR_USEBURST);

    ROM_uDMAChannelControlSet(UDMA_CH14_ADC0_0 | UDMA_PRI_SELECT,
                          UDMA_SIZE_32 | UDMA_SRC_INC_NONE | UDMA_NEXT_USEBURST |
                          UDMA_ARB_256 | UDMA_DST_INC_32);

    ROM_uDMAChannelControlSet(UDMA_CH14_ADC0_0 | UDMA_ALT_SELECT,
                          UDMA_SIZE_32 | UDMA_SRC_INC_NONE | UDMA_NEXT_USEBURST |
                          UDMA_ARB_256 | UDMA_DST_INC_32);

    ROM_uDMAChannelTransferSet(UDMA_CH14_ADC0_0 | UDMA_PRI_SELECT, UDMA_MODE_PINGPONG,
                           (void *)(ADC0_BASE + ADC_O_SSFIFO0),
                           g_ADCui8RxBufA,
                           NUMBER_OF_SETSADC * NUMBER_OF_STEPSADC);

    ROM_uDMAChannelTransferSet(UDMA_CH14_ADC0_0 | UDMA_ALT_SELECT, UDMA_MODE_PINGPONG,
                           (void *)(ADC0_BASE + ADC_O_SSFIFO0),
                           g_ADCui8RxBufB,
                           NUMBER_OF_SETSADC * NUMBER_OF_STEPSADC);

    ROM_uDMAChannelEnable(UDMA_CH14_ADC0_0);
}

uint32_t Matrix_IOs[6][2] =
{ { GPIO_PORTE_BASE, GPIO_PIN_4 },  // PE4;
  { GPIO_PORTE_BASE, GPIO_PIN_5 },  // PE5;
  { GPIO_PORTD_BASE, GPIO_PIN_4 },  // PD4;
  { GPIO_PORTD_BASE, GPIO_PIN_5 },  // PD5;
  { GPIO_PORTD_BASE, GPIO_PIN_6 },  // PD6;
  { GPIO_PORTD_BASE, GPIO_PIN_7 }}; // PD7;

uint32_t Matrix_Other_IO[2][2] =
{ { GPIO_PORTK_BASE, GPIO_PIN_0 },  // PK0;
  { GPIO_PORTK_BASE, GPIO_PIN_1 }}; // PK1;

void Configure_IO(uint32_t value)
{
    for(ig = 0; ig < AMOUNT_OF_IO; ig++)
    {
        //
        // Isolates I/O configuration command from variable Bits_IO_EE.
        //
        IO_Buffer = (uint8_t)((value & (0x00000003 << (ig*2))) >> 2*ig);

        //
        // Disable pin.
        //
        if(IO_Buffer == 0)
        {
            ROM_GPIOPinTypeGPIOInput(Matrix_IOs[ig][0], Matrix_IOs[ig][1]);
            Output_States &= (uint32_t)(0x000000FF - (uint32_t)(pow(2, ig)));
            ui32AnalogInput[ig] = 0;
        }
        //
        // Set pin as digital input.
        //
        else if(IO_Buffer == 1)
        {
            ROM_GPIOPinTypeGPIOInput(Matrix_IOs[ig][0], Matrix_IOs[ig][1]);
            GPIOPadConfigSet(Matrix_IOs[ig][0], Matrix_IOs[ig][1],
                             GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
            Output_States &= (uint32_t)(0x000000FF - (uint32_t)(pow(2, ig)));
            ui32AnalogInput[ig] = 0;
        }
        //
        // Set pin as analog input.
        //
        else if(IO_Buffer == 2)
        {
            ROM_GPIOPinTypeADC(Matrix_IOs[ig][0], Matrix_IOs[ig][1]);
            Output_States &= (uint32_t)(0x000000FF - (uint32_t)(pow(2, ig)));
            ui32AnalogInput[ig] = 0;
        }
        //
        // Set pin as digital output.
        //
        else if(IO_Buffer == 3)
        {
            ROM_GPIOPinTypeGPIOOutput(Matrix_IOs[ig][0], Matrix_IOs[ig][1]);
        }
    }

    //
    // Configures the other ADCs.
    //
    for(ig = 0; ig < AMOUNT_OF_OTHER_ADCS; ig++)
    {
        ROM_GPIOPinTypeADC(Matrix_Other_IO[ig][0], Matrix_Other_IO[ig][1]);
    }

    //
    // Enable clock to ADC0.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0)){}

    //Configure the ADC to use PLL at 120 MHz divided by 6 to get an ADC clock of 20 MHz.
    ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PLL | ADC_CLOCK_RATE_FULL, 6);

    //
    // Disables a sample sequence.
    //
    ROM_ADCSequenceDisable(ADC0_BASE, 0);

    //
    // Configure ADC0 Sample Sequencer 0 for processor trigger operation.
    //
    ROM_ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);

    //
    // Set up the ADC0 sequencer 0 for samples from the following ADC ports.
    //
    ROM_ADCSequenceStepConfigure (ADC0_BASE, 0, 0, ADC_CTL_CH9);  // EXTRA_IO1
    ROM_ADCSequenceStepConfigure (ADC0_BASE, 0, 1, ADC_CTL_CH8);  // EXTRA_IO2
    ROM_ADCSequenceStepConfigure (ADC0_BASE, 0, 2, ADC_CTL_CH7);  // EXTRA_IO3
    ROM_ADCSequenceStepConfigure (ADC0_BASE, 0, 3, ADC_CTL_CH6);  // EXTRA_IO4
    ROM_ADCSequenceStepConfigure (ADC0_BASE, 0, 4, ADC_CTL_CH5);  // EXTRA_IO5
    ROM_ADCSequenceStepConfigure (ADC0_BASE, 0, 5, ADC_CTL_CH4);  // EXTRA_IO6
    ROM_ADCSequenceStepConfigure (ADC0_BASE, 0, 6, ADC_CTL_CH16); // L_Out
    ROM_ADCSequenceStepConfigure (ADC0_BASE, 0, 7, ADC_CTL_CH17 | // R_Out
                                  ADC_CTL_IE |ADC_CTL_END);

    //Configure the hardware oversampling factor of the ADC.
    //ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 2);

    //Enable ADC Sequence 0 Interrupt on the processor (NVIC).
    ROM_IntEnable(INT_ADC0SS0);

    //Enables DMA for sample sequencers.
    ROM_ADCSequenceDMAEnable(ADC0_BASE, 0);

    // Enables a sample sequence interrupt.
    ROM_ADCIntEnableEx(ADC0_BASE, ADC_INT_DMA_SS0);

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

    // Clear the interrupt status flag.  This is done to make sure the interrupt flag is cleared before we sample.
    ROM_ADCIntClear(ADC0_BASE, 0);

    // Trigger the ADC conversion.
    ROM_ADCProcessorTrigger(ADC0_BASE, 0);
}

void Configure_Timer1(void)
{
    //
    //Configure Timer 1
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
    while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER1)){}

    ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
    ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, g_ui32SysClock / 20);
    ROM_IntEnable(INT_TIMER1A);
    ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

    ROM_TimerEnable(TIMER1_BASE, TIMER_A);
}

void Timer1AIntHandler(void)
{
    //Clear Timer 1 interrupt flag
    ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

    //Trigger ADC conversion
    ROM_ADCProcessorTrigger(ADC0_BASE, 0);
}

void ADC0S0IntHandler(void)
{
    static uint16_t i, j;
    static uint32_t intStatusEx = 0;
    static uint32_t priChMode, altChMode;

    //Get interrupt status
    intStatusEx = ROM_ADCIntStatusEx(ADC0_BASE, 0);

    //Get mode of primary DMA channel
    priChMode = ROM_uDMAChannelModeGet(UDMA_CH14_ADC0_0 | UDMA_PRI_SELECT);

    //Get mode of alternative DMA channel
    altChMode = ROM_uDMAChannelModeGet(UDMA_CH14_ADC0_0 | UDMA_ALT_SELECT);

    //Clear interrupt flag
    ADCIntClearEx(ADC0_BASE, ADC_INT_DMA_SS0);

    //Clear and re-init primary DMA buffer if it's full
    if (priChMode == 0)
    {
        ROM_uDMAChannelTransferSet(UDMA_CH14_ADC0_0 | UDMA_PRI_SELECT, UDMA_MODE_PINGPONG,
                                   (void *)(ADC0_BASE + ADC_O_SSFIFO0),
                                   g_ADCui8RxBufA,
                                   NUMBER_OF_SETSADC * NUMBER_OF_STEPSADC);

        for (i = 0; i < NUMBER_OF_STEPSADC; i++)
            pui32ADC0Value[i] = g_ADCui8RxBufA[0][i];

        for (i = 0; i < NUMBER_OF_STEPSADC; i++)
        {
            for (j = 1; j < NUMBER_OF_SETSADC; j++)
            {
                pui32ADC0Value[i] += g_ADCui8RxBufA[j][i];
                pui32ADC0Value[i] /= 2;
            }
        }
    }

    //Clear and re-init alternative DMA buffer if it's full
    if (altChMode == 0)
    {
        ROM_uDMAChannelTransferSet(UDMA_CH14_ADC0_0 | UDMA_ALT_SELECT, UDMA_MODE_PINGPONG,
                                               (void *)(ADC0_BASE + ADC_O_SSFIFO0),
                                               g_ADCui8RxBufB,
                                               NUMBER_OF_SETSADC * NUMBER_OF_STEPSADC);

        for (i = 0; i < NUMBER_OF_STEPSADC; i++)
            pui32ADC0Value[i] = g_ADCui8RxBufB[0][i];

        for (i = 0; i < NUMBER_OF_STEPSADC; i++)
        {
            for (j = 1; j < NUMBER_OF_SETSADC; j++)
            {
                pui32ADC0Value[i] += g_ADCui8RxBufB[j][i];
                pui32ADC0Value[i] /= 2;
            }
        }
    }
}

  • Hi Simion,

      Can you try with a simpler setup for 1 ADC channel instead of 8? With only 1 channel what are you getting? It will be easier to debug by starting with a simpler setup and then gradually expand the number of channels.

      Attached is one example with adc and dma. Please try it. This example uses DMA but with only one ADC channel. Compare the result of this example with your own 1-channel set and see if you are getting different result. if there is difference then you can then compare the code. 

    adc_dma.zip

  • Ok, I tested it and the values ​​are really correct for an AD channel, but after a short time no more reading is done.

    The only detail I couldn't implement in the code was this line:

    g_ui32SysClock = SysCtlClockFreqSet ((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_240), 120000000);

    There is no defined value for 'SYSCTL_CFG_VCO_240', so I left the value that was already set, 'SYSCTL_CFG_VCO_480'.

    What could be happening?

  • Hi Simion,

      Sorry, the example code that I attached was planned for the next soon-to-be released TivaWare library. The new TivaWare example will use SYSCTL_CFG_VCO_240 instead of SYSCTL_CFG_VCO_480. The definition for these two macros are identical but they have different names to address some errata. When you use SYSCTL_CFG_VCO_480, the VCO was actually 240MHz, not 480MHz. The new release uses SYSCTL_CFG_VCO_240  to reflect the real VCO output. You are fine to use SYSCTL_CFG_VCO_480. 

     

  • I understand.

    What could be preventing the reading of the AD channel?

  • Simion Bernardo said:
    Ok, I tested it and the values ​​are really correct for an AD channel, but after a short time no more reading is done.

    Can you elaborate the problem? Are you running the example as is other than changing the SYSCTL_CFG_VCO_240 to SYSCTL_CFG_VCO_480? I see in your screenshot you have a variable g_ui64SystemTimeMS. The example doesn't have this variable? Did you modify the example? 

    What do you mean after a short time there is no more reading. The ADC is triggered by the timer at a 16kHz sampling rate. Unless the timer stops for some reason, it should trigger the ADC continuously.  

    You said the values are really correct for an AD channel. This is at least a good starting point. In contrast, your original post stated that the result of ADC conversion was off if uDMA was used. 

     

  • I include the example in my project, exactly as it is in the file you sent me.
    The values ​​measured by the AD channel are perfectly correct now, previously the values ​​were totally inconsistent ...
    At least one problem has been solved!

    However, within my "while (1) {...}", in addition to the routine included in the adc_udma_pingpong example, there are several other routines in my own project, such as I2C_uDMA, UART_uDMA communication, and etc ... When I disable them, reading the analog input is done correctly without problems, but under normal conditions it is as if the code no longer enters 'ADCSeq0Handler' after a few seconds ...

    EDIT:
    I noticed that the code keeps calling the 'ADCSeq0 Handler' function, but no condition is true, I think it's because the variable at some point received the values ​​pui32BufferStatus = {EMPTY, EMPTY}.

  • HI,

      I will suggest to aid you debugging, you add one peripheral at a time. For example, while you have a working ADC_uDMA, add UART_uDMA. If both ADC and UART are working then add the next peripheral, i.e. I2C_uDMA. 

      Not sure if the problem is related to to the channel priority. The ADC is mapped to channel 14. You might want to play with the priority too. 

    If all the peripherals are set for high priority then the channels (i.e. UART0 at channel 8) will have higher priority than ADC. 

      Again, you should start with a simple setup with two peripherals and gradually add the next peripheral. This way you know what peripherals might be interfering with each other and understand the root cause.

  • Even disabling all the DMA features of the code, leaving only the reading of the AD channel, still, the reading is interrupted at some point...

    Wouldn't that be wrong with the logic of the example?

  • I'm not clear with what you are saying. Did you disable all the DMA features including for ADC? The example was written for ADC with DMA? If you disable the DMA, then what do you have left? Are you just using the CPU to move the data?

      What other peripherals are also running and requiring the CPU to service their interrupts? See the below interrupt table and its default priority. the lower the vector value the higher the priority. The ADC SS0 is mapped to vector 30. If you have other peripherals also interrupting the CPU, then the higher priority interrupts (i.e. UART0 at vector 21) will preempt the ADC interrupt. You can reassign the interrupt priority among peripherals or you can disable interrupts when you enter the ADCSeq0Handler(). Process the ADC data and then re-enable interrupt before you exit the ISR. 

  • My project uses 3 peripherals along with DMA, I2C1 TX and RX, UART0 and ADC0.

    First I tried to implement the example in my code along with all the peripherals, and I realized that after some time the reading was no longer updated.

    I followed your tip and disabled all I2C and UART communication in my code, and the problem persisted.

    From there I doubted how the data was read in 'while (1) {}' and in 'ADCSeq0Handler' and decided to do it my way, and apparently solved the problem, I will leave my solution here.

    I will also leave the code running for 24 hours to see if any problems will occur.

    void ADC0S0IntHandler(void)
    {
        //
        // Clear the Interrupt Flag.
        //
        ROM_ADCIntClear(ADC0_BASE, 0);
    
        ui32Mode = ROM_uDMAChannelModeGet(UDMA_CHANNEL_ADC0 | UDMA_PRI_SELECT);
    
        if(ui32Mode == UDMA_MODE_STOP)
        {
    
        //
        // Enable for another uDMA block transfer.
        //
        ROM_uDMAChannelTransferSet(UDMA_CHANNEL_ADC0 | UDMA_PRI_SELECT,
                                   UDMA_MODE_PINGPONG,
                                   (void *)(ADC0_BASE + ADC_O_SSFIFO0),
                                   &pui16ADCBuffer1, ADC_SAMPLE_BUF_SIZE);
    
            g_ui32ADCBufACount++;
    
            if(g_ui32ADCBufACount >= 100000)
                g_ui32ADCBufACount = 0;
        }
    
        ui32Mode = ROM_uDMAChannelModeGet(UDMA_CHANNEL_ADC0 | UDMA_ALT_SELECT);
    
        if(ui32Mode == UDMA_MODE_STOP)
        {
            ROM_uDMAChannelTransferSet(UDMA_CHANNEL_ADC0 | UDMA_ALT_SELECT,
                                   UDMA_MODE_PINGPONG,
                                   (void *)(ADC0_BASE + ADC_O_SSFIFO0),
                                   &pui16ADCBuffer2, ADC_SAMPLE_BUF_SIZE);
    
            g_ui32ADCBufBCount++;
    
            if(g_ui32ADCBufBCount >= 100000)
                g_ui32ADCBufBCount = 0;
        }
    }

    while(1) {
    
        if(old_pos_ADC_A != g_ui32ADCBufACount)
        {
            if(Lock_ADC == 1)
            {
                Lock_ADC = 0;
                old_pos_ADC_A++;
    
                if(old_pos_ADC_A >= 100000)
                    old_pos_ADC_A = 0;
    
                ui32AverageResult1 = 0;
    
                for(ui32Count = 0; ui32Count < ADC_SAMPLE_BUF_SIZE; ui32Count++)
                {
                    ui32AverageResult1 += pui16ADCBuffer1[ui32Count];
                    pui16ADCBuffer1[ui32Count] = 0;
                }
    
                ui32AverageResult1 = ((ui32AverageResult1 +
                                      (ADC_SAMPLE_BUF_SIZE / 2)) /
                                       ADC_SAMPLE_BUF_SIZE);
    
                pui32ADC0Value[0] = ui32AverageResult1;
            }
        }
    
        if(old_pos_ADC_B != g_ui32ADCBufBCount)
        {
            if(Lock_ADC == 0)
            {
                Lock_ADC = 1;
                old_pos_ADC_B++;
    
                if(old_pos_ADC_B >= 100000)
                    old_pos_ADC_B = 0;
    
                ui32AverageResult2 = 0;
    
                for(ui32Count =0; ui32Count < ADC_SAMPLE_BUF_SIZE; ui32Count++)
                {
                    ui32AverageResult2 += pui16ADCBuffer2[ui32Count];
                    pui16ADCBuffer2[ui32Count] = 0;
                }
    
                ui32AverageResult2 = ((ui32AverageResult2 +
                                      (ADC_SAMPLE_BUF_SIZE / 2)) /
                                       ADC_SAMPLE_BUF_SIZE);
    
                pui32ADC0Value[0] = ui32AverageResult2;
            }
        }
    }

  • ok, glad that your own code works. Please let us know how it goes. In the meantime I will also run the example i sent you and see if I see the same problem as you.

  • Just a quick update. I've run the example as it for a couple of minutes and it is still running. I don't see a problem. With that said, if your own code is working and and you are getting consistent result then I think you should go with your code. Do let us know. 

  • I modified my code a little to avoid some problems that were occurring, basically eliminated everything that was in 'while (1) {}' and transferred it to 'ADCSeq0Handler'.

    Now my code works normally with all peripherals.

    void ADC0S0IntHandler(void)
    {
        //
        // Clear the Interrupt Flag.
        //
        ROM_ADCIntClear(ADC0_BASE, 0);
    
        ui32Mode = ROM_uDMAChannelModeGet(UDMA_CH14_ADC0_0 | UDMA_PRI_SELECT);
    
        if(ui32Mode == UDMA_MODE_STOP)
        {
    
            //
            // Enable for another uDMA block transfer.
            //
            ROM_uDMAChannelTransferSet(UDMA_CH14_ADC0_0 | UDMA_PRI_SELECT,
                                       UDMA_MODE_PINGPONG,
                                       (void *)(ADC0_BASE + ADC_O_SSFIFO0),
                                       &pui16ADCBuffer1, ADC_SAMPLE_BUF_SIZE);
    
            ROM_uDMAChannelEnable(UDMA_CH14_ADC0_0 | UDMA_PRI_SELECT);
    
            ui32AverageResult1 = 0;
    
            for(ui32Count = 0; ui32Count < ADC_SAMPLE_BUF_SIZE; ui32Count++)
            {
                ui32AverageResult1 += pui16ADCBuffer1[ui32Count];
                pui16ADCBuffer1[ui32Count] = 0;
            }
    
            ui32AverageResult1 = ((ui32AverageResult1 +
                                  (ADC_SAMPLE_BUF_SIZE / 2)) /
                                   ADC_SAMPLE_BUF_SIZE);
    
            pui32ADC0Value[0] = ui32AverageResult1;
        }
    
        ui32Mode = ROM_uDMAChannelModeGet(UDMA_CHANNEL_ADC0 | UDMA_ALT_SELECT);
    
        if(ui32Mode == UDMA_MODE_STOP)
        {
            ROM_uDMAChannelTransferSet(UDMA_CHANNEL_ADC0 | UDMA_ALT_SELECT,
                                   UDMA_MODE_PINGPONG,
                                   (void *)(ADC0_BASE + ADC_O_SSFIFO0),
                                   &pui16ADCBuffer2, ADC_SAMPLE_BUF_SIZE);
    
            ROM_uDMAChannelEnable(UDMA_CHANNEL_ADC0 | UDMA_ALT_SELECT);
    
            ui32AverageResult2 = 0;
    
            for(ui32Count =0; ui32Count < ADC_SAMPLE_BUF_SIZE; ui32Count++)
            {
                ui32AverageResult2 += pui16ADCBuffer2[ui32Count];
                pui16ADCBuffer2[ui32Count] = 0;
            }
    
            ui32AverageResult2 = ((ui32AverageResult2 +
                                  (ADC_SAMPLE_BUF_SIZE / 2)) /
                                   ADC_SAMPLE_BUF_SIZE);
    
            pui32ADC0Value[0] = ui32AverageResult2;
        }
    }

    Now I need to read more 7 AD channels, I have some doubts...

    How to define arbitration?

    How is the data organized in 'pui16ADCBuffer1'?

  • Glad you are making progress. 

    Simion Bernardo said:
    How to define arbitration?

      Arbitration size is programmable. This is the size of the data the uDMA will transfer before moving to the next highest priority channel. The priority between channels can also be programmable. Below please find the datasheet description about arbitration and priority.

    9.2.2 Priority
    The ìDMA controller assigns priority to each channel based on the channel number and the priority
    level bit for the channel. Channel number 0 has the highest priority and as the channel number
    increases, the priority of a channel decreases. Each channel has a priority level bit to provide two

    levels of priority: default priority and high priority. If the priority level bit is set, then that channel has
    higher priority than all other channels at default priority. If multiple channels are set for high priority,
    then the channel number is used to determine relative priority among all the high priority channels.


    The priority bit for a channel can be set using the DMA Channel Priority Set (DMAPRIOSET)
    register and cleared with the DMA Channel Priority Clear (DMAPRIOCLR) register.


    Note: If one peripheral is mapped to two different channels, then the application should either use
    the default mapping for that peripheral or change the default mapping to another source.
    For example, if UART1 channels 8 and 9 are enabled for use, then even if channels 22 and
    23 are disabled, they must be mapped to software or another peripheral (if available).


    9.2.3 Arbitration Size


    When a ìDMA channel requests a transfer, the ìDMA controller arbitrates among all the channels
    making a request and services the ìDMA channel with the highest priority. Once a transfer begins,
    it continues for a selectable number of transfers before rearbitrating among the requesting channels
    again. The arbitration size can be configured for each channel, ranging from 1 to 1024 item transfers.
    After the ìDMA controller transfers the number of items specified by the arbitration size, it then
    checks among all the channels making a request and services the channel with the highest priority.


    If a lower priority ìDMA channel uses a large arbitration size, the latency for higher priority channels
    is increased because the ìDMA controller completes the lower priority burst before checking for
    higher priority requests. Therefore, lower priority channels should not use a large arbitration size
    for best response on high priority channels.

    Simion Bernardo said:
    How is the data organized in 'pui16ADCBuffer1


    Not clear with your question. It is just an array buffer holding your ADC data. It is a buffer holding

    ADC_SAMPLE_BUF_SIZE number of ADC data.

      

  • I managed to implement all the functions I needed.
    All analog inputs working perfectly now.

    Just a final question, will the new version of the TivaWare library include an update to the latest version of the LwIP stack?

  • Hi Simion,

      It will still be LwIP 1.4.1 in the new TivaWare version. 

  • I will need to resurrect the topic ...

    Initially I needed to use 8 analog inputs, but that number needs to increase to 16 now.

    I tried to compile in ADC1 everything that was done in ADC0, but I don't get any reading.

    Here's what has been done so far:

    Config_uDMA()

    #pragma DATA_ALIGN(pui8ControlTable, 1024)
    uint8_t pui8ControlTable[1024];
    void Config_uDMA(void)
    {
    
        ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_UDMA);
        ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_UDMA);
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
        while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_UDMA)){}
    
        ROM_uDMAEnable();
    
        ROM_uDMAControlBaseSet(pui8ControlTable);
    }
    


    Config_ADC0_uDMA()

    void Config_ADC0_uDMA(void)
    {
    
        ROM_uDMAChannelAttributeDisable(UDMA_CH14_ADC0_0,
                                        UDMA_ATTR_ALTSELECT | UDMA_ATTR_HIGH_PRIORITY |
                                        UDMA_ATTR_REQMASK);
    
        ROM_uDMAChannelControlSet(UDMA_CH14_ADC0_0 | UDMA_PRI_SELECT, UDMA_SIZE_16 |
                                  UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_1);
    
        ROM_uDMAChannelControlSet(UDMA_CH14_ADC0_0 | UDMA_ALT_SELECT, UDMA_SIZE_16 |
                                  UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_1);
    
        ROM_uDMAChannelTransferSet(UDMA_CH14_ADC0_0 | UDMA_PRI_SELECT,
                                   UDMA_MODE_PINGPONG,
                                   (void *)(ADC0_BASE + ADC_O_SSFIFO0),
                                   &pui16ADC0Buffer1,
                                   ADC_SAMPLE_BUF_SIZE * NUMBER_OF_STEPSADC);
    
        ROM_uDMAChannelTransferSet(UDMA_CH14_ADC0_0 | UDMA_ALT_SELECT,
                                   UDMA_MODE_PINGPONG,
                                   (void *)(ADC0_BASE + ADC_O_SSFIFO0),
                                   &pui16ADC0Buffer2,
                                   ADC_SAMPLE_BUF_SIZE * NUMBER_OF_STEPSADC);
    
        ROM_uDMAChannelAttributeEnable(UDMA_CH14_ADC0_0, UDMA_ATTR_USEBURST);
    
        ROM_uDMAChannelEnable(UDMA_CH14_ADC0_0);
    }


    Config_ADC1_uDMA()

    void Config_ADC1_uDMA(void)
    {
    
        ROM_uDMAChannelAttributeDisable(UDMA_CH24_ADC1_0,
                                        UDMA_ATTR_ALTSELECT | UDMA_ATTR_HIGH_PRIORITY |
                                        UDMA_ATTR_REQMASK);
    
        ROM_uDMAChannelControlSet(UDMA_CH24_ADC1_0 | UDMA_PRI_SELECT, UDMA_SIZE_16 |
                                  UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_1);
    
        ROM_uDMAChannelControlSet(UDMA_CH24_ADC1_0 | UDMA_ALT_SELECT, UDMA_SIZE_16 |
                                  UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_1);
    
        ROM_uDMAChannelTransferSet(UDMA_CH24_ADC1_0 | UDMA_PRI_SELECT,
                                   UDMA_MODE_PINGPONG,
                                   (void *)(ADC1_BASE + ADC_O_SSFIFO0),
                                   &pui16ADC1Buffer1,
                                   ADC_SAMPLE_BUF_SIZE * NUMBER_OF_STEPSADC);
    
        ROM_uDMAChannelTransferSet(UDMA_CH24_ADC1_0 | UDMA_ALT_SELECT,
                                   UDMA_MODE_PINGPONG,
                                   (void *)(ADC1_BASE + ADC_O_SSFIFO0),
                                   &pui16ADC1Buffer2,
                                   ADC_SAMPLE_BUF_SIZE * NUMBER_OF_STEPSADC);
    
        ROM_uDMAChannelAttributeEnable(UDMA_CH24_ADC1_0, UDMA_ATTR_USEBURST);
    
        ROM_uDMAChannelEnable(UDMA_CH24_ADC1_0);
    }


    Configure_IO()

    void Configure_IO(uint32_t value)
    {
        static uint8_t i;
    
        //
        // Configures the function of each I/O.
        //
        for(i = 0; i < AMOUNT_OF_IO; i++)
        {
            //
            // Isolates I/O configuration command from variable Bits_IO_EE.
            //
            IO_Buffer = (uint8_t)((value & (0x00000003 << (i*2))) >> 2*i);
    
            //
            // Disable pin.
            //
            if(IO_Buffer == 0)
            {
                ROM_GPIOPinTypeGPIOInput(Matrix_IOs[i][0], Matrix_IOs[i][1]);
                Output_States &= (uint32_t)(0x000000FF - (uint32_t)(pow(2, i)));
                ui32AnalogInput[i] = 0;
            }
            //
            // Set pin as digital input.
            //
            else if(IO_Buffer == 1)
            {
                ROM_GPIOPinTypeGPIOInput(Matrix_IOs[i][0], Matrix_IOs[i][1]);
                if(i <= 7)
                    GPIOPadConfigSet(Matrix_IOs[i][0], Matrix_IOs[i][1],
                                     GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
                Output_States &= (uint32_t)(0x000000FF - (uint32_t)(pow(2, i)));
                ui32AnalogInput[i] = 0;
            }
            //
            // Set pin as analog input.
            //
            else if(IO_Buffer == 2)
            {
                ROM_GPIOPinTypeADC(Matrix_IOs[i][0], Matrix_IOs[i][1]);
                Output_States &= (uint32_t)(0x000000FF - (uint32_t)(pow(2, i)));
                ui32AnalogInput[i] = 0;
            }
            //
            // Set pin as digital output.
            //
            else if(IO_Buffer == 3)
            {
                ROM_GPIOPinTypeGPIOOutput(Matrix_IOs[i][0], Matrix_IOs[i][1]);
            }
        }
    
        //
        // ADC0
        //
    
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
        while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0)){}
    
        ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_HALF, 1);
    
        ROM_SysCtlDelay(10);
    
        ROM_IntDisable(INT_ADC0SS0);
    
        ROM_ADCIntDisable(ADC0_BASE, 0);
    
        ROM_ADCSequenceDisable(ADC0_BASE, 0);
    
        ROM_ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0);
    
        ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH7);
        ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH6);
        ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH5);
        ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH4);
        ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_CH15);
        ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 5, ADC_CTL_CH14);
        ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 6, ADC_CTL_CH13);
        ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 7, ADC_CTL_CH12 |
                                     ADC_CTL_IE |ADC_CTL_END);
    
        ROM_ADCSequenceEnable(ADC0_BASE, 0);
    
        ROM_ADCIntClear(ADC0_BASE, 0);
    
        ROM_ADCSequenceDMAEnable(ADC0_BASE, 0);
    
        ROM_ADCIntEnable(ADC0_BASE, 0);
    
        ROM_IntEnable(INT_ADC0SS0);
    
    
        //
        // ADC1
        //
    
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
        while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_ADC1)){}
    
        ADCClockConfigSet(ADC1_BASE, ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_HALF, 1);
    
        ROM_SysCtlDelay(10);
    
        ROM_IntDisable(INT_ADC1SS0);
    
        ROM_ADCIntDisable(ADC1_BASE, 0);
    
        ROM_ADCSequenceDisable(ADC1_BASE, 0);
    
        ROM_ADCSequenceConfigure(ADC1_BASE, 0, ADC_TRIGGER_TIMER, 0);
    
        ROM_ADCSequenceStepConfigure(ADC1_BASE, 0, 0, ADC_CTL_CH0);
        ROM_ADCSequenceStepConfigure(ADC1_BASE, 0, 1, ADC_CTL_CH1);
        ROM_ADCSequenceStepConfigure(ADC1_BASE, 0, 2, ADC_CTL_CH2);
        ROM_ADCSequenceStepConfigure(ADC1_BASE, 0, 3, ADC_CTL_CH3);
        ROM_ADCSequenceStepConfigure(ADC1_BASE, 0, 4, ADC_CTL_CH16);
        ROM_ADCSequenceStepConfigure(ADC1_BASE, 0, 5, ADC_CTL_CH17);
        ROM_ADCSequenceStepConfigure(ADC1_BASE, 0, 6, ADC_CTL_CH18);
        ROM_ADCSequenceStepConfigure(ADC1_BASE, 0, 7, ADC_CTL_CH19 |
                                     ADC_CTL_IE |ADC_CTL_END);
    
        ROM_ADCSequenceEnable(ADC1_BASE, 0);
    
        ROM_ADCIntClear(ADC1_BASE, 0);
    
        ROM_ADCSequenceDMAEnable(ADC1_BASE, 0);
    
        ROM_ADCIntEnable(ADC1_BASE, 0);
    
        ROM_IntEnable(INT_ADC1SS0);
    }


    Configure_Timer0()

    void Configure_Timer0(void)
    {
    
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
        while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0)){}
    
        ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC);
    
        ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, (g_ui32SysClock/2000) - 0);
    
        TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
    
        ROM_IntMasterEnable();
    
        ROM_TimerEnable(TIMER0_BASE, TIMER_A);
    }


    ADC0S0IntHandler()

    void ADC0S0IntHandler(void)
    {
        static uint32_t ui32AverageResult1;
        static uint32_t ui32AverageResult2;
        static uint32_t ui32Mode;
        static uint8_t  i, j;
    
        ROM_ADCIntClear(ADC0_BASE, 0);
    
        ui32Mode = ROM_uDMAChannelModeGet(UDMA_CH14_ADC0_0 | UDMA_PRI_SELECT);
    
        if(ui32Mode == UDMA_MODE_STOP)
        {
    
            ROM_uDMAChannelTransferSet(UDMA_CH14_ADC0_0 | UDMA_PRI_SELECT,
                                       UDMA_MODE_PINGPONG,
                                       (void *)(ADC0_BASE + ADC_O_SSFIFO0),
                                       &pui16ADC0Buffer1,
                                       ADC_SAMPLE_BUF_SIZE * NUMBER_OF_STEPSADC);
    
            ROM_uDMAChannelEnable(UDMA_CH14_ADC0_0 | UDMA_PRI_SELECT);
    
            for(j = 0; j < NUMBER_OF_STEPSADC; j++)
            {
                ui32AverageResult1 = 0;
    
                for(i = 0; i < ADC_SAMPLE_BUF_SIZE; i++)
                {
                    ui32AverageResult1 += pui16ADC0Buffer1[i][j];
                    pui16ADC0Buffer1[i][j] = 0;
                }
    
                ui32AverageResult1 = ((ui32AverageResult1 +
                                      (ADC_SAMPLE_BUF_SIZE / 2)) /
                                       ADC_SAMPLE_BUF_SIZE);
    
                pui32ADC0Value[j] = ui32AverageResult1;
            }
        }
    
        ui32Mode = ROM_uDMAChannelModeGet(UDMA_CH14_ADC0_0 | UDMA_ALT_SELECT);
    
        if(ui32Mode == UDMA_MODE_STOP)
        {
            ROM_uDMAChannelTransferSet(UDMA_CH14_ADC0_0 | UDMA_ALT_SELECT,
                                   UDMA_MODE_PINGPONG,
                                   (void *)(ADC0_BASE + ADC_O_SSFIFO0),
                                   &pui16ADC0Buffer2,
                                   ADC_SAMPLE_BUF_SIZE * NUMBER_OF_STEPSADC);
    
            ROM_uDMAChannelEnable(UDMA_CH14_ADC0_0 | UDMA_ALT_SELECT);
    
            for(j = 0; j < NUMBER_OF_STEPSADC; j++)
            {
                ui32AverageResult2 = 0;
    
                for(i =0; i < ADC_SAMPLE_BUF_SIZE; i++)
                {
                    ui32AverageResult2 += pui16ADC0Buffer2[i][j];
                    pui16ADC0Buffer2[i][j] = 0;
                }
    
                ui32AverageResult2 = ((ui32AverageResult2 +
                                      (ADC_SAMPLE_BUF_SIZE / 2)) /
                                       ADC_SAMPLE_BUF_SIZE);
    
                pui32ADC0Value[j] = ui32AverageResult2;
            }
        }
    }


    ADC1S0IntHandler()

    void ADC1S0IntHandler(void)
    {
        static uint32_t ui32AverageResult1;
        static uint32_t ui32AverageResult2;
        static uint32_t ui32Mode;
        static uint8_t  i, j;
    
        ROM_ADCIntClear(ADC1_BASE, 0);
    
        ui32Mode = ROM_uDMAChannelModeGet(UDMA_CH24_ADC1_0 | UDMA_PRI_SELECT);
    
        if(ui32Mode == UDMA_MODE_STOP)
        {
    
            ROM_uDMAChannelTransferSet(UDMA_CH24_ADC1_0 | UDMA_PRI_SELECT,
                                       UDMA_MODE_PINGPONG,
                                       (void *)(ADC1_BASE + ADC_O_SSFIFO0),
                                       &pui16ADC1Buffer1,
                                       ADC_SAMPLE_BUF_SIZE * NUMBER_OF_STEPSADC);
    
            ROM_uDMAChannelEnable(UDMA_CH24_ADC1_0 | UDMA_PRI_SELECT);
    
            for(j = 0; j < NUMBER_OF_STEPSADC; j++)
            {
                ui32AverageResult1 = 0;
    
                for(i = 0; i < ADC_SAMPLE_BUF_SIZE; i++)
                {
                    ui32AverageResult1 += pui16ADC1Buffer1[i][j];
                    pui16ADC1Buffer1[i][j] = 0;
                }
    
                ui32AverageResult1 = ((ui32AverageResult1 +
                                      (ADC_SAMPLE_BUF_SIZE / 2)) /
                                       ADC_SAMPLE_BUF_SIZE);
    
                pui32ADC0Value[j + 8] = ui32AverageResult1;
            }
        }
    
        ui32Mode = ROM_uDMAChannelModeGet(UDMA_CH24_ADC1_0 | UDMA_ALT_SELECT);
    
        if(ui32Mode == UDMA_MODE_STOP)
        {
            ROM_uDMAChannelTransferSet(UDMA_CH24_ADC1_0 | UDMA_ALT_SELECT,
                                   UDMA_MODE_PINGPONG,
                                   (void *)(ADC1_BASE + ADC_O_SSFIFO0),
                                   &pui16ADC1Buffer2,
                                   ADC_SAMPLE_BUF_SIZE * NUMBER_OF_STEPSADC);
    
            ROM_uDMAChannelEnable(UDMA_CH24_ADC1_0 | UDMA_ALT_SELECT);
    
            for(j = 0; j < NUMBER_OF_STEPSADC; j++)
            {
                ui32AverageResult2 = 0;
    
                for(i =0; i < ADC_SAMPLE_BUF_SIZE; i++)
                {
                    ui32AverageResult2 += pui16ADC1Buffer2[i][j];
                    pui16ADC1Buffer2[i][j] = 0;
                }
    
                ui32AverageResult2 = ((ui32AverageResult2 +
                                      (ADC_SAMPLE_BUF_SIZE / 2)) /
                                       ADC_SAMPLE_BUF_SIZE);
    
                pui32ADC0Value[j + 8] = ui32AverageResult2;
            }
        }
    }


    The code goes in 'ADC1S0IntHandler ()', but 'ui32Mode' is never the same as 'UDMA_MODE_STOP'.

    What can this be?

  • Hi,

      What does the ui32Mode in ADC1S0IntHandler return? Can you get the ADC1 with uDMA to work by itself without the ADC0 at all? It will be easier to debug if you can isolate the problem to a smaller area. Glancing through your code, I don't really spot anything wrong. 

  • 'ui32Mode' always returns 0x00.
    I tried to isolate ADC1 without success.
    However I found out what was missing, I should have added the line 'ROM_uDMAChannelAssign (UDMA_CH24_ADC1_0);' in 'Config_ADC1_uDMA ()'.
    I just did it and it worked!

    I'm sorry for the inconvenience, and thanks for your attention!