cancel
Showing results for 
Search instead for 
Did you mean: 

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

MBrei.4
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 https://wiki.st.com/stm32mpu/wiki/How_to_use_the_IIO_user_space_interface#How_to_set_up_a_TIM_or_LPTIM_trigger_using_the_sysfs_interface .

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 https://wiki.st.com/stm32mpu/wiki/TIM_device_tree_configuration

and https://wiki.st.com/stm32mpu/wiki/ADC_device_tree_configuration) :

[...]
&adc{
	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>;
 
	adc2:adc@100{
		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 https://wiki.st.com/stm32mpu/wiki/How_to_use_the_IIO_user_space_interface#How_to_set_up_a_TIM_or_LPTIM_trigger_using_the_sysfs_interface | 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

Malte

0 REPLIES 0