ADC simultaneous sampling?

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
User avatar
CraigUK
Posts: 12
Joined: Fri Jan 11, 2019 11:28 am

ADC simultaneous sampling?

Post by CraigUK » Thu Jan 17, 2019 9:12 pm

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

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: ADC simultaneous sampling?

Post by stijn » Fri Jan 18, 2019 8:58 am

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.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: ADC simultaneous sampling?

Post by dhylands » Fri Jan 18, 2019 6:53 pm

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.

User avatar
CraigUK
Posts: 12
Joined: Fri Jan 11, 2019 11:28 am

Re: ADC simultaneous sampling?

Post by CraigUK » Fri Jan 18, 2019 10:15 pm

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

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: ADC simultaneous sampling?

Post by dhylands » Fri Jan 18, 2019 11:13 pm

Yep - that looks correct

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ADC simultaneous sampling?

Post by pythoncoder » 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.
Peter Hinch
Index to my micropython libraries.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: ADC simultaneous sampling?

Post by OutoftheBOTS_ » Sat Jan 19, 2019 8:43 pm

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

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ADC simultaneous sampling?

Post by pythoncoder » 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.
Peter Hinch
Index to my micropython libraries.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: ADC simultaneous sampling?

Post by OutoftheBOTS_ » Mon Jan 21, 2019 3:53 am

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.

User avatar
CraigUK
Posts: 12
Joined: Fri Jan 11, 2019 11:28 am

Re: ADC simultaneous sampling?

Post by CraigUK » Tue Jan 22, 2019 9:46 am

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!

Post Reply