新手上路
- 积分
- 42
- 金钱
- 42
- 注册时间
- 2013-7-23
- 在线时间
- 0 小时
|

楼主 |
发表于 2013-7-23 19:18:41
|
显示全部楼层
回复【2楼】正点原子:
我的程序如下,为什么中断都没有进入呢?是少了什么设置还是哪些设置错了?
---------------------------------
//?¨?±?÷2?¨??123????????????
TIM_ICInitTypeDef TIM2_ICInitStructure;
void TIM2_Cap_Init(u16 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); //????TIM2?±??
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //????GPIOA?±??
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //PA2????
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //PA2 ????
GPIO_Init(GPIOA, &GPIO_InitStructure);//??????GPIOA.2
GPIO_ResetBits(GPIOA,GPIO_Pin_0); //PA0 ????
TIM_TimeBaseStructure.TIM_Period = arr; //?è?¨?????÷×?????×°??
TIM_TimeBaseStructure.TIM_Prescaler =psc; //?¤·?????
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; // TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM?ò??????????
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); //??????TIM2
TIM2_ICInitStructure.TIM_Channel = TIM_Channel_1|TIM_Channel_2|TIM_Channel_3; // ?????????? IC3??????TI2??
TIM2_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //??????????
TIM2_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //??????TI2??
TIM2_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //????????·???????·???
TIM2_ICInitStructure.TIM_ICFilter = 0x00;//IC1F=0000 ?????¨
TIM_ICInit(TIM2, &TIM2_ICInitStructure);//??????TIM2?????????¨??3
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; //TIM2????
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //??????????2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //????????0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ?¨??????
NVIC_Init(&NVIC_InitStructure); //??????NVIC
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM2,TIM_SlaveMode_Reset); //????????
/* Enable the Master/Slave Mode */
TIM_SelectMasterSlaveMode(TIM2,TIM_MasterSlaveMode_Enable); //?÷??????????
TIM_ITConfig( TIM2,TIM_IT_Update|TIM_IT_CC1|TIM_IT_CC2|TIM_IT_CC3|TIM_IT_Trigger,ENABLE);//???í?ü??????????????
TIM_Cmd(TIM2,ENABLE ); //?????¨?±?÷2
}
u16 maikuan1,maikuan2,maikuan3;
//?¨?±?÷2????·??????ò
void TIM2_IRQHandler(void)
{
if((TIM_GetITStatus(TIM2,TIM_IT_Trigger) == SET))//????????
{
TIM_OC1PolarityConfig(TIM2,TIM_ICPolarity_Falling); //?è??????????????
TIM_OC2PolarityConfig(TIM2,TIM_ICPolarity_Falling); //?è??????????????
TIM_OC3PolarityConfig(TIM2,TIM_ICPolarity_Falling); //?è??????????????
}
if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET)//????3·??ú????????
{
maikuan1=TIM_GetCapture1(TIM2);
maikuan2=TIM_GetCapture2(TIM2);
maikuan3=TIM_GetCapture3(TIM2);
TIM_OC1PolarityConfig(TIM2,TIM_ICPolarity_Rising); //
TIM_OC2PolarityConfig(TIM2,TIM_ICPolarity_Rising); //
TIM_OC3PolarityConfig(TIM2,TIM_ICPolarity_Rising); //?è??????????????
}
TIM_ClearITPendingBit(TIM2, TIM_Channel_1|TIM_Channel_2|TIM_IT_CC3|TIM_IT_Update|TIM_IT_Trigger);
//????????±ê????
}
回复【2楼】正点原子:
一个定时器,总共才一个计数器啊.
你清零了,就是0了.
下降沿有效是你设置定时器输入捕获通道的时候就设置好了.不过过程中可以通过修改寄存器修改捕获沿.
--------------------------------- |
|