完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
tiM1脉冲数可以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 脉冲数 |
|
相关推荐
4个回答
|
|
坐等大神解答
|
|
|
|
说个问题都说不明白
|
|
|
|
没有说明吗7没有解释清楚的话
|
|
|
|
问题已经解决 编码器模式需要连接两个A B 两根线
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
878 浏览 0 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
936 浏览 2 评论
2044 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
1145 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1568 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 01:43 , Processed in 0.594835 second(s), Total 48, Slave 41 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号