我想用通用定时器TIM3的通道3来测量一个外部方波的频率,却不知道应该怎么设置。 我的程序:
void TIM3_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_DeInit(TIM3);
TIM_TimeBaseStructure.TIM_Prescaler = 0x0; //时钟预分频得CK_INT时钟提供给计数器 APB2时钟/(n+1) n=1~65536
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseStructure.TIM_Period = 0xFFFF; //自动重装载值,值越小频率越大,值越大频率越小
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //时钟倍频因子,输出时钟供给死区发生器等
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure); //初始化
TIM_ICInitStructure.TIM_ICMode = TIM_ICMode_ICAP; //配置为输入捕获模式
TIM_ICInitStructure.TIM_Channel = TIM_Channel_3; //选择通道3
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //输入上升沿捕获
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //通道方向选择
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //每次检测到捕获输入就触发一次捕获
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_ICInit(TIM3,&TIM_ICInitStructure); //IC1通道初始化
/* Select the TIM2 Input Trigger: TI2FP2 【输入触发源选择】*/
TIM_SelectInputTrigger(TIM3, TIM_TS_TI3FP3); //参考TIM结构图选择滤波后的TI1输入作为触发源,触发下面程序的复位
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset); //复位模式-选中的触发输入(TRGI)的上升沿初始化计数器,并且产生一个更新线号
/* Enable the Master/Slave Mode */
TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);
//主从模式选择
TIM_Cmd(TIM3,ENABLE); //使能定时器3
//TIM_CtrlPWMOutputs(ENABLE); //使能PWM输出
}
可是触发源根本没有这一项啊,我要怎么实现用外部脉冲作为触发呢? |