Skip to main content
Explorer
July 2, 2024
Solved

Two DMA buffers for alternate ADC samples on the same pin

  • July 2, 2024
  • 2 replies
  • 1847 views

I sample a 1000Hz periodic signal twice  each period. At 50us after the start of the period for samples A and after 850us for samples B with a single ADC and a single channel. I trigger the ADC with a delayed PWM (Combined PWM1 on a G431) and the results go in a circular 32 values long DMA buffer and I get 16 A and 16 B samples alternated in it. Circular since I do not process the values constantly. 

But the fact that A and B samples are alternating in one buffer doesn’t please me. Is there a way to get two DMA buffers out with A samples triggered by the rising edge of the timer and B on the falling edge (10us conversion times)?

 

I have explored DMAMUX a bit. Was new to me. But that seems to only have one input from the ADC that cannot be multiplexed further based on ADC conversion complete combined with the value of the PWM trigger signal. 

Is there a logical way to do this? 

    This topic has been closed for replies.
    Best answer by AScha.3

    Why not set the buffer as two dimensional array ?

    (The DMA dont care about, how you call the members in the array.)

    Then have A in one and B in other "one line" :

    uint16_t   ADCdata[16][2] ;

    A in [0..15][0] , B in [0..15][1] .

    2 replies

    AScha.3Answer
    Super User
    July 2, 2024

    Why not set the buffer as two dimensional array ?

    (The DMA dont care about, how you call the members in the array.)

    Then have A in one and B in other "one line" :

    uint16_t   ADCdata[16][2] ;

    A in [0..15][0] , B in [0..15][1] .

    Fanuc30Author
    Explorer
    July 2, 2024

    Interesting and hadn’t thought that that is possible of course. Makes coding easier. But still I want it to be super explicit that A’s are rising edge and B falling edge samples. I stop and start the PWM triggers now and then and do not want to risk adding two A’s or B’s and messing up the order for good. I can prevent that in code by resetting the DMA pointer but I see all of that as a risk. If I can do it in the peripherals that would be best imo. 

    Super User
    July 2, 2024

    You will not mess up anything, as long as you start the (circular) DMA - and never stop it.

    If dont need data....just dont use them, but dont stop the running DMA process.

    It will be correct until...ever or a strong spike destroys the cpu. :)

    If you just stop the trigger, it will stay in this position and continue with next, when next trigger comes.

    I see no problem here.

    Visitor II
    August 9, 2024

    can you share a code?