0tiM1脉冲数可以TIM1ITCount 获取 TIM3获取脉冲数TIM3->CN TIM3->只能获取一圈200个脉冲 很奇怪? 求大神解惑 void TIM1_Size_Encoder_Init(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_ICInitTypeDef TIM_ICInitStructure; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);//?????4??? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);//??PA???? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Prescaler = 0x0; // ???? TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;//??????:??? TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;////TIM???? TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;//TIM1高级定时器特有 TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); TIM_EncoderInteRFaceConfig(TIM1, TIM_EncoderMode_TI1, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising); TIM_ICStructInit(&TIM_ICInitStructure); TIM_ICInitStructure.TIM_ICFilter = 6; TIM_ICInit(TIM1, &TIM_ICInitStructure); NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); TIM_ClearFlag(TIM1, TIM_FLAG_Update);//??TIM?????? TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE); //TIM_ITConfig(TIM1, TIM_IT_Update | TIM_IT_Trigger, ENABLE); //Reset counter TIM_SetCounter(TIM1,0); TIM_Cmd(TIM1, ENABLE); } uint16_t TIM1ITCount=0;//脉冲数 void TIM1_UP_IRQHandler(void) { IF(TIM1->SR&0x0001)// { TIM1ITCount++; } TIM1->SR&=~(1<<0);// } void TIM3_Angle_Encode_Init(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_ICInitTypeDef TIM_ICInitStructure; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);//?????4??? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);//??PA???? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Prescaler = 0x0; // ???? TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;//??????:??? TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;////TIM???? TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI11, TIM_ICPolarity_Falling, TIM_ICPolarity_Rising); //TIM_ICPolarity_BothEdge ,TIM_ICPolarity_BothEdge); TIM_ICStructInit(&TIM_ICInitStructure); TIM_ICInitStructure.TIM_ICFilter = 6; TIM_ICInit(TIM3, &TIM_ICInitStructure); 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); TIM_ClearFlag(TIM3, TIM_FLAG_Update);//??TIM?????? TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE); //Reset counter TIM_SetCounter(TIM3,0); TIM_Cmd(TIM3, ENABLE); } TIM3->CN 脉冲数 |
共2条
1/1 1 跳转至页
[问答] stm32 TIM1 TIM3 编码器模式?
关键词: stm32 编码器 模式
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动——B站互动赢积分】活动开启啦! | |
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |