cancel
Showing results for 
Search instead for 
Did you mean: 

ADC in Dual Mode Simultaneously

paul-henri
Associate II
Posted on July 22, 2013 at 15:27

Hi everyones,

I am stuying the example from STM32 libraries (ADC_DualModeRegulSimu). I understand how the whole program works but I need some information and I have few questions about this code confronting to my project.

First of all, I need to convert 2 analog values simultaneously because I plan to compute a phase correlation (that's why I need the simultaneously conversion).

In the code, the converted value are put in a word of length 32 bits : 

extern __IO uint16_t aADCDualConvertedValue[2];

I want to stock the first and second value (half-word) in two vector that I have defined. I first decided to create a while statement like this :

while(counter<Max && ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC && ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC)) {

vector1[counter] = aADCDualConvertedValue[0];

vector2[counter] = aADCDualConvertedValue[1];

counter++;

}

But, this method seems to be unsafe because, we can't be certain that aADCDualConvertedValue[0] and aADCDualConvertedValue[1] are sampled at the same time owing to the number of cycles taken by while conditions.

So, what's the best way to stock the simultaneously data safely ?

Another problem, the conversion starts like this (after initializing the two ADC) :

ADC_SoftwareStartConv(ADC1);

 

ADC_SoftwareStartConv(ADC2);

 

Does-it mean that ADC2 starts to convert one cycle after ADC1, thus first both samples are not converted simultaneously ?

Thks.

#adc #stm32
23 REPLIES 23
paul-henri
Associate II
Posted on July 30, 2013 at 17:44

I make a cast...

i = (uint8_t) convertedValue;

Changing the sample time doesn't change anything...

paul-henri
Associate II
Posted on July 31, 2013 at 10:57

Notice I juste use USB power as power source supply. I think the Vref for ADC can be omitted ?

And, once I connect GND or input PIN, my computer lauches the USB On/Off sound..., actually, It seems weird ?

If I change, ADC3 to ADC2 (I use Channel 12 on GPIO Port C, so I read on PC2), I don't have funky values but juste the value 0...

I can't understand what's the issue.

I check ACD_GetConversionValue and returns the same funky values. So, the problem really comes from ADC conversion...

Thks.

Posted on July 31, 2013 at 17:17

The results are going to be highly dependent on the stability of VREF, 1V would be in the 1365 range, beyond the scope of 8-bit. But the swing does look rather excessive for a DC source.

You'll probably need to debug/analyse this yourself.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
paul-henri
Associate II
Posted on August 01, 2013 at 14:26

Ok...

It seems ADC don't work as well. ADC2 doesn't send anythink and ADC3 ignore entries and send funky values.

Do you have an advice or an idea to test the funcioning of these devices (JTAG or SWD) ?

Thks.

John F.
Senior
Posted on August 02, 2013 at 09:07

ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
i = (uint8_t) convertedValue;

Are you looking at a 12 bit result? If so, which 8 of the 12 are you seeing?
paul-henri
Associate II
Posted on August 02, 2013 at 09:28

I tested with an ADC's resolution of 8 bits, so I avoid the cast, and same problems appeared (random values but lower).

mstsai
Associate II
Posted on August 04, 2013 at 14:38

Dear clive1:

Thanks for share your codes which help a lot for me to understand the ADC+DMA mechanism. I tried your code on a home made 407IGT6 andfed two signals to the ADC channels, a 60Hz signal with Vpp~1.1V, offset 0.5v and a DC 3.3v.The PIO toggles every 2ms as shown on the scope. I expects that the buffer contains a continuous number for Ch1.But when I look at the contents of the buffer, the data seems a little awkward. It turns out that the data in the buffer is in several discrete pieces as shown in the attached file (plot1.jpg). For Ch2, the number seems fine as they are acquired from a DC source. First few lines of the contents of the buffer are:

d 0x2000002c,0x2000034b

0x2000002C 66 00 FF 0F 50 00 F3 0F - 54 00 FD 0F 4D 00 FD 0F f...P...T...M...

0x2000003C 4A 00 FC 0F 51 00 F9 0F - 4D 00 FC 0F 58 00 FF 0F J...Q...M...X...

0x2000004C 46 00 FB 0F 4F 00 FD 0F - 4C 00 FD 0F 4E 00 FB 0F F...O...L...N...

0x2000005C 54 00 FB 0F 58 00 FC 0F - 56 00 FD 0F 54 00 FC 0F T...X...V...T...

0x2000006C 55 00 FC 0F 63 00 FA 0F - 51 00 FC 0F 52 00 FD 0F U...c...Q...R...

0x2000007C 55 00 FF 0F 5D 01 FB 0F - 6C 01 FF 0F 59 01 FD 0F U...]...l...Y...

0x2000008C 59 01 FA 0F 68 01 FF 0F - 52 01 FD 0F 65 01 FA 0F Y...h...R...e...

0x2000009C 5E 01 FD 0F 4F 01 FF 0F - 4E 01 FD 0F 5B 01 FF 0F ^...O...N...[...

0x200000AC 58 01 FB 0F 56 01 FE 0F - 2C 00 FC 0F 40 00 FF 0F X...V...,...@...

0x200000BC 33 00 FF 0F 3A 00 FD 0F - 2A 00 FD 0F 3D 00 FF 0F 3...:...*...=...

0x200000CC 3A 00 FD 0F 30 00 F9 0F - 27 00 FC 0F 39 00 FD 0F :...0...'...9...

0x200000DC 27 00 FD 0F 2B 00 FD 0F - 39 00 FF 0F 28 00 FC 0F '...+...9...(...

0x200000EC 35 00 FE 0F 28 00 FC 0F - 23 00 FD 0F 3A 00 FC 0F 5...(...#...:...

0x200000FC 23 00 FD 0F 84 00 FE 0F - 8E 00 FC 0F 90 00 FD 0F #...............

0x2000010C 82 00 FC 0F 8E 00 FE 0F - 8A 00 FA 0F 86 00 FB 0F ................

0x2000011C 94 00 FF 0F 8D 00 FB 0F - 88 00 FC 0F 95 00 FD 0F ................

If I changed the ADC sampling rate to 10K, the contents of buffer seems correct (plot2.jpg)

I checked the codes and they seems correct to me. Do you have any idea about this?

Thanks

Men-Shen Tsai

________________

Attachments :

plot1.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1MK&d=%2Fa%2F0X0000000blq%2Frh0rx9eqtPPkNYz6d0gxu9nPAP4tHG6l9qXZrE7Rd_U&asPdf=false

plot2.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1MF&d=%2Fa%2F0X0000000blp%2FaROOW2rCW.8lGyQzHFM6NNqiaBjJ57Kve18lhvopnMU&asPdf=false
Posted on August 04, 2013 at 17:41

I checked the codes and they seems correct to me.  Do you have any idea about this? 

I guess I'd ponder how, and at what rate, the data had been offloaded from the system.

I didn't spend any time plotting the data, but rather confirmed the sample rate seemed to be correct. DC level seem to have been Ok

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mstsai
Associate II
Posted on August 07, 2013 at 02:09

I set a break point at 

DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);

and expected that the buffer should contain a continuous sampled signal.  Since the LED toggles every 2ms, the sampling rate should be correct.  I need to figure out how the adc (or dma) fills the buffer.

Thanks

MS

Posted on August 07, 2013 at 02:24

Alternating halves of the buffer should have been filled between each interrupt. HT the first half, TC the second half.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..