当前位置: 首页>>代码示例>>C++>>正文


C++ TIM_ICInit函数代码示例

本文整理汇总了C++中TIM_ICInit函数的典型用法代码示例。如果您正苦于以下问题:C++ TIM_ICInit函数的具体用法?C++ TIM_ICInit怎么用?C++ TIM_ICInit使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了TIM_ICInit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TIM2_IRQHandler

void TIM2_IRQHandler()
{
  if (TIM_GetITStatus(TIM2, TIM_IT_CC1) == SET) {
    /* Clear TIM2 Capture compare interrupt pending bit */
    TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);

      /* Get the Input Capture value */
    timebaseCapture_prev = timebaseCapture_current;
    timebaseCapture_current = TIM_GetCapture1(TIM2);

    if(TIM_ICInitStructure.TIM_ICPolarity == TIM_ICPolarity_Rising){

      TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
      TIM_ICInit(TIM2, &TIM_ICInitStructure);

    }
    else if(TIM_ICInitStructure.TIM_ICPolarity == TIM_ICPolarity_Falling){

      TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
      TIM_ICInit(TIM2, &TIM_ICInitStructure);

      if(timebaseCapture_current > timebaseCapture_prev){

        timebaseCapture_output = (timebaseCapture_current - timebaseCapture_prev);//*5/18;

      }
      else{
        timebaseCapture_output  = (20000 - timebaseCapture_prev + timebaseCapture_current);//*5/18;
      }
    }      
  }
}
开发者ID:numkang,项目名称:STM32F429_Training,代码行数:32,代码来源:main.c

示例2: capture_config

//ÊäÈ벶»ñÅäÖÃ
void capture_config(void)
{
    TIM_ICInitTypeDef TIM_ICInitStructure;

    gpio_af_pp_up_init(GPIOB, GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_9);//CH1|CH2|CH4
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_TIM4);
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_TIM4);
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_TIM4);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);

    TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
    TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
    TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
    TIM_ICInitStructure.TIM_ICFilter = 0x0;

    TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
    TIM_ICInit(TIM4, &TIM_ICInitStructure);

    TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
    TIM_ICInit(TIM4, &TIM_ICInitStructure);

    TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
    TIM_ICInit(TIM4, &TIM_ICInitStructure);

    TIM_Cmd(TIM4, ENABLE);
    TIM_ITConfig(TIM4, TIM_IT_CC1, ENABLE);
    TIM_ITConfig(TIM4, TIM_IT_CC2, ENABLE);
    TIM_ITConfig(TIM4, TIM_IT_CC4, ENABLE);

    nvic_config(TIM4_IRQn, 2);
}
开发者ID:glocklueng,项目名称:stm32f4-sound-wave-navigation,代码行数:33,代码来源:capture.c

示例3: capture_config

//输入捕获配置
void capture_config(void)
{
	TIM_ICInitTypeDef TIM_ICInitStructure;
	
	gpio_af_pp_up_init(GPIOC, GPIO_Pin_8|GPIO_Pin_9);//CH3|CH4
	GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_TIM3);
	GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_TIM3);
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
	
	TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge;
	TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
	TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
	TIM_ICInitStructure.TIM_ICFilter = 10;
	
	TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;
	TIM_ICInit(TIM3, &TIM_ICInitStructure);
	
	TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
	TIM_ICInit(TIM3, &TIM_ICInitStructure);
	
	TIM_Cmd(TIM3, ENABLE);
	TIM_ITConfig(TIM3, TIM_IT_CC3, ENABLE);
	TIM_ITConfig(TIM3, TIM_IT_CC4, ENABLE);
	
	nvic_config(TIM3_IRQn, 0);
	TIM7_init(500, 8400);
}
开发者ID:glocklueng,项目名称:smart-car,代码行数:29,代码来源:capture.c

示例4: ENC_Init

void ENC_Init(void)
{
	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
	TIM_ICInitTypeDef TIM_ICInitStructure;
	
	//Encoder uint connected to TIM2
	GPIO_InitTypeDef GPIO_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;

	//RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
	RCC_APB1PeriphClockCmd(ENC_TIMER_CLK,ENABLE);
	RCC_APB2PeriphClockCmd(ENC_GPIO_CLK ,ENABLE);

	GPIO_StructInit(&GPIO_InitStructure);
	//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
	GPIO_InitStructure.GPIO_Pin = ENC_GPIO_PIN_A  | ENC_GPIO_PIN_B ;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
	GPIO_Init(ENC_GPIO_PORT ,&GPIO_InitStructure);

	NVIC_InitStructure.NVIC_IRQChannel = ENC_TIMER_IRQn ;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = TIMx_PRE_EMPTION_PRIORITY;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = TIMx_SUB_PRIORITY;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);

	TIM_DeInit(ENC_TIMER);
	//TIM_TimeBaseInit(&TIM_TimeBaseStructure);

	TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
	TIM_TimeBaseStructure.TIM_Period = (4*ENCODER_PPR)-1;
	TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseInit(ENC_TIMER,&TIM_TimeBaseStructure);

	TIM_EncoderInterfaceConfig(ENC_TIMER,TIM_EncoderMode_TI12,
	TIM_ICPolarity_Rising,TIM_ICPolarity_Rising);
	TIM_ICStructInit(&TIM_ICInitStructure);
	TIM_ICInitStructure.TIM_ICFilter = ICx_FILTER;
	TIM_ICInit(ENC_TIMER,&TIM_ICInitStructure);
 
	TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;//注意通道
	TIM_ICInit(ENC_TIMER, &TIM_ICInitStructure);

	TIM_ClearFlag(ENC_TIMER,TIM_FLAG_Update);
	TIM_ITConfig(ENC_TIMER,TIM_IT_Update,ENABLE);

	TIM2->CNT = COUNTER_RESET;//!!此处注意修改

	//局部初始化
	ENC_Clear_Speed_Buffer();
	hPrevious_angle=0;
  hRot_Speed=0;;
  bSpeed_Buffer_Index = 0;
  hEncoder_Timer_Overflow=0;
  bIs_First_Measurement = true;
  hEncoder_Revolutions_Num=0; 
   
  TIM_Cmd(ENC_TIMER,ENABLE);
}
开发者ID:wangdie1,项目名称:ElectronicDesignContest,代码行数:59,代码来源:Encoder.c

示例5: TIM3_Mode_Config

void TIM3_Mode_Config(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
	TIM_ICInitTypeDef TIM_ICInitStructure;
	//TIM_OCInitTypeDef  TIM_OCInitStructure;
	
	/*----------------------------------------------------------------*/
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
	
	
	GPIO_StructInit(&GPIO_InitStructure);
	/* Configure PA.06,07 as encoder input */
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
	GPIO_Init(GPIOA, &GPIO_InitStructure);
	
	/*----------------------------------------------------------------*/        
	
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //使能TIM3
	TIM_DeInit(TIM3);
	TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
	
	TIM_TimeBaseStructure.TIM_Period =0xffff;       //
	TIM_TimeBaseStructure.TIM_Prescaler =0;            //设置预分频:
	TIM_TimeBaseStructure.TIM_ClockDivision =TIM_CKD_DIV1 ;        //设置时钟分频系数:不分频
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //向上计数模式
	//TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned1; 
	/*初始化TIM2定时器 */
	TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
	
	/*-----------------------------------------------------------------*/
	//编码配置                        编码模式
	TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI12, 
	TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);  //TIM_ICPolarity_Rising上升沿捕获


	TIM_ICStructInit(&TIM_ICInitStructure);

	TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;//配置通道1的滤波器
	TIM_ICInitStructure.TIM_ICFilter = 6;         	//比较滤波器
	TIM_ICInit(TIM3, &TIM_ICInitStructure);

	TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;//配置通道2的滤波器
	TIM_ICInitStructure.TIM_ICFilter = 6;         	//比较滤波器
	TIM_ICInit(TIM3, &TIM_ICInitStructure);
	
	TIM_ARRPreloadConfig(TIM3, ENABLE);
	// Clear all pending interrupts
	TIM_ClearFlag(TIM3, TIM_FLAG_Update);
	TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);   //使能中断
	//Reset counter
	TIM3->CNT =0;	
	TIM_Cmd(TIM3, ENABLE);   //使能定时器3
}
开发者ID:alone888,项目名称:TreeProtect,代码行数:57,代码来源:timer.c

