本文整理汇总了C++中TIM_OCStructInit函数的典型用法代码示例。如果您正苦于以下问题:C++ TIM_OCStructInit函数的具体用法?C++ TIM_OCStructInit怎么用?C++ TIM_OCStructInit使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TIM_OCStructInit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TIM_Config
/**
* @brief TIM3 configuration
* @param None
* @retval None
*/
static void TIM_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
/* ADC1 Peripheral clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_DeInit(TIM3);
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_OCStructInit(&TIM_OCInitStructure);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 0xFF;
TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* TIM3 TRGO selection */
TIM_SelectOutputTrigger(TIM3, TIM_TRGOSource_Update);
/* TIM3 enable counter */
TIM_Cmd(TIM3, ENABLE);
}
示例2: MyMotor_TIM2_PWM_Config
void MyMotor_TIM2_PWM_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_IS;
TIM_OCInitTypeDef TIM_OC_IS;
TIM_TimeBaseStructInit(&TIM_IS);
TIM_OCStructInit(&TIM_OC_IS);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
TIM_IS.TIM_Period = 2000;
TIM_IS.TIM_Prescaler = 720;//PWM周期20ms 50Hz
TIM_IS.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_IS.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2,&TIM_IS);
TIM_OC_IS.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OC_IS.TIM_OutputState = TIM_OutputState_Enable;
TIM_OC_IS.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC_IS.TIM_Pulse = THROTTLE_BASE;
TIM_OC1Init(TIM2,&TIM_OC_IS);
TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable);
TIM_OC_IS.TIM_Pulse = THROTTLE_BASE;
TIM_OC2Init(TIM2,&TIM_OC_IS);
TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable);
TIM_OC_IS.TIM_Pulse = THROTTLE_BASE;
TIM_OC3Init(TIM2,&TIM_OC_IS);
TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable);
TIM_OC_IS.TIM_Pulse = THROTTLE_BASE;
TIM_OC4Init(TIM2,&TIM_OC_IS);
TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Enable);
}
示例3: motor_pwm_setup
void motor_pwm_setup(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM17, ENABLE);
TIM_TimeBaseInitTypeDef recue_tim;
TIM_TimeBaseStructInit(&recue_tim);
recue_tim.TIM_CounterMode = TIM_CounterMode_Down;
recue_tim.TIM_Period = 4000;
recue_tim.TIM_Prescaler = 48 - 1;
TIM_TimeBaseInit(TIM17, &recue_tim);
TIM_OCInitTypeDef pwm_motor_channel;
TIM_OCStructInit(&pwm_motor_channel);
pwm_motor_channel.TIM_OCMode = TIM_OCMode_PWM1;
pwm_motor_channel.TIM_OutputState = TIM_OutputState_Enable;
pwm_motor_channel.TIM_Pulse = MOTOR_PWM_PERIOD;
TIM_OC1Init(TIM17, &pwm_motor_channel);
TIM_OC1PreloadConfig(TIM17, ENABLE);
/* without enabling there will be no signal on corresponding channels */
TIM_CtrlPWMOutputs(TIM17, DISABLE);
TIM_Cmd(TIM17, DISABLE);
}
示例4: LedShow_Init
/*******************************************************************************
* Function Name : LedShow_Init
* Description : Configure the leds pins as output pushpull: LED1, LED2, LED3
* and LED4
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LedShow_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_OCStructInit(&TIM_OCInitStructure);
/* PF.06, PF.07, PF.08 and PF.09 as output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOF, &GPIO_InitStructure);
/* Time Base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 719;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = 0x270F;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/* Channel 1 Configuration in Timing mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
TIM_OCInitStructure.TIM_Pulse = 0x0;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
}
示例5: hwtm_ctrl_config
/******************************************************************************
* Function Name : hwtm_ctrl_config
* Description : Initialize the TIM Controller
* Input : None
* Output : None
* Return : 0
******************************************************************************/
int hwtm_ctrl_config(void) {
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
/* Enable TIM2 APB1 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
TIM_OCStructInit(&TIM_OCInitStructure);
/* TIM2 used for timing, the timing period depends on wav file sample rate */
TIM_TimeBaseStructure.TIM_Prescaler = 0x00; /* TIM2CLK = 72 MHz */
TIM_TimeBaseStructure.TIM_Period = tim_arr_val;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* Channel 1 Configuration in Timing mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
TIM_OCInitStructure.TIM_Pulse = 0x0;
TIM_OC1Init(TIM2, &TIM_OCInitStructure);
TIM_Cmd(TIM2, DISABLE);
return 0;
}
示例6: ausbeeInitServo
/**
* @brief Initialize the timer channel linked to the servo in PWM mode.
* @param servo: pointer to a ausbeeServo structure that contains the
* configuration information for the specified servo.
* @retval None
*/
void ausbeeInitServo(ausbeeServo* servo)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 1999;
TIM_TimeBaseStructure.TIM_Prescaler = 812;
#ifdef SLOW_MCU
TIM_TimeBaseStructure.TIM_Prescaler /= 5;
#endif
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(servo->TIMx, &TIM_TimeBaseStructure);
TIM_OCInitTypeDef OCInit_PWM; // Create a OCInitTypeDef for PWM
TIM_OCStructInit(&OCInit_PWM);
OCInit_PWM.TIM_OCMode = TIM_OCMode_PWM1; // Set PWM Mode
OCInit_PWM.TIM_Pulse = 1500; // Duty cycle to 5%
OCInit_PWM.TIM_OutputState = TIM_OutputState_Enable;
if(servo->CHANx == TIM_Channel_1)
TIM_OC1Init(servo->TIMx, &OCInit_PWM); // Initialize OSC1
else if(servo->CHANx == TIM_Channel_2)
TIM_OC2Init(servo->TIMx, &OCInit_PWM); // Initialize OSC2
else if(servo->CHANx == TIM_Channel_3)
TIM_OC3Init(servo->TIMx, &OCInit_PWM); // Initialize OSC3
else if(servo->CHANx == TIM_Channel_4)
TIM_OC4Init(servo->TIMx, &OCInit_PWM); // Initialize OSC4
}
示例7: RGBLED_Update
void RGBLED_Update(uint8_t RED_Val, uint8_t GREEN_Val, uint8_t BLUE_Val)
{
//printf("r: %x g: %x b:%x\n", RED_Val, GREEN_Val, BLUE_Val);
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCStructInit(&TIM_OCInitStructure);
/* PWM1 Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = GREEN_Val;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
/* PWM1 Mode configuration: Channel2 */
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = BLUE_Val;
TIM_OC2Init(TIM3, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);
/* PWM1 Mode configuration: Channel3 */
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = RED_Val;
TIM_OC3Init(TIM3, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);
}
示例8: TIM_Configuration
/**
* @brief configure the TIM4 for PWM mode
* @param None
* @retval None
*/
void TIM_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
TIM_OCInitTypeDef TIM_OCInitStruct;
// Let PWM frequency equal 100Hz.
// Let period equal 1000. Therefore, timer runs from zero to 1000. Gives 0.1Hz resolution.
// Solving for prescaler gives 240.
TIM_TimeBaseStructInit( &TIM_TimeBaseInitStruct );
TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV4;
TIM_TimeBaseInitStruct.TIM_Period = 1000 - 1;
TIM_TimeBaseInitStruct.TIM_Prescaler = 72 - 1;
TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit( TIM3, &TIM_TimeBaseInitStruct );
TIM_OCStructInit( &TIM_OCInitStruct );
TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1;
// Initial duty cycle equals 0%. Value can range from zero to 65535.
//TIM_Pulse = TIM4_CCR1 register (16 bits)
TIM_OCInitStruct.TIM_Pulse = 100 - 1; //(0=Always Off, 65535=Always On)
TIM_OC1Init( TIM3, &TIM_OCInitStruct ); // Channel 1 LED
TIM_OC2Init( TIM3, &TIM_OCInitStruct ); // Channel 2 LED
TIM_OC3Init( TIM3, &TIM_OCInitStruct ); // Channel 3 LED
TIM_OC4Init( TIM3, &TIM_OCInitStruct ); // Channel 4 LED
TIM_Cmd( TIM3, ENABLE );
}
示例9: TIMER2_CH2_PWM_Init
void TIMER2_CH2_PWM_Init(int prescaler,int autoreload){
//USER LED / PB3 / TIM2_CH2 / AF1
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOBEN ,ENABLE);
GPIO_InitTypeDef myGPIO;
GPIO_StructInit(&myGPIO);
myGPIO.GPIO_Pin=GPIO_Pin_3;
myGPIO.GPIO_Mode=GPIO_Mode_AF;
myGPIO.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(GPIOB,&myGPIO);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource3,GPIO_AF_1);
//select the output mode by writing the CCS bits in the CCMRx register
//Timer time base configuration
RCC_APB1PeriphClockCmd(RCC_APB1ENR_TIM2EN,ENABLE);
TIM_TimeBaseInitTypeDef myTimeBase;
TIM_TimeBaseStructInit(&myTimeBase);
myTimeBase.TIM_CounterMode=TIM_CounterMode_Up;
myTimeBase.TIM_Period=autoreload;
myTimeBase.TIM_Prescaler=prescaler;
myTimeBase.TIM_ClockDivision= TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM2,&myTimeBase);
//Timer capture compare configuration
TIM_OCInitTypeDef myTimerOC;
TIM_OCStructInit(&myTimerOC);
myTimerOC.TIM_OCMode=TIM_OCMode_PWM1;
myTimerOC.TIM_OCPolarity=TIM_OCPolarity_High;
myTimerOC.TIM_OutputState=TIM_OutputState_Enable;
myTimerOC.TIM_Pulse=autoreload;//0 Duty cycle at start
TIM_OC2Init(TIM2,&myTimerOC);
TIM_CCxCmd(TIM2,TIM_Channel_2,TIM_CCx_Enable);//enable CCP2
//start Timer
TIM_Cmd(TIM2,ENABLE);//Counter enabled
}
示例10: _ws_Timer_Init
static void _ws_Timer_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = WS_PERIOD;
TIM_TimeBaseStructure.TIM_Prescaler = WS_PRESCALE;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(WS_OUTPUT_TIM, &TIM_TimeBaseStructure);
/* PWM1 Mode configuration */
TIM_OCStructInit(&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = WS_PERIOD+1;
WS_OUTPUT_TIM_OC_INIT_CMD(WS_OUTPUT_TIM, &TIM_OCInitStructure);
WS_OUTPUT_TIM_OC_PLOAD_CMD(WS_OUTPUT_TIM, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(WS_OUTPUT_TIM, ENABLE);
TIM_CCxCmd(WS_OUTPUT_TIM, WS_OUTPUT_TIM_CH, TIM_CCx_Enable);
/* WS_OUTPUT_TIM enable/disable counter */
TIM_Cmd(WS_OUTPUT_TIM, ENABLE);
}
示例11: Buzzer_Configuration
void Buzzer_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCStructInit(&TIM_OCInitStructure);
// Timer Base Init - Buzzer
TIM_DeInit(TIM4);
TIM_TimeBaseStructure.TIM_Prescaler = 72-1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = 2000;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
// PWM Init - Buzzer
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 = TIM_TimeBaseStructure. TIM_Period / 2;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OC4Init(TIM4, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Disable);
TIM_Cmd(TIM4, ENABLE);
TIM_CtrlPWMOutputs(TIM4, ENABLE);
}
示例12: pwmOCConfig
static void pwmOCConfig(TIM_TypeDef *tim, uint8_t channel, uint16_t value)
{
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCStructInit(&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
TIM_OCInitStructure.TIM_Pulse = value;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
switch (channel) {
case TIM_Channel_1:
TIM_OC1Init(tim, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(tim, TIM_OCPreload_Enable);
break;
case TIM_Channel_2:
TIM_OC2Init(tim, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(tim, TIM_OCPreload_Enable);
break;
case TIM_Channel_3:
TIM_OC3Init(tim, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(tim, TIM_OCPreload_Enable);
break;
case TIM_Channel_4:
TIM_OC4Init(tim, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(tim, TIM_OCPreload_Enable);
break;
}
}
示例13: configBeeperPWMTimer
static void configBeeperPWMTimer(const beeperDevConfig_t *config)
{
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCStructInit(&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = (1000000 / BEEPER_PWM_FREQUENCY) * 50 / 100; // 50% duty cycle
TIM_OCInitStructure.TIM_OCPolarity = config->isInverted ? TIM_OCPolarity_High : TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCIdleState = config->isInverted ? TIM_OCIdleState_Reset : TIM_OCIdleState_Set;
configTimeBase(BEEPER_PWM_TIMER, 1000000 / BEEPER_PWM_FREQUENCY, PWM_TIMER_MHZ);
TIM_Cmd(BEEPER_PWM_TIMER, ENABLE);
switch (BEEPER_PWM_TIMER_CH) {
case TIM_Channel_1:
TIM_OC1Init(BEEPER_PWM_TIMER, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(BEEPER_PWM_TIMER, TIM_OCPreload_Enable);
break;
case TIM_Channel_2:
TIM_OC2Init(BEEPER_PWM_TIMER, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(BEEPER_PWM_TIMER, TIM_OCPreload_Enable);
break;
case TIM_Channel_3:
TIM_OC3Init(BEEPER_PWM_TIMER, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(BEEPER_PWM_TIMER, TIM_OCPreload_Enable);
break;
case TIM_Channel_4:
TIM_OC4Init(BEEPER_PWM_TIMER, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(BEEPER_PWM_TIMER, TIM_OCPreload_Enable);
break;
}
TIM_CtrlPWMOutputs(BEEPER_PWM_TIMER, DISABLE);
}
示例14: TIMER_Configuration
/**
* @brief Configures the Timer.
* @param None
* @retval None
*/
void TIMER_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; // Timer base configuration
TIM_OCInitTypeDef TIM_OCInitStructure; // Timer for PWM mode
// Time Base configuration
TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
TIM_TimeBaseStructure.TIM_Period = 720; // 72MHz / 720 = 100kHz
TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down;
TIM_TimeBaseInit( TIM1, &TIM_TimeBaseStructure );
// TIM1 channel1 configuration in PWM mode
TIM_OCStructInit( &TIM_OCInitStructure );
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init( TIM1, &TIM_OCInitStructure );
TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);
TIM_ClearITPendingBit(TIM1, TIM_IT_Update);
// TIM1 counter enable
TIM_Cmd( TIM1, ENABLE );
// TIM1 main Output Enable
TIM_CtrlPWMOutputs( TIM1, ENABLE );
}
示例15: pwmServoInit
void pwmServoInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_StructInit(&GPIO_InitStructure);
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_OCStructInit(&TIM_OCInitStructure);
// Outputs
// SERVO PWM0 TIM5 CH1 PA0
// SERVO PWM1 TIM5 CH2 PA1
// SERVO PWM2 TIM5 CH3 PA2
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_1 | GPIO_Pin_0;
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(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_TIM5);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_TIM5);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_TIM5);
// Output timers
TIM_TimeBaseStructure.TIM_Period = (uint16_t)(2000000 / eepromConfig.servoPwmRate) - 1;
TIM_TimeBaseStructure.TIM_Prescaler = 42 - 1;
//TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
//TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
//TIM_TimeBaseStructure.TIM_RepititionCounter = 0x0000;
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
//TIM_OCInitStructure.TIMOutputNState = TIM_OutputNState_Disable;
TIM_OCInitStructure.TIM_Pulse = SERVO_PULSE_1p5MS;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
//TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
//TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;
TIM_OC1Init(TIM5, &TIM_OCInitStructure);
TIM_OC2Init(TIM5, &TIM_OCInitStructure);
TIM_Cmd(TIM5, ENABLE);
TIM_CtrlPWMOutputs(TIM5, ENABLE);
}