为什么我的TIM2能输出而TIM1没有输出?
void GPIO_Configuration(void)
{
/* 定义 GPIO 初始化结构体 GPIO_InitStructure */
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void TIM_Configuration(void)
{
/* 定义 TIM_TimeBase 初始化结构体 TIM_TimeBaseStructure */
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* 定义 TIM_OCInit 初始化结构体 TIM_OCInitStructure */
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_TimeBaseStructure.TIM_Period = 60000;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM1 , &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_Pulse = 30000;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = 30000;
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = 30000;
TIM_OC3Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = 30000;
TIM_OC4Init(TIM1, &TIM_OCInitStructure);
/* 使能预装载寄存器 */
TIM_OC1PreloadConfig(TIM1 , TIM_OCPreload_Enable);
TIM_OC2PreloadConfig(TIM1 , TIM_OCPreload_Enable);
TIM_OC3PreloadConfig(TIM1 , TIM_OCPreload_Enable);
TIM_OC4PreloadConfig(TIM1 , TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM1, ENABLE);
/* 启动 TIM 计数 */
TIM_Cmd(TIM1 , ENABLE);
TIM_TimeBaseStructure.TIM_Period = 60000;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2 , &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_Pulse = 30000;
TIM_OC1Init(TIM2, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = 30000;
TIM_OC2Init(TIM2, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = 30000;
TIM_OC3Init(TIM2, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = 30000;
TIM_OC4Init(TIM2, &TIM_OCInitStructure);
/* 使能预装载寄存器 */
TIM_OC1PreloadConfig(TIM2 , TIM_OCPreload_Enable);
TIM_OC2PreloadConfig(TIM2 , TIM_OCPreload_Enable);
TIM_OC3PreloadConfig(TIM2 , TIM_OCPreload_Enable);
TIM_OC4PreloadConfig(TIM2 , TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM2, ENABLE);
/* 启动 TIM 计数 */
TIM_Cmd(TIM2 , ENABLE);
} |