Skip to main content
Jo-Jo Smith
Associate II
October 20, 2017
Solved

Timer16 PWM Not Working

  • October 20, 2017
  • 4 replies
  • 1329 views
Posted on October 20, 2017 at 02:46

I am using an STM32F072B-DISCO. I am trying to get a PWM on pin A6 using timer 16. The timer seems to be counting as expected, but there is no output on A6.

Here is my code:

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16, ENABLE);

    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;

    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;

    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOA, &GPIO_InitStruct);    

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_5);

 

    TIM_TimeBaseStructInit(&TIM_TimeBaseInitStruct);

    TIM_TimeBaseInitStruct.TIM_Period = 480;   //LED Intensity. Frequnecy (100kHz)

    TIM_TimeBaseInitStruct.TIM_Prescaler = 0;

    TIM_TimeBaseInit(TIM16, &TIM_TimeBaseInitStruct);

 

    TIM_OCStructInit(&TIM_OCInit);

    TIM_OCInit.TIM_OCMode = TIM_OCMode_PWM1;

    TIM_OCInit.TIM_OutputState = TIM_OutputState_Enable;

    TIM_OCInit.TIM_OCPolarity = TIM_OCPolarity_High;

    TIM_OCInit.TIM_Pulse = 48;

    TIM_OC1Init(TIM16, &TIM_OCInit);

    

    TIM_Cmd(TIM16, ENABLE);

Can someone tell me why A6 does not have an output?

    This topic has been closed for replies.
    Best answer by Tesla DeLorean
    Posted on October 20, 2017 at 20:20

    Check SB29

    0690X000006049fQAA.jpg

    4 replies

    waclawek.jan
    Super User
    October 20, 2017
    Posted on October 20, 2017 at 10:16

    You have to set TIM16_BDTR.MOE.

    JW

    Jo-Jo Smith
    Associate II
    October 20, 2017
    Posted on October 20, 2017 at 19:38

    Thanks for the reply, unfortunately, it didn't work.

    I added the following line before TIM_Cmd():

    TIM16->BDTR |= TIM_BDTR_MOE;

    I also tried adding the following line after TIM_Cmd():

     TIM_CtrlPWMOutputs(TIM16, ENABLE);

    Just like before, I can see the timer counting in the debugger, but there is no output on A6.

    I can't find any sample code for timer 16. I have tried using cube to generate LL PWM code, but nothing it generates puts out anything on any timer (not even the ones I already have working).

    Does anyone have any other ideas, or can someone provide an example?

    Tesla DeLorean
    Tesla DeLoreanBest answer
    Guru
    October 20, 2017
    Posted on October 20, 2017 at 20:20

    Check SB29

    0690X000006049fQAA.jpg
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Jo-Jo Smith
    Associate II
    October 20, 2017
    Posted on October 20, 2017 at 20:40

    Thanks Clive. The open SB29 was the problem. I need to pay closer attention to the schematics.