示例6: PIOS_PWM_tim_edge_cb

static void PIOS_PWM_tim_edge_cb (uint32_t tim_id, uint32_t context, uint8_t chan_idx, uint16_t count)
{
	/* Recover our device context */
	struct pios_pwm_dev * pwm_dev = (struct pios_pwm_dev *)context;

	if (!PIOS_PWM_validate(pwm_dev)) {
		/* Invalid device specified */
		return;
	}

	if (chan_idx >= pwm_dev->cfg->num_channels) {
		/* Channel out of range */
		return;
	}

	const struct pios_tim_channel * chan = &pwm_dev->cfg->channels[chan_idx];

	if (pwm_dev->CaptureState[chan_idx] == 0) {
		pwm_dev->RiseValue[chan_idx] = count;
		pwm_dev->us_since_update[chan_idx] = 0;
	} else {
		pwm_dev->FallValue[chan_idx] = count;
	}
			
	// flip state machine and capture value here
	/* Simple rise or fall state machine */
	TIM_ICInitTypeDef TIM_ICInitStructure = pwm_dev->cfg->tim_ic_init;
	if (pwm_dev->CaptureState[chan_idx] == 0) {
		/* Switch states */
		pwm_dev->CaptureState[chan_idx] = 1;

		/* Switch polarity of input capture */
		TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
		TIM_ICInitStructure.TIM_Channel = chan->timer_chan;
		TIM_ICInit(chan->timer, &TIM_ICInitStructure);
	} else {
		/* Capture computation */
		if (pwm_dev->FallValue[chan_idx] > pwm_dev->RiseValue[chan_idx]) {
			pwm_dev->CaptureValue[chan_idx] = (pwm_dev->FallValue[chan_idx] - pwm_dev->RiseValue[chan_idx]);
		} else {
			pwm_dev->CaptureValue[chan_idx] = ((chan->timer->ARR - pwm_dev->RiseValue[chan_idx]) + pwm_dev->FallValue[chan_idx]);
		}

		/* Switch states */
		pwm_dev->CaptureState[chan_idx] = 0;

		/* Increase supervisor counter */
		pwm_dev->CapCounter[chan_idx]++;

		/* Switch polarity of input capture */
		TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
		TIM_ICInitStructure.TIM_Channel = chan->timer_chan;
		TIM_ICInit(chan->timer, &TIM_ICInitStructure);
	}
	
}
开发者ID:01iv3r,项目名称:OpenPilot,代码行数:56,代码来源:pios_pwm.c

示例7: TIM3_IRQHandler

void TIM3_IRQHandler(void)
{
	uint16_t val =0,i=0;
	for(i=0;i<4;i++){
		if (Channels[i+2].tim == TIM3 && (TIM_GetITStatus(TIM3, Channels[i+2].cc) == SET)){
			TIM_ClearITPendingBit(TIM3, Channels[i+2].cc);
			switch (Channels[i+2].channel)
			{
				case TIM_Channel_1:
					val = TIM_GetCapture1(TIM3);
					break;
				case TIM_Channel_2:
					val = TIM_GetCapture2(TIM3);
					break;
				case TIM_Channel_3:
					val = TIM_GetCapture3(TIM3);
					break;
				case TIM_Channel_4:
					val = TIM_GetCapture4(TIM3);
					break;
			}
			if (Inputs[i+2].state == 0)
				Inputs[i+2].rise = val;
			else
				Inputs[i+2].fall = val;
			if (Inputs[i+2].state == 0) {
				Inputs[i+2].state = 1;
				TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
				TIM_ICInitStructure.TIM_Channel = Channels[i+2].channel;
				TIM_ICInit(TIM3, &TIM_ICInitStructure);
			}else{
				if(Inputs[i+2].fall > Inputs[i+2].rise ){
					val = (Inputs[i+2].fall - Inputs[i+2].rise);
					if(val < 2100 && val>900)
						Inputs[i+2].capture = val;
				}else{
					val = ((0xffff - Inputs[i+2].rise) + Inputs[i+2].fall);
					if(val < 2100 && val>900)
					Inputs[i+2].capture = val;
				}
				Inputs[i+2].state = 0;
				TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
				TIM_ICInitStructure.TIM_Channel = Channels[i+2].channel;
				TIM_ICInit(TIM3, &TIM_ICInitStructure);
			}
		}
	}
	rc_in.thr=Inputs[0].capture;
	rc_in.roll=Inputs[1].capture;
	rc_in.pitch=Inputs[2].capture;
	rc_in.yaw=Inputs[3].capture;
	rc_in.mode=Inputs[4].capture;
	rc_in.serve=Inputs[5].capture;
}
开发者ID:xydang,项目名称:Sender,代码行数:54,代码来源:pwm_in.c

