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


C++ TIM_OC4Init函数代码示例

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


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

示例1: servo_set

/**
 * @param pos Servo position.
 *         0   = Middle
 *        -127 = Max left
 *        +127 = max right
 */
void servo_set(int num, int8_t pos) {
    int wpulse;
    uint16_t pulse;

    TIM_OCInitTypeDef oc_init;

    oc_init = TIM_OC_CONFIG;

    wpulse = ((int)pos)*500/127 +PULSE_1_5_MS;
    pulse = MIN(PULSE_2_0_MS,wpulse);
    pulse = MAX(PULSE_1_0_MS,wpulse);
    oc_init.TIM_Pulse = pulse;

    switch( num ) {
    case 2:
        TIM_OC2Init(TIMER, &oc_init);
        break;
    case 1:
        TIM_OC3Init(TIMER, &oc_init);
        break;
    case 0:
        TIM_OC4Init(TIMER, &oc_init);
        break;
    default:
        assert_param(0);
    }
}
开发者ID:powertomato,项目名称:cocktailbot,代码行数:33,代码来源:servo.c

示例2: Tim_pulse_set

//----------------------------------------------------------
//TIM PWMモード時のパルス幅変更
void Tim_pulse_set(TIM_TypeDef *tim,int ch,unsigned int pulse){
	TIM_OCInitTypeDef TIM_OCInitStructure;					//TIMを設定するための構造体

	TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
	TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
	TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

	if((ch&TIM_CH1) != 0){
		TIM_OCInitStructure.TIM_Pulse = pulse;
		TIM_OC1Init(tim,&TIM_OCInitStructure);
		TIM_OC1PreloadConfig(tim,TIM_OCPreload_Disable);
	}
	if((ch&TIM_CH2) != 0){
		TIM_OCInitStructure.TIM_Pulse = pulse;
		TIM_OC2Init(tim,&TIM_OCInitStructure);
		TIM_OC2PreloadConfig(tim,TIM_OCPreload_Disable);
	}
	if((ch&TIM_CH3) != 0){
		TIM_OCInitStructure.TIM_Pulse = pulse;
		TIM_OC3Init(tim,&TIM_OCInitStructure);
		TIM_OC3PreloadConfig(tim,TIM_OCPreload_Disable);
	}
	if((ch&TIM_CH4) != 0){
		TIM_OCInitStructure.TIM_Pulse = pulse;
		TIM_OC4Init(tim,&TIM_OCInitStructure);
		TIM_OC4PreloadConfig(tim,TIM_OCPreload_Disable);
	}
	TIM_Cmd(tim,ENABLE);
	TIM_ARRPreloadConfig(tim,ENABLE);
}
开发者ID:t-nagatani,项目名称:jyuubako,代码行数:32,代码来源:init_system_stm32f4.c

示例3: TIM4_Config

void TIM4_Config(void)
{
	TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;  
    TIM_OCInitTypeDef  TIM_OCInitStructure;  
    /* PWM??????? */  
    u16 CCR1= 36000;          
    u16 CCR2= 36000;  
    /*PCLK1??2?????TIM3??????72MHz*/  
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);  
    /* Time base configuration */                                            
    TIM_TimeBaseStructure.TIM_Period =0xEA5F;  
    TIM_TimeBaseStructure.TIM_Prescaler = 2;                                    //?????:???=2,??72/3=24MHz  
    TIM_TimeBaseStructure.TIM_ClockDivision = 0;                                //????????:???  
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;                 //????????  
    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);  
    /* PWM1 Mode configuration: Channel1 */  
    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;                           //???PWM??1  
    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;                
    TIM_OCInitStructure.TIM_Pulse = CCR1;                                       //?????,???????????,??????  
    TIM_OCInitStructure.TIM_OCPolarity =TIM_OCPolarity_High;                    //?????????CCR1?????  
    TIM_OC3Init(TIM4, &TIM_OCInitStructure);                                    //????1      
    TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);  
    /* PWM1 Mode configuration: Channel2 */  
    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;  
    TIM_OCInitStructure.TIM_Pulse = CCR2;                                       //????2??????,??????????PWM  
    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;                    //?????????CCR2????? 
    TIM_OC4Init(TIM4, &TIM_OCInitStructure);                                    //????2  
    TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable);  
    TIM_ARRPreloadConfig(TIM4, ENABLE);                                         //??TIM3?????ARR  
    /* TIM3 enable counter */                      
}
开发者ID:yuwentengbo,项目名称:Wind-pendulum,代码行数:31,代码来源:dc_moter.c

