金牌会员
- 积分
- 1826
- 金钱
- 1826
- 注册时间
- 2015-12-18
- 在线时间
- 209 小时
|
1金钱
void TIM1_PWM_init()
{
GPIO_Init(GPIOC, GPIO_PIN_3, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(GPIOC, GPIO_PIN_4, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(GPIOC, GPIO_PIN_6, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(GPIOC, GPIO_PIN_7, GPIO_MODE_OUT_PP_HIGH_FAST);
CLK->PCKENR1 |=0X80; //使能TIME1时钟源
TIM1->EGR |=0X01; //初始化计数器,产生更新事件
TIM1->RCR =0X00; //关闭计数器
//=======================================================开启时钟、关闭计数器
TIM1->SMCR =0X00;
TIM1->ETR =0X00; //使用内部Fmaster时钟,16M
TIM1->PSCRH =0X00;
TIM1->PSCRL =0X02; //2分频
TIM1->ARRH =0x00;
TIM1->ARRL =Cycle_50us; //重装值 -->50us/次
TIM1->RCR =0X00; //重复计数0
TIM1->CR1 =0X00; //向上计数
//=======================================================时基单元
//通道1 CH1 输出 CH1N禁止输出
TIM1->CCMR1 =0x70; //PWM模式2,CC1通道配置为输出
TIM1->CCR1H =0X00;
TIM1->CCR1L =Cycle_50us>>1; //占空比
TIM1->CCER1 |=0X03; //CC1配置为输出,低电平有效
//通道2
TIM1->CCMR2 =0X70;
TIM1->CCR2H =0X00;
TIM1->CCR2L =Cycle_50us>>1;
TIM1->CCER1 |=(1<<5)|(1<<4);
//通道3
TIM1->CCMR3 =0X70;
TIM1->CCR3H =0X00;
TIM1->CCR3L =Cycle_50us>>1;
TIM1->CCER2 |=(1<<1)|(1<<0);
//通道4
TIM1->CCMR4 =0X70;
TIM1->CCR4H =0X00;
TIM1->CCR4L =Cycle_50us>>1;
TIM1->CCER2 |=(1<<5)|(1<<4);
TIM1->BKR =0X80; //静止刹车
TIM1->CR1 |=0X01; //使能时钟源
}
|
|