Page 1 of 1

ADC simultaneous sampling?

Posted: Thu Jan 17, 2019 9:12 pm
by CraigUK
Hi all,

I'd like to measure the phase of a 50Hz ac waveform relative to another.
I think that simultaneous sampling would be the best way to do that which the MCU on the pyboard supports.

Is there any support for this feature?
If not, is there another way to acheive it?

Thanks,
Craig

Re: ADC simultaneous sampling?

Posted: Fri Jan 18, 2019 8:58 am
by stijn
As a general principle if you don't have simultaneous sampling you figure out the delay between the channels (usually nChannels/fs for consecutive channels) and shift your waveforms accordingly in post-processing.

Re: ADC simultaneous sampling?

Posted: Fri Jan 18, 2019 6:53 pm
by dhylands
MicroPython doesn't support simultaneous sampling on the pyboard. Theoretically it's possible by using two different ADC blocks (IIRC there are 3 on the STM32F405) and using one of the trigger modes to get them to start sampling at the same time.

You might be able to get something to work by tweaking the ADC registers directly using the stm module.

Re: ADC simultaneous sampling?

Posted: Fri Jan 18, 2019 10:15 pm
by CraigUK
dhylands wrote:
Fri Jan 18, 2019 6:53 pm
You might be able to get something to work by tweaking the ADC registers directly using the stm module.
That sounds interesting.
A quick google brought me here: http://wiki.micropython.org/platforms/b ... ard/modstm
Am I looking in the right place?

Thanks
Craig

Re: ADC simultaneous sampling?

Posted: Fri Jan 18, 2019 11:13 pm
by dhylands
Yep - that looks correct

Re: ADC simultaneous sampling?

Posted: Sat Jan 19, 2019 12:12 pm
by pythoncoder
You might consider the ADC.read_timed_multi method. This was intended for exactly this purpose, it produces good phase measurements at frequencies over 50KHz. The sampling isn't simultaneous but relative to 50Hz it's extremely close.

Re: ADC simultaneous sampling?

Posted: Sat Jan 19, 2019 8:43 pm
by OutoftheBOTS_
pythoncoder wrote:
Sat Jan 19, 2019 12:12 pm
You might consider the ADC.read_timed_multi method. This was intended for exactly this purpose, it produces good phase measurements at frequencies over 50KHz. The sampling isn't simultaneous but relative to 50Hz it's extremely close.
STM32 does have a hardware injected peripheral that will read a number of ADC in a row as fast as possible then use DMA to transfer each result. I assume the ADC.read_timed_multi uses this injected/DMA method??

Timing of min requirements for ADC conversions from the STM32F4 reference manual
12 bits: 3 + 12 = 15 ADCCLK cycles
10 bits: 3 + 10 = 13 ADCCLK cycles
8 bits: 3 + 8 = 11 ADCCLK cycles
6 bits: 3 + 6 = 9 ADCCLK cycles

Re: ADC simultaneous sampling?

Posted: Sun Jan 20, 2019 11:38 am
by pythoncoder
It doesn't use DMA and (like read_timed) is a blocking method. A nonblocking DMA equivalent would be great if someone has the skill to write it ;) I simply adapted the existing read_timed code.

Re: ADC simultaneous sampling?

Posted: Mon Jan 21, 2019 3:53 am
by OutoftheBOTS_
pythoncoder wrote:
Sun Jan 20, 2019 11:38 am
It doesn't use DMA and (like read_timed) is a blocking method. A nonblocking DMA equivalent would be great if someone has the skill to write it ;) I simply adapted the existing read_timed code.
I am so bogged down at work (my real job that pays the bills) and also with too many projects currently on the go I am unliely to take on a project like this anytime soon.

It would be an interesting project for me to take on though. I have already been using ADCs to read a touch screen, and have been using DMA to transfer data from 8bit camera interface DCMI to 16 bit screen interface FMC and have also been using timers for lots of things setting them up by setting up the registers in C on a STM32F407. I think the most difficult thing would be to work out how to make a good python interface.

Re: ADC simultaneous sampling?

Posted: Tue Jan 22, 2019 9:46 am
by CraigUK
pythoncoder wrote:
Sat Jan 19, 2019 12:12 pm
You might consider the ADC.read_timed_multi method. This was intended for exactly this purpose, it produces good phase measurements at frequencies over 50KHz. The sampling isn't simultaneous but relative to 50Hz it's extremely close.
Thanks for this, I don't know why I didn't find this myself in the docs!