完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
高级定时器都有正交编码功能,可参考F0xx或F1xx的库
|
|
|
|
/* 配置定时器处于编码器模式 */
TIM_DeInit(TIM3); TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Prescaler = 0x0; TIM_TimeBaseStructure.TIM_Period = 65535 - 1; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI1,TIM_ICPolarity_Falling, TIM_ICPolarity_Falling); TIM_ICStructInit(&TIM_ICInitStructure); TIM_ICInitStructure.TIM_ICFilter = 15; TIM_ICInit(TIM3, &TIM_ICInitStructure); // 清除所有未决中断 TIM_ClearFlag(TIM3, TIM_FLAG_Update); TIM_ITConfig(TIM3, TIM_IT_Update, DISABLE); TIM3->SR = 0xfffe; TIM_Cmd(TIM3, ENABLE); |
|
|
|
正交编码实在厉害,误差基本为零了
|
|
|
|
|
|
|
|
fantasyo老时光 发表于 2018-10-3 09:14 ~非常感谢~中断服务程序需要做什么吗? |
|
|
|
|
|
|
|
我也只是听说,也没用过
|
|
|
|
我也在研究,哈哈
|
|
|
|
void TIM3_IRQHandler(void) { /* Clear the interrupt pending flag */ ENCODER_TIMER->SR = 0xfffe; if ( (ENCODER_TIMER->CR1 & TIM_CounterMode_Down) == TIM_CounterMode_Down) { Encoder--; } else { Encoder++; } } |
|
|
|
|
|
|
|
ENCODER_TIMER是tim3吗? Encoder是全局变量? 非常的感谢 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Tim3_init(void) { GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_ICInitTypeDef TIM_ICInitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); //TIM3 GPIO_PinAFConfig(GPIOA,GPIO_PinSource6,GPIO_AF_2); GPIO_PinAFConfig(GPIOA,GPIO_PinSource7,GPIO_AF_2); //TIM2 CH2,CH3,CH4 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType=GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL; GPIO_Init(GPIOA,&GPIO_InitStructure); TIM_DeInit(TIM3); TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Prescaler = 0x0; TIM_TimeBaseStructure.TIM_Period = 65535 - 1; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI1,TIM_ICPolarity_Falling, TIM_ICPolarity_Falling); TIM_ICStructInit(&TIM_ICInitStructure); TIM_ICInitStructure.TIM_ICFilter = 15; TIM_ICInit(TIM3, &TIM_ICInitStructure); TIM_ClearFlag(TIM3, TIM_FLAG_Update); TIM_ITConfig(TIM3, TIM_IT_Update, DISABLE); TIM3->SR = 0xfffe; TIM_Cmd(TIM3, ENABLE); } 这样吗?没有任何反应 |
|
|
|
|
|
|
|
|
|
|
|
GPIOA的时钟使能了,TIM3的中断初始化是说中断优先级的初始化吗/ |
|
|
|
查看手册就好了
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1107 浏览 0 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1055 浏览 2 评论
2159 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
1253 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1678 浏览 1 评论
浏览过的版块 |
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 10:19 , Processed in 0.926597 second(s), Total 80, Slave 73 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号