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;
}
}
}
}
