野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 13682|回复: 1

TIM8中断

[复制链接]
发表于 2015-1-24 17:42:45 | 显示全部楼层 |阅读模式
使用TIM5和TIM8做两个正交解码的计数程序,可是TIM5可以进中断,而TIM8进不了,求解乱码的都是注释

/*----------------------------------------------------------------*/       
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
        TIM_DeInit(TIM5);
        TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
/*----------------------------------------------------------------*/       
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);
        TIM_DeInit(TIM8);
        TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
       
/*----------------------------------------------------------------*/               
  TIM_TimeBaseStructure.TIM_Period =0xffff;       //
  TIM_TimeBaseStructure.TIM_Prescaler =0;          
  TIM_TimeBaseStructure.TIM_ClockDivision =TIM_CKD_DIV1 ;       
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  
  //TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned1;
       
  TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
       
  TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
       
        /*-----------------------------------------------------------------*/
        //±àÂëÅäÖà                       ±àÂëÄ£ê½
        TIM_EncoderInterfaceConfig(TIM5, TIM_EncoderMode_TI12,
                             TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);  //TIM_ICPolarity_RisingéÏéyÑØ2¶»ñ
        /*-----------------------------------------------------------------*/
        //±àÂëÅäÖà                       ±àÂëÄ£ê½
        TIM_EncoderInterfaceConfig(TIM8, TIM_EncoderMode_TI12,
                             TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);  //TIM_ICPolarity_RisingéÏéyÑØ2¶»ñ
       
        /*-----------------------------------------------------------------*/
  TIM_ICStructInit(&TIM_ICInitStructure);
  TIM_ICInitStructure.TIM_ICFilter = 6;         //±è½ÏÂË2¨Æ÷
  TIM_ICInit(TIM5, &TIM_ICInitStructure);
       
        TIM_ICStructInit(&TIM_ICInitStructure);
  TIM_ICInitStructure.TIM_ICFilter = 6;         //±è½ÏÂË2¨Æ÷
  TIM_ICInit(TIM8, &TIM_ICInitStructure);
        /*-----------------------------------------------------------------*/
// Clear all pending interrupts
  TIM_ClearFlag(TIM5, TIM_FLAG_Update);
  TIM_ITConfig(TIM5, TIM_IT_Update, ENABLE);   //ê1ÄüÖD¶Ï
  //Reset counter
  TIM5->CNT =0;
        TIM_Cmd(TIM5, ENABLE);   //ê1Äü¶¨ê±Æ÷3
        /*-----------------------------------------------------------------*/
        // Clear all pending interrupts
  TIM_ClearFlag(TIM8, TIM_FLAG_Update);
  TIM_ITConfig(TIM8, TIM_IT_Update, ENABLE);   //ê1ÄüÖD¶Ï
  //Reset counter
  TIM8->CNT =0;
        TIM_Cmd(TIM8, ENABLE);   //ê1Äü¶¨ê±Æ÷3
        /*-----------------------------------------------------------------*/       
        /* Configure one bit for preemption priority */

        /* Timer5ÖD¶Ï*/
        NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
        /* Timer8ÖD¶Ï*/
        NVIC_InitStructure.NVIC_IRQChannel = TIM8_UP_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);


回复

使用道具 举报

发表于 2015-1-26 09:11:22 | 显示全部楼层
不太清楚什么问题,帮顶
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-11-23 05:01 , Processed in 0.027267 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表