如题,做了个TIM3作为外部脉冲计数,选定通道二,代码如下:
void TIM3_External_Clock_CountingMode(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
// TIM_ICInitTypeDef TIM_ICInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
//TIM_DeInit(TIM3);
TIM_TimeBaseStructure.TIM_Period = 0x3AB6
TIM_TimeBaseStructure.TIM_Prescaler = 0x00;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit( TIM3, &TIM_TimeBaseStructure); // Time base configuration
TIM_TIxExternalClockConfig(TIM3,TIM_TIxExternalCLK1Source_TI2,TIM_ICPolarity_Rising,7);
TIM_SetCounter(TIM3, 0);
TIM_ClearFlag(TIM3,TIM_FLAG_Update);
TIM_Cmd(TIM3,ENABLE);
}
复制代码
明明TIM3 CH2对应的引脚是PA7,可是为什么开启的是GPIOB的时钟啊!!我曾经把它改成GPIOA时钟,结果不能计数了。 |