cancel
Showing results for 
Search instead for 
Did you mean: 

TIM1 ch1 as pwm, ch2 as cc to trigger adc caputre

aaron.gao
Associate

On STM32F105 chip, i need to output a pwm, then adc caputure the voltage on pwm high stable level.

So i try to set tim1 ch1 to pwm out, and then set tim1 ch2 as compare output wih no pwm to trigger adc capture with DMA. (CC2<CC1)

Eventrually, i cannot achieve this.

on cubeMX platform.

  • I use tim1 ch1 as pwm output, and use tim3 ch1 to trigger adc, set tim3 "Trigger Event Selection" as "Update Event", and set adc "External Trigger Conversions Source" as "Timer3 Trigger Out event", then i can step into adc interrupt.
  • When i use tim1 ch1 as pwm output, and use tim1 ch2 to trigger adc, set tim1 "Trigger Event Selection" as "Output Compare(OC2REF)", and set adc "External Trigger Conversions Source" as "Timer1 capture compare 2 event", then i cannot step into adc interrupt

Both of above, i can step into CC interrupt, and i put gpio set in CC interrupt, the behaviour is right.

What am i wrong, I so am so confused on this, can someone help. I have been for stuck for several days.

Thanks a lot.

1 REPLY 1

> set tim1 "Trigger Event Selection" as "Output Compare(OC2REF)",

You don't need to do that, as ADC is not set to "TIM1 trigger out event" (there may be no such setting at all, I don't check)

> and set adc "External Trigger Conversions Source" as "Timer1 capture compare 2 event", then i cannot step into adc interrupt

You need to enable the TIM1 CH2 PWM exactly as if you would want the PWM output, i.e. set up one of the PWM modes in TIM1_CCMR1, enable it in TIM1_CCER, and probably also set TIM1_BDTR.MOE. The only thing you don't need to do is actually set the given pin to AF mode. You may want to start with actually outputting the PWM to the pin, to see that the PWM on CH2 is working as you intended.

I don't use the 'F1 nor Cube/CubeMX.

JW

PS. Please change your usename to a normal nick.