Showing results for 
Search instead for 
Did you mean: 

Trigger ADC conversion by Timer in PWM Input Capture Mode in Linux.

Associate II

Hello everyone,

I'm currently working with a STM32MP157c. 

This microcontroller includes multiple timer peripherals (General-purpose timers / Advanced-control timers) and also ADC peripherals. Therefore it is possible to trigger the ADC conversion by a timer. This is working without any problems using the timer as PWM Generator following the instructions in .

When the Timer is used in PWM Capture Mode, I haven't managed to trigger an ADC conversion.

My approach so far:

1) Adjusting Device Tree as follows (according to

and :

	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&adc_pins_mx>;
	pinctrl-1 = <&adc_sleep_pins_mx>;
	status = "okay";
	vdd-supply = <&vdd>;
	vdda-supply = <&vdd>;
	vref-supply = <&vrefbuf>;
		st,min-sample-time-nsecs = <5000>;
		st,adc-channels = <2 6>;
		status = "okay";
&timers1 {
	status = "okay";
	/* Enable DMA "ch1" for PWM input on TIM1_CH1 */
	dmas = <&dmamux1 11 0x400 0x5>;
	dma-names = "ch1";
	pwm {
		/* configure PWM input pins, e.g. TIM1_CH1 */
		pinctrl-0 = <&pwm1_in_pins_a>;
		pinctrl-1 = <&pwm1_in_sleep_pins_a>;
		pinctrl-names = "default", "sleep";
		/* enable PWM on TIM1 */
		status = "okay";

2) Configuration in sysfs (according to | Chapter 3.2)

### ADC Device (ADC2 CH2 & CH6) ###
cd /sys/bus/iio/devices/iio:device3
echo 1 > ./scan_elements/in_voltage2_en
echo 1 > ./scan_elements/in_voltage6_en
echo "tim1_ch1" > ./trigger/current_trigger
echo 1 > ./buffer/enable
### Timer Peripheral (TIM1 CH1 (& CH2)) ###
cd /sys/bus/platform/devices/44000000.timer:pwm/pwm/pwmchip2
echo 0 > export 

This is not working, no ADC conversion is triggered. However, when using a different Trigger (like tim6_trgo) it is working as expected.

I hope someone could answer some questions:

  • Is it generally possible to trigger an ADC conversion by a timer in PWM Capture Mode? Reference Manual is not absolutly clear about that at my understanding.
  • Is there an error in my current approach?
  • Is there a possible workaround to measure a PWM and triggering an ADC conversion using the same pin?

If you have any questions, I will of course be happy to answer all your questions!

Have a nice Day