Skip to main content
John Craven
Senior
December 15, 2016
Question

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

  • December 15, 2016
  • 12 replies
  • 3006 views
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.

    This topic has been closed for replies.

    12 replies

    Jeroen3
    Senior
    December 15, 2016
    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
    December 15, 2016
    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
    December 15, 2016
    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
    December 16, 2016
    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
    December 16, 2016
    Posted on December 16, 2016 at 08:02

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

    asafbit
    Associate II
    September 5, 2017
    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?

    John Craven
    Senior
    September 5, 2017
    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)

    asafbit
    Associate II
    September 16, 2017
    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
    September 16, 2017
    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.

    John Craven
    Senior
    September 18, 2017
    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.