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/CC3220: Configuring Timer+DMA+ADC for continuous sampling

Part Number: CC3220
Other Parts Discussed in Thread: CC3200

Tool/software: Code Composer Studio

Hi,

I would like to acquire data from two ADC channels at a fixed rate of 3.2ksps and perform RMS calculation on 64 samples. I am planning to use a timer (running at 3,2kHz) to trigger two DMAs which collects data from ADCs and put it in a ping-pong memory buffer. Once it collects 64 samples, CPU is notified and does RMS computation. Is there any example/drivers showcasing similar type of implementation?

Thanking you,

Prasanna

  • Hi Prasanna,

    I think this reference design ( www.ti.com/.../TIDC-CC3200SMARTPLUG ) sounds me like a good start-point even though it is based on 1st generation (CC3200). That means is based on driverlib not at new TI drivers.

    Jan
  • Hi Jan,

    Thanks for the link. This is a good starting point. 

    With Regards,

    Prasanna

  • Hi Prasanna,

    To build on Jan's post, the section of interest to you would be InitMetrologyAdcDma() and ADCIntHandler() in metrology.c of the smartplug-gen1 project.

    The InitMetrologyAdcDma() inits and sets up the ADC as well as the DMA ping-pong transfer. You'll note that for each ADC channel, you issue two DMA transfers on the same DMA channel before you start - one on the primary (UDMA_PRI_SELECT) and one on the alternate (UDMA_ALT_SELECT) paths.

    Then, in ADCIntHandler() you handle the DMA transfer complete interrupts that you get once the entire DMA transfer is done, as defined by the size of the transfer passed in in InitMetrologyAdcDMA(). When you get the interrupt, you would issue a new DMA transfer on the channel + primary/alternate that just completed. This way, you will always have one DMA transfer active and one DMA transfer in the queue for that channel to allow for continuous ping-pong. You do not need to worry about switching between the primary or alternate paths; the dma controller will automatically switch as long as the just-completed transfer on that channel was done with UDMA_MODE_PINGPONG.

    I suggest you examine the TRM for more detail on the operation of the DMA:
    www.ti.com/.../swru465.pdf

    Section 4 of the TRM is a very useful resource for understanding the DMA controller, and the various registers that are set when you run a DMA ping-pong transfer.

    Now, one complication you might have noticed with the CC3220 is that the ADC is not very configurable. Specifically, the ADC samples at the fixed rate of 62.5Ksps. This is probably why you wanted to use the timer-triggered DMA, but I wanted to bring this up in case you haven't discovered that info yet.

    To get the timer-triggered DMA, you need to setup your DMA transfers to not use the ADC channel, but the channel used for the timer. See figure 4-1 for the channel assignments of the DMA controller. Then, you should follow something along the lines of this E2E post to setup the timer + DMA:
    e2e.ti.com/.../385010
    Section 9 of the TRM is also a good resource.
    Do note that you would want to ensure that the DMA source address corresponds to the ADCFIFO address for the ADC channel you are using.

    That post only shows the setup. You will need a timer interrupt handler to take care of the DMAAINT interrupt source. This interrupt is asserted whenever the DMA transfer is complete, so when your 64 samples are collected. When it is asserted, you should follow what the ADCIntHandler() does and clear the interrupt and reissue the DMA transfer on that channel + pri/alt. After that, you can signal to the application to inform it that data is ready and do the RMS calculation. With DMA ping-pong buffering at your 3.2ksps rate the application has 20ms or 1.6M cycles per buffer to do processing, which should be more than enough for your RMS calculation.

    Let me know if you need more guidance, or if you have trouble implementing the timer-triggered DMA described above.

    Regards,
    Michael