Likewise, there are some additional info we must feed when configuring the OC channels. We need to
set info about complementary channels even if we don't need them. We can additionally set the
default idle states of PWMs apart from polarities.
void TIM1_setup(void)
{
TIM1_DeInit();
TIM1_TimeBaseInit(16, TIM1_COUNTERMODE_UP, 1000, 1);
TIM1_OC1Init(TIM1_OCMODE_PWM1,
TIM1_OUTPUTSTATE_ENABLE,
TIM1_OUTPUTNSTATE_ENABLE,
1000,
TIM1_OCPOLARITY_LOW,
TIM1_OCNPOLARITY_LOW,
TIM1_OCIDLESTATE_RESET,
TIM1_OCNIDLESTATE_RESET);
TIM1_CtrlPWMOutputs(ENABLE);
TIM1_Cmd(ENABLE);
}
To change the duty cycle of a channel, we need to call this function:
TIM1_SetCompareX(duty_cycle);
Complementary outputs occur in pairs and so they are interdependent. That's why there is no
separate function for outputs labelled N.
// where X represents channel ID (1, 2, 3 or 4)
Need help?
Do you have a question about the STM8 and is the answer not in the manual?
Questions and answers