void PWM_Init(void)
{
GPIO_Init(GPIOA, GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST);//TIM2_CH3
GPIO_Init(GPIOC, GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST);//TIM1_CH3
GPIO_Init(GPIOC, GPIO_PIN_4, GPIO_MODE_OUT_PP_LOW_FAST);//TIM1_CH4
GPIO_Init(GPIOC, GPIO_PIN_7, GPIO_MODE_OUT_PP_LOW_FAST);//TIM1_CH2
GPIO_Init(GPIOD, GPIO_PIN_3, GPIO_MODE_OUT_PP_LOW_FAST);//TIM2_CH2
GPIO_Init(GPIOD, GPIO_PIN_4, GPIO_MODE_OUT_PP_LOW_FAST);//TIM2_CH1
TIM2_DeInit();
TIM2_TimeBaseInit(TIM2_PRESCALER_8, 4999);
TIM2_OC1Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE, 0x0000, TIM2_OCPOLARITY_HIGH);
TIM2_OC2Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE, 0x0000, TIM2_OCPOLARITY_HIGH);
TIM2_OC3Init(TIM2_OCMODE_PWM1, TIM2_OUTPUTSTATE_ENABLE, 0x0000, TIM2_OCPOLARITY_HIGH);
TIM2_OC1PreloadConfig(ENABLE);
TIM2_OC2PreloadConfig(ENABLE);
TIM2_OC3PreloadConfig(ENABLE);
TIM2_Cmd(ENABLE);
TIM1_DeInit();
TIM1_TimeBaseInit(8, TIM1_COUNTERMODE_UP, 4999, 0x00);
TIM1_OC2Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, 0x0000, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET);
TIM1_OC3Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, 0x0000, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_RESET);
TIM1_OC4Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE, 0x0000, TIM1_OCPOLARITY_HIGH, TIM1_OCIDLESTATE_SET);
TIM1_OC2PreloadConfig(ENABLE);
TIM1_OC3PreloadConfig(ENABLE);
TIM1_OC4PreloadConfig(ENABLE);
TIM1_Cmd(ENABLE);
TIM1_CtrlPWMOutputs(ENABLE);
}
void main(void)
{
Sys_Clock_Init();
PWM_Init();
/* Infinite loop */
while (1)
{
TIM2_SetCompare1(4000);
TIM2_SetCompare2(2499);
TIM2_SetCompare3(1200);
TIM1_SetCompare2(2499);
TIM1_SetCompare3(3800);
TIM1_SetCompare4(2499);
}
}
|