Exemplo n.º 1
0
void TIM_Configuration (void)
{

	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);		     //-----TIM7
	NVIC_InitStructure.NVIC_IRQChannel =TIM7_IRQn;	
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;	 //使能优先级
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =2;			//配置抢断优先级	2
	NVIC_InitStructure.NVIC_IRQChannelSubPriority =1;		   //配置响应优先级	  0
	NVIC_Init(&NVIC_InitStructure); 	
	NVIC_SetVectorTable (NVIC_VectTab_FLASH ,0x0);	 //设置存入寄存器             设置向量表的位置和偏移???????????????????????
	
	TIM_TimeBaseStructure.TIM_Period =9999;   //设置计数溢出大小,每计2000个数就产生一个更新事件
	TIM_TimeBaseStructure.TIM_Prescaler =7199;	   //预分频系数为36000-1,这样计数器时钟为72MHz/36000 = 2kHz
	TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;   //设置时钟分割 TIM_CKD_DIV1=0x0000,不分割
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up ;	  //设置计数器模式为向上计数模式
	TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
	TIM_TimeBaseInit(TIM7,&TIM_TimeBaseStructure); //将配置应用到TIM7中
		
	TIM_UpdateRequestConfig( TIM7, TIM_UpdateSource_Regular);	
	TIM_Cmd(TIM7, ENABLE); //使能计数器
	TIM_ITConfig(TIM7,TIM_IT_Update,ENABLE);	//使能中断
	//TIM_ClearFlag(TIM7, TIM_FLAG_Update);//清除标志位
	

 }
// Configuration of TIM3
void config_tim3(void){
	
	// Enable TIM3 clock
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
	
	TIM_TimeBaseInitTypeDef TIM3_initStruct;
	NVIC_InitTypeDef NVIC_initStruct;
	
	// Configure TIM3 timer
	TIM3_initStruct.TIM_Prescaler		= TIM3_PRESCALAR;
	TIM3_initStruct.TIM_CounterMode		= TIM_CounterMode_Up;
	TIM3_initStruct.TIM_Period			= TIM3_PERIOD;
	TIM3_initStruct.TIM_ClockDivision	= TIM_CKD_DIV1;	
	TIM_TimeBaseInit(TIM3, &TIM3_initStruct);
	
	// Enable and set TIM3 Interrupt to the highest priority
	NVIC_initStruct.NVIC_IRQChannel						= TIM3_IRQn;
	NVIC_initStruct.NVIC_IRQChannelPreemptionPriority	= 0x01;
	NVIC_initStruct.NVIC_IRQChannelSubPriority			= 0x00;
	NVIC_initStruct.NVIC_IRQChannelCmd					= ENABLE;
	NVIC_Init(&NVIC_initStruct);
	
	TIM_UpdateRequestConfig(TIM3, TIM_UpdateSource_Regular);
	TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
	TIM_Cmd(TIM3, ENABLE);
}
Exemplo n.º 3
0
/*************************************************************************
 * Function Name: Init
 * Description: initialize FPS timer settings.  This timer has a step size of 100us
 *
 *************************************************************************/
