TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; //时间基准配置基本结构体变量定义
TIM_OCInitTypeDef TIM_OCInitStructure; //输出结构体变量定义
TIM_BDTRInitTypeDef TIM_BDTRInitStructure; //死区刹车结构体变量定义
TIM_DeInit(TIM1);
TIM_TimeBaseStructure.TIM_Prescaler = 2; //TIM基本初始化预分频
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned2;//中央对齐模式2计数模式
TIM_TimeBaseStructure.TIM_Period = 1499; //PWM 16K 计数周期
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //72mhz 运与计算死区时间
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; //不重复计数
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //TIM输出通道初始化脉冲宽度调制模式2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable; ////0C1输出失能
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable; //
TIM_OCInitStructure.TIM_Pulse =1200; //待装入捕获比较寄存器的值 占空比的值
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //输出比较记性高
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; //两路互补输出
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; //死区后 输出状态 1
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; // 0
TIM_OC1Init(TIM1,&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse =1200; //占空比的值 CCR1
TIM_OC2Init(TIM1,&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse =1200;
TIM_OC3Init(TIM1,&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //TIM输出通道4初始化,用来触发AD注入采样
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable; // 不输出
TIM_OCInitStructure.TIM_Pulse =1495; //满值 占空比
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //输出极性高
TIM_OC4Init(TIM1,&TIM_OCInitStructure);
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable; //死区刹车初始化
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF;
TIM_BDTRInitStructure.TIM_DeadTime = 100; //死区时间设置
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable; //不使能刹车输入 如打开,开机无输出且状态紊乱????
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_Low; //刹车输入极性 1:刹车输入高电平有效 不使能刹车 就没做用了
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Disable; //自动输出 AOE
TIM_BDTRConfig(TIM1,&TIM_BDTRInitStructure);
TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable); //使能捕获比较寄存器预装载(通道1)
TIM_OC2PreloadConfig(TIM1,TIM_OCPreload_Enable); //使能捕获比较寄存器预装载(通道2)
TIM_OC3PreloadConfig(TIM1,TIM_OCPreload_Enable); //使能捕获比较寄存器预装载(通道3)
TIM_SelectInputTrigger(TIM1, TIM_TS_ITR2); // 这个我就不懂事什么意思了??输入触发源选择TIM3 0x0020 TIMx->SMCR 010:内部触发2(ITR2)
TIM_CtrlPWMOutputs(TIM1,ENABLE); //定时器1 输出使能 moe位
TIM_Cmd(TIM1,ENABLE); //打开定时器1
|