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 );
    
  }
  
}

 

posted @ 2015-08-28 00:27  IAmAProgrammer  阅读(2147)  评论(0编辑  收藏  举报