2024-07-02 12:07 PM
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?
Solved! Go to Solution.
2024-07-02 12:46 PM - edited 2024-07-02 12:47 PM
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] .
2024-07-02 12:46 PM - edited 2024-07-02 12:47 PM
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] .
2024-07-02 01:11 PM
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.
2024-07-02 01:27 PM
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.
2024-07-03 01:29 AM
AScha.3, thanks, that helps me in my thinking of part of the problem. I will refrain from stopping DMA. And you are right: Stopping/stopping the PWM trigger doesn’t matter: rising and falling edges will always alternate perfectly. Hence the DMA will have A at the same edge as it initially started. OK, that issue is not an issue then. Learned something important (2D buffer and the consistency).
But I have an issue of my own: the PWM trigger signal is phase locked to the signal which works perfect if the signal oscillates and I start/stop the PWM trigger using your input. That phase lock also means that if the signal itself stops oscillating (it will and I detect that by a timer overrunning) I will generate a second PWM to sample the static signal. Probably your arguments still hold, but I do not want to create a rare case I hadn’t thought of.
Can we go back to a theoretical question then that will explore possibilities of the DMAMUX most probably:
- if I trigger the ADC at both edges of a PWM signal T resulting a samples A for the rising edges and B for the falling edges,
- and knowing that ADC conversion takes some time, but that that is shorter than the positive or negative duty of T,
- can the DMAMUX of an stm32G4 store the samples A and B in different buffers?
- after ADC conversion (and DMA request) T will be HIGH for samples A and LOW for samples B.
Quite sure there is something to learn.
2024-07-03 04:02 AM
>can the DMAMUX of an stm32G4 store the samples A and B in different buffers?
If you can "tell" the DMA, what you want now... (I would say: NO. )
The solution with two-dimensonal array is not enough ?
+
> I will generate a second PWM to sample the static signal
So why not use another DMA +ADC (or same in injected mode?) , have other trigger anyway here.
Then no mix of data possible.
Maybe need to connect a second pin to the first ADC, or can choose a pin, that is connected to two ADCs, then even with one pin possible. (Some pins have more than one ADC , that can be connected. See it in Cube...easy.)
2024-07-03 12:58 PM
2D buffer works. Thanks!
2024-08-09 07:46 AM
can you share a code?