cancel
Showing results for 
Search instead for 
Did you mean: 

ADC with DMA triggered by ADC Watchdog (Signal Peak Recording)

John Craven
Senior
Posted on December 15, 2016 at 16:14

I would like to record signal peaks from an ADC to a DMA buffer.

I have this working in continuous and software triggered modes to circular buffers.

I have a adc watchdog interrupt working to detect a 'high signal'.

I am trying to put them together to record 'high' peaks in the signal to a buffer.

what i cant figure out is how to start the DMA on event for a ADC that is already running in continuous mode with interrupts for the high level watchdog.

in am use HAL libraries.

currently i have been starting the ADC with DMA with;

HAL_ADC_Start_DMA(&hadc1,(uint32_t*) &ADC_Data, 5000);

i know i can start ADC with interrupts for watchdog using;

HAL_ADC_Start_IT(&hadc1);

what do i need in my watchdog interrupt to start DMA transfer?

void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc)

{

    if (__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_AWD1) != RESET)

    {

        //Start DMA here

    }

}

Additionally:

i don't need continuous DMA or a circular buffer.

I can have a fixed buffer size. Filling to the end and stopping is fine.

I can controlled ADC triggering rate with timer to give peak sampling rate and duration

Basically, i need to know what HAL_ADC_Start_DMA(&hadc1,(uint32_t*) &ADC_Data, 5000); does

in addition too what HAL_ADC_Start_IT(&hadc1); does; and put that in my watchdog interrupt handler.

Sorry i an really new to the STM32 world. Hope one of you gurus can help.

12 REPLIES 12
Jeroen3
Senior
Posted on December 15, 2016 at 16:38

You didn't specify the chip you are using. But this sounds like something which is maybe possible using the HRTIM analog watchdog or comparator protection inputs in the F3's.

Good Luck. You'll need it, really need it.

John Craven
Senior
Posted on December 15, 2016 at 16:52

I am using STM32F303RE and 303VC chips.

Both have 4 x ADC units each with 3 x  AWD (watchdogs)

I have lots of comparators, but comparators need a reference voltage.

Each of my peak detecting ADC units will trigger at a arbitrary software set level.

Without 4 x DACs, which i don't have a way to make 4 x compator reference voltages via software.

I have my ADC working.

I have it doing DMA to circular buffer.

I have the AWD interrupts working during DMA and i am toggling an LED on above my 'peak' threshold

I know i have to start my ADC in regular continuous mode.

I just need some help figuring out how to initiate DMA on a ADC unit that is already started using regular continuous conversions when my AWD interrupts fires.

Jeroen3
Senior
Posted on December 15, 2016 at 19:53

Well, from quickly looking at the manual, it looks like the AWD outputs go to ETR of timers, and the timers have TRGO, which you can use as inject channel trigger.

You can't use regular channel dma, since that's running already.

I suggest you print the pages with data about peripherals interconnects, and start puzzling.

Dear ST,

This is where a complete overview of perihperal interconnects is helpful. Now it's spread across registers and tables all over the place. Since it's a puzzle to allocate resources, since some choice exclude others.

RTFM, the F3 has such thing.

John Craven
Senior
Posted on December 16, 2016 at 04:43

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6qw&d=%2Fa%2F0X0000000bwl%2F9ABJE9R3I3.fUVhXpP4aVMxWu5V57kOeRgUr7NLMb9U&asPdf=false
Jeroen3
Senior
Posted on December 16, 2016 at 08:02

I hope interrupt delay and jitter isn't too much of an issue.

asafbit
Associate II
Posted on September 05, 2017 at 10:50

Hi

Trying to take your code as an example of use of HAL_ADC_AnalogWDGConfig();

using a ADC2 with single channel

missing in your code (or i don't understand): how to declare the ADC interrupt on NVIC, do i need to use :

HAL_NVIC_SetPriority(ADC_IRQn, 0, 1);

HAL_NVIC_EnableIRQ(ADC_IRQn);

what is the IRQHandler function?

Posted on September 05, 2017 at 15:59

There are 2 interrupt handlers.

While waiting for a peak, ie the ADC is running in IT mode with AWD watching, the AWD Out of Window interrupt handler, switches the the IT based ADC/AWD off, and starts a DMA recording of the peak.

//detect the peak, ie outside AWD1 window
void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc)

Whenrecording a peak in DMA mode, when the DMA buffer fills, the following interrupt fires and which puts the ADC back into AWD IT mode and sets a flag so that the buffer (peak data) can be processed in the main loop.

//DMA transfer is complete, ie data buffer full
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

Posted on September 05, 2017 at 16:14

Here is the CubeMX project. With it, youshouldhave no issue to generate a template for ADC2.

________________

Attachments :

NUC-ADC-DMA.ioc.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HySt&d=%2Fa%2F0X0000000b81%2FlEwZQkvULz7NLjc0aoaTVfQ8y4FfgdENIrz26Aw_C_A&asPdf=false
Posted on September 05, 2017 at 16:21

If i was doing this again, i would follow the same DMA pattern used with UART receives and circular FIFO buffers.

I would run the DMA continuously with a circular buffer. I would setup the AWD so that both peak start (above threshold) and peak stop (below threshold) events were detected. When the events occurred, the DMA buffer pointer (CNDTR) would be captured. The data between those events would be read out out of the circular buffer to a processing buffer, and then processed.