STM32:为什么连续几次烧写同样程序电机行为不同
用定时器编码器模式计数,计数到一定值后电机使停止转动,但三次烧写后电机转动的周数不一样。已经通过示波器确定码盘正常,左右电机码盘配置代码如下,有大牛看出有什么问题么???void Encoder_L_Configration(void)
{
//u16 CCR1_Val = 2500;
//u16 CCR2_Val = 1000;
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDefTIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//TIM_OCInitTypeDefTIM_OCInitStructure;
/*----------------------------------------------------------------*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
/* Configure PA.06,07 as encoder input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/*------------------ NVIC_InitTypeDef NVIC_InitStructure;*/
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/*----------------------------------------------*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_DeInit(TIM3);
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period =0xffff;
TIM_TimeBaseStructure.TIM_Prescaler =0;
TIM_TimeBaseStructure.TIM_ClockDivision =TIM_CKD_DIV1 ;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
//TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned1;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/*-----------------------------------------------------------------*/
//±àÂëÅäÖÃ
TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI1,
TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
TIM_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_ICFilter = 6;
TIM_ICInit(TIM3, &TIM_ICInitStructure);
//TIM_ARRPreloadConfig(TIM3, ENABLE);
// Clear all pending interrupts
TIM_ClearFlag(TIM3, TIM_FLAG_Update);
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
//Reset counter
TIM3->CNT =0;
TIM_Cmd(TIM3, ENABLE);
}
呜呜~~没人么~使用码盘可以只接一相到定时器的CH1或CH2,另一项悬空么{:mad:}好难吖 Touwei 发表于 2013-10-26 16:53 static/image/common/back.gif
呜呜~~没人么~使用码盘可以只接一相到定时器的CH1或CH2,另一项悬空么好难吖 ...
我没实际弄过 但是看过些资料 接 u一相 应该只能获得一个方向的速度信息 虫虫好 发表于 2013-10-26 18:20 static/image/common/back.gif
我没实际弄过 但是看过些资料 接 u一相 应该只能获得一个方向的速度信息...
谢谢~这个还没搞清楚>< 用JLink单步调试发现用来计数的TIM的CNT寄存器只有1和FFFF两个值,又困惑了一晚上
页:
[1]