Page 1 of 1

External trigger to ADC

Posted: Fri Jun 10, 2022 10:27 am
by bittware
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?

Re: External trigger to ADC

Posted: Fri Jun 10, 2022 10:35 am
by Roberthh
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.

Re: External trigger to ADC

Posted: Fri Jun 10, 2022 10:48 am
by bittware
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.

Re: External trigger to ADC

Posted: Fri Jun 10, 2022 11:05 am
by Roberthh
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.

Re: External trigger to ADC

Posted: Fri Jun 10, 2022 11:42 am
by bittware
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?

Re: External trigger to ADC

Posted: Fri Jun 10, 2022 12:21 pm
by Roberthh
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.

Re: External trigger to ADC

Posted: Fri Jun 10, 2022 1:01 pm
by bittware
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

Re: External trigger to ADC

Posted: Fri Jun 10, 2022 1:09 pm
by Roberthh
The reference manual of the stm32F405, chapter 13.7, states: a 12 Bit ADC conversion takes 15 clock cycles.

Re: External trigger to ADC

Posted: Fri Jun 10, 2022 1:29 pm
by bittware
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?