示例8: TIM3_PWM_In_Init

/*
 * 函数名:TIM3_PWM_In_Init
 * 描述  :定时器3输入捕获初始化函数
 * 输入  :arr:自动重装载寄存器周期的值;psc:时钟频率除数的预分频值
 * 输出  :无
 */ 
void TIM3_PWM_In_Init(u16 arr,u16 psc)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
	TIM_ICInitTypeDef  TIM3_ICInitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);  	//使能GPIOB时钟
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);		//使能TIM3时钟
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); 
	GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3,ENABLE);
 	
	GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_4 | GPIO_Pin_5;  												
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;           										
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	
	GPIO_ResetBits(GPIOB,GPIO_Pin_4);
	GPIO_ResetBits(GPIOB,GPIO_Pin_5);

	//初始化TIM3	 
	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(TIM3, &TIM_TimeBaseStructure);                                //初始化TIMx的时间基数单位
  
	//初始化TIM3通道1输入捕获参数
	TIM3_ICInitStructure.TIM_Channel = TIM_Channel_1 ; 														 //选择输入端 IC1映射到TI1上
  TIM3_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;									 //上升沿捕获
  TIM3_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; 							 //映射到TI1上
 	TIM3_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;	                       //配置输入分频,不分频 
 	TIM3_ICInitStructure.TIM_ICFilter = 0x00;																			 //配置输入滤波器,不滤波
  TIM_ICInit(TIM3, &TIM3_ICInitStructure);
//初始化TIM3通道2输入捕获参数
	TIM3_ICInitStructure.TIM_Channel = TIM_Channel_2 ; 														 //选择输入端 IC1映射到TI1上
  TIM3_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;									 //上升沿捕获
  TIM3_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; 							 //映射到TI1上
  TIM3_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;	 											 //配置输入分频,不分频 
  TIM3_ICInitStructure.TIM_ICFilter = 0x00;																			 //配置输入滤波器 不滤波
  TIM_ICInit(TIM3, &TIM3_ICInitStructure);
		
	//中断分组初始化
	NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn  ;  														 //TIM3中断
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;  										 //先占优先级
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;  												 	 //从优先级
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 															 //IRQ通道被使能
	NVIC_Init(&NVIC_InitStructure);  																							 //初始化外设NVIC寄存器 

	TIM_ITConfig(TIM3,TIM_IT_Update | TIM_IT_CC1 | TIM_IT_CC2,ENABLE);								 //允许更新中断 ,允许CC1IE捕获中断	
	
 	TIM_Cmd(TIM3,ENABLE ); 																												 //使能定时器3
}
开发者ID:Strongc,项目名称:FourAxis-M,代码行数:59,代码来源:pwm_in.c

示例9: tim3_capture_init

void tim3_capture_init(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
	TIM_ICInitTypeDef TIM3_ICInitStructure;

	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

	//初始化定时器4 TIM3
	TIM_TimeBaseStructure.TIM_Period = 0xffff;
	TIM_TimeBaseStructure.TIM_Prescaler = 71;
	TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

	//初始化TIM3输入捕获参数
	TIM3_ICInitStructure.TIM_Channel = TIM_Channel_1;
	TIM3_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
	TIM3_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
	TIM3_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
	TIM3_ICInitStructure.TIM_ICFilter = 0x00;
	TIM_ICInit(TIM3, &TIM3_ICInitStructure);

	TIM3_ICInitStructure.TIM_Channel = TIM_Channel_2;
	TIM3_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
	TIM3_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
	TIM3_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
	TIM3_ICInitStructure.TIM_ICFilter = 0x00;
	TIM_ICInit(TIM3, &TIM3_ICInitStructure);

	TIM3_ICInitStructure.TIM_Channel = TIM_Channel_3;
	TIM3_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
	TIM3_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
	TIM3_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
	TIM3_ICInitStructure.TIM_ICFilter = 0x00;
	TIM_ICInit(TIM3, &TIM3_ICInitStructure);

	TIM3_ICInitStructure.TIM_Channel = TIM_Channel_4;
	TIM3_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
	TIM3_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
	TIM3_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
	TIM3_ICInitStructure.TIM_ICFilter = 0x00;
	TIM_ICInit(TIM3, &TIM3_ICInitStructure);

	TIM_Cmd(TIM3, ENABLE);

	TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);
	TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);
	TIM_ITConfig(TIM3, TIM_IT_CC3, ENABLE);
	TIM_ITConfig(TIM3, TIM_IT_CC4, ENABLE);

}
开发者ID:houcy,项目名称:PA-Quadcopter,代码行数:53,代码来源:pwm_in.c

示例10: TIM4_Config

void TIM4_Config(void) //PWM正脉宽捕获
{
	GPIO_InitTypeDef GPIO_InitStructure;
	TIM_TimeBaseInitTypeDef TIM_BaseInitStructure; 
	TIM_ICInitTypeDef  TIM_ICInitStructure; 

	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7| GPIO_Pin_8| GPIO_Pin_9;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOB, &GPIO_InitStructure);

	TIM_BaseInitStructure.TIM_Period = 40000; //40ms          
    TIM_BaseInitStructure.TIM_Prescaler = (uint16_t) (SystemCoreClock / 1000000) - 1; //1us       
    TIM_BaseInitStructure.TIM_ClockDivision = 0;     
    TIM_BaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;  
    TIM_TimeBaseInit(TIM4, &TIM_BaseInitStructure); 

   	TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; 		   //定时器2通道1输入捕获模式
   	TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling; 
   	TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; 
   	TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; 
   	TIM_ICInitStructure.TIM_ICFilter = 0x0;     
   	TIM_ICInit(TIM4, &TIM_ICInitStructure); 

   	TIM_ICInitStructure.TIM_Channel = TIM_Channel_2; 		   //定时器2通道1输入捕获模式
   	TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling; 
   	TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; 
   	TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; 
   	TIM_ICInitStructure.TIM_ICFilter = 0x0;     
   	TIM_ICInit(TIM4, &TIM_ICInitStructure); 

   	TIM_ICInitStructure.TIM_Channel = TIM_Channel_3; 		   //定时器2通道1输入捕获模式
   	TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling; 
   	TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; 
   	TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; 
   	TIM_ICInitStructure.TIM_ICFilter = 0x0;     
   	TIM_ICInit(TIM4, &TIM_ICInitStructure); 

   	TIM_ICInitStructure.TIM_Channel = TIM_Channel_4; 		   //定时器2通道1输入捕获模式
   	TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling; 
   	TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; 
   	TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; 
   	TIM_ICInitStructure.TIM_ICFilter = 0x0;     
   	TIM_ICInit(TIM4, &TIM_ICInitStructure); 
   	
	TIM_ITConfig(TIM4, TIM_IT_CC1|TIM_IT_CC2|TIM_IT_CC3|TIM_IT_CC4, ENABLE); 
  	TIM_Cmd(TIM4, ENABLE);    
}
开发者ID:intchar90,项目名称:AHRS,代码行数:51,代码来源:pwm.c

示例11: TIM3_IRQHandler

//void PIOS_PWM_irq_handler(TIM_TypeDef * timer)
void TIM3_IRQHandler(void)
{
	/* Zero value always will be changed but this prevents compiler warning */
	int32_t i = 0;

	/* Do this as it's more efficient */
	if (TIM_GetITStatus(TIM3, TIM_IT_CC2) == SET) {
		i = 7;
		if (CaptureState == 0) {
			RiseValue = TIM_GetCapture2(TIM3);
		} else {
			FallValue = TIM_GetCapture2(TIM3);
		}
	}

	/* Clear TIM3 Capture compare interrupt pending bit */
	TIM_ClearITPendingBit(TIM3, TIM_IT_CC2);

	/* Simple rise or fall state machine */
	if (CaptureState == 0) {
		/* Switch states */
		CaptureState = 1;

		/* Switch polarity of input capture */
		TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
		TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
		TIM_ICInit(TIM3, &TIM_ICInitStructure);

	} else {
		/* Capture computation */
		if (FallValue > RiseValue) {
			CaptureValue = (FallValue - RiseValue);
		} else {
			CaptureValue = ((0xFFFF - RiseValue) + FallValue);
		}

		/* Switch states */
		CaptureState = 0;

		/* Increase supervisor counter */
		CapCounter++;
		TIM_ITConfig(TIM3, TIM_IT_CC2, DISABLE);

		/* Switch polarity of input capture */
		TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
		TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
		TIM_ICInit(TIM3, &TIM_ICInitStructure);

	}
}
开发者ID:jgoppert,项目名称:openpilot,代码行数:51,代码来源:pios_hcsr04.c

示例12: PWD_Config

void PWD_Config(void)
{
	TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;//定时器初始化结构
	TIM_ICInitTypeDef TIM_ICInitStructure;         //通道输入初始化结构
	GPIO_InitTypeDef GPIO_InitStructure;

	//浮动输入方式
	GPIO_InitStructure.GPIO_Pin = /* GPIO_Pin_0 | */GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
  	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
	GPIO_Init(GPIOA, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6; 
	GPIO_Init(GPIOB, &GPIO_InitStructure);

	//输出初始化
  	TIM_TimeBaseStructure.TIM_Period = 65535;     //周期
  	TIM_TimeBaseStructure.TIM_Prescaler = 720;       //时钟分频
  	TIM_TimeBaseStructure.TIM_ClockDivision = 0;   //时钟分割
  	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//模式
  	TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);//基本初始化
  	TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

	//捕捉初始化  
	TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;//下降沿
 	TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;//管脚与寄存器对应关系
  	TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;//分频器
  	TIM_ICInitStructure.TIM_ICFilter = 0x4;        //滤波设置,经历几个周期跳变认定波形稳定0x0~0xF
 	TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;//通道选择	
//  TIM_ICInit(TIM2, &TIM_ICInitStructure);        //初始化	
  	TIM_ICInit(TIM4, &TIM_ICInitStructure);        //初始化				 
 	TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;//通道选择
  	TIM_ICInit(TIM2, &TIM_ICInitStructure);        //初始化
 	TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;//通道选择
  	TIM_ICInit(TIM2, &TIM_ICInitStructure);        //初始化
 	TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;//通道选择
  	TIM_ICInit(TIM2, &TIM_ICInitStructure);        //初始化
  
  	TIM_SelectInputTrigger(TIM2, TIM_TS_TI1FP1);   //选择时钟触发源				   
  	TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);//触发方式					  
  	TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable); //启动定时器的被动触发
  	TIM_ITConfig(TIM2, /*TIM_IT_CC1|*/TIM_IT_CC2|TIM_IT_CC3|TIM_IT_CC4, ENABLE);        //打开中断
 
	TIM_SelectInputTrigger(TIM4, TIM_TS_TI1F_ED);   //选择时钟触发源				   
  	TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_Reset);//触发方式					  
  	TIM_SelectMasterSlaveMode(TIM4, TIM_MasterSlaveMode_Enable); //启动定时器的被动触发
  	TIM_ITConfig(TIM4, TIM_IT_CC1, ENABLE);        //打开中断

  	TIM_Cmd(TIM2, ENABLE);		  //启动TIM2
	TIM_Cmd(TIM4, ENABLE);
}
开发者ID:Alimjan2009,项目名称:FSM,代码行数:49,代码来源:pwd.c

示例13: Encoder_Init_TIM3

/**************************************************************************
函数功能:把TIM4初始化为编码器接口模式
入口参数:无
返回  值:无
**************************************************************************/
void Encoder_Init_TIM3(void)
{
	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;  
  TIM_ICInitTypeDef TIM_ICInitStructure;  
  GPIO_InitTypeDef GPIO_InitStructure;
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);//使能定时器3的时钟
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);//使能PA端口时钟
	
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;	//端口配置
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入
  GPIO_Init(GPIOA, &GPIO_InitStructure);					      //根据设定参数初始化GPIOA
  
  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
  TIM_TimeBaseStructure.TIM_Prescaler = 0x0; // 预分频器 
  TIM_TimeBaseStructure.TIM_Period = ENCODER_TIM_PERIOD; //设定计数器自动重装值
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;//选择时钟分频:不分频
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;////TIM向上计数  
  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
  TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);//使用编码器模式3
  TIM_ICStructInit(&TIM_ICInitStructure);
  TIM_ICInitStructure.TIM_ICFilter = 10;
  TIM_ICInit(TIM3, &TIM_ICInitStructure);
  TIM_ClearFlag(TIM3, TIM_FLAG_Update);//清除TIM的更新标志位
  TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
  //Reset counter
  TIM_SetCounter(TIM3,0);
  TIM_Cmd(TIM3, ENABLE); 
}
开发者ID:LYF-HXW,项目名称:BANLANCE-CAR,代码行数:33,代码来源:encoder.c

示例14: main

/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s)
       before to branch to application main. 
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */     
       
  /* TIM1 Configuration */
  TIM_Config();

  /* TIM1 configuration: Input Capture mode ---------------------
     The external signal is connected to TIM1 CH2 pin (PE.11)  
     The Rising edge is used as active edge,
     The TIM1 CCR2 is used to compute the frequency value 
  ------------------------------------------------------------ */

  TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
  TIM_ICInitStructure.TIM_ICFilter = 0x0;

  TIM_ICInit(TIM1, &TIM_ICInitStructure);
  
  /* TIM enable counter */
  TIM_Cmd(TIM1, ENABLE);

  /* Enable the CC2 Interrupt Request */
  TIM_ITConfig(TIM1, TIM_IT_CC2, ENABLE);

  while (1);
}
开发者ID:scottmnowakowski,项目名称:sensor_suite,代码行数:40,代码来源:main.c

示例15: TIM8_Encoder_Init

void TIM8_Encoder_Init()
{
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);
	TIM_DeInit(TIM8);
	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
	TIM_ICInitTypeDef TIM_ICInitStructure;
     
	TIM_TimeBaseStructure.TIM_Prescaler = 0;
	TIM_TimeBaseStructure.TIM_Period = 0xFFFFFFFF; // Max value for encoder pulse
	TIM_TimeBaseStructure.TIM_ClockDivision = 0;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
	TIM_EncoderInterfaceConfig(TIM8, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
	TIM_ICStructInit(&TIM_ICInitStructure);
	TIM_ICInitStructure.TIM_ICFilter = 0;
	TIM_ICInit(TIM8, &TIM_ICInitStructure);
	//	TIM_SetAutoreload(TIM2, 0xFFFF);
	TIM_SetCounter(TIM8, 0);
	TIM_Cmd(TIM8, ENABLE);
	GPIO_InitTypeDef GPIO_InitStruct;
	GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
	GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_Init(GPIOC, &GPIO_InitStruct);
	GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_4);
	GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_4);
}
开发者ID:vincentwenxuan,项目名称:smores_document,代码行数:30,代码来源:main.cpp


注:本文中的TIM_ICInit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。