void Timers::Init()
{
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  GPIO_InitTypeDef GPIO_InitStructure;
  
   /* Compute the prescaler value */
  uint16_t PrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 10000);
  
  //Timer Configuration
  TIM_TimeBaseStructure.TIM_Period = 65536;
  TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); 
  TIM_ARRPreloadConfig(TIM2, DISABLE);
 
  /* TIM Interrupts enable */
  TIM_UpdateRequestConfig(TIM2, TIM_UpdateSource_Regular);

  /* TIM3 enable counter */
  TIM_Cmd(TIM2, ENABLE);
  
  // enable debug output pin if active
  if(TimerOutEnable)
  {
    GPIO_InitStructure.GPIO_Pin =  TIMER_MASK;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_Init(TIMER_PORT, &GPIO_InitStructure);
  }
}
void setup_dma_timer(void)
{
        /* We use Timer 7 */
        TIM_TypeDef* const timer = TIM7;

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);
        TIM_DeInit(timer);

        TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
        TIM_TimeBaseStructInit(&TIM_TimeBaseInitStructure);
        /* Proc is 168MHz, so prescalar is 168 - 1 to make clock 1MHz */
        TIM_TimeBaseInitStructure.TIM_Prescaler = 167;
        /* With above clock, each tick is 1 us. We want interrupts every 1ms */
        TIM_TimeBaseInitStructure.TIM_Period = 1000;
        TIM_TimeBaseInit(timer, &TIM_TimeBaseInitStructure);

        TIM_UpdateDisableConfig(timer, DISABLE);
        TIM_UpdateRequestConfig(timer, TIM_UpdateSource_Global);

        NVIC_InitTypeDef NVIC_InitStructure;
        NVIC_InitStructure.NVIC_IRQChannel = TIM7_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = DMA_IRQ_PRIORITY;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
        TIM_ITConfig(timer, TIM_IT_Update, ENABLE);

        TIM_Cmd(timer, ENABLE);
}
Exemplo n.º 5
0
static void init_dbg_watchdog( void )
{
    TIM_TimeBaseInitTypeDef tim_time_base_init_struct;

    RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM7, ENABLE  );
    RCC_APB1PeriphResetCmd( RCC_APB1Periph_TIM7, DISABLE );

    /* Set dbg_watchdog timeout to 90% of the actual watchdog timeout to ensure it break before the actual watchdog bites
     * Timeout calculation
     * - Period per TIM clock cycle : 120MHz (CPU clock) / 2 (APB1 pre-scaler) / DBG_WATCHDOG_PRESCALER = 2.5ms
     *                                DBG_WATCHDOG_PRESCALER = 24000
     * - Timeout                    : ( 0.9 * 2.5ms * 1000 ) * timeout_in_seconds
     *                                DBG_WATCHDOG_TIMEOUT_MULTIPLIER =  ( 0.9 * 2.5ms * 1000 ) = 2250
     */

    tim_time_base_init_struct.TIM_Prescaler         = DBG_WATCHDOG_PRESCALER;
    tim_time_base_init_struct.TIM_CounterMode       = TIM_CounterMode_Up;
    tim_time_base_init_struct.TIM_Period            = DBG_WATCHDOG_TIMEOUT;
    tim_time_base_init_struct.TIM_ClockDivision     = TIM_CKD_DIV1;
    tim_time_base_init_struct.TIM_RepetitionCounter = 0;
    TIM_TimeBaseInit( TIM7, &tim_time_base_init_struct );

    TIM_ClearITPendingBit( TIM7, TIM_IT_Update );
    TIM_ITConfig( TIM7, TIM_IT_Update, ENABLE );

    TIM_UpdateRequestConfig( TIM7, TIM_UpdateSource_Regular );

    NVIC_EnableIRQ( TIM7_IRQn );

    TIM_Cmd( TIM7, ENABLE );
}
Exemplo n.º 6
0
void hw::spindle::initialize()
{
	// Index pin
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_StructInit(&GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin = _index_pin;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
	GPIO_Init(_index_port, &GPIO_InitStructure);

	// Get system frequency
	RCC_ClocksTypeDef RCC_Clocks;
	RCC_GetClocksFreq(&RCC_Clocks);

	// Setup timer for index pin
	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
	TIM_DeInit(_index_timer);

	// Tick every 0.1ms
	TIM_TimeBaseStructure.TIM_Prescaler = (RCC_Clocks.HCLK_Frequency / 10000)
			- 1;
	TIM_TimeBaseStructure.TIM_Period = 0xffff;
	TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
	TIM_TimeBaseInit(_index_timer, &TIM_TimeBaseStructure);

	// Configure capture
	TIM_ICInitTypeDef TIM_ICInitStructure;
	TIM_ICStructInit(&TIM_ICInitStructure);

	TIM_ICInitStructure.TIM_Channel = TIM_Channel_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 = 2;
	TIM_ICInit(_index_timer, &TIM_ICInitStructure);

	// Configure slave mode, reset on capture
	TIM_SelectSlaveMode(_index_timer, TIM_SlaveMode_Reset);
	TIM_SelectInputTrigger(_index_timer, TIM_TS_TI1FP1);

	// We don't want capture event to generate update interrupt.
	// Update interrupt is used to detect cases when spindle speed is too low
	// (or spindle is stopped)
	TIM_UpdateRequestConfig(_index_timer, TIM_UpdateSource_Regular);

	// Configure interrupts
	TIM_ClearITPendingBit(_index_timer, TIM_IT_Update | TIM_IT_CC1);
	TIM_ITConfig(_index_timer, TIM_IT_Update | TIM_IT_CC1, ENABLE);

	TIM_Cmd(_index_timer, ENABLE);
}
Exemplo n.º 7
0
/**
 * @brief miscTIM_run config miscTIM to run with msec interrupt periodically.
 * @param TIM_Typedef* miscTIM, can be only basic timer (TM6 and TM7)
 * @param uint16_t prescaler
 * @param uint16_t reloadVal
 * @return void
 */
 void miscTIM_run (TIM_TypeDef* miscTIM, uint16_t prescaler, uint16_t reloadVal){
    /**< declare vars */
    bool isTIM6;
    uint32_t PCLK1, prescaler_x_reloadVal;
    RCC_ClocksTypeDef clocksStruct;
    NVIC_InitTypeDef nvicStruct;


    /**< check condition */
    if ( miscTIM == TIM6)
        isTIM6 = true;
    else if (miscTIM == TIM7)
        isTIM6 = false;
    else
        return;

    /**< init miscTIM in update mode with prescaler and reloadVal */
    RCC_APB1PeriphClockCmd ( (isTIM6 ? RCC_APB1Periph_TIM6 : RCC_APB1Periph_TIM7), ENABLE );

    TIM_ARRPreloadConfig (miscTIM, ENABLE);
    TIM_ITConfig (miscTIM, TIM_IT_Update, ENABLE);
    TIM_PrescalerConfig (miscTIM, prescaler, TIM_PSCReloadMode_Immediate);
    TIM_SetAutoreload (miscTIM, reloadVal);
    TIM_UpdateDisableConfig (miscTIM, DISABLE);
    TIM_UpdateRequestConfig (miscTIM, TIM_UpdateSource_Global);
    TIM_SelectOnePulseMode (miscTIM, TIM_OPMode_Repetitive);

    TIM_Cmd (miscTIM, ENABLE);

    /**< init NVIC TIM6 channel */
    nvicStruct.NVIC_IRQChannel = TIM6_IRQn;
    nvicStruct.NVIC_IRQChannelCmd = ENABLE;
    nvicStruct.NVIC_IRQChannelPreemptionPriority = 0x0F;
    nvicStruct.NVIC_IRQChannelSubPriority = 0x0F;

    NVIC_Init (&nvicStruct);


    /**< calculate miscTIM_period */
    RCC_GetClocksFreq (&clocksStruct);
    PCLK1 = clocksStruct.PCLK1_Frequency;

    PCLK1 /= 1000;

    prescaler_x_reloadVal = prescaler*reloadVal;

    miscTIM_period = prescaler_x_reloadVal / PCLK1;


    return;
}
void TIM7_Configuration(int period)
{

	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; 
	
	TIM_TimeBaseStructure.TIM_Prescaler = 36 - 1;				//??????36000-1,????????72MHz/36000 = 2kHz
	TIM_TimeBaseStructure.TIM_ClockDivision = 0;					//?????? TIM_CKD_DIV1=0x0000,???
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up ; 	//??????????????
	TIM_TimeBaseStructure.TIM_Period = period;		 			//????????,??1000???????????
	
	TIM_TimeBaseInit(TIM7,&TIM_TimeBaseStructure);		  			//??????TIM7?
	
	TIM_UpdateRequestConfig( TIM7, TIM_UpdateSource_Regular);

	TIM_Cmd(TIM7, ENABLE);											//?????
	TIM_ITConfig(TIM7,TIM_IT_Update,ENABLE);						//????
}
Exemplo n.º 9
0
/**
  * @brief  Initialize the RC5 decoder module ( Time range)
  * @param  None
  * @retval None
  */
void RC5_Init(void)
{ 
  GPIO_InitTypeDef GPIO_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
  TIM_ICInitTypeDef TIM_ICInitStructure;
  
  /*  Clock Configuration for TIMER */
  RCC_APB1PeriphClockCmd(IR_TIM_CLK , ENABLE);

  /* Enable Button GPIO clock */
  RCC_AHBPeriphClockCmd(IR_GPIO_PORT_CLK , ENABLE);
 
  /* Pin configuration: input floating */
  GPIO_InitStructure.GPIO_Pin = IR_GPIO_PIN;
  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
  GPIO_Init(IR_GPIO_PORT, &GPIO_InitStructure);
  
  GPIO_PinAFConfig( IR_GPIO_PORT,IR_GPIO_SOURCE,GPIO_AF_2);
  
  /* Enable the TIM global Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = IR_TIM_IRQn ;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
    
  /* TIMER frequency input */
  TIM_PrescalerConfig(IR_TIM, TIM_PRESCALER, TIM_PSCReloadMode_Immediate);
  
  TIM_ICStructInit(&TIM_ICInitStructure);
  
  /* TIM configuration */
  TIM_ICInitStructure.TIM_Channel = IR_TIM_Channel;
  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_PWMIConfig(IR_TIM, &TIM_ICInitStructure); 

  /* Timer Clock */
  TIMCLKValueKHz = TIM_GetCounterCLKValue()/1000; 

  /* Select the TIM Input Trigger: TI2FP2 */
  TIM_SelectInputTrigger(IR_TIM, TIM_TS_TI2FP2);

  /* Select the slave Mode: Reset Mode */
  TIM_SelectSlaveMode(IR_TIM, TIM_SlaveMode_Reset);

  /* Enable the Master/Slave Mode */
  TIM_SelectMasterSlaveMode(IR_TIM, TIM_MasterSlaveMode_Enable);

  /* Configures the TIM Update Request Interrupt source: counter overflow */
  TIM_UpdateRequestConfig(IR_TIM,  TIM_UpdateSource_Regular);
   
  RC5TimeOut = TIMCLKValueKHz * RC5_TIME_OUT_US/1000;

  /* Set the TIM auto-reload register for each IR protocol */
  IR_TIM->ARR = RC5TimeOut;
  
  /* Clear update flag */
  TIM_ClearFlag(IR_TIM, TIM_FLAG_Update);

  /* Enable TIM Update Event Interrupt Request */
  TIM_ITConfig(IR_TIM, TIM_IT_Update, ENABLE);
    
  /* Enable the CC2/CC1 Interrupt Request */
  TIM_ITConfig(IR_TIM, TIM_IT_CC2, ENABLE);
    /* Enable the CC2/CC1 Interrupt Request */
  TIM_ITConfig(IR_TIM, TIM_IT_CC1, ENABLE);

  /* Enable the timer */
  TIM_Cmd(IR_TIM, ENABLE);  
  
  if (CECDemoStatus == 0)
  {
    /* Set the LCD Back Color */
    LCD_SetBackColor(LCD_COLOR_RED);
    
    /* Set the LCD Text Color */
    LCD_SetTextColor(LCD_COLOR_GREEN);    
    LCD_DisplayStringLine(LCD_LINE_0, "   STM320518-EVAL   ");
    LCD_DisplayStringLine(LCD_LINE_1, " RC5 InfraRed Demo  ");
    LCD_SetBackColor(LCD_COLOR_BLUE);
    
    /* Set the LCD Text Color */
    LCD_SetTextColor(LCD_COLOR_WHITE);  
  }
  
  /* Bit time range */
  RC5MinT = (RC5_T_US - RC5_T_TOLERANCE_US) * TIMCLKValueKHz / 1000;
  RC5MaxT = (RC5_T_US + RC5_T_TOLERANCE_US) * TIMCLKValueKHz / 1000;
  RC5Min2T = (2 * RC5_T_US - RC5_T_TOLERANCE_US) * TIMCLKValueKHz / 1000;
  RC5Max2T = (2 * RC5_T_US + RC5_T_TOLERANCE_US) * TIMCLKValueKHz / 1000;
  
  /* Default state */
  RC5_ResetPacket();
}
Exemplo n.º 10
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
}
Exemplo n.º 11
0
/******************************************************************************
 * TIM1 Initialization Code Template
******************************************************************************/
void TIM1_Init()
{
    TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
    
    #if (((STRCMP($ch1CCSel$, CH1_Cap_Func) == 1) && (STRCMP($ch1CCEnable$, ENABLE) == 1)) || \
	((STRCMP($ch2CCSel$, CH2_Cap_Func) == 1) && (STRCMP($ch2CCEnable$, ENABLE) == 1)) || \
	((STRCMP($ch3CCSel$, CH3_Cap_Func) == 1) && (STRCMP($ch3CCEnable$, ENABLE) == 1)) || \
	((STRCMP($ch4CCSel$, CH4_Cap_Func) == 1) && (STRCMP($ch4CCEnable$, ENABLE) == 1)))
    TIM_ICInitTypeDef TIM_ICInitStruct;
    #endif
    #if (((STRCMP($ch1CCSel$, CH1_Comp_Func) == 1) && (STRCMP($ch1CCEnable$, ENABLE) == 1)) || \
	((STRCMP($ch2CCSel$, CH2_Comp_Func) == 1) && (STRCMP($ch2CCEnable$, ENABLE) == 1)) || \
	((STRCMP($ch3CCSel$, CH3_Comp_Func) == 1) && (STRCMP($ch3CCEnable$, ENABLE) == 1)) || \ 
	((STRCMP($ch4CCSel$, CH4_Comp_Func) == 1) && (STRCMP($ch4CCEnable$, ENABLE) == 1)))
    TIM_OCInitTypeDef TIM_OCInitStruct;
    #endif
  
    #if(STRCMP($brkInt$ ,ENABLE) == 1 || STRCMP($upInt$ ,ENABLE) == 1 || STRCMP($tcInt$ ,0) == 0 || STRCMP($ccInt$ ,0) == 0) 
    NVIC_InitTypeDef NVIC_InitStructure;
	#endif
	
    //PUT_A_NEW_LINE_HERE
    //
    // Enable peripheral clock of TIM1
    //
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);  

    //PUT_A_NEW_LINE_HERE
    //
    // Time base configuration
    //
    TIM_TimeBaseStructInit(&TIM_TimeBaseInitStruct);
    TIM_TimeBaseInitStruct.TIM_Period = $counterPeriod$;
    TIM_TimeBaseInitStruct.TIM_Prescaler = $prescaler$;
    TIM_TimeBaseInitStruct.TIM_ClockDivision = $clockDivision$;
    TIM_TimeBaseInitStruct.TIM_CounterMode = $counterMode$;
    TIM_TimeBaseInitStruct.TIM_RepetitionCounter = $repetition$;
    TIM_TimeBaseInit(TIM1, &TIM_TimeBaseInitStruct);
    
    #if (STRCMP($ch1CCEnable$, ENABLE) == 1)
    //PUT_A_NEW_LINE_HERE
    #if (STRCMP($ch1CCSel$, CH1_Cap_Func) == 1)
    //
    // TIM1 Channel 1 Input Configuration
    //
    TIM_ICStructInit(&TIM_ICInitStruct);
    TIM_ICInitStruct.TIM_Channel = TIM_Channel_1;
    TIM_ICInitStruct.TIM_ICPolarity = $ch1ICPol$;
    TIM_ICInitStruct.TIM_ICSelection = $ch1ICSel$;
    TIM_ICInitStruct.TIM_ICPrescaler = $ch1ICPSC$;
    TIM_ICInitStruct.TIM_ICFilter = $ch1ICFilter$;
    TIM_ICInit(TIM1, &TIM_ICInitStruct);
    #endif
    
    #if (STRCMP($ch1CCSel$, CH1_Comp_Func) ==1)
    //
    // TIM1 Channel 1 Output configuration
    //
    TIM_OCStructInit(&TIM_OCInitStruct);
    TIM_OCInitStruct.TIM_OCMode = $ch1OutputMode$;
    TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStruct.TIM_Pulse = $ch1PsValue$;
    TIM_OCInitStruct.TIM_OCPolarity = $ch1OCPol$;
    TIM_OCInitStruct.TIM_OCIdleState = $ch1IdleState$;
    TIM_OC1Init(TIM1, &TIM_OCInitStruct);
    TIM_ForcedOC1Config(TIM1, $ch1ForceAction$);
    #if (STRCMP($ch1CCRPreload$, ENABLE) == 1)
    TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
    #endif
    #if (STRCMP($ch1OREFClear$, ENABLE) == 1)
    TIM_ClearOC1Ref(TIM1, TIM_OCClear_Enable);
    #endif
    #endif
    
    #endif
        
    #if (STRCMP($ch2CCEnable$, ENABLE) == 1)
    //PUT_A_NEW_LINE_HERE
    #if (STRCMP($ch2CCSel$, CH2_Cap_Func) == 1)
    //
    // TIM1 Channel 2 Input Configuration
    //
    TIM_ICStructInit(&TIM_ICInitStruct);
    TIM_ICInitStruct.TIM_Channel = TIM_Channel_2;
    TIM_ICInitStruct.TIM_ICPolarity = $ch2ICPol$;
    TIM_ICInitStruct.TIM_ICSelection = $ch2ICSel$;
    TIM_ICInitStruct.TIM_ICPrescaler = $ch2ICPSC$;
    TIM_ICInitStruct.TIM_ICFilter = $ch2ICFilter$;
    TIM_ICInit(TIM1, &TIM_ICInitStruct);
    #endif
    
    #if (STRCMP($ch2CCSel$, CH2_Comp_Func) ==1)
    //
    // TIM1 Channel 2 Output configuration
    //
    TIM_OCStructInit(&TIM_OCInitStruct);
    TIM_OCInitStruct.TIM_OCMode = $ch2OutputMode$;
    TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStruct.TIM_Pulse = $ch2PsValue$;
    TIM_OCInitStruct.TIM_OCPolarity = $ch2OCPol$;
    TIM_OCInitStruct.TIM_OCIdleState = $ch2IdleState$;
    TIM_OC2Init(TIM1, &TIM_OCInitStruct);
    TIM_ForcedOC2Config(TIM1, $ch2ForceAction$);
    #if (STRCMP($ch2CCRPreload$, ENABLE) == 1)
    TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable);
    #endif
    #if (STRCMP($ch2OREFClear$, ENABLE) == 1)
    TIM_ClearOC2Ref(TIM1, TIM_OCClear_Enable);
    #endif
    #endif
    
    #endif
        
    #if (STRCMP($ch3CCEnable$, ENABLE) == 1)
    //PUT_A_NEW_LINE_HERE
    #if (STRCMP($ch3CCSel$, CH3_Cap_Func) == 1)
    //
    // TIM1 Channel 3 Input Configuration
    //
    TIM_ICStructInit(&TIM_ICInitStruct);
    TIM_ICInitStruct.TIM_Channel = TIM_Channel_3;
    TIM_ICInitStruct.TIM_ICPolarity = $ch3ICPol$;
    TIM_ICInitStruct.TIM_ICSelection = $ch3ICSel$;
    TIM_ICInitStruct.TIM_ICPrescaler = $ch3ICPSC$;
    TIM_ICInitStruct.TIM_ICFilter = $ch3ICFilter$;
    TIM_ICInit(TIM1, &TIM_ICInitStruct);
    #endif
    
    #if (STRCMP($ch3CCSel$, CH3_Comp_Func) ==1)
    //
    // TIM1 Channel 3 Output configuration
    //
    TIM_OCStructInit(&TIM_OCInitStruct);
    TIM_OCInitStruct.TIM_OCMode = $ch3OutputMode$;
    TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStruct.TIM_Pulse = $ch3PsValue$;
    TIM_OCInitStruct.TIM_OCPolarity = $ch3OCPol$;
    TIM_OCInitStruct.TIM_OCIdleState = $ch3IdleState$;
    TIM_OC3Init(TIM1, &TIM_OCInitStruct);
    TIM_ForcedOC3Config(TIM1, $ch3ForceAction$);
    #if (STRCMP($ch3CCRPreload$, ENABLE) == 1)
    TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Enable);
    #endif
    #if (STRCMP($ch3OREFClear$, ENABLE) == 1)
    TIM_ClearOC3Ref(TIM1, TIM_OCClear_Enable);
    #endif
    #endif
    
    #endif
        
    #if (STRCMP($ch4CCEnable$, ENABLE) == 1)
    //PUT_A_NEW_LINE_HERE
    #if (STRCMP($ch4CCSel$, CH4_Cap_Func) == 1)
    //
    // TIM1 Channel 4 Input Configuration
    //
    TIM_ICStructInit(&TIM_ICInitStruct);
    TIM_ICInitStruct.TIM_Channel = TIM_Channel_4;
    TIM_ICInitStruct.TIM_ICPolarity = $ch4ICPol$;
    TIM_ICInitStruct.TIM_ICSelection = $ch4ICSel$;
    TIM_ICInitStruct.TIM_ICPrescaler = $ch4ICPSC$;
    TIM_ICInitStruct.TIM_ICFilter = $ch4ICFilter$;
    TIM_ICInit(TIM1, &TIM_ICInitStruct);
    #endif
    
    #if (STRCMP($ch4CCSel$, CH4_Comp_Func) ==1)
    //
    // TIM1 Channel 4 Output configuration
    //
    TIM_OCStructInit(&TIM_OCInitStruct);
    TIM_OCInitStruct.TIM_OCMode = $ch4OutputMode$;
    TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStruct.TIM_Pulse = $ch4PsValue$;
    TIM_OCInitStruct.TIM_OCPolarity = $ch4OCPol$;
    TIM_OCInitStruct.TIM_OCIdleState = $ch4IdleState$;
    TIM_OC4Init(TIM1, &TIM_OCInitStruct);
    TIM_ForcedOC4Config(TIM1, $ch4ForceAction$);
    #if (STRCMP($ch4CCRPreload$, ENABLE) == 1)
    TIM_OC4PreloadConfig(TIM1, TIM_OCPreload_Enable);
    #endif
    #if (STRCMP($ch4OREFClear$, ENABLE) == 1)
    TIM_ClearOC4Ref(TIM1, TIM_OCClear_Enable);
    #endif
    #endif
    
    #endif
    
    #if (STRCMP($upEVDis$, ENABLE) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    // Enable the Update event
    //
    TIM_UpdateDisableConfig(TIM1, DISABLE);
    TIM_UpdateRequestConfig(TIM1, $requestIntSrc$);
    #endif
    
    #if ((STRCMP($extTriEnable$, ENABLE) == 1) && (STRCMP($extClkEnable$, ENABLE) == 1))
	#if (STRCMP($extClkMode$, MODE1) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    // ETR clock Mode1 Config
    //
    TIM_ETRClockMode1Config(TIM1, $exTriPSCSet$, $exTriPolSet$, $exTriFilterSet$);
    #endif
    #if (STRCMP($extClkMode$, MODE2) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    // ETR clock Mode2 Config
    //
    TIM_ETRClockMode2Config(TIM1, $exTriPSCSet$, $exTriPolSet$, $exTriFilterSet$);
    #endif
	#endif
	
	#if ((STRCMP($intTriEnable$, ENABLE) == 1) && (STRCMP($extClkEnable$, ENABLE) == 1))
    //PUT_A_NEW_LINE_HERE
    //
    // ITR clock Config
    //
    TIM_ITRxExternalClockConfig(TIM1, $intTriSrc$);
	#endif
	
    #if (STRCMP($mmEnable$, ENABLE) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    // Master Mode selection
    //
    TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable);
    #endif    
    
    #if (STRCMP($smEnable$, ENABLE) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    // Slave Mode selection
    //
    TIM_SelectSlaveMode(TIM1, $smSel$);
    #endif
    
    #if (STRCMP($hsiEnable$, ENABLE) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    // Enable Hall Sensor Interface
    //
    TIM_SelectHallSensor(TIM1, ENABLE);
    #endif
    
    #if (STRCMP($spmEnable$, ENABLE) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    // Single Pulse Mode selection
    //
    TIM_SelectOnePulseMode(TIM1, $spmSet$);
	#endif
	
	#if (STRCMP($tomEnable$, ENABLE) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    // Trigger Output Mode selection
    //
    TIM_SelectOutputTrigger(TIM1, $tomSrc$);
	#endif
    
    #if (STRCMP($eimEnable$, ENABLE) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    // Encoder Interface Mode selection
    //
    TIM_EncoderInterfaceConfig(TIM1, $eimSet$,
                                $encodeIC1Polar$, $encodeIC2Polar$);
	#endif
	
    //PUT_A_NEW_LINE_HERE
    //
    // Enable TIM1 
    //
    TIM_Cmd(TIM1, ENABLE);

    
    #if(STRCMP($brkInt$, ENABLE) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    // Enable BRK Interrupt
    //
    TIM_ITConfig(TIM1, TIM_IT_Break, ENABLE);
    NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
    #endif
	
	#if(STRCMP($upInt$, ENABLE) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    // Enable UP Interrupt
    //
    TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);
    NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
    #endif
	
	#if(STRCMP($tcInt$, 0) == 0)
    //PUT_A_NEW_LINE_HERE
    //
    // Enable TRG/COM Interrupt
    //
    TIM_ITConfig(TIM1, $TCInt$, ENABLE);
    NVIC_InitStructure.NVIC_IRQChannel = TIM1_TRG_COM_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
    #endif
	
	#if(STRCMP($ccInt$, 0) == 0)
    //PUT_A_NEW_LINE_HERE
    //
    // Enable CC Interrupt
    //
    TIM_ITConfig(TIM1, $CCInt$, ENABLE);
    NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
    #endif
}