示例4: 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);
}
开发者ID:Pirate-Team,项目名称:RT_Thread_Base_On_STM32F401,代码行数:35,代码来源:motor.c

示例5: 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);
}
开发者ID:Carlitoscadiz,项目名称:inav,代码行数:33,代码来源:sound_beeper.c

示例6: initPWM

void initPWM() {
    TIM_OCInitTypeDef TIM_OCInitStructure;

    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStructure.TIM_Pulse = 0;
    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

    /* PWM1 Mode configuration: Channel1 (GPIOD Pin 12)*/
    TIM_OC1Init(TIM4, &TIM_OCInitStructure);
    TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);

    /* PWM1 Mode configuration: Channel2 (GPIOD Pin 13)*/
    TIM_OC2Init(TIM4, &TIM_OCInitStructure);
    TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);

    /* PWM1 Mode configuration: Channel3 (GPIOD Pin 14)*/
    TIM_OC3Init(TIM4, &TIM_OCInitStructure);
    TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);

    /* PWM1 Mode configuration: Channel4 (GPIOD Pin 15)*/
    TIM_OC4Init(TIM4, &TIM_OCInitStructure);
    TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable);

    TIM_Cmd(TIM4, ENABLE);
}
开发者ID:Marcin1311,项目名称:stm32f4-examples,代码行数:26,代码来源:main.c

示例7: 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;
    }
}
开发者ID:180jacob,项目名称:cleanflight,代码行数:31,代码来源:pwm_output.c

示例8: 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
}
开发者ID:darwikey,项目名称:Eirbot2015,代码行数:37,代码来源:servo.c

示例9: 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);


}
开发者ID:DresnerRobotics,项目名称:CM730-Firmware,代码行数:33,代码来源:system_init.c

示例10: PWM_Config

void PWM_Config(void)
{
  /* Configure PWM mode for TIM4 Channels 1->4*/
	
	TIM_OCInitTypeDef  TIM_OCInitStructure;
	
  /* PWM Mode configuration: Channel1 */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 0;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

  TIM_OC1Init(TIM4, &TIM_OCInitStructure);

  TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);
	
	TIM_ARRPreloadConfig(TIM4, ENABLE);
	
	//3 other channels
	TIM_OC2Init(TIM4, &TIM_OCInitStructure);

  TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);
	
	TIM_OC3Init(TIM4, &TIM_OCInitStructure);

  TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);
	
	TIM_OC4Init(TIM4, &TIM_OCInitStructure);

  TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable);

  /* TIM4 enable counter */
  TIM_Cmd(TIM4, ENABLE);
}
开发者ID:dangkhoa1992,项目名称:MyProject_STM32F4_HMI_MotorControl,代码行数:34,代码来源:stm_init.c

示例11: TIM3_PWM_Init

void TIM3_PWM_Init( void )
{
	GPIO_InitTypeDef	GPIO_InitStructure;
	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
	TIM_OCInitTypeDef	TIM_OCInitStructure;

	RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3, ENABLE );
	RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE );

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init( GPIOA, &GPIO_InitStructure );
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
	GPIO_Init( GPIOB, &GPIO_InitStructure );


/* ------------------------------------------------------------
 * TIM3 Configuration: generate 4 PWM signals with 4 different duty cycles:
 * TIM3CLK = 72 MHz, Prescaler = 0x0, TIM3 counter clock = 72 MHz
 * TIM3 ARR Register = 999 => TIM3 Frequency = TIM3 counter clock/(ARR + 1)
 * TIM3 Frequency = 72 KHz.
 * TIM3 Channel1 duty cycle = (TIM3_CCR1/ TIM3_ARR)* 100 = 50%
 * TIM3 Channel2 duty cycle = (TIM3_CCR2/ TIM3_ARR)* 100 = 37.5%
 * TIM3 Channel3 duty cycle = (TIM3_CCR3/ TIM3_ARR)* 100 = 25%
 * TIM3 Channel4 duty cycle = (TIM3_CCR4/ TIM3_ARR)* 100 = 12.5%
 * ------------------------------------------------------------- */
