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
asafbit
Associate II
Posted on September 16, 2017 at 07:05

Thank you for your reply.

i was finally make it work.

what you gave as an options for callback are just callback which the ADC IRQHandler function should call.

that means you have to declare this inturrept on NVIC by us

i

ng :

HAL_NVIC_SetPriority(ADC_IRQn, 0, 1);

HAL_NVIC_EnableIRQ(ADC_IRQn);

as suggested earlier.

then at the IRQ file you have to have ADC_IRQHandler functiom which called for any type of ADC IRQ (cptr/outwindow).

can post full flow if needed

thank you.

S.Ma
Principal
Posted on September 16, 2017 at 12:04

On a generic STM32, I would run adc dma on a circular buffer and the watchdog interrupt used to snapshot the dma buffer pointer value. Then get interrupt when the sampling time is over, and finally sweep for the max value.

Posted on September 18, 2017 at 03:40

two posts ago I recommended the circ dma buffer and pointer sampling on both ends using awd interrupts. If you do it  as you suggest, the awd enter interrupt might happened every near the dma complete interrupt. And you won't have many or maybe enough samples, so then you have to decide if you will go another loop around the buffer or maybe halfway.

The awd feature has multiple windows, so it seems a lot more simpler to setup one window for an 'enter' peak sample interrupt and a second for ''leave' peak sample interrupt. You end up with just the peak data, not extra data after the peak.