你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

stm32定时器tim10、11、13、14一起使用出现问题

[复制链接]
逍遥九剑 提问时间:2014-11-15 10:07 /
大家有没有用过stm32f405的tim10、11、13、14,我用这几路的ch1来测量四路PWM,结果出现问题,只有tim13能正常测量,其他的都无法进入中断
收藏 评论3 发布时间:2014-11-15 10:07

举报

3个回答
逍遥九剑 回答时间:2014-11-15 10:09:00
附上代码:
static void PPM_Configure_TIME10_11_13_14(void)
{
        uint16_t PrescalerValue_APB1 = 0;
        uint16_t PrescalerValue_APB2 = 0;
       
        TIM_ICInitTypeDef  TIM_ICInitStructure;
        TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;

        /* CLK = 168000000/(PrescalerValue+1) = 1000000hz = 1us */
        PrescalerValue_APB1 = (uint16_t) ((SystemCoreClock / PPM_FREQ) / 2) - 1;
        PrescalerValue_APB2 = (uint16_t) (SystemCoreClock / PPM_FREQ) - 1;
       
        /************************* TIM 10 *************************/
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10, ENABLE);

        /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Period = PPM_PEIOD_DUTY;
  TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue_APB2;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

        TIM_TimeBaseInit(TIM10, &TIM_TimeBaseStructure);
       
        /* TIM_Channel_1 */
  TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter = 0x0;

  TIM_ICInit(TIM10, &TIM_ICInitStructure);
               
        /************************* TIM 11 *************************/
       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11, ENABLE);

        /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Period = PPM_PEIOD_DUTY;
  TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue_APB2;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

        TIM_TimeBaseInit(TIM11, &TIM_TimeBaseStructure);
       
        /* TIM_Channel_1 */
  TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter = 0x0;

  TIM_ICInit(TIM11, &TIM_ICInitStructure);
               
        /************************* TIM 13 *************************/
       
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM13, ENABLE);

        /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Period = PPM_PEIOD_DUTY;
  TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue_APB1;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

        TIM_TimeBaseInit(TIM13, &TIM_TimeBaseStructure);
       
        /* TIM_Channel_1 */
  TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter = 0x0;

  TIM_ICInit(TIM13, &TIM_ICInitStructure);
               
        /************************* TIM 14 *************************/
       
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14, ENABLE);

        /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Period = PPM_PEIOD_DUTY;
  TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue_APB1;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

        TIM_TimeBaseInit(TIM14, &TIM_TimeBaseStructure);
       
        /* TIM_Channel_1 */
  TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter = 0x0;

  TIM_ICInit(TIM14, &TIM_ICInitStructure);

  /************************* TIM enable counter *************************/
  TIM_Cmd(TIM10, ENABLE);
        TIM_Cmd(TIM11, ENABLE);
        TIM_Cmd(TIM13, ENABLE);
        TIM_Cmd(TIM14, ENABLE);
  /************************* Enable the CCx Interrupt Request *************************/
  TIM_ITConfig(TIM10, TIM_IT_CC1, ENABLE);                                        //PPM_CH1
        TIM_ITConfig(TIM11, TIM_IT_CC1, ENABLE);                                        //PPM_CH2
        TIM_ITConfig(TIM13, TIM_IT_CC1, ENABLE);                                        //PPM_CH6
        TIM_ITConfig(TIM14, TIM_IT_CC1, ENABLE);                                        //PPM_CH5
}


static void PPM_Configure_NVIC_TIMER(void)
{
        NVIC_InitTypeDef   NVIC_InitStructure;
        /* NVIC_PriorityGroup */
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);                        //0~f

  NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
       
        NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_TIM10_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
       
        NVIC_InitStructure.NVIC_IRQChannel = TIM1_TRG_COM_TIM11_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
       
        NVIC_InitStructure.NVIC_IRQChannel = TIM8_UP_TIM13_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
       
        NVIC_InitStructure.NVIC_IRQChannel = TIM8_TRG_COM_TIM14_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

