Skip to main content
Graduate
May 7, 2024
Solved

How do I generate an Output Compare square wave on TIM8_CH2N using STM32CubeIDE?

  • May 7, 2024
  • 2 replies
  • 1167 views

I'm working with the STM32F407G-DISC1 development board and I would like to generate a square wave on PB14 (TIM8_CH2N). I'm able to successfully toggle PB14 using "bit-banging" and I'm able to successfully generate square waves PC6 (TIM8_CH1) and PC8 (TIM8_CH3). However, no matter what I do, I can't make TIM8 output anything on PB14 (TIM8_CH2N). Does anybody know what I'm doing wrong (please see attached screenshot)? Please note that I can't use any other timer/pin instead.

    This topic has been closed for replies.
    Best answer by arnold_w

    TIMx_BDT->MOE is being set in HAL_TIM_OC_Start. I solved it like this instead:
    HAL_TIM_OC_Start(&htim8, TIM_CHANNEL_2);
    TIM8->CCER |= TIM_CCER_CC2NE;

    2 replies

    ST Employee
    May 7, 2024

    Hello @arnold_w

    Try enabling the main output of the timer, which is necessary for advanced-control timers like TIM8

    using __HAL_TIM_MOE_ENABLE(&htim8) or by registers BDTR.MOE 

    arnold_wAuthorAnswer
    Graduate
    May 8, 2024

    TIMx_BDT->MOE is being set in HAL_TIM_OC_Start. I solved it like this instead:
    HAL_TIM_OC_Start(&htim8, TIM_CHANNEL_2);
    TIM8->CCER |= TIM_CCER_CC2NE;