进不了中断,求大神指点

2019-07-14 16:12发布

#include "bsp_spwm_output.h"
uint16_t  CCR1_Val ;
uint16_t  CCR2_Val = 1500 ;
uint16_t  CCR3_Val = 900;
static void TIM1_Mode_Config(void)
{
   
  GPIO_InitTypeDef GPIO_InitStructure;
    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
    TIM_OCInitTypeDef  TIM_OCInitStructure;

    /* GPIOA clocks enable */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
    /* TIM1 clock enable */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_9 | GPIO_Pin_10;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOA,&GPIO_InitStructure);

    /* Connect TIM pins to AF6 */
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_6);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_6);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_6);

    /* Time Base configuration */
     
    TIM_TimeBaseStructure.TIM_Period =2999;      
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;    //ÉèÖÃÔ¤·ÖƵ£º²»Ô¤·ÖƵ£¬¼´Îª72MHz
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;    //ÉèÖÃʱÖÓ·ÖƵϵÊý£º²»·ÖƵ(ÕâÀïÓò»µ½)
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned1;  //ÏòÉϼÆÊýģʽ
  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

  /*PWM1 Mode configuration: Channel1 */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;        //ÅäÖÃΪPWMģʽ1
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;   
  TIM_OCInitStructure.TIM_Pulse = CCR2_Val;       //ÉèÖÃÌø±äÖµ£¬µ±¼ÆÊýÆ÷¼ÆÊýµ½Õâ¸öֵʱ£¬µçƽ·¢ÉúÌø±ä
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;  //µ±¶¨Ê±Æ÷¼ÆÊýֵСÓÚCCR1_ValʱΪ¸ßµçƽ
    TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;      
    TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;     
    TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Set;  

  TIM_OC2Init(TIM1, &TIM_OCInitStructure);     //ʹÄÜͨµÀ1
  TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable);
  TIM_ARRPreloadConfig( TIM1,ENABLE);
   
    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;   
  TIM_OCInitStructure.TIM_Pulse = CCR3_Val;   
  TIM_OC3Init(TIM1, &TIM_OCInitStructure);     //ʹÄÜͨµÀ4
  TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Enable);
  TIM_ARRPreloadConfig( TIM1,ENABLE);
   
  TIM_ARRPreloadConfig( TIM1,ENABLE);
    TIM_UpdateRequestConfig( TIM1, TIM_UpdateSource_Regular);
  TIM_ITConfig(TIM1,TIM_IT_Update | TIM_IT_Trigger,ENABLE);/* TIM3 enable counter */
  TIM_Cmd(TIM1, ENABLE);     //ʹÄܶ¨Ê±Æ÷3   
    TIM_ClearFlag(TIM1, TIM_FLAG_Update);
    TIM_CtrlPWMOutputs(TIM1, ENABLE);
}

     void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;   //TIM1ÖжÏ
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 6;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;  
  NVIC_Init(&NVIC_InitStructure);      
}         

void TIM1_SPWM_Init(void)
{
     TIM1_Mode_Config();
     NVIC_Configuration();
} // /*****/     
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
7条回答
yichengming
1楼-- · 2019-07-15 00:02
触发中断,我用TIM2可以,TIM1就不行,不知道哪里出问题了。。。
szzjfyp
2楼-- · 2019-07-15 00:25
签到签到
tyewybvwe
3楼-- · 2019-07-15 04:18
先用TIM1调调定时中断能进去不,先保证配置什么没有问题。
yichengming
4楼-- · 2019-07-15 07:49
进不去啊!
kpj3026
5楼-- · 2019-07-15 08:46
 精彩回答 2  元偷偷看……
kpj3026
6楼-- · 2019-07-15 13:18
既不是定时模式,也不是计数模式,更不是输入捕获。

一周热门 更多>