完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
定时1中断由定时3的3路霍尔传感器异或触发,
求大神给我分析下这样配置出什么问题了? /******************************************************************************* * 函数名 :tiM_Configuration * 输出结果 :None * 函数描述 :设置TIM各通道 * 返回值 :None * 输出参数 :None *******************************************************************************/ void BLDC_TIM1Config(void) { 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;//中央对齐计数模式 TIM_TimeBaseStructure.TIM_Period = 1499; //PWM 16K TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //TIM输出通道初始化 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; TIM_OCInitStructure.TIM_Pulse =1400; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; TIM_OC1Init(TIM1,&TIM_OCInitStructure); TIM_OCInitStructure.TIM_Pulse =1400; TIM_OC2Init(TIM1,&TIM_OCInitStructure); TIM_OCInitStructure.TIM_Pulse =1400; TIM_OC3Init(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; TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable; 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 //TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_Trigger);//从模式选择 触发 TIM_CtrlPWMOutputs(TIM1,ENABLE); TIM_Cmd(TIM1,ENABLE); } /********************************************************************** * Description : None * Input : None * Output : None * Return : None * Attention : None **********************************************************************/ void BLDC_TIM3Config(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; //基本结构体变量定义 TIM_ICInitTypeDef TIM_ICInitStructure; //定义结构体变量 TIM_OCInitTypeDef TIM_OCInitStructure; //输出结构体变量定义 TIM_DeInit(TIM3); TIM_TimeBaseStructure.TIM_Prescaler = 71; //TIM基本初始化 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period =65535; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure); TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; //选择通道1 TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //输入上升沿捕获 TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_TRC; //配置通道为输入,并映射到哪里 TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //输入捕获预分频值 TIM_ICInitStructure.TIM_ICFilter = 10; //输入滤波器带宽设置 TIM_ICInit(TIM3, &TIM_ICInitStructure); //输入通道配置 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //TIM输出通道初始化 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse =1023; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC2Init(TIM3,&TIM_OCInitStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing; //TIM输出通道初始化 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable; TIM_OCInitStructure.TIM_Pulse =65535; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC4Init(TIM3,&TIM_OCInitStructure); TIM_SelectHallSensor(TIM3,ENABLE); //使能TIMx的霍尔传感器接口 TIM_SelectInputTrigger(TIM3, TIM_TS_TI1F_ED); //输入触发源选择 TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset); //从模式选择 TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);//主从模式选择 TIM_SelectOutputTrigger(TIM3, TIM_TRGOSource_OC2Ref); //选择输出触发模式(TRGO端) TIM_ITConfig(TIM3, TIM_IT_Trigger|TIM_IT_CC4, ENABLE); //开定时器中断 } |
|
相关推荐
4 个讨论
|
|
这个需要根据手册看一下TIME是否试着正确 参考一下代码
|
|
|
|
|
|
你现在的问题是什么呢?给出一段长代码让别人分析吗?要先定位问题才能解决问题
|
|
|
|
|
|
你正在撰写讨论
如果你是对讨论或其他讨论精选点评或询问,请使用“评论”功能。
2005 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1858 浏览 3 评论
4442 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
2007 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
2513 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-20 07:34 , Processed in 0.591017 second(s), Total 42, Slave 36 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号