STM32F1 기본 구성 8.TIMER 가져오기 캡처 구성

입력 캡처
    :    CHx      ,     
       ,        TIMx_CNT   
           ,      。

캡처 구성 가져오기
	//        
	GPIO_InitTypeDef GPIO_InitStructure;
	TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
 	NVIC_InitTypeDef NVIC_InitStructure;

	//    
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
 	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);  

	//  IO     	
	GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_0;  
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; 
	GPIO_Init(GPIOA, &GPIO_InitStructure);
	GPIO_ResetBits(GPIOA,GPIO_Pin_0);						 
	
	//   TIM2	 
	TIM_TimeBaseStructure.TIM_Period = arr; //      
	TIM_TimeBaseStructure.TIM_Prescaler =psc; 	//     
	TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //    :
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //TIM    
	TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); 
  
	//   TIM2      
	TIM2_ICInitStructure.TIM_Channel = TIM_Channel_1; //TC1  
    TIM2_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //     
    TIM2_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //TC1  TI1
    TIM2_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;	 //    
    TIM2_ICInitStructure.TIM_ICFilter = 0x00;//   
    TIM_ICInit(TIM2, &TIM2_ICInitStructure);

	//       
	NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;  //TIM2  
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;  //  2
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;  //  0
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ     
	NVIC_Init(&NVIC_InitStructure);  //  NVIC_InitStruct           NVIC    
	
	TIM_ITConfig(TIM2,TIM_IT_Update|TIM_IT_CC1,ENABLE);//       ,  CC1IE    	
	
    TIM_Cmd(TIM2,ENABLE ); 	//     2

인터럽트 함수
void TIM2_IRQHandler(void)
{ 
	if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET)//  1      
		{	
			//    
   			TIM_ClearITPendingBit(TIM2, TIM_IT_CC1|TIM_IT_Update); //       
		}			     	    					   
 
}

좋은 웹페이지 즐겨찾기