在线时间0 小时
UID199331
ST金币0
蝴蝶豆0
注册时间2010-7-12
新手上路
- 最后登录
- 1970-1-1
|
a0a.1 0b0c
TIM_TimeBaseStructure.TIM_Period = 0xFFFF; //周期0~FFFF
TIM_TimeBaseStructure.TIM_Prescaler = 5; //时钟分频
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //时钟分割
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//模式
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);//基本初始化
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
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 = 0x4;
//TIM_PWMIConfig(TIM2, &TIM_ICInitStructure);
TIM_ICInit(TIM2, &TIM_ICInitStructure); //初始化
/* Select the TIM2 Input Trigger: TI2FP2 */
TIM_SelectInputTrigger(TIM2, TIM_TS_TI2FP2); //选择时钟触发源
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset); //触发方式
/* Enable the Master/Slave Mode */
TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable); //启动定时器的被动触发
/* TIM enable counter */
TIM_Cmd(TIM2, ENABLE);
/* Enable the CC2 Interrupt Request */
TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);
/* TIM2 channel 2 pin (PA.01) configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel; //设置TIM2通道输入中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; /* Configure the NVIC Preemption Priority Bits[配置优先级组] */
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; /* Enable the TIM2 gloabal Interrupt [允许TIM2全局中断]*/
NVIC_Init(&NVIC_InitStructure);
TIM2_IRQHandler(void)
{
/* Clear TIM2 Capture compare interrupt pending bit */
TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
/* Get the Input Capture value */
IC2Value = TIM_GetCapture2(TIM2);
if (IC2Value != 0)
{
/* Duty cycle computation */
DutyCycle = (TIM_GetCapture1(TIM2) * 100) / IC2Value;
/* Frequency computation */
Frequency = 72000000 / IC2Value;
}
else
{
DutyCycle = 0;
Frequency = 0;
}
}
请大家帮忙分析我的程序为什么进不了捕获中断 |
|