• sTM32 使用TIMx_CH1作为 Tx1F_ED 计数器时钟


    环境:iar arm 5.3 

    stm32f103vbt6  

    使用PA.8 外部输入10Mhz的方波。可从systick中断得到数据4. 

    4×5000(预分频值)×1000(tick中断时间)=20MHz 

    属于双边沿检测,一个PA.8个脉冲有2个边沿,所以时钟加倍。

    由于使用了TI1F_ED它的结构如下:

    void RCC_Configuration( void )
    {
      /* Setup STM32 system (clock, PLL and Flash configuration) */
      SystemInit( );
      
      /* Enable GPIOA, GPIOC and USART1 clock  */
      RCC_APB2PeriphClockCmd(
        RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC | RCC_APB2Periph_TIM1, ENABLE );
    }
    
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    
    void TIM1_Init( void )
    {
      
      TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
      
      TIM_TimeBaseStructure.TIM_Period = 65535;
      TIM_TimeBaseStructure.TIM_Prescaler = 5000;
      TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
      TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
      TIM_TimeBaseInit( TIM1, &TIM_TimeBaseStructure );
      
      TIM_TIxExternalClockConfig( TIM1, TIM_TIxExternalCLK1Source_TI1ED,
        TIM_ICPolarity_Rising, 0 );
      
      TIM_Cmd( TIM1, ENABLE );
      
    }
    
    int main( void )
    {
      RCC_Configuration( );
      GPIO_Config( );
      TIM1_Init( );
      /* Setup SysTick Timer for 1 msec interrupts  */
      if ( SysTick_Config( SystemFrequency / 1000 ) )
      {
        /* Capture error */
        while ( 1 )
          ;
      }
      
      while ( 1 )
      {
      }
    }
    
    void SysTick_Handler( void )
    {
      static u32 i = 0;
      
      if ( i == 0 )
      {
        i = 1;
        gusData = 0;
        TIM_SetCounter( TIM1, 0 );
        
      }
      else
      {
        i = 0;
        gusData = TIM_GetCounter( TIM1 );
        
      }
      
    }
  • 相关阅读:
    ActiveSync合作关系对话框的配置
    WINCE对象存储区(object store)
    Wince 隐藏TASKBAR的方法
    Wince输入法换肤换语言机制
    poj 3080 Blue Jeans 解题报告
    codeforces A. Vasily the Bear and Triangle 解题报告
    hdu 1050 Moving Tables 解题报告
    hdu 1113 Word Amalgamation 解题报告
    codeforces A. IQ Test 解题报告
    poj 1007 DNA Sorting 解题报告
  • 原文地址:https://www.cnblogs.com/shangdawei/p/4765203.html
Copyright © 2020-2023  润新知