新手上路
- 积分
- 29
- 金钱
- 29
- 注册时间
- 2017-9-12
- 在线时间
- 5 小时
|
5金钱
这几天在做外部时钟2计数求脉冲频率,完整的按照参考手册上的例程试了一下,也找了网上的很多资料,但CNT一直不能计数,实在没有办法了,求各位大佬帮我看看到底哪儿出了问题
void TIM3_Counter_Init(u32 arr,u16 psc)
{
GPIO_DeInit(GPIOD);
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructuer;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); ///使能TIM3时钟
RCC_APB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
GPIO_InitStructuer.GPIO_Pin=GPIO_Pin_2;
GPIO_InitStructuer.GPIO_Mode=GPIO_Mode_AF;
//GPIO_InitStructuer.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructuer.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructuer.GPIO_PuPd =GPIO_PuPd_UP;
GPIO_Init(GPIOD,&GPIO_InitStructuer);
GPIO_PinAFConfig( GPIOD,GPIO_PinSource2,GPIO_AF_TIM3);
//timer1 NVIC 配置
// NVIC_InitStructure.NVIC_IRQChannel = TIM3_UP_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;//抢占优先级2
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;//子优先级2
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//IRQ通道使能
// NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器*/
TIM_DeInit(TIM3);
TIM_TimeBaseInitStructure.TIM_Period = arr;//自动重装载值
TIM_TimeBaseInitStructure.TIM_Prescaler=psc; //定时器分频
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;//向上计数模式
TIM_TimeBaseInitStructure.TIM_ClockDivision=0x0;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);//初始化TIM2
//TIM_SelectInputTrigger(TIM3,TIM_TS_ETRF);
TIM_ETRConfig(TIM3,TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_Inverted,0);
TIM_TIxExternalClockConfig(TIM3,TIM_TIxExternalCLK1Source_TI2, TIM_ICPolarity_Rising,0); //选择外部时钟
TIM_ETRClockMode2Config(TIM3, TIM_ExtTRGPSC_DIV2,TIM_ExtTRGPolarity_NonInverted, 0);//0次采样滤波 外部时钟模式3
TIM_ClearITPendingBit(TIM3,TIM_IT_Update); //清除中断标志位,避免第一次自动进入中断一次
//TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);
TIM_SetCounter(TIM3,0);//设置计数初值
TIM_Cmd(TIM3,ENABLE); //使能定时器1
|
-
TIM3寄存器
|