STM32F0 Timer3 作为定时器输出,中断输出

设置Timer3 中断

void TIM3_INT_Config(void)
{
   NVIC_InitTypeDef NVIC_InitStructure;

  /* TIM3 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

  /*  TIM3 ÖжÏǶÌ×Éè¼Æ*/
  NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

设置Timer3 模式

void TIM3_OUT_Config(void)
{    
    TIM_TimeBaseInitTypeDef  TIM3_TimeBaseStructure;
    TIM_OCInitTypeDef  TIM3_OCInitStructure;    
  /* ¼ÆËãÔ¤·ÖƵֵ */
  TM3_PrescalerValue = (uint16_t) (SystemCoreClock  / TM3_PRESCALER) - 1;

  /* Time ¶¨Ê±Æ÷»ù´¡ÉèÖà */
  TIM3_TimeBaseStructure.TIM_Period = 65535;
  TIM3_TimeBaseStructure.TIM_Prescaler = 0;
  TIM3_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM3_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM3, &TIM3_TimeBaseStructure);

  /* Ô¤·ÖƵÆ÷ÅäÖà */
  TIM_PrescalerConfig(TIM3, TM3_PrescalerValue, TIM_PSCReloadMode_Immediate);

  /* Êä³ö±È½ÏʱÐòģʽÅäÖÃÉèÖà */
  TIM3_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
  TIM3_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

  /* Êä³ö±È½ÏʱÐòģʽÅäÖÃ: ƵµÀ3*/
  TIM3_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM3_OCInitStructure.TIM_Pulse = TM3_CCR1_Val;  //3000
  TIM_OC3Init(TIM3, &TIM3_OCInitStructure);
  TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Disable);
   
  /* TIM ÖжÏʹÄÜ */
  TIM_ITConfig(TIM3, TIM_IT_CC3 , ENABLE);

  /* TIM3 ʹÄÜ */
  TIM_Cmd(TIM3, ENABLE);
    
}
3. 中断子程序

void TIM3_IRQHandler(void)
{
  if (TIM_GetITStatus(TIM3, TIM_IT_CC3) != RESET)
  {
    TIM_ClearITPendingBit(TIM3, TIM_IT_CC3);

    /* LED3 toggling with frequency = 219.7 Hz */
//    LED1_Toggle();
//    capture3 = TIM_GetCapture3(TIM3);
//    TIM_SetCompare3(TIM3, capture3 + TM3_CCR1_Val);
        
        OutToggle();
        
        if(TimeRxFlag)
        {
            TimeInterval++;
            if(TimeInterval>4)
            {
                RxFrameEndFlag =1;
            }
        }
        if(KeyCtrl.bDebunceTime != 0)
        {
                KeyCtrl.bDebunceTime--;
        }
//        SevenSegShow(DispBuffer);
    capture3 = TIM_GetCapture3(TIM3);
    TIM_SetCompare3(TIM3, capture3 + TM3_CCR1_Val);
  }
}    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值