External trigger to ADC

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
bittware
Posts: 45
Joined: Mon Aug 18, 2014 3:27 am

External trigger to ADC

Post by bittware » Fri Jun 10, 2022 10:27 am

Hello
Is it possible to use an external trigger source to initiate ADC conversion on pyboard?
It seems that micropython only supports the internal timer as the ADC conversion clock. Is it correct?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: External trigger to ADC

Post by Roberthh » Fri Jun 10, 2022 10:35 am

You can use Pin.irq and call ADC in the handler. When using a hard irq, the latency is constant with Pyboard and just a few.us.

bittware
Posts: 45
Joined: Mon Aug 18, 2014 3:27 am

Re: External trigger to ADC

Post by bittware » Fri Jun 10, 2022 10:48 am

Roberthh wrote:
Fri Jun 10, 2022 10:35 am
You can use Pin.irq and call ADC in the handler. When using a hard irq, the latency is constant with Pyboard and just a few.us.
So the sampling rate still relies on the internal timer? Can the ADC conversion be done on a per trigger basis? I need to sample and hold just once following the trigger event immdediately.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: External trigger to ADC

Post by Roberthh » Fri Jun 10, 2022 11:05 am

Pin.irq is triggered by an external event. There is no internal timer, just some constant internal handling time. Whether that delay is acceptable for you, depends on your needs. The pin-irq latency is a few µs, until the handler starts executing. So I assume that you wil end up with a total latency trigger to ADC start of about 10 µs.

bittware
Posts: 45
Joined: Mon Aug 18, 2014 3:27 am

Re: External trigger to ADC

Post by bittware » Fri Jun 10, 2022 11:42 am

Roberthh wrote:
Fri Jun 10, 2022 11:05 am
Pin.irq is triggered by an external event. There is no internal timer, just some constant internal handling time. Whether that delay is acceptable for you, depends on your needs. The pin-irq latency is a few µs, until the handler starts executing. So I assume that you wil end up with a total latency trigger to ADC start of about 10 µs.
But I referred to the STM32F405 datasheet ADC characteristics section (i.e. Table 67), the typical condition is written as fADC = 30MHz.
So how comes the fADC? I understand Pin.irq initiates the ADC conversion, but there must be a separate sampling clock source out there?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: External trigger to ADC

Post by Roberthh » Fri Jun 10, 2022 12:21 pm

The sampling clock is internal and configured by the firmware. I would have to dig into the sources myself to tell, at which frequency. But let's say, it's 15 MHz. The conversion of of a 12 Bit ADC value takes at least 12 cycles of this clock, so the whole conversion takes about 1 µs, once started.

bittware
Posts: 45
Joined: Mon Aug 18, 2014 3:27 am

Re: External trigger to ADC

Post by bittware » Fri Jun 10, 2022 1:01 pm

Roberthh wrote:
Fri Jun 10, 2022 12:21 pm
The sampling clock is internal and configured by the firmware. I would have to dig into the sources myself to tell, at which frequency. But let's say, it's 15 MHz. The conversion of of a 12 Bit ADC value takes at least 12 cycles of this clock, so the whole conversion takes about 1 µs, once started.
I assume it may take only ONE clock cycle to finish one ADC conversion considering it's an internal ADC with a parallel bus connection to the MCU core. My original concern was "can I use an external conversion enable signal to initiate such one cycle ADC conversion?"
Or in AN3116 Application note STM32™’s ADC modes and their applications, it's called injected conversion mode.
https://www.st.com/resource/en/applicat ... ronics.pdf

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: External trigger to ADC

Post by Roberthh » Fri Jun 10, 2022 1:09 pm

The reference manual of the stm32F405, chapter 13.7, states: a 12 Bit ADC conversion takes 15 clock cycles.

bittware
Posts: 45
Joined: Mon Aug 18, 2014 3:27 am

Re: External trigger to ADC

Post by bittware » Fri Jun 10, 2022 1:29 pm

Roberthh wrote:
Fri Jun 10, 2022 1:09 pm
The reference manual of the stm32F405, chapter 13.7, states: a 12 Bit ADC conversion takes 15 clock cycles.
Wow, this is critical information. Thanks for the correction.
By referring to the section 13.6 Conversion on external trigger and trigger polarity of the manual, I found there is a possible route to implement the injected conversion. GPIO -> EXTI line11 or EXTI line15 -> ADC
But I still don't know if micropython supports the injected conversion mode and how to hook up GPIO with the EXTI line?

Post Reply