新手上路
- 积分
- 48
- 金钱
- 48
- 注册时间
- 2019-5-9
- 在线时间
- 9 小时
|
做一个TIM2 3 4 5接四个编码器并输出脉冲数的程序,经本人测试,TIM3 4 5可以正常输出脉冲,但TIM2不行。TIM2的GPIO经过重映射映射到PA15 PB3,TIM2 GPIO配置void TIM2_Encoder_Init(u16 arr,u16 psc){
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);// 使能定时器时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE); //io口使能使用到的捕获编码器AB相接
GPIO_PinRemapConfig(GPIO_FullRemap_TIM2,ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);//完全禁用SWD及JTAG
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
|