AnsweredAssumed Answered

Dual Combined Simultaneous Scan Mode with DMA and how to choose sampling time?

Question asked by Pablo Cottens on Jul 24, 2017

Hello,

 

I have a project in which I want to measure voltages and currents of 3 phases and calculate the energy consumption for each power line. For this, after reading some documentation I learned that the dual mode is what I was looking for. My setup for this is putting all V1, V2 and V3 in ADC1 and I1 I2 and I3 in ADC2. This way I can get adc values for Vn and An simultaneously, which means that there would be no phase delay between voltage and current.

 

Getting here was easy, what started bothering me a little is that I'm unable to understand how the DMA acquires the data. From the reference manual there are many modes it can get the data, DMA mode 1, 2 and 3.

 

DMA mode 1 -> consecutive requests for each ADC;

DMA mode 2 -> used in interleaved mode (doesn't interest me)

DMA mode 3 -> similar to mode 2

 

I would either get a DMA request for every  conversion and I'd read 2 bytes every time, or get a DMA request every 2 conversions

 

For set up purposes, Imagine ADC1 channels 0 2 and 4 (V1, V2 and V3 respectively) and ADC2 channels 1 3 and 5 (I1, I2, and I3 respectively) are being used and I configure the highest sampling rate (15 cycles, 450ns @30MHz) and I set up a timer to trigger the ADC every 10us. In my array I would get V1, V2, V3, V1, ...  and in the other I1, I2, I3, I1, ...??? I would have to configure 2 DMAs, one for ADC1 and the other for ADC2. This seems the best way for using SIMD instructions. It would make it easy for me to calculate power and calculate Vrms and Irms

 

After some reading I found the injected mode, which generates a DMA request at the end of the conversion of all channels, each with their own register ?? How would this work for the DMA? Is the DMA triggered to read from 4 registers (maximum .. in my case it would be 3) for each ADC? Would it be better for my application? This mode got me confused.

 

So .. to sum it up.

  1. I want to configure 2 ADCs @30MHz with the shortest conversion times (15 cycles for each channel per ADC, so a total of 45 cycles for conversion time?) and set up the ADCs for continuous scan mode?
  2. I want them to be triggered by a timer every ~100us.
  3. For this I would configure ADC1 to be triggered by timer and set up ADC2 as a slave
  4. I configure 2 DMA streams according to the DMA mapping table. One for ADC1 and one for ADC2, each pointing to the ADCx_DR registers. Considering that I want to get 120 points for every cycle (from the power line) I would need 1/(60*120), since the values are retrieved from the register every conversion is done and I'm reading 3 phases, each array must have 120*3=360 data entries of 2 bytes with a grande total of 720 bytes per array and the DMAs would be configured in a circular buffer

 

After this I would get my sine waves. So now comes the filtering part in order to remove DC offset but this is a whole different story and a subject for another question or forum.

 

Basically this question was asked because I'm not sure if I understood the dual simultaneous mode and how it works with DMA. Also I don't know if my calculations for sampling rate can be done, maybe and if it can still be triggered by the timer even though it is continuous mode. It's the first time I'm using STM32's ADC and it's a lot of information and a lot of possibilities.

 

PS: I also didn't understand the ADC_JOFRx. Well, I understood it, it subtracts the offset from the read value so that it would remove the DC offset given by my hardware. But ... is it a good idea to use it? I want to hack my development board and use an external 0.1% 3V voltage reference since it's more stable than Vdd, but I'm inserting an 1V5 offset using the same Vdd as my board. Would it be safe to assume a static 2047 offset? I think a high pass filter would be better here.

Outcomes