AnsweredAssumed Answered

STM32F072 Alternate PWM

Question asked by spinello.daniele on Jan 28, 2015
Latest reply on Jan 29, 2015 by spinello.daniele
Hi guys.
I'm having a little issue about using 6 pwm on different timers, on my STM32F072.
Application is:
a board with an adjustable sensor. The adjust phase works with a generation of pwm, changing the duty cycle until a signal on another port change.

This is the actual working code, with the PWM on timer 17


/* Installing pwm and definitions */
#define HW_TIM_PWM_OUT_DIS        TIM_CtrlPWMOutputs(TIM17, DISABLE)
#define HW_TIM_PWM_DIS            TIM_Cmd(TIM17, DISABLE)
#define HW_TIM_PWM_ENA            TIM_Cmd(TIM17, ENABLE)
#define HW_TIM_PWM_CLR            TIM_SetCounter(TIM17, 0)

#define HW_TIM_PWM_INS(duty) \
{ \
TIM_TimeBaseInitTypeDef loc; \
    TIM_OCInitTypeDef oloc; \
                                                        /* TIM clock enable */ \
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM17, ENABLE); \
                                                        /* Time base configuration */ \
    loc.TIM_Period = 480; \
    loc.TIM_Prescaler = (word) (SystemCoreClock  / 4800000) - 1; \
    loc.TIM_ClockDivision = TIM_CKD_DIV1; \
    loc.TIM_CounterMode = TIM_CounterMode_Up; \
    TIM_TimeBaseInit(TIM17, &loc); \
                                                        /* Output compare PWM 1 */ \
    TIM_OCStructInit(&oloc); \
    oloc.TIM_OCMode = TIM_OCMode_PWM1; \
    oloc.TIM_Pulse = ((dword)480 * (dword)duty + 128UL) / 256UL; \
    oloc.TIM_OutputState = TIM_OutputState_Enable; \
    TIM_OC1Init(TIM17, &oloc); \
    TIM_CtrlPWMOutputs(TIM17, ENABLE); \


On calibration phase, this is what I actually do (with success), on a cycle where "duty_n" changes as described before

HW_TIM_PWM_INS(duty_n);
HW_TIM_PWM_CLR;
HW_TIM_PWM_ENA;


Hope you understand.
Now, I have to do the exact same thing for another pwm, tied on timer 2.
My issue is: since there's no way to set TIM2 on function
TIM_CtrlPWMOutputs
what can I do as "workaround"?

Ps. I found the TIM_CCxCmd routine on library, but it's not working. Damn. Help me!

Outcomes