2019-09-02 03:21 AM
SYS_RC TIMER_setup(void)
{
TIM_TimeBaseInitTypeDef TIMER_BaseInitStruct;
TIM_OCInitTypeDef TIMER_OCInitStruct = {0, };
GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);
TIMER_BaseInitStruct.TIM_Prescaler = 19;
TIMER_BaseInitStruct.TIM_Period = 10;
TIMER_BaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIMER_BaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIMER_BaseInitStruct.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &TIMER_BaseInitStruct);
TIM_Cmd(TIM4, ENABLE);
TIMER_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1;
TIMER_OCInitStruct.TIM_Pulse = 285;
TIMER_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
TIM_OC1Init(TIM4, &TIMER_OCInitStruct);
TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);
TIMER_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1;
TIMER_OCInitStruct.TIM_Pulse = 570;
TIMER_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
TIM_OC2Init(TIM4, &TIMER_OCInitStruct);
TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);
return (RC_OKAY);
}