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.

Using the ADC and uDMA simultaniously with TM4C123GXL

Hi all,

I've been trying to get a TM4C123GXL to transmit a chirp by using the on-board PWM to make a DAC and simultaniously record it with the on-board ADC. So far I haven't had much success, partly due to using the PWM and ADC with interrupts, causing the functions to interfere with each other (while trying to set a new PWM value I miss an ADC sequence-getting interrupt). Due to the microcontroller's relatively small memory for this cause (I have to work with the FPU so I can't make my arrays too large) I've been forced to try and split the labor between two MCUs- one to transmit said chirp and one to receive it, that are synchronized.

The DAC part seems to be working well, but the ADC's giving me some problems. The ADC interrupt isn't very long- the relevant code:

void ADC0Sequencer1IntHandler(void)
{
	uint32_t ui32ADC0Value[4];
	ROM_ADCIntClear(ADC0_BASE, 1);
	ROM_ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
for(i = 0; i < 4; i++) { y[ADC_sample_counter + i] = (float)(ui32ADC0Value[i]); } ADC_sample_counter += 4; ADC_flag = 0; }

but even that seems to be long enough for me to spend a significant amount of time putting the values received into an array, and miss out on some of the transmitted signal. So, I've been doing a bit of reading into the uDMA as I've been told it might help me with the issue. This brings me to the following questions:

1. Is there anywhere I can get an example code of using the ADC and the uDMA together? I've been trying to change the example given in the workshop for using the UART and the uDMA, but I'm having some issues with it.

2. Is there a way to transfer data from the ADC directly to an array of floats using the uDMA? This seems like an odd question but I'm trying to avoid any extra arrays if at all possible, including the uint32_t array I'll have to make otherwise.

Thanks in advance,

Avner.

  • Hello Avner,

    It is possible to have ADC and uDMA work together though we do not have an example to show the same. But since you are using an ADC to sample the data, I have some questions

    1. What is the sampling rate?
    2. If the signal is in audio band then do you really need a high sampling rate, A sampler of 48KHz is more than enough for med quality audio, though the 12 bit SAR ADC will not give the accuracy that is generally got from 16 bit sigma delta ADCs for audio
    3. Did you try to auto trigger the ADC so that sampler does not have to be triggered by the CPU
    4. Instead of ui32ADC0Value[4] being a local variable and then copy operation, can you make it global

    UDMA cannot do perform UINT to FLOAT conversion.

    Regards
    Amit
  • Hi Amit,

    Thanks for the quick reply!

    1+2. I'm using 16x hardware averaging to approximate a sampling frequency of 62.5kHz. Seeing as I'm using audio, this is supposedly the least wasteful I can be.

    3. I actually haven't. Are there any other ways to trigger a sampling sequence which would save me time?

    4. When I tried to do that I got a warning regarding the type of ui32ADC0Value (I tried making is a volatile uint32_t and define it outside of the functions). Is there a better way to do this?

    Too bad about the lack of conversion capability- I hope it doesn't stop me from using this feature.

    Avner

  • Hello Avner,

    You can use a periodic timer or a PWM generator to trigger the ADC, and that way CPU does not need to trigger the ADC every time and not required to have the hardware average.

    I have used the following to read the data into float.

    float32_t adcInput_buff1[TEST_LENGTH_SAMPLES];

    ADCSequenceDataGet(ADC0_BASE, 3, (float32_t *)adcInput_buff1[g_ui16Index++]);

    Regards
    Amit