/* Time base configuration */
	TIM_TimeBaseStructure.TIM_Period = PWM_ARR;
	TIM_TimeBaseStructure.TIM_Prescaler = 0;
	TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseInit( TIM3, &TIM_TimeBaseStructure );

	TIM_ARRPreloadConfig( TIM3, ENABLE );
	TIM_Cmd( TIM3, ENABLE );

	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 = 0;
	TIM_OC1Init( TIM3, &TIM_OCInitStructure );
	TIM_OC1PreloadConfig( TIM3, TIM_OCPreload_Enable );

	TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
	TIM_OCInitStructure.TIM_Pulse = 0;
	TIM_OC2Init( TIM3, &TIM_OCInitStructure );
	TIM_OC2PreloadConfig( TIM3, TIM_OCPreload_Enable );

	TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
	TIM_OCInitStructure.TIM_Pulse = 0;
	TIM_OC3Init( TIM3, &TIM_OCInitStructure );
	TIM_OC3PreloadConfig( TIM3, TIM_OCPreload_Enable );

	TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
	TIM_OCInitStructure.TIM_Pulse = 0;
	TIM_OC4Init( TIM3, &TIM_OCInitStructure );
	TIM_OC4PreloadConfig( TIM3, TIM_OCPreload_Enable );
}
开发者ID:david-pzh,项目名称:ballBot,代码行数:60,代码来源:PWM.c

示例12: PWM_Config

void PWM_Config(void)
{
	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
	TIM_OCInitTypeDef TIM_OCInitStructure;

//	Update_event = TIM_CLK/((PSC + 1)*(ARR + 1)*(RCR + 1))
//	10e3=64e6/(2*3200*1)
	//10kHz
	TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
	TIM_TimeBaseStructure.TIM_Prescaler= 1; //32Mz
	TIM_TimeBaseStructure.TIM_Period=3200-1; //10kHz
	TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;

	TIM_TimeBaseInit(TIM4,&TIM_TimeBaseStructure);

	TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
	TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
	TIM_OCInitStructure.TIM_Pulse = 0;
	TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

	TIM_OC1Init(TIM4,&TIM_OCInitStructure);
	TIM_OC2Init(TIM4,&TIM_OCInitStructure);
	TIM_OC3Init(TIM4,&TIM_OCInitStructure);
	TIM_OC4Init(TIM4,&TIM_OCInitStructure);
	TIM_OC1PreloadConfig(TIM4,TIM_OCPreload_Enable);

	TIM_ARRPreloadConfig(TIM4, ENABLE);

	TIM_Cmd(TIM4, ENABLE);





}
开发者ID:halom87,项目名称:oltetfail,代码行数:35,代码来源:PWM.c

示例13: TIM4_PWM_Init

void TIM4_PWM_Init(u16 arr, u16 psc)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    static TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
    static TIM_OCInitTypeDef  TIM_OCInitStructure;

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);   //使能定时器3时钟
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOD, ENABLE);  //使能GPIO外设和AFIO复用功能模块时钟
 
   	GPIO_PinAFConfig(GPIOB,GPIO_PinSource8,GPIO_AF_TIM4); //GPIOA0复用为定时器2
	  GPIO_PinAFConfig(GPIOB,GPIO_PinSource9,GPIO_AF_TIM4); //GPIOA0复用为定时器2
   	GPIO_PinAFConfig(GPIOD,GPIO_PinSource12,GPIO_AF_TIM4); //GPIOA0复用为定时器2
	  GPIO_PinAFConfig(GPIOD,GPIO_PinSource13,GPIO_AF_TIM4); //GPIOA0复用为定时器2
	
  	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;
    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_UP;        //上拉
    GPIO_Init(GPIOB, &GPIO_InitStructure);
	
  	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13;
    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_UP;        //上拉
    GPIO_Init(GPIOD, &GPIO_InitStructure);
  
    //初始化TIM4
    TIM_TimeBaseStructure.TIM_Period = arr - 1;    //设置在下一个更新事件装入活动的自动重装载寄存器周期的值
    TIM_TimeBaseStructure.TIM_Prescaler = psc - 1; //设置用来作为TIMx时钟频率除数的预分频值
    TIM_TimeBaseStructure.TIM_ClockDivision = 0x00;//设置时钟分割:TDTS = Tck_tim
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM向上计数模式
    TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0;          //循环计数次数值
    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); //根据TIM_TimeBaseInitStruct中指定的参数初始化TIMx的时间基数单位

    //初始化TIM4  PWM模式
    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //选择定时器模式
    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;  //比较输出使能
    TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;//使能定时器互补输出
    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;       //输出极性
    TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;     //打开空闲状态选择关闭

    TIM_CtrlPWMOutputs(TIM4, ENABLE); //使能定时器8的PWM输出
		
    TIM_OC1Init(TIM4, &TIM_OCInitStructure);
    TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);
		
		TIM_OC2Init(TIM4, &TIM_OCInitStructure);
    TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);

    TIM_OC3Init(TIM4, &TIM_OCInitStructure);
    TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);
		
		TIM_OC4Init(TIM4, &TIM_OCInitStructure);
    TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable);

    TIM_Cmd(TIM4, ENABLE);  //使能TIM4

}
开发者ID:jasongwq,项目名称:F4Fly,代码行数:60,代码来源:pwm.c

