cancel
Showing results for 
Search instead for 
Did you mean: 

Timer16 PWM Not Working

Jo-Jo Smith
Associate II
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?

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on October 20, 2017 at 20:20

Check SB29

0690X000006049fQAA.jpg
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

4 REPLIES 4
Posted on October 20, 2017 at 10:16

You have to set TIM16_BDTR.MOE.

JW

Jo-Jo Smith
Associate II
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?

Jo-Jo Smith
Associate II
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.

Posted on October 20, 2017 at 20:20

Check SB29

0690X000006049fQAA.jpg
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..