求一份编码器双路脉冲鉴相程序

2019-08-14 00:30发布

求一份编码器双路脉冲鉴相程序     正准备2013年电赛控制题    求大神伸手
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
5条回答
YUSHI
1楼-- · 2019-08-14 06:07
[mw_shl_code=c,true]void ENCODER_INIT(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_ICInitTypeDef TIM_ICInitStructure; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* TIM1 clock source enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); /* Enable GPIOA, clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_StructInit(&GPIO_InitStructure); /* Configure PA.08,09 as encoder input */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Enable the TIM1 Update Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Timer configuration in Encoder mode */ TIM_DeInit(ENCODER_TIMER); TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Prescaler = 0x0; // No prescaling TIM_TimeBaseStructure.TIM_Period = 0xFFFF; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(ENCODER_TIMER, &TIM_TimeBaseStructure); TIM_EncoderInterfaceConfig(ENCODER_TIMER, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising); TIM_ICStructInit(&TIM_ICInitStructure); TIM_ICInitStructure.TIM_ICFilter = ICx_FILTER; TIM_ICInit(ENCODER_TIMER, &TIM_ICInitStructure); //TIM_ICInitStructure.TIM_Channel = TIM_Channel_2 | TIM_Channel_1; //TIM_ICInit(ENCODER_TIMER, &TIM_ICInitStructure); // Clear all pending interrupts TIM_ClearFlag(ENCODER_TIMER, TIM_FLAG_Update); TIM_ITConfig(ENCODER_TIMER, TIM_IT_Update, ENABLE); //Reset counter TIM2->CNT = 0; TIM_Cmd(ENCODER_TIMER, ENABLE); } [/mw_shl_code]
菜鸟哦
2楼-- · 2019-08-14 10:37
 精彩回答 2  元偷偷看……
菜鸟哦
3楼-- · 2019-08-14 12:23
回复【2楼】YUSHI:
---------------------------------
大神   我试了一下   没有弄出来    A8和PA9是TIM1的通道    怎么用的是 TIM2->CNT  能加我好友吗1792681370   我想请教一下
菜鸟哦
4楼-- · 2019-08-14 17:57
回复【2楼】YUSHI:
---------------------------------
大神   看到了请回复
YUSHI
5楼-- · 2019-08-14 22:21
菜鸟哦 发表于 2015-7-21 22:39
回复【2楼】YUSHI:
---------------------------------
大神   我试了一下  &nbs ...

#define ENCODER_TIMER         TIM1          // Encoder unit connected to TIM1
TIM_SetCounter(ENCODER_TIMER,32767);
那行是错的也没什么意义,我main()里边并没从零开始计数,我算的是偏移量,但初始化没问题,时隔多年,祝你好运

一周热门 更多>