文档库

最新最全的文档下载
当前位置:文档库 > STM32中TIM1-CH1和TIM1-CH1N的区别

STM32中TIM1-CH1和TIM1-CH1N的区别

STM32中TIM1-CH1和TIM1-CH1N的区别

高级定时器控制电机,我使用互补PWM输出,,但是项目一种情况要同时输出高或低电平,才可以使得电机不因为惯性而立刻停。。

下面是配置的代码。。停止时TIM_SetCompare1(TIM1,1800); 就可以停。但是不是立刻停,因为惯性吧
void MotorTIM1_INIT(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure;

/* TIM1, GPIOA, GPIOB, GPIOE and AFIO clocks enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);

/* GPIO Configuration */
GPIO_Configuration();
TIM_DeInit(TIM1);

/* Time Base configuration */
TIM_TimeBaseStructure.TIM_Period = 3600-1; //设置在下一个更新事件装入活动的自动重装载寄存器周期的值 80K
TIM_TimeBaseStructure.TIM_Prescaler = 0; //设置用来作为TIMx时钟频率除数的预分频值 不分频
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //计数器模式 /* 向上计数模式 */
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //设置时钟分割:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; //设置 周期 计数值

TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);


/* Channel 1, 2,3 and 4 Configuration in PWM mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //选择定时器模式:TIM脉冲宽度调制模式2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //使能输出比较状态
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; //使能 互补 输出状态
TIM_OCInitStructure.TIM_Pulse = 1800; //设置待装入捕获比较寄存器的脉冲值 占空时间
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //输出极性:TIM输出比较极性低
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low; //互补 输出极性高
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; //MOE=0 设置 TIM1输出比较空闲状态
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; //MOE=0 重置 TIM1输出比较空闲状态
TIM_OC1Init(TIM1, &TIM_OCInitStructure); //设定好的参数 初始化TIM
TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);
//设置刹车特性 死区时间 锁电平 OSSI OSSR 状态 AOE(自动输出使能)
/* Automatic Output enable, Break, dead time and lock configuration*/
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable; //设置在运行模式下 非

免费下载Word文档免费下载: STM32中TIM1-CH1和TIM1-CH1N的区别

(共3页)