示例14: pwm_out_mode_config

void pwm_out_mode_config()
{
	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
	TIM_OCInitTypeDef TIM_OCInitStructure;

	TIM_TimeBaseStructure.TIM_Period = TIM_PERIOD;
	TIM_TimeBaseStructure.TIM_Prescaler = TIM_PRESCALER;
	TIM_TimeBaseStructure.TIM_ClockDivision = 0;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

	TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
	TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
	TIM_OCInitStructure.TIM_Pulse = TIM_PULSE;
	TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

	//output Channel1
	TIM_OC1Init(TIM4, &TIM_OCInitStructure);
	TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);
	//output Channel2
	TIM_OC2Init(TIM4, &TIM_OCInitStructure);
	TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);
	//output Channel3
	TIM_OC3Init(TIM4, &TIM_OCInitStructure);
	TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);
	//output Channel4
	TIM_OC4Init(TIM4, &TIM_OCInitStructure);
	TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable);
	//enable TIM4
	TIM_ARRPreloadConfig(TIM4, ENABLE);
	TIM_Cmd(TIM4, ENABLE);
}
开发者ID:houcy,项目名称:PA-Quadcopter,代码行数:32,代码来源:pwm_out.c

示例15: PWM_Init

void PWM_Init()
{
	//配置TIM1
	TIM_TimeBaseInitTypeDef 	TIM_TimeBaseInitStructure;
	TIM_OCInitTypeDef 	TIM_OCInitStrycture;
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
	TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
	TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
	TIM_TimeBaseInitStructure.TIM_Period=7199;
	TIM_TimeBaseInitStructure.TIM_Prescaler=0;//不分频
	TIM_TimeBaseInit(TIM1,&TIM_TimeBaseInitStructure);
	
	
	//配置TIM1OC1,4
	TIM_OCInitStrycture.TIM_OCMode=TIM_OCMode_PWM1;
	TIM_OCInitStrycture.TIM_OutputState=TIM_OutputState_Enable;	
	TIM_OCInitStrycture.TIM_OCPolarity=TIM_OCPolarity_High;
	TIM_OC1Init(TIM1,&TIM_OCInitStrycture);
	TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);

	TIM_OCInitStrycture.TIM_OCMode=TIM_OCMode_PWM1;
	TIM_OCInitStrycture.TIM_OutputState=TIM_OutputState_Enable;	
	TIM_OCInitStrycture.TIM_OCPolarity=TIM_OCPolarity_High;
	TIM_OC4Init(TIM1,&TIM_OCInitStrycture);
	TIM_OC4PreloadConfig(TIM1,TIM_OCPreload_Enable);
	
	//TIM1->CR1|=1<<0;//是使能计数器
	//TIM1->CR1|=1<<7;//APRE使能
	//TIM1->BDTR |= 1<<15; //TIM1必须有这句话才能输出pwm	
	TIM_ARRPreloadConfig(TIM1, ENABLE);			                   // 使能TIM1重载寄存器ARR  
  TIM_Cmd(TIM1, ENABLE); 
	TIM_CtrlPWMOutputs(TIM1, ENABLE); 	
}
开发者ID:jzh2016,项目名称:phc,代码行数:33,代码来源:MOTOR.C


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