2017-10-19 05:46 PM
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?
Solved! Go to Solution.
2017-10-20 01:20 PM
Check SB29
2017-10-20 01:16 AM
You have to set TIM16_BDTR.MOE.
JW
2017-10-20 10:38 AM
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?
2017-10-20 11:40 AM
Thanks Clive. The open SB29 was the problem. I need to pay closer attention to the schematics.
2017-10-20 01:20 PM
Check SB29