你的浏览器版本过低,可能导致网站不能正常访问!为了你能正常使用网站功能,请使用这些浏览器。
举报
小蚂蚁快溜跑 发表于 2015-7-31 17:01 GPIOA的时钟使能了,TIM3的中断初始化是说中断优先级的初始化吗/
yanhaijian 发表于 2015-7-30 16:42 前面还要初始化相关引脚,使能相关外设时钟。我以为你应该知道的。
sting 发表于 2015-7-29 08:02 高级定时器都有正交编码功能,可参考F0xx或F1xx的库
yanhaijian 发表于 2015-7-29 08:14 /* 配置定时器处于编码器模式 */ TIM_DeInit(TIM3); TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
夏明smile 发表于 2015-7-29 11:49 正交编码实在厉害,误差基本为零了
小蚂蚁快溜跑 发表于 2015-7-29 14:31 ~非常感谢~中断服务程序需要做什么吗?
54chenjq 发表于 2015-7-29 21:00 我也在研究,哈哈
yanhaijian 发表于 2015-7-30 08:34 void TIM3_IRQHandler(void) { /* Clear the interrupt pending flag */
小蚂蚁快溜跑 发表于 2015-7-30 11:04 ENCODER_TIMER是tim3吗? Encoder是全局变量? 非常的感谢
yanhaijian 发表于 2015-7-30 11:57 你说的是对的。
小蚂蚁快溜跑 发表于 2015-7-30 12:35 读出来的数没有任何变化,一直是0
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_TIM4);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_TIM4);
GPIO_StructInit(&GPIO_InitStructure);
/* Configure PB.06,07 as encoder input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_DeInit(X_ENCODER_TIMER);
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
TIM_TimeBaseStructure.TIM_Period = 40000-1;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(X_ENCODER_TIMER, &TIM_TimeBaseStructure);
TIM_EncoderInterfaceConfig(X_ENCODER_TIMER, TIM_EncoderMode_TI12,TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
TIM_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_ICFilter = X_ICx_FILTER;
TIM_ICInit(X_ENCODER_TIMER, &TIM_ICInitStructure);
// Clear all pending interrupts
TIM_ClearFlag(X_ENCODER_TIMER, TIM_FLAG_Update);
TIM_ITConfig(X_ENCODER_TIMER, TIM_IT_Update, ENABLE);
X_ENCODER_TIMER->SR = 0xfffe;
TIM_Cmd(X_ENCODER_TIMER, ENABLE);
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);
}
这样吗?没有任何反应
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);
~~谢谢~~
~非常感谢~中断服务程序需要做什么吗?
看了些开发板的资料,好像没讲过这方面的,过来请教下大神
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是全局变量?
非常的感谢
你说的是对的。
读出来的数没有任何变化,一直是0
前面还要初始化相关引脚,使能相关外设时钟。我以为你应该知道的。