打印
[STM32F1]

tim1输入捕获设置问题

[复制链接]
744|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
sackfc|  楼主 | 2016-1-13 20:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我想用pe9作为tim1  通道1,设置如下,现在的问题是不能进入捕获中断。tim1 定时器中断能进入。

void TIM1_Int_Init(u16 arr,u16 psc)
{
    TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
        NVIC_InitTypeDef NVIC_InitStructure;

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); //ʱÖÓʹÄÜ
       
        //¶¨Ê±Æ÷TIM1³õʼ»¯
        TIM_TimeBaseStructure.TIM_Period = arr; //ÉèÖÃÔÚÏÂÒ»¸ö¸üÐÂʼþ×°Èë»î¶¯µÄ×Ô¶¯ÖØ×°ÔؼĴæÆ÷ÖÜÆÚµÄÖµ       
        TIM_TimeBaseStructure.TIM_Prescaler =psc; //ÉèÖÃÓÃÀ´×÷ΪTIMxʱÖÓƵÂʳýÊýµÄÔ¤·ÖƵֵ
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //ÉèÖÃʱÖÓ·Ö¸î:TDTS = Tck_tim
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //TIMÏòÉϼÆÊýģʽ
        TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); //¸ù¾ÝÖ¸¶¨µÄ²ÎÊý³õʼ»¯TIMxµÄʱ¼ä»ùÊýµ¥Î»

        TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE ); //ʹÄÜÖ¸¶¨µÄTIM3ÖжÏ,ÔÊÐí¸üÐÂÖжÏ

        //ÖжÏÓÅÏȼ¶NVICÉèÖÃ
        NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;  //TIM1ÖжÏ
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;  //ÏÈÕ¼ÓÅÏȼ¶0¼¶
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5;  //´ÓÓÅÏȼ¶3¼¶
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨµÀ±»Ê¹ÄÜ
        NVIC_Init(&NVIC_InitStructure);  //³õʼ»¯NVIC¼Ä´æÆ÷

        TIM_Cmd(TIM1, ENABLE);  //ʹÄÜTIMx                                         
}





TIM_ICInitTypeDef  TIM_ICInitStructure;

void TIM1_Cap_Init(u16 arr,u16 psc)
{         
        GPIO_InitTypeDef GPIO_InitStructure;
        TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
           NVIC_InitTypeDef NVIC_InitStructure;

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE|RCC_APB2Periph_AFIO, ENABLE);        //ʹÄÜGPIOEʱÖÓ

        //
        GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_9;  //PE9 Çå³ý֮ǰÉèÖà 
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; //PE9 ÊäÈë  
       
        GPIO_Init(GPIOE, &GPIO_InitStructure);
        GPIO_ResetBits(GPIOE,GPIO_Pin_9);                                                 //PE9 ÏÂÀ­
       
        GPIO_PinRemapConfig(GPIO_FullRemap_TIM1, ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period = arr; //ÉèÖÃÔÚÏÂÒ»¸ö¸üÐÂʼþ×°Èë»î¶¯µÄ×Ô¶¯ÖØ×°ÔؼĴæÆ÷ÖÜÆÚµÄÖµ       
        TIM_TimeBaseStructure.TIM_Prescaler =psc; //ÉèÖÃÓÃÀ´×÷ΪTIMxʱÖÓƵÂʳýÊýµÄÔ¤·ÖƵֵ
        TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //ÉèÖÃʱÖÓ·Ö¸î:TDTS = Tck_tim
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //TIMÏòÉϼÆÊýģʽ
        TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); //¸ù¾ÝÖ¸¶¨µÄ²ÎÊý³õʼ»¯TIMxµÄʱ¼ä»ùÊýµ¥Î»
       
        //³õʼ»¯TIM1ÊäÈ벶»ñ²ÎÊý

        TIM_ICInitStructure.TIM_Channel = TIM_Channel_1|TIM_Channel_2|TIM_Channel_3|TIM_Channel_4; //CC1S=01         Ñ¡ÔñÊäÈë¶Ë IC1Ó³Éäµ½TI1ÉÏ
          TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;        //ÉÏÉýÑز¶»ñ
          TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //Ó³Éäµ½TI1ÉÏ
          TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;         //ÅäÖÃÊäÈë·ÖƵ,²»·ÖƵ
          TIM_ICInitStructure.TIM_ICFilter = 0x00;//IC1F=0000 ÅäÖÃÊäÈëÂ˲¨Æ÷ ²»Â˲¨
          TIM_ICInit(TIM1, &TIM_ICInitStructure);
       
        //ÖжϷÖ×é³õʼ»¯
        NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;  //TIM1²¶»ñÖжÏ
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;  //ÏÈÕ¼ÓÅÏȼ¶2¼¶
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;  //´ÓÓÅÏȼ¶0¼¶
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨµÀ±»Ê¹ÄÜ
        NVIC_Init(&NVIC_InitStructure);  //¸ù¾ÝNVIC_InitStructÖÐÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèNVIC¼Ä´æÆ÷
       
        TIM_ITConfig(TIM1,TIM_IT_CC1,ENABLE);//ÔÊÐí¸üÐÂÖÐ¶Ï ,ÔÊÐíCC1IE²¶»ñÖжϠ      
       
           TIM_Cmd(TIM1,ENABLE );         //ʹÄܶ¨Ê±Æ÷1

}

void TIM1_UP_IRQHandler(void)
{
        if (TIM_GetITStatus(TIM1, TIM_IT_Update) != RESET)  //¼ì²éTIM1¸üÐÂÖжϷ¢ÉúÓë·ñ
                {
                TIM_ClearITPendingBit(TIM1, TIM_IT_Update  );  //Çå³ýTIMx¸üÐÂÖжϱêÖ¾
                LED2=!LED2;
                }  
}






void TIM1_CC_IRQHandler(void)
{
        LED4=!LED4;
        if (TIM_GetITStatus(TIM1, TIM_IT_CC1) != RESET)  //¼ì²éTIM1²¶»ñÖжϷ¢ÉúÓë·ñ
                {
                TIM_ClearITPendingBit(TIM1, TIM_IT_CC1  );  //Çå³ýTIMx¸üÐÂÖжϱêÖ¾
               
                }  
}


main
{
TIM1_Cap_Init(50000,719);        //ÒÔ1MhzµÄƵÂʼÆÊý

    TIM1_Int_Init(50000,719);
}

注释都是乱码
哪位帮忙看下,哪里设置不对。谢谢!
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:活到老,学到老

13

主题

69

帖子

1

粉丝