打印

菜鸟请教STM32TIM1和TIM2PWM输出配置有什么不同?

[复制链接]
1783|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
csuzzp|  楼主 | 2012-11-20 21:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
为什么我的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);
}
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

28

帖子

0

粉丝