新手上路
- 积分
- 22
- 金钱
- 22
- 注册时间
- 2018-10-15
- 在线时间
- 6 小时
|
5金钱
我自己画的板子,使用了3个编码器,定时器1和定时器8的正交解码模式可以用,为什么定时器5的的就不行呢,配置都是一模一样的。各位大佬求解答啊- void Speed_ENC(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE); //TIM1时钟使能
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE); //使能PORTE时钟
-
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE); //TIM5时钟使能
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); //使能PORTA时钟
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8,ENABLE); //TIM8时钟使能
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); //使能PORTC时钟
-
- /************定时器1引脚初始化******************/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_11; //PTE9 PTE11
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //浮空输入,其实默认就是浮空输入
-
- GPIO_Init(GPIOE,&GPIO_InitStructure);
- /***********************************************/
-
-
- /************定时器5引脚初始化******************/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1; //PTA0 PTA1
- GPIO_Init(GPIOA,&GPIO_InitStructure);
- /***********************************************/
-
-
- /***********定时器8引脚初始化*******************/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7; //PTC6 PTC7
- GPIO_Init(GPIOC,&GPIO_InitStructure);
- /***********************************************/
-
- GPIO_PinAFConfig(GPIOE,GPIO_PinSource9,GPIO_AF_TIM1); //复用位定时器1
- GPIO_PinAFConfig(GPIOE,GPIO_PinSource11,GPIO_AF_TIM1); //复用位定时器1
-
- GPIO_PinAFConfig(GPIOA,GPIO_PinSource0,GPIO_AF_TIM5); //复用位定时器5
- GPIO_PinAFConfig(GPIOA,GPIO_PinSource1,GPIO_AF_TIM5); //复用位定时器5
-
- GPIO_PinAFConfig(GPIOC,GPIO_PinSource6,GPIO_AF_TIM8); //复用位定时器8
- GPIO_PinAFConfig(GPIOC,GPIO_PinSource7,GPIO_AF_TIM8); //复用位定时器8
-
- TIM_TimeBaseStructure.TIM_Prescaler=0; //定时器分频
- TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
- TIM_TimeBaseStructure.TIM_Period=65535; //自动重装载值
-
- TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);
- TIM_TimeBaseInit(TIM5,&TIM_TimeBaseStructure);
- TIM_TimeBaseInit(TIM8,&TIM_TimeBaseStructure);
-
-
- TIM_EncoderInterfaceConfig(TIM1,TIM_EncoderMode_TI12,TIM_ICPolarity_Rising,TIM_ICPolarity_Rising);
- TIM_EncoderInterfaceConfig(TIM5,TIM_EncoderMode_TI12,TIM_ICPolarity_Rising,TIM_ICPolarity_Rising);
- TIM_EncoderInterfaceConfig(TIM8,TIM_EncoderMode_TI12,TIM_ICPolarity_Rising,TIM_ICPolarity_Rising);
- TIM_Cmd(TIM1, ENABLE); //使能定时器1
- TIM_Cmd(TIM5, ENABLE); //使能定时器5
- TIM_Cmd(TIM8, ENABLE); //使能定时器8
- }
- //***************TIM1计数寄存器赋值**************
- void TIM1_Encoder_Write(int data)
- {
- TIM1->CNT = data;
- }
- //*************读计数TIM1个数**************
- int TIM1_Encoder_Read(void)
- {
- s16 data;
- data=(s16)(TIM_GetCounter(TIM1));
- return (int)data;
- }
- //***************TIM5计数寄存器赋值**************
- void TIM5_Encoder_Write(int data)
- {
- TIM5->CNT = data;
- }
- //*************读计数TIM5个数**************
- int TIM5_Encoder_Read(void)
- {
- s16 data;
- data=(s16)(TIM_GetCounter(TIM5));
- return (int)data;
- }
- //***************TIM8计数寄存器赋值**************
- void TIM8_Encoder_Write(int data)
- {
- TIM8->CNT = data;
- }
- //*************读计数TIM8个数**************
- int TIM8_Encoder_Read(void)
- {
- s16 data;
- data=(s16)(TIM_GetCounter(TIM8));
- return (int)data;
- }
复制代码
|
最佳答案
查看完整内容[请看2#楼]
自己解决了,检查了一下午程序,最后发现焊核心板时PA0和PA1短接了... 这篇帖子就当作f407编码器正交解码模式的参考吧 对了 定时器5是32为定时器,我的重新装载数值写错了,应该给0xffffffff
|