void pwm_init (void) { /* Time Base configuration */ TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 1199; // 24MHz clock, 24MHz/1200 = 20KHz TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); /* Channel 1, 2,3 Configuration in PWM mode */ TIM_OCInitTypeDef TIM_OCInitStructure; TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable; TIM_OCInitStructure.TIM_Pulse = 0; // start with 0% duty cycle TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; TIM_OC1Init(TIM1, &TIM_OCInitStructure); TIM_OC2Init(TIM1, &TIM_OCInitStructure); TIM_OC3Init(TIM1, &TIM_OCInitStructure); /* configure ETR for current control */ TIM_ETRConfig (TIM1, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0); TIM_ClearOC1Ref (TIM1, TIM_OCClear_Enable); TIM_ClearOC2Ref (TIM1, TIM_OCClear_Enable); TIM_ClearOC3Ref (TIM1, TIM_OCClear_Enable); /* TIM1 counter enable */ TIM_Cmd (TIM1, ENABLE); /* TIM1 Main Output Enable */ TIM_CtrlPWMOutputs (TIM1, ENABLE); }
/************************************************************* * 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 }
/****************************************************************************** * 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 }