/*
*********************************************************************************************************
*                                  PPM_IRQHandler_CH1
*
* Description : PPM CH1
*
* Arguments  :
*
* Returns     : none
*
* Notes       : none
*               
*********************************************************************************************************
*/
extern void PPM_IRQHandler_CH1(void)
{
        if(TIM10->SR & TIM_IT_CC1)
        {
                TIM10->SR &= ~TIM_FLAG_CC1;       
                TIM10->SR &= ~TIM_FLAG_CC1OF;               
                if(GPIOB->IDR & GPIO_Pin_8)             /*PPM  CH1  if PB.8 is high  Rising*/
                        timer10_ccr1 = TIM10->CCR1;
                else
                {
                        if((TIM10->CCR1) < timer10_ccr1)
                                PPM_Channel_Table[0] = PPM_PEIOD_DUTY        - timer10_ccr1 + TIM10->CCR1;
                        else
                                PPM_Channel_Table[0] = TIM10->CCR1 - timer10_ccr1;
                }       
        }
}


/*
*********************************************************************************************************
*                                  PPM_IRQHandler_CH2
*
* Description : PPM CH2
*
* Arguments  :
*
* Returns     : none
*
* Notes       : none
*               
*********************************************************************************************************
*/
extern void PPM_IRQHandler_CH2(void)
{
        if(TIM11->SR & TIM_IT_CC1)
        {
                TIM11->SR &= ~TIM_FLAG_CC1;       
                TIM11->SR &= ~TIM_FLAG_CC1OF;               
                if(GPIOB->IDR & GPIO_Pin_9)             /*PPM  CH2  if PB.9 is high  Rising*/
                        timer11_ccr1 = TIM11->CCR1;
                else
                {
                        if((TIM11->CCR1) < timer11_ccr1)
                                PPM_Channel_Table[1] = PPM_PEIOD_DUTY        - timer11_ccr1 + TIM11->CCR1;
                        else
                                PPM_Channel_Table[1] = TIM11->CCR1 - timer11_ccr1;
                }       
        }
}


/*
*********************************************************************************************************
*                                  PPM_IRQHandler_CH5
*
* Description : PPM CH5
*
* Arguments  :
*
* Returns     : none
*
* Notes       : none
*               
*********************************************************************************************************
*/
extern void PPM_IRQHandler_CH5(void)
{
        if(TIM14->SR & TIM_IT_CC1)
        {
                TIM14->SR &= ~TIM_FLAG_CC1;       
                TIM14->SR &= ~TIM_FLAG_CC1OF;               
                if(GPIOA->IDR & GPIO_Pin_7)             /*PPM  CH5  if PA.7 is high  Rising*/
                        timer14_ccr1 = TIM14->CCR1;
                else
                {
                        if((TIM14->CCR1) < timer14_ccr1)
                                PPM_Channel_Table[4] = PPM_PEIOD_DUTY        - timer14_ccr1 + TIM14->CCR1;
                        else
                                PPM_Channel_Table[4] = TIM14->CCR1 - timer14_ccr1;
                }       
        }
}


/*
*********************************************************************************************************
*                                  PPM_IRQHandler_CH6
*
* Description : PPM CH6
*
* Arguments  :
*
* Returns     : none
*
* Notes       : none
*               
*********************************************************************************************************
*/
extern void PPM_IRQHandler_CH6(void)
{
        if(TIM13->SR & TIM_IT_CC1)
        {
                TIM13->SR &= ~TIM_FLAG_CC1;       
                TIM13->SR &= ~TIM_FLAG_CC1OF;               
                if(GPIOA->IDR & GPIO_Pin_6)             /*PPM  CH6  if PA.6 is high  Rising*/
                        timer13_ccr1 = TIM13->CCR1;
                else
                {
                        if((TIM13->CCR1) < timer13_ccr1)
                                PPM_Channel_Table[5] = PPM_PEIOD_DUTY        - timer13_ccr1 + TIM13->CCR1;
                        else
                                PPM_Channel_Table[5] = TIM13->CCR1 - timer13_ccr1;
                }       
        }
}
沐紫 回答时间:2014-11-18 14:13:13
代码比较长,麻烦各位朋友帮忙看看
回答时间:2014-11-18 16:46:36
把NVIC的优先级错开呢?现在是同时在产生中断,楼主可以考虑先只开一个中断,确认中断正常工作,然后再根据不同的优先顺序来设置优先级。

所属标签

相似问题

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32Cube扩展软件包
意法半导体边缘AI套件
ST - 理想汽车豪华SUV案例
ST意法半导体智能家居案例
STM32 ARM Cortex 32位微控制器
关注我们
st-img 微信公众号
st-img 手机版