EasyManua.ls Logo

STMicroelectronics STM8 - Page 89

STMicroelectronics STM8
126 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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); // where X represents channel ID (1, 2, 3 or 4)
Complementary outputs occur in pairs and so they are interdependent. That’s why there is no
separate function for outputs labelled N.

Related product manuals