Example #1
0
void configuration_timer(void)
{

	  TIM_TimeBaseInitTypeDef TIM3_TimeBase;                      // Time Base structure

	  TIM3_TimeBase.TIM_ClockDivision=TIM_CKD_DIV1;
	  TIM3_TimeBase.TIM_RepetitionCounter = 0;                        // Not dividing
	  TIM3_TimeBase.TIM_CounterMode   = TIM_CounterMode_Up;       // Upcounting configuration
	  TIM3_TimeBase.TIM_Period        = TIM_PERIOD;               // Autoreload value (ARR)
	  TIM3_TimeBase.TIM_Prescaler     = 0;            // dividing APB1 by 2
	  TIM_TimeBaseInit(TIM3, &TIM3_TimeBase);                     // Initializing Time Base structure

	  TIM_TIxExternalClockConfig(TIM3, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Rising, 0);
	/*  TIM_OCInitTypeDef       TIM3_OC;                            // Output Compare structure

	  TIM3_OC.TIM_OCMode      = TIM_OCMode_PWM2;                  // Edge-aligned mode
	  //TIM_OCMode_Active
	  TIM3_OC.TIM_OutputState = TIM_OutputState_Enable;           // Enabling the Output Compare state
	  TIM3_OC.TIM_OCPolarity  = TIM_OCPolarity_High;              // Regular polarity (low will inverse it)
	  TIM3_OC.TIM_Pulse       = TIM_PULSE_CH1;                    // Output Compare 1 reg value
	  TIM_OC1Init(TIM3, &TIM3_OC);                                // Initializing Output Compare 1 structure
	  TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Disable);          // Disabling Ch.1 Output Compare preload*/

/*	  TIM3_OC.TIM_OutputState = TIM_OutputState_Enable;           // Enabling again in case the values changed
	  TIM3_OC.TIM_Pulse       = TIM_PULSE_CH1;                    // Output Compare 2 reg value
	  TIM_OC2Init(TIM3, &TIM3_OC);                                // Initializing Output Compare 2 structure
	  TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Disable);          // Disabling Ch.2 Output Compare preload
	 */
	  TIM_Cmd(TIM3, ENABLE);                                      // Ready, Set, Go!
}
Example #2
0
void ausbee_encoder_init_timer(TIM_TypeDef *TIMX, uint8_t use_encoder_quadrature)
{
  if (use_encoder_quadrature)
  {
    // Set them up as encoder inputs
    // Set both inputs to rising polarity to let it use both edges
    TIM_EncoderInterfaceConfig(TIMX, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
    TIM_SetAutoreload(TIMX, 0xffff);

    // Turn on the timer/counters
    TIM_Cmd(TIMX, ENABLE);
  }
  else
  {
    TIM_TimeBaseInitTypeDef timeBaseInitTypeDef;

    TIM_TimeBaseStructInit(&timeBaseInitTypeDef);

    timeBaseInitTypeDef.TIM_Period = 0xFFFF;

    TIM_TimeBaseInit(TIMX, &timeBaseInitTypeDef);

    TIM_TIxExternalClockConfig(TIMX, TIM_TS_TI1FP1, TIM_ICPolarity_Rising, 0x0);

    TIM_Cmd(TIMX, ENABLE);
  }

  // Reset of the timer counter
  TIM_SetCounter(TIMX, 0);
}
Example #3
0
void Time4_TI1Config(void)
{
	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;  
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);
	TIM_DeInit(TIM4);
	
	TIM_TimeBaseStructure.TIM_Period =10;                               
	TIM_TimeBaseStructure.TIM_Prescaler = 0;
	TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;  
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  
	TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); 

	TIM_TIxExternalClockConfig(TIM4,TIM_TIxExternalCLK1Source_TI1,TIM_ICPolarity_Rising,0);

	TIM_ClearFlag(TIM4,TIM_IT_Update);
  TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE);
	
	TIM_ClearFlag(TIM4,TIM_IT_Trigger);
  TIM_ITConfig(TIM4,TIM_IT_Trigger,ENABLE);
	
	TIM_Cmd(TIM4, ENABLE); 
	
}
Example #4
0
/*************************************************************
 * TIM4 Initialization
**************************************************************/
void TIM4_Init()
{
	#if (STRCMP($tim4IntEn$, 0) == 0)
    NVIC_InitTypeDef NVIC_InitStructure;
	#endif

	#if (STRCMP($ch1_0Pin$, DISABLE) == 0 || STRCMP($ch1_1Pin$, DISABLE) == 0 || \
	STRCMP($ch2_0Pin$, DISABLE) == 0 || STRCMP($ch2_1Pin$, DISABLE) == 0 || \
    STRCMP($ch3_0Pin$, DISABLE) == 0 || STRCMP($ch3_1Pin$, DISABLE) == 0 || \
    STRCMP($ch4_0Pin$, DISABLE) == 0 || STRCMP($ch4_1Pin$, DISABLE) == 0)
    GPIO_InitTypeDef GPIO_InitStructure;
	#endif	

    TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
	
    #if ( (STRCMP($ch1En$, DISABLE) == 0 && STRCMP($ch1sel$, CAPTURE_ENABLE) == 0) || \
	(STRCMP($ch2En$, DISABLE) == 0 && STRCMP($ch2sel$, CAPTURE_ENABLE) == 0) || \
	(STRCMP($ch3En$, DISABLE) == 0 && STRCMP($ch3sel$, CAPTURE_ENABLE) == 0) || \
	(STRCMP($ch4En$, DISABLE) == 0 && STRCMP($ch4sel$, CAPTURE_ENABLE) == 0) )
    TIM_OCInitTypeDef  TIM_OCInitStructure;
	#endif

    #if ( (STRCMP($ch1En$, DISABLE) == 0 && STRCMP($ch1sel$, COMPARE_ENABLE) == 0) || \
	(STRCMP($ch2En$, DISABLE) == 0 && STRCMP($ch2sel$, COMPARE_ENABLE) == 0) || \
	(STRCMP($ch3En$, DISABLE) == 0 && STRCMP($ch3sel$, COMPARE_ENABLE) == 0) || \
	(STRCMP($ch4En$, DISABLE) == 0 && STRCMP($ch4sel$, COMPARE_ENABLE) == 0) )	
    TIM_ICInitTypeDef  TIM_ICInitStructure;
	#endif
	
	//PUT_A_NEW_LINE_HERE
    //
    // Enable TIM4 clock
    //	
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);

	#if (STRCMP($tim4PinRemap$, DEFAULT) == 0 )
    //PUT_A_NEW_LINE_HERE
    //
    // Enable TIM4's GPIOD, GPIOE, AFIO clock
    //	
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);
	#else
    //PUT_A_NEW_LINE_HERE
    //
    // Enable TIM4's GPIOB , GPIOE, AFIO clock
    //	
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);	
	#endif

	#if (STRCMP($tim4PinRemap$, DEFAULT) == 1)
	#if (STRCMP($ch1_0Pin$, DISABLE) == 0 || STRCMP($ch2_0Pin$, DISABLE) == 0 || STRCMP($ch3_0Pin$, DISABLE) == 0 || STRCMP($ch4_0Pin$, DISABLE) == 0)
    //   
    // Configure TIM4 pins: ETR, CH1, CH2, CH3, CH4, when Pin Remap is Default
    //
	#endif
	#if (STRCMP($etrPin$, DISABLE) == 0)
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOE, &GPIO_InitStructure);
	#endif
	#if (STRCMP($ch1_0Pin$, DISABLE) == 0)
    //PUT_A_NEW_LINE_HERE
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6;	
    #if (STRCMP($ch1sel$, CAPTURE_ENABLE) == 1)
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    #else
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    #endif
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
	#endif
	#if (STRCMP($ch2_0Pin$, DISABLE) == 0)
    //PUT_A_NEW_LINE_HERE
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_7;	
    #if (STRCMP($ch2sel$, CAPTURE_ENABLE) == 1)
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    #else
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    #endif
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
	#endif
	#if (STRCMP($ch3_0Pin$, DISABLE) == 0)
    //PUT_A_NEW_LINE_HERE
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_8;
    #if (STRCMP($ch3sel$, CAPTURE_ENABLE) == 1)
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    #else
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    #endif
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
	#endif
	#if (STRCMP($ch4_0Pin$, DISABLE) == 0)
    //PUT_A_NEW_LINE_HERE
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_9;
    #if (STRCMP($ch4sel$, CAPTURE_ENABLE) == 1)
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    #else
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    #endif
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
	#endif
	#endif
	
	#if (STRCMP($tim4PinRemap$, GPIO_Remap_TIM4) == 1)
    //   
    // Configure TIM4 pins: ETR, CH1, CH2, CH3, CH4, when Pin Remap is PartialRemap1
    // 
    GPIO_PinRemapConfig(GPIO_Remap_TIM4, ENABLE);
	#if (STRCMP($etrPin$, DISABLE) == 0)
    //PUT_A_NEW_LINE_HERE
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOE, &GPIO_InitStructure);
	#endif
	#if (STRCMP($ch1_1Pin$, DISABLE) == 0)
    //PUT_A_NEW_LINE_HERE
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_12;	
    #if (STRCMP($ch1sel$, CAPTURE_ENABLE) == 1)
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    #else
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    #endif
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
	#endif
	#if (STRCMP($ch2_1Pin$, DISABLE) == 0)
    //PUT_A_NEW_LINE_HERE
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_13;
    #if (STRCMP($ch2sel$, CAPTURE_ENABLE) == 1)
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    #else
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    #endif
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
	#endif
	#if (STRCMP($ch3_0Pin$, DISABLE) == 0)
    //PUT_A_NEW_LINE_HERE
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_14;
    #if (STRCMP($ch3sel$, CAPTURE_ENABLE) == 1)
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    #else
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    #endif
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
	#endif
	#if (STRCMP($ch4_0Pin$, DISABLE) == 0)
    //PUT_A_NEW_LINE_HERE
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_15;
    #if (STRCMP($ch4sel$, CAPTURE_ENABLE) == 1)
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    #else
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    #endif
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
	#endif
	#endif
	
	//PUT_A_NEW_LINE_HERE
    //
    // Initializes the TIM4 Time Base Unit
    //	
    TIM_TimeBaseStructure.TIM_Period = $tim4Period$;
    TIM_TimeBaseStructure.TIM_Prescaler = $tim4Psclr$;
    TIM_TimeBaseStructure.TIM_ClockDivision = $tim4ClkDiv$;
    TIM_TimeBaseStructure.TIM_CounterMode = $tim4CntMode$;
    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
	
    #if (STRCMP($tim4ARRMode$, DISABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Enables Preload register on ARR
    //	
    TIM_ARRPreloadConfig(TIM3, ENABLE);
	#endif	

    #if (STRCMP($ch1En$, DISABLE) == 0)
	
    #if (STRCMP($ch1sel$, CAPTURE_ENABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Initializes Output Compare Channel1 of the TIM4 
    //	
    TIM_OCInitStructure.TIM_OCMode = $oc1Mode$;
    TIM_OCInitStructure.TIM_OutputState = $oc1State$;
    TIM_OCInitStructure.TIM_Pulse = $oc1Pluse$;
    TIM_OCInitStructure.TIM_OCPolarity = $oc1Polar$;
    TIM_OC1Init(TIM4, &TIM_OCInitStructure);

    #if (STRCMP($oc1Preload$, DISABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Enables Preload register on CCR1
    //	
    TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
	#endif

    #if (STRCMP($oc1Preload$, DISABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Clears or safeguards the OCREF1 signal on an external event
    //	
	TIM_ClearOC1Ref(TIM4, TIM_OCClear_Enable);  
	#endif

    #if ( STRCMP($oc1FastEn$, DISABLE) == 0 && (STRCMP($oc1Mode$, TIM_OCMode_PWM1) == 1 || STRCMP($oc1Mode$, TIM_OCMode_PWM2) == 1) )
	//PUT_A_NEW_LINE_HERE
    //
    // Configures the TIM4 Output Compare Channel1 Fast feature
    //	
	TIM_OC1FastConfig(TIM4, TIM_OCClear_Enable);  
	#endif	
	#endif	

    #if (STRCMP($ch1sel$, COMPARE_ENABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Initializes Input Capture Channel1 of the TIM4 
    //	
    TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;                   
    TIM_ICInitStructure.TIM_ICPolarity = $ic1Polar$;     
    TIM_ICInitStructure.TIM_ICSelection = $ic1Sel$;
    TIM_ICInitStructure.TIM_ICPrescaler = $ic1Psc$;
    TIM_ICInitStructure.TIM_ICFilter = $ic1Filter$; 
    TIM_ICInit(TIM4, &TIM_ICInitStructure);
	#endif
    #endif
	
    #if (STRCMP($ch2En$, DISABLE) == 0)
	
    #if (STRCMP($ch2sel$, CAPTURE_ENABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Initializes Output Compare Channel2 of the TIM4 
    //	
    TIM_OCInitStructure.TIM_OCMode = $oc2Mode$;
    TIM_OCInitStructure.TIM_OutputState = $oc2State$;
    TIM_OCInitStructure.TIM_Pulse = $oc2Pluse$;
    TIM_OCInitStructure.TIM_OCPolarity = $oc2Polar$;
    TIM_OC2Init(TIM4, &TIM_OCInitStructure);

    #if (STRCMP($oc2Preload$, DISABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Enables Preload register on CCR2
    //	
    TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);
	#endif

    #if (STRCMP($oc2Preload$, DISABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Clears or safeguards the OCREF2 signal on an external event
    //	
	TIM_ClearOC2Ref(TIM4, TIM_OCClear_Enable);  
	#endif

    #if ( STRCMP($oc2FastEn$, DISABLE) == 0 && (STRCMP($oc2Mode$, TIM_OCMode_PWM1) == 1 || STRCMP($oc2Mode$, TIM_OCMode_PWM2) == 1) )
	//PUT_A_NEW_LINE_HERE
    //
    // Configures the TIM4 Output Compare Channel2 Fast feature
    //	
	TIM_OC2FastConfig(TIM4, TIM_OCClear_Enable);  
	#endif	
	#endif	

    #if (STRCMP($ch2sel$, COMPARE_ENABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Initializes Input Capture Channel2 of the TIM4
    //	
    TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;                   
    TIM_ICInitStructure.TIM_ICPolarity = $ic2Polar$;     
    TIM_ICInitStructure.TIM_ICSelection = $ic2Sel$;
    TIM_ICInitStructure.TIM_ICPrescaler = $ic2Psc$;
    TIM_ICInitStructure.TIM_ICFilter = $ic2Filter$; 
    TIM_ICInit(TIM4, &TIM_ICInitStructure);
	#endif
    #endif


    #if (STRCMP($ch3En$, DISABLE) == 0)
	
    #if (STRCMP($ch3sel$, CAPTURE_ENABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Initializes Output Compare Channel3 of the TIM4 
    //	
    TIM_OCInitStructure.TIM_OCMode = $oc3Mode$;
    TIM_OCInitStructure.TIM_OutputState = $oc3State$;
    TIM_OCInitStructure.TIM_Pulse = $oc3Pluse$;
    TIM_OCInitStructure.TIM_OCPolarity = $oc3Polar$;
    TIM_OC3Init(TIM4, &TIM_OCInitStructure);

    #if (STRCMP($oc3Preload$, DISABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Enables Preload register on CCR3
    //	
    TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);
	#endif

    #if (STRCMP($oc3Preload$, DISABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Clears or safeguards the OCREF3 signal on an external event
    //	
	TIM_ClearOC3Ref(TIM4, TIM_OCClear_Enable);  
	#endif

    #if ( STRCMP($oc3FastEn$, DISABLE) == 0 && (STRCMP($oc3Mode$, TIM_OCMode_PWM1) == 1 || STRCMP($oc3Mode$, TIM_OCMode_PWM2) == 1) )
	//PUT_A_NEW_LINE_HERE
    //
    // Configures the TIM4 Output Compare Channel3 Fast feature
    //	
	TIM_OC3FastConfig(TIM4, TIM_OCClear_Enable);  
	#endif	
	#endif	

    #if (STRCMP($ch3sel$, COMPARE_ENABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Initializes Input Capture Channel3 of the TIM4
    //	
    TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;                   
    TIM_ICInitStructure.TIM_ICPolarity = $ic3Polar$;     
    TIM_ICInitStructure.TIM_ICSelection = $ic3Sel$;
    TIM_ICInitStructure.TIM_ICPrescaler = $ic3Psc$;
    TIM_ICInitStructure.TIM_ICFilter = $ic3Filter$; 
    TIM_ICInit(TIM4, &TIM_ICInitStructure);
	#endif
    #endif


    #if (STRCMP($ch4En$, DISABLE) == 0)
	
    #if (STRCMP($ch4sel$, CAPTURE_ENABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Initializes Output Compare Channel4 of the TIM4 
    //	
    TIM_OCInitStructure.TIM_OCMode = $oc4Mode$;
    TIM_OCInitStructure.TIM_OutputState = $oc4State$;
    TIM_OCInitStructure.TIM_Pulse = $oc4Pluse$;
    TIM_OCInitStructure.TIM_OCPolarity = $oc4Polar$;
    TIM_OC4Init(TIM4, &TIM_OCInitStructure);

    #if (STRCMP($oc4Preload$, DISABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Enables Preload register on CCR4
    //	
    TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable);
	#endif

    #if (STRCMP($oc4Preload$, DISABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Clears or safeguards the OCREF4 signal on an external event
    //	
	TIM_ClearOC4Ref(TIM4, TIM_OCClear_Enable);  
	#endif

    #if ( STRCMP($oc4FastEn$, DISABLE) == 0 && (STRCMP($oc4Mode$, TIM_OCMode_PWM1) == 1 || STRCMP($oc4Mode$, TIM_OCMode_PWM2) == 1) )
	//PUT_A_NEW_LINE_HERE
    //
    // Configures the TIM4 Output Compare Channel4 Fast feature
    //	
	TIM_OC4FastConfig(TIM4, TIM_OCClear_Enable);  
	#endif	
	#endif	

    #if (STRCMP($ch4sel$, COMPARE_ENABLE) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Initializes Input Capture Channel4 of the TIM4
    //	
    TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;                   
    TIM_ICInitStructure.TIM_ICPolarity = $ic4Polar$;     
    TIM_ICInitStructure.TIM_ICSelection = $ic4Sel$;
    TIM_ICInitStructure.TIM_ICPrescaler = $ic4Psc$;
    TIM_ICInitStructure.TIM_ICFilter = $ic4Filter$; 
    TIM_ICInit(TIM4, &TIM_ICInitStructure);
	#endif
    #endif

    //PUT_A_NEW_LINE_HERE
    //
    // Enables TIM4 peripheral
    //	
    TIM_Cmd(TIM4, ENABLE);
	
    #if (STRCMP($masterEn$, DISABLE) == 0 && STRCMP($masterTRGOSrc$, None) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Selects the TIM4 Trigger Output Mode
    //	
    TIM_SelectOutputTrigger(TIM4, $masterTRGOSrc$);
	#endif	

    #if (STRCMP($slaveEn$, DISABLE) == 0 )
	//PUT_A_NEW_LINE_HERE
    //
    // Sets the TIM4 Master/Slave Mode
    //
    TIM_SelectMasterSlaveMode(TIM4, TIM_MasterSlaveMode_Enable);	
	#endif
	
    #if (STRCMP($slaveEn$, DISABLE) == 0 && STRCMP($slaveModeSet$, Disable(Internal Clock)) == 0)
	//PUT_A_NEW_LINE_HERE
    //
    // Selects the TIM4 Slave Mode
    //	
    TIM_SelectSlaveMode(TIM4, $slaveModeSet$);
	#endif
	
    #if (STRCMP($onePulseEn$, TIM_OPMode_Repetitive) == 0 )
	//PUT_A_NEW_LINE_HERE
    //
    // Selects the TIM4's One Pulse Mode
    //
    TIM_SelectOnePulseMode(TIM4, TIM_OPMode_Single);	
	#endif
	
    #if (STRCMP($hallSensorEn$, DISABLE) == 0 )
	//PUT_A_NEW_LINE_HERE
    //
    // Enables the TIM4's Hall sensor interface
    //
    TIM_SelectHallSensor(TIM4, ENABLE);	
	#endif
	
    #if (STRCMP($encoderEn$, DISABLE) == 0 )
	//PUT_A_NEW_LINE_HERE
    //
    // Configures the TIM4 Encoder Interface
    //
    TIM_EncoderInterfaceConfig(TIM4, $extiCh1OutputPin$,
                                $EncodeIC1Polar$, $EncodeIC2Polar$);
	#endif
		
	
    #if (STRCMP($interClkEn$, ENABLE) == 0 )

    #if (STRCMP($interTrigr$, DISABLE) == 0 )
    //PUT_A_NEW_LINE_HERE
    //
    // Configures the TIM4 Internal Trigger as External Clock
    //
    TIM_ITRxExternalClockConfig(TIM4, $interTrigr$);
	#endif

    #if (STRCMP($timxTrigr$, DISABLE) == 0 )
    //PUT_A_NEW_LINE_HERE
    //
    // Configures the TIM4 Trigger as External Clock
    //
    TIM_TIxExternalClockConfig(TIM4, $timxTrigr$, TIM_ICPolarity_Rising, 0x0);
	#endif
	
    #if (STRCMP($extTrigr$, DISABLE) == 0 )
    #if (STRCMP($extTrigr$, ExternalTriggerMode1) == 1 )
    //PUT_A_NEW_LINE_HERE
    //
    // Configures the External clock Mode1
    //
    TIM_ETRClockMode1Config(TIM4, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_Inverted, 0x0);
	#endif
    #if (STRCMP($extTrigr$, ExternalTriggerMode2) == 1 )
    //PUT_A_NEW_LINE_HERE
    //
    // Configures the External clock Mode2
    //
    TIM_ETRClockMode2Config(TIM4, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_Inverted, 0x0);
	#endif
	#endif
	#endif
	
    #if (STRCMP($evtUpdate$, DISABLE) == 0 )
    //PUT_A_NEW_LINE_HERE
    //
    // Enables the TIM4 Update event
    //
    TIM_UpdateRequestConfig(TIM4, $updateRqstSrc$);
    TIM_UpdateDisableConfig(TIM4, DISABLE);
	#endif

    #if (STRCMP($tim4IntEn$, 0) == 0 )
    //PUT_A_NEW_LINE_HERE
    //
    // Enables TIM4 interrupts
    //
    TIM_ITConfig(TIM4, $tim4IntEn$, ENABLE);
    NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
	#endif
	
    #if (STRCMP($tim4dmaEn$, DISABLE) == 0 )
    //PUT_A_NEW_LINE_HERE
    //
    // Enables the TIM4's DMA Requests
    //
    TIM_DMAConfig(TIM4, $dmaBaseAddr$, $dmaBurstLen$);
    #if (STRCMP($tim4dmaRqstSrc$, 0) == 0 )
    TIM_DMACmd(TIM4, $tim4dmaRqstSrc$, ENABLE);
	#endif
    TIM_SelectCCDMA(TIM4, ENABLE);	
	#endif
}