Skip to main content
Associate II
September 28, 2026
Solved

Help: TIM CC can not triger ADC on STM32F429

  • September 28, 2026
  • 7 replies
  • 71 views

I configured ADC1 to be triggered by TIM2_CH2 and TIM2 compare channel 2 on STM32F429 with CubeMX, and enabled their interrupt, TIM2 CC2 ISR was run but ADC EOC ISR not run. I tested both by LED and by debug in CubeIDE, both results were the same. When debug in CubeIDE, after TIM2 CC2 ISR was run, STRT=0 and EOC=0 in ADC1 SR, which indicated that ADC1 was not triggered. However, if I configured ADC1 to be triggered by TIM2_TRGO and TIM2 trigger output from Update event, ADC1 was triggered.

My settings in CubeMX:

CubeMX and CubeIDE project files:

Best answer by waclawek.jan

If the ADC is set to “TIMx_CHx event”, it is *not* triggered by the Capture-Compare Event, but by the given channel’s output. You have to set it up exactly if you would want to generate signal on a pin - i.e. the given channel needs to be set as Output Compare in TIMx_CCMR, set to one of the modes which generates rising edges (PWM or Trigger) and enabled in TIMx_CCER (in Advanced timers you’d need to set TIMx_BDTR.MOE, too; TIM2 is not an Advanced timer, though). You don’t actually need to assign a pin to it in the GPIO AF matrix, but if you would, you should see the given signal at that pin.

This is a documentation problem which is discussed here for years.

If in doubts, read out and check/post relevant TIM and ADC registers content (and as I’ve said, you can see the signal working if you assign it a pin in GPIO).

JW

 

7 replies

Associate
September 28, 2026

Hi,

In your IOC, your TIM2 CH2 is in Toggle Output Compare mode with “No Output”, which means that it is not generating an event for the ADC interrupt to be triggered by. Try switching your TIM2 CH2 to PWM Generation CH2 as this generates a clear waveform with a rising edge, I would leave all the settings as standard for now and see whether that change works, 

harpAuthor
Associate II
September 29, 2026

I have tried  PWM Generation CH2,  it does not work. I alse have tried Output Compare CH2, it does not work, either. I think not output the signal on MCU pin is not the reason. The CC2IF flag in TIM2 SR is set, and the ISR is run, so the event should occur, no matter whether signal is output on MCU pin. The problem is why ADC1 not triggered.

Associate
September 29, 2026

I have just had a look through your main and spotted the following line.

  __HAL_TIM_ENABLE_IT(&htim2, TIM_IT_CC1);

CC1interrupt is enabled not CC2

 

try changing it to

HAL_TIM_OC_Start_IT(&htim2, TIM_CHANNEL_2);

 

harpAuthor
Associate II
September 30, 2026

I tried, it did not work. It’s weird that CC2IF in TIM2 SR is set, but STRT in ADC1 SR is not, which means ADC1 is not triggered. Either output signal on MCU pin, or no output, either compare mode, or pwm mode, ADC1 can not be tiggered by CC event. But ADC1 can be triggered by TRGO, no matter it is from Update event, or CC event.

waclawek.jan
waclawek.janBest answer
Super User
September 30, 2026

If the ADC is set to “TIMx_CHx event”, it is *not* triggered by the Capture-Compare Event, but by the given channel’s output. You have to set it up exactly if you would want to generate signal on a pin - i.e. the given channel needs to be set as Output Compare in TIMx_CCMR, set to one of the modes which generates rising edges (PWM or Trigger) and enabled in TIMx_CCER (in Advanced timers you’d need to set TIMx_BDTR.MOE, too; TIM2 is not an Advanced timer, though). You don’t actually need to assign a pin to it in the GPIO AF matrix, but if you would, you should see the given signal at that pin.

This is a documentation problem which is discussed here for years.

If in doubts, read out and check/post relevant TIM and ADC registers content (and as I’ve said, you can see the signal working if you assign it a pin in GPIO).

JW

 

harpAuthor
Associate II
September 30, 2026

Thanks for your reply.

harpAuthor
Associate II
September 30, 2026

Call HAL_TIM_OC_Start() instead of HAL_TIM_Base_Start_IT() to start TIM2, ADC1 will be triggered.