Spark Logic

Problems with regular simultaneous dual ADC conversion with DMA transfer

robca Tue Nov 24, 2015 5:06 pm

EDIT: I finally solved this, please see http://www.stm32duino.com/viewtopic.php … 8474#p8474 for more info

I’m at the end of my wits :? I have read the ADC and DMA docs at least 5 times each. Looked at the RegSimul_DualMode example from ST (and that was fun enough, since it uses completely different conventions than the Arduino/Maple libraries but in the end I understand what it does)… and I still can’t make it work… help, please.

Problem statement: on a Maple Mini, using STM32duino, convert 4 analog channels (connected to pins D3-D6, i.e. IN8-5, respectively) and transfer the data in memory using DMA (I need fast and predictable timing).

I basically would need to combine “dual simultaneous mode” with “continuous scan”, in order to capture ~2000 samples from each channel. But I fear it might not be possible, and the only mention I found is here (no reply, though) https://my.st.com/public/STe2ecommuniti … x?tags=adc

The code below sets a sequence for each ADC: in SQR1 sequence length is 1 (i.e. 2 conversions), and I set the SQR2 registers to have ADC1 convert IN8 while ADC2 converts IN7, then ADC1 convert IN6 while ADC2 converts IN5. I set regular (not injected) SW triggers.

After setting the ADC1 and ADC2 registers and the DMA1 Channel 1, in theory setting ADC1->regs->CR2 |= ADC_CR2_SWSTART; should start the conversion for the master ADC1 and slave ADC2 and in parallel start the DMA (one 32 bit DMA transfer for each conversion: in dual mode the ADC1 SR register holds both the values for ADC1 and ADC2).

What I noticed, though, is that when ADC_CR2_CONT is enabled, the ADC continuously scans, and the DMA keeps sending data to my buffer. What that means is the the order of the odd and even channels in the buffer can be off. Basically, when ADC_CR2_CONT is enabled, the ADC keeps scanning all the time, and that triggers DMA transfers in a random order.

If I don’t use ADC_CR2_CONT, I can only sequence a limited number of channels (and even if I repeat the sequence, I can only still do 16 conversions per ADC max (using SQR1-3). Or I can convert 2 channels (one on ADC1, one on ADC2) continuously in parallel…

But there seems no way to do scan and dual simultaneous at the same time… am I missing something? Any suggestion? If this doesn’t work, I can use two Maple Mini synchronized to capture 4 channels, but it makes everything harder to code (one as a master, one as a slave, with the conversion triggered at the same time, and transferring data)

Here’s my non-working code (if you uncomment the delay() statement you will see the problem)

EDIT: removed non-working code, see http://www.stm32duino.com/viewtopic.php?f=3&t=757&p=8474#p8474 for working code

Replies

RogerClark Thu Nov 26, 2015 12:50 am

robca wrote:My question still stands, though: if I want to use direct registry access for the DMA, I need to add libmaple\dma.h

robca Thu Nov 26, 2015 4:04 pm

@Roger: I am using dma.h and direct DMA registry access…

The question (please look at Andy’s post before yours) is why adc.h is auto-included, but dma.h is not. Is it a configuration problem?

I mean, can be easily addressed, I just wonder if it’s something worth addressing

robca Thu Nov 26, 2015 5:01 pm

I have a new version of my code that samples all microphones for a a few cycles, calculates the average “noise level” and defines the values to be used for triggers.

The trigger code works, and it’s followed by a very fast sampling loop perfectly capable of capturing the types of wave form I need for the TDOA analysis. I can see plots of my samples with GNUplot :)

I’m running into a problem, though, and I think it has to do with how the ADC and mic amplifiers interact. I hope someone here might be able to shed some light.

To get started, I have these cheap modules http://www.ebay.com/itm/3-3V-3-5V-MAX98 … 1742472725, and they use a MAX9812 amplifier https://datasheets.maximintegrated.com/ … X9813L.pdf. The circuit is pretty much the reference circuit (plus a XC6206 LDO to power the MAX9812 with 3.3V). Please note that the MAX9812 is a fixed gain amplifier, which is what I want to avoid problems with AGC

According to the datasheet, the output impedance is 0.5 Ohm, and that should work well for the F103 ADC.

But I’m seeing a very weird behavior with that amplifier (but not with just an electret microphone): the average sampled value is around 2000 (out of 4096, makes sense). But when I have a trigger, you can see the initial sample to be much lower (around 1250), and then it drifts back to 2000. Please see the attached image.

ADCdrift.PNG
ADCdrift.PNG (42.53 KiB) Viewed 682 times

zmemw16 Thu Nov 26, 2015 7:11 pm

actually this memory popped up a couple of days back when i started reading or maybe because i was.
long time back, i had to write automated test equipment software for a 16 input analogue multiplexor.
unused channels were supposed to be in mV, but not 300mV; that’s about 5% of the input test signal.
turned out the input filtering capacitors were acting as a potential divider.

stephen

RogerClark Thu Nov 26, 2015 8:06 pm

@robca

Ah.

I see what you mean.

Can you try editing the file that includes adc.h and add an include for dma.h and let me know if it causes any build problems.

If it works, let me know and I will update the core

ahull Fri Nov 27, 2015 12:36 am

robca wrote:… My theory is that the capacitor on the MAX9812 output is interacting in a weird way with the ADC. To test my theory, I put a 1k resistor between gnd and the mic module out, and another between vcc and out. That actually seems to stabilize the output and the ADC doesn’t drift anymore, as you can see here.
…
When I want to also test (but haven’t had time to get the soldering iron) is what happens if I bypass (short circuit) the capacitor on the out.

Do you have any other suggestion on how to address the weird drift I’m seeing?

RogerClark Fri Nov 27, 2015 12:56 am

Do you need that capacitor between the output of the MAX9812 and the STM32?

Its either there to provide isolation or to remove a DC offset, but you may be better off with a resistor divider network if the issue is the supply voltage on the MAX9812 (assuming its not 3.3V)

From memory I thought the input impedance of the STM32 was somewhere in the range of 50k. Well I recall a tech note that said that care should be taken when trying to read external inputs with impedance of greater than 50k. Which probably means the input impedance is more than 50k but not in the meg ohm range.

BTW.
I think for this sort of work having a scope is almost essential.

mrburnette Fri Nov 27, 2015 12:59 am

RogerClark wrote:
<…>
BTW.
I think for this sort of work having a scope is almost essential.

RogerClark Fri Nov 27, 2015 1:11 am

Unfortunately my scope is 5+ years ago and it doesn’t have FFT :-(

I occasionally look to upgrade, but I can think of better things to spend $2k on ;-)

martinayotte Fri Nov 27, 2015 1:17 am

In French, we say “Cordonnier mal chaussé !” (google translated it as “Poorly shod shoemaker”)
I’m also in this trouble, my analog scope is pretty old, more than 25 years old, and limited to 10MHz.

ahull Fri Nov 27, 2015 1:33 am

Well I have access to a better ‘scope at work, but the one I have at home that I use most, cost twenty quid from ebay (and didn’t work).

For tear down and repair pictures, follow the link.

https://plus.google.com/u/0/photos/1110 … 2229320338

Its a Metrix OX-803B 40MHz – so a good old fashioned analog scope. In addition I of course have the Pig-O-scope, but it is very limited in its abilities, and another HP 100MHz analog that is 99% functional, and awaiting further “medical intervention”, when I have some spare time.

Next to a couple of multimeters I think a good oscilloscope probably one of the most important tools to have.

mrburnette Fri Nov 27, 2015 1:37 am

RogerClark wrote:Unfortunately my scope is 5+ years ago and it doesn’t have FFT :-(

I occasionally look to upgrade, but I can think of better things to spend $2k on ;-)

zmemw16 Fri Nov 27, 2015 1:44 am

@ray
that’s teasing; mention p&p :D

i’ve never understood fft, what would it give me in this situation?

stephen

RogerClark Fri Nov 27, 2015 2:14 am

mrburnette wrote:RogerClark wrote:Unfortunately my scope is 5+ years ago and it doesn’t have FFT :-(

I occasionally look to upgrade, but I can think of better things to spend $2k on ;-)

martinayotte Fri Nov 27, 2015 2:19 am

Should I start dreaming about SantaClaus ?
I would love to have one of those Rigol scopes.

RogerClark Fri Nov 27, 2015 2:24 am

My old DS1102D is quite a nice scope (though it looks a bit dated)

I was about to write that I don’t use 75% of the features…

So I fired it up and pressed the MATH button, and … It does do FFT !!

:lol: :lol: :lol:

RogerClark Fri Nov 27, 2015 2:27 am

zmemw16 wrote:@ray

i’ve never understood fft, what would it give me in this situation?

stephen

robca Fri Nov 27, 2015 9:45 am

Thanks for all the input (this is fun). i spend half of my time in the UK, half in US (in the UK at this time). I have a 100MHz dual trace analog scope in the US and I can borrow much better instruments there. In the UK I only have a very low end (20MHz) USB scope, not good enough for this. So further analysis will have to wait a few weeks

I tried shorting the capacitor: the mic amplifier is powered from the 3.3V supply of the Maple Mini and there’s an LDO with a ~250mV drop (which I will remove, since it’s not needed and needlessly reduces the range), so it’s safe to bypass it. Predictably the voltages are a bit lower: the resistor network I used before forced the capacitor to “float” at exactly half of VCC (~1.65V), while the output of the amplifier when there’s no signal is half of the amplifier voltage, i.e. ~1.5V. In either case conversion is stable and noise acceptable. So I have a decent starting point to make progress coding, and can finalize the hw design later on.

Good point about creating a RC filter with the addition of the resistor network, I will have to figure out what values work better. I also found this http://electronics.stackexchange.com/qu … as-of-2-5v and there’s a mention to use 100k resistors for a similar case (in that case they use 5V, but nothing would change with 3.3V). But 100K might be too high for the F103, which wants to see a low impedance on its input.

Please keep the suggestions/ideas coming :)

ahull Fri Nov 27, 2015 1:37 pm

RogerClark wrote:zmemw16 wrote:@ray

i’ve never understood fft, what would it give me in this situation?

stephen

Sign in to reply