• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ HAL_TIM_PWM_ConfigChannel函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: setPWMHeaterValue

/** \brief 设置加热PWM值
 *
 * \param index uint8_t   0-ex1; 1-bed; 2-ex2; 3-ex3
 * \return uint16_t
 */
void setPWMHeaterValue(uint8_t index, uint8_t value)
{
    TIM_OC_InitTypeDef  TIM_InitStruct;

    TIM_InitStruct.OCMode = TIM_OCMODE_PWM1;
    TIM_InitStruct.OCPolarity = TIM_OCPOLARITY_HIGH;
    TIM_InitStruct.OCFastMode = TIM_OCFAST_DISABLE;
    TIM_InitStruct.Pulse = (uint32_t)value;

    if (index == 0){
        HAL_TIM_PWM_ConfigChannel(&TIM_PWM_HandleStruct, &TIM_InitStruct, TIM_CHANNEL_1);
    }
#ifdef HEATBED_ENABLED
    else if (index == 1){
        HAL_TIM_PWM_ConfigChannel(&TIM_PWM_HandleStruct, &TIM_InitStruct, TIM_CHANNEL_2);
    }
#endif
#ifdef EXTRUDER_2_ENABLED
    else if (index == 2){
        HAL_TIM_PWM_ConfigChannel(&TIM_PWM_HandleStruct, &TIM_InitStruct, TIM_CHANNEL_3);
    }
#endif
#ifdef EXTRUDER_3_ENABLED
    else if (index == 3){
        HAL_TIM_PWM_ConfigChannel(&TIM_PWM_HandleStruct, &TIM_InitStruct, TIM_CHANNEL_4);
    }
#endif
}
开发者ID:RennWang,项目名称:JawsFromMarlin,代码行数:33,代码来源:Temperature.cpp


示例2: Steer_Pwm_Init

/**
  * @brief  初始化舵机PWM.
  * @param  None
  * @retval None
  */	
void Steer_Pwm_Init(void){
  //B0引脚定义
  GPIO_InitTypeDef GPIO_InitStruct;

  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_TIM3_CLK_ENABLE();
  GPIO_InitStruct.Pin = GPIO_PIN_0;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
	//C7引脚定义
	 __HAL_RCC_GPIOC_CLK_ENABLE();
	GPIO_InitStruct.Pin = GPIO_PIN_7;
	 GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  //TIM3
	
  TimHandleT3.Instance = TIM3;
  TimHandleT3.Init.Period =  1000 - 1;;
  TimHandleT3.Init.Prescaler = 1680-1;
  TimHandleT3.Init.ClockDivision = 0;
  TimHandleT3.Init.CounterMode = TIM_COUNTERMODE_UP;  
  HAL_TIM_PWM_Init(&TimHandleT3);

  pwmConfig.OCMode=TIM_OCMODE_PWM1;
  pwmConfig.Pulse=79;
  HAL_TIM_PWM_ConfigChannel(&TimHandleT3, &pwmConfig, TIM_CHANNEL_2);
  HAL_TIM_PWM_ConfigChannel(&TimHandleT3, &pwmConfig, TIM_CHANNEL_3);
  HAL_TIM_PWM_Start(&TimHandleT3, TIM_CHANNEL_3);
	HAL_TIM_PWM_Start(&TimHandleT3, TIM_CHANNEL_2);
  }
开发者ID:photon0414,项目名称:Balance_Car_STM32,代码行数:38,代码来源:function.c


示例3: LBF_PWM4_Ch34_Init

/*******************************************************************************
 * @brief  : Initialise and configure PWM of a Timer 
 * @param  : Aucun.
 * @return : Rien.
 ******************************************************************************/
void LBF_PWM4_Ch34_Init ( void )
{
// Derived from Cube MX code and STM32L152 project example in Cube Library package

// To set Prescaler and Pulse values:
//  Prescaler = (TIMxCLK / Prescaled clock) - 1
//  ARR Period = (Prescaled clock / Target PWM Fqcy) - 1
//  TIM2 Channely duty cycle = (TIMx_CCRy/ TIMx_ARR + 1)* 100%


  TIM_OC_InitTypeDef sConfigOC; // or NEEDS TO BE GLOBAL ????

// First, confirgure the TIM (timer) peripheral

  htim4.Instance = TIM4;
  htim4.Init.Prescaler = (HAL_RCC_GetPCLK1Freq()/1000000) - 1; // so prescaled clock always 1MHz
    // Caution: TIM4CLK is 1x PCLK2 if APB1 prescaler=1 else is 2x -- see STM32 UserMan
  htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim4.Init.Period = 0 ;  // Initial Value, Target Value to be set by Application 
  htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; // ie no division
  HAL_TIM_PWM_Init(&htim4);

// Second, configure the PWM channel

  sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = 0 ;  // Initial Value, Target Value to be set by Application
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_3);

  sConfigOC.Pulse = 0 ;  // Initial Value, Target Value to be set by Application
  HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_4);

}
开发者ID:OlivierGrenoble,项目名称:LBF-V2-SW-WIP,代码行数:39,代码来源:LBF_PWM4_Ch34_Init.c


示例4: SC_TIM3_Init

/* TIM3 init function */
void SC_TIM3_Init(SERVO_CONTROLLER_Frequency frequency)
{

  TIM_ClockConfigTypeDef sClockSourceConfig;
  TIM_MasterConfigTypeDef sMasterConfig;
  TIM_OC_InitTypeDef sConfigOC;

  htim3.Instance = TIM3;
  htim3.Init.Prescaler = CORE_FCLK / TIM_FCLK - 1;
  htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim3.Init.Period = (uint16_t)(TIM_FCLK / frequency);   //should not exceed 0xFFFF
  htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  HAL_TIM_Base_Init(&htim3);

  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig);

  HAL_TIM_PWM_Init(&htim3);

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig);

  sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = 0;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1);

  HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2);

  HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_3);

}
开发者ID:itsergeyla,项目名称:Quadruped,代码行数:35,代码来源:ServoController.c


示例5: MX_TIM9_Init

/* TIM9 init function */
void MX_TIM9_Init(void)
{
  TIM_ClockConfigTypeDef sClockSourceConfig;
  TIM_OC_InitTypeDef sConfigOC;

  htim9.Instance = TIM9;
  htim9.Init.Prescaler = 167;
  htim9.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim9.Init.Period = 19999;
  htim9.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  HAL_TIM_Base_Init(&htim9);

  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  HAL_TIM_ConfigClockSource(&htim9, &sClockSourceConfig);

  HAL_TIM_PWM_Init(&htim9);

  sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = 1500;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  HAL_TIM_PWM_ConfigChannel(&htim9, &sConfigOC, TIM_CHANNEL_1);

  HAL_TIM_PWM_ConfigChannel(&htim9, &sConfigOC, TIM_CHANNEL_2);

}
开发者ID:dokor,项目名称:RobotCarto,代码行数:27,代码来源:tim.c


示例6: MX_TIM2_Init

/* TIM2 init function */
void MX_TIM2_Init(void)
{

  TIM_ClockConfigTypeDef sClockSourceConfig;
  TIM_MasterConfigTypeDef sMasterConfig;
  TIM_OC_InitTypeDef sConfigOC;

  htim2.Instance = TIM2;
  htim2.Init.Prescaler = 0;
  htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim2.Init.Period = 47;
  htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  HAL_TIM_Base_Init(&htim2);

  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig);

  HAL_TIM_PWM_Init(&htim2);

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig);

  sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = 0;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1);

  HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4);

  HAL_TIM_MspPostInit(&htim2);

}
开发者ID:yingwang88,项目名称:StmSmoke,代码行数:35,代码来源:main.c


示例7: pwmout_write

void pwmout_write(pwmout_t* obj, float value) {
    TIM_OC_InitTypeDef sConfig;
  
    TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
  
    if (value < (float)0.0) {
        value = 0.0;
    } else if (value > (float)1.0) {
        value = 1.0;
    }
   
    obj->pulse = (uint32_t)((float)obj->period * value);
    
    sConfig.OCMode     = TIM_OCMODE_PWM1;
    sConfig.OCFastMode = TIM_OCFAST_DISABLE;
    sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
    sConfig.Pulse      = obj->pulse;

    if (obj->pin == PB_3) {
        HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2);
        HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_2);
    }
    
    if ((obj->pin == PB_4) || (obj->pin == PB_6)) {
        HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1);
        HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_1);
    } 
}
开发者ID:brain5lug,项目名称:mbed-for-baremetal-qtcreator,代码行数:28,代码来源:pwmout_api.c


示例8: init

void Fan::setSpeed(uint8_t fanspeed)
{
    if (fan_init != 1){
        init();
        fan_init = 1;
    }

    TIM_OC_InitTypeDef  TIM_InitStruct;

    TIM_InitStruct.OCMode = TIM_OCMODE_PWM1;
    TIM_InitStruct.OCPolarity = TIM_OCPOLARITY_HIGH;
    TIM_InitStruct.OCFastMode = TIM_OCFAST_DISABLE;
    TIM_InitStruct.Pulse = (uint32_t)fanspeed * 257;

    fan_speed = fanspeed;

    if (fan_index == 0){
        HAL_TIM_PWM_ConfigChannel(&TIM_PWM_HandleStruct, &TIM_InitStruct, TIM_CHANNEL_1);
        HAL_TIM_PWM_Start(&TIM_PWM_HandleStruct, TIM_CHANNEL_1);
//        HAL_TIM_PWM_ConfigChannel(&TIM_PWM_HandleStruct, &TIM_InitStruct, TIM_CHANNEL_3);
//        HAL_TIM_PWM_Start(&TIM_PWM_HandleStruct, TIM_CHANNEL_3);
    }
    else if (fan_index == 1){
        HAL_TIM_PWM_ConfigChannel(&TIM_PWM_HandleStruct, &TIM_InitStruct, TIM_CHANNEL_2);
        HAL_TIM_PWM_Start(&TIM_PWM_HandleStruct, TIM_CHANNEL_2);
    }
}
开发者ID:RennWang,项目名称:JawsFromMarlin,代码行数:27,代码来源:Fan.cpp


示例9: MX_TIM4_Init

/* TIM4 init function */
void MX_TIM4_Init(void)
{

  TIM_MasterConfigTypeDef sMasterConfig;
  TIM_OC_InitTypeDef sConfigOC;

  htim4.Instance = TIM4;
  htim4.Init.Prescaler = 49;
  htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim4.Init.Period = 19999;
  htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  HAL_TIM_PWM_Init(&htim4);

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig);

  sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = 0;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_1);

  HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_2);

  HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_3);

  HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_4);

}
开发者ID:cjackie,项目名称:Quadcopter-Flight-Controller,代码行数:31,代码来源:main.c


示例10: motorsbsp_init

void motorsbsp_init(void)
{
	MOTORS_CLK;

	// Configura os GPIOs do drive dos motores como sa�das push/pull
	GPIO_InitTypeDef GPIO_InitStructure;
	for (int i = 0; i < N_PINS; i++)
	{
		GPIO_InitStructure.Pin = MOTORES_PIN[i];
		GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
		GPIO_InitStructure.Pull = GPIO_PULLUP;
		GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
		HAL_GPIO_Init(MOTORES_PORT[i], &GPIO_InitStructure);
	}
	HAL_GPIO_WritePin(STBY_PORT, STBY_PIN, GPIO_PIN_SET);

	// Configura os GPIOs de PWM como Alternate Function
	GPIO_InitStructure.Pin = L_PWM_PIN;
	GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
	GPIO_InitStructure.Pull = GPIO_NOPULL;
	GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
	GPIO_InitStructure.Alternate = PWM_AF_TIM;
	HAL_GPIO_Init(L_PWM_PORT, &GPIO_InitStructure);
	GPIO_InitStructure.Pin = R_PWM_PIN;
	HAL_GPIO_Init(R_PWM_PORT, &GPIO_InitStructure);

	// Time base PWM COnfig
	// PWMf:	f = [(168M / 2) / (PS + 1) ] / T

	//TIM4 connected on APB1 and prescaller is 4 (the minimal!!) -> Pag. 67 - Reference Manual
                                /*   (168M/4)    */
	// timer_tick_frequency = Timer_default_frequency / (prescaller_set + 1)
	// ttf = 10500000
	// PWM_frequency = (timer_tick_frequency / (TIM_Period + 1))
	// PWMf = 10500
	TimHandle.Instance = PWM_TIM;
	TimHandle.Init.Period = PWM_PERIOD;
	TimHandle.Init.Prescaler = PWM_PRESCALER;
	TimHandle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
	TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
	HAL_TIM_PWM_Init(&TimHandle);

	// Output Compare - PWM
	// TIM_Period = timer_tick_frequency / PWM_frequency - 1
	// TIM_Period = 10500000 / 10500 = 1000
	TIM_OC_InitTypeDef sConfig;
	sConfig.OCMode = TIM_OCMODE_PWM1;
	sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
	sConfig.OCFastMode = TIM_OCFAST_DISABLE;
	sConfig.Pulse = 999;
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, L_PWM_CHANNEL);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, R_PWM_CHANNEL);

	HAL_TIM_PWM_Start(&TimHandle, L_PWM_CHANNEL);
	HAL_TIM_PWM_Start(&TimHandle, R_PWM_CHANNEL);
}
开发者ID:Felipeasg,项目名称:lf_lite_plus,代码行数:56,代码来源:motorsbsp.c


示例11: POLOLU_MOTOR_Run_InIn

void POLOLU_MOTOR_Run_InIn(DRIVER_InitTypeDef *driver, MOTOR_InitTypeDef *motor, uint32_t mode, uint32_t speed)
{
	if (mode == MOTOR_IN_IN_BREAK)
	{
		POLOLU_MOTOR_Break_InIn(driver, motor);
		return;
	}

	TIM_OC_InitTypeDef sConfigOC;
	sConfigOC.OCMode = TIM_OCMODE_PWM1;
	sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
	sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;

	switch (mode)
	{
	case MOTOR_IN_IN_COAST:
		HAL_TIM_PWM_Stop(motor->htimIn1, motor->ChannelIn1);
		HAL_TIM_PWM_Stop(motor->htimIn2, motor->ChannelIn2);
		motor->GPIOxIn1->BSRR = (uint32_t)(motor->PinIn1) << 16;
		motor->GPIOxIn2->BSRR = (uint32_t)(motor->PinIn2) << 16;
		break;
	case MOTOR_IN_IN_REVERSE_COAST:
		HAL_TIM_PWM_Stop(motor->htimIn1, motor->ChannelIn1);
		motor->GPIOxIn1->BSRR = (uint32_t)(motor->PinIn1) << 16;		
		sConfigOC.Pulse = count_pulse(motor->htimIn2->Init.Period, speed);		
		HAL_TIM_PWM_ConfigChannel(motor->htimIn2, &sConfigOC, motor->ChannelIn2);
		HAL_TIM_MspPostInit(motor->htimIn2);
		HAL_TIM_PWM_Start(motor->htimIn2, motor->ChannelIn2);
		break;
	case MOTOR_IN_IN_FORWARD_COAST:
		HAL_TIM_PWM_Stop(motor->htimIn2, motor->ChannelIn2);
		motor->GPIOxIn2->BSRR = (uint32_t)(motor->PinIn2) << 16;
		sConfigOC.Pulse = count_pulse(motor->htimIn1->Init.Period, speed);
		HAL_TIM_MspPostInit(motor->htimIn1);
		HAL_TIM_PWM_Start(motor->htimIn1, motor->ChannelIn2);
		break;
	case MOTOR_IN_IN_REVERSE:
		HAL_TIM_PWM_Stop(motor->htimIn2, motor->ChannelIn2);
		motor->GPIOxIn2->BSRR = motor->PinIn2;
		sConfigOC.Pulse = count_pulse(motor->htimIn1->Init.Period, speed);
		HAL_TIM_MspPostInit(motor->htimIn1);
		HAL_TIM_PWM_Start(motor->htimIn1, motor->ChannelIn2);
		break;
	case MOTOR_IN_IN_FORWARD:
		HAL_TIM_PWM_Stop(motor->htimIn1, motor->ChannelIn1);
		motor->GPIOxIn1->BSRR = motor->PinIn1;
		sConfigOC.Pulse = count_pulse(motor->htimIn2->Init.Period, speed);
		HAL_TIM_PWM_ConfigChannel(motor->htimIn2, &sConfigOC, motor->ChannelIn2);
		HAL_TIM_MspPostInit(motor->htimIn2);
		HAL_TIM_PWM_Start(motor->htimIn2, motor->ChannelIn2);
	}
}
开发者ID:kyberpunk,项目名称:Robot,代码行数:52,代码来源:pololu_drv8835.c


示例12: Motors_stop

/**********************************************************
 * @brief  Motors_stop
 * @param  Direction and speed of the motor (0 to 100)
 * @retval None
**********************************************************/
void Motors_stop(void)
{
  TIMER_OC_InitStruct.Pulse = 0;
  HAL_TIM_PWM_ConfigChannel(&TIMER_InitStruct, &TIMER_OC_InitStruct, TIM_CHANNEL_3);
  HAL_TIM_PWM_ConfigChannel(&TIMER_InitStruct, &TIMER_OC_InitStruct, TIM_CHANNEL_4);

  HAL_TIM_PWM_Start(&TIMER_InitStruct,TIM_CHANNEL_3);
  HAL_TIM_PWM_Start(&TIMER_InitStruct,TIM_CHANNEL_4);

  s_motorRight.speed = 0;
  s_motorLeft.speed = 0;

}
开发者ID:macerobotics,项目名称:MRPi1,代码行数:18,代码来源:Motors.c


示例13: pwm_set

void pwm_set(PWM_NAME pwm, int32_T val)
{
    int32_T period = 0;

    /* 参数检查 */
    if(pwm > PWM_MAX)
    {
        ERR_STR("参数错误.");
    }

    /* 限制val在有效值范围内 [0,period] */
    period = pwm_get_period();
    if(val < 0)
    {
        val = 0;
    }
    if(val > period)
    {
        val = period;
    }

    /* 修改占空比 */
    s_sConfig.Pulse = val;
    if (HAL_TIM_PWM_ConfigChannel(&s_tim_handle, &s_sConfig, g_pwm_ch_list[pwm].ch) != HAL_OK)
    {
        ERR_STR("执行失败.");
    } 

    /* 启动PWM */
    if (HAL_TIM_PWM_Start(&s_tim_handle, g_pwm_ch_list[pwm].ch) != HAL_OK)
    {
        ERR_STR("执行失败.");
    }
}
开发者ID:yougukepp,项目名称:flyer,代码行数:34,代码来源:pwm.c


示例14: POLOLU_MOTOR_Run_EnablePhase

void POLOLU_MOTOR_Run_EnablePhase(DRIVER_InitTypeDef *driver, MOTOR_InitTypeDef *motor, uint32_t mode, uint32_t speed)
{
	switch (mode)
	{
	case MOTOR_ENABLE_PHASE_FORWARD:
		motor->GPIOxIn1->BSRR = motor->PinIn1;
		break;
	case MOTOR_ENABLE_PHASE_REVERSE:
		motor->GPIOxIn1->BSRR = (uint32_t)(motor->PinIn1) << 16;
		break;
	case MOTOR_ENABLE_PHASE_BREAK:
		POLOLU_MOTOR_Break_EnablePhase(driver, motor);
		return;
	}

	uint32_t pulse = count_pulse(motor->htimIn2->Init.Period, speed);

	TIM_OC_InitTypeDef sConfigOC;
	sConfigOC.OCMode = TIM_OCMODE_PWM1;
	sConfigOC.Pulse = pulse;
	sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
	sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;	
	HAL_TIM_PWM_ConfigChannel(motor->htimIn2, &sConfigOC, motor->ChannelIn2);
	HAL_TIM_MspPostInit(motor->htimIn2);
	HAL_TIM_PWM_Start(motor->htimIn2, motor->ChannelIn2);
}
开发者ID:kyberpunk,项目名称:Robot,代码行数:26,代码来源:pololu_drv8835.c


示例15: MX_TIM10_Init

/* TIM10 init function */
void MX_TIM10_Init(void)
{
  TIM_OC_InitTypeDef sConfigOC;

  htim10.Instance = TIM10;
  htim10.Init.Prescaler = 0;
  htim10.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim10.Init.Period = 0;
  htim10.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  if (HAL_TIM_Base_Init(&htim10) != HAL_OK)
  {
    Error_Handler();
  }

  if (HAL_TIM_PWM_Init(&htim10) != HAL_OK)
  {
    Error_Handler();
  }

  sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = 0;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  if (HAL_TIM_PWM_ConfigChannel(&htim10, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  {
    Error_Handler();
  }

  HAL_TIM_MspPostInit(&htim10);

}
开发者ID:RoboSec,项目名称:rs_sensor_board,代码行数:32,代码来源:tim.c


示例16: MX_TIM3_Init

/* TIM3 init function */
void MX_TIM3_Init(void)
{
  TIM_MasterConfigTypeDef sMasterConfig;
  TIM_OC_InitTypeDef sConfigOC;
	
	uint32_t uhPrescalerValue = (uint32_t) ((SystemCoreClock /2) / 1300) - 1;


  htim3.Instance = TIM3;
  htim3.Init.Prescaler = uhPrescalerValue;
  htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim3.Init.Period = PERIOD_VALUE;
  htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  HAL_TIM_PWM_Init(&htim3);

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig);

  sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = PULSE1_VALUE;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1);

  HAL_TIM_MspPostInit(&htim3);

}
开发者ID:hlmpost,项目名称:st-nordic-3-11,代码行数:29,代码来源:tim.c


示例17: MX_TIM4_Init

/* TIM4 init function */
void MX_TIM4_Init(DeviceConfig *x)
{

  HAL_TIM_PWM_Init(&(x->htim4));
  HAL_TIM_OC_Init(&(x->htim4));

  HAL_TIMEx_MasterConfigSynchronization(&(x->htim4),&(x->sTIMMasterConfig));

  HAL_TIM_PWM_ConfigChannel(&(x->htim4), &(x->TIMConfigOC1), TIM_CHANNEL_1);
  HAL_TIM_PWM_ConfigChannel(&(x->htim4), &(x->TIMConfigOC2), TIM_CHANNEL_2);
  HAL_TIM_PWM_ConfigChannel(&(x->htim4), &(x->TIMConfigOC3), TIM_CHANNEL_3);
  HAL_TIM_PWM_ConfigChannel(&(x->htim4), &(x->TIMConfigOC4), TIM_CHANNEL_4);

  HAL_TIM_MspPostInit(&(x->htim4));

}
开发者ID:LabAdaptive,项目名称:MicroKit,代码行数:17,代码来源:tim.c


示例18: updatePulseWidth

void updatePulseWidth(eTimer timer, uint32_t pulse, uint32_t channel)
{
    TIM_OC_InitTypeDef outputChannelInit = {0,};

    outputChannelInit.OCMode = TIM_OCMODE_PWM1;
    outputChannelInit.Pulse = pulse;
    outputChannelInit.OCPolarity = TIM_OCPOLARITY_HIGH;
    outputChannelInit.OCFastMode = TIM_OCFAST_DISABLE;
    outputChannelInit.OCIdleState = TIM_OCIDLESTATE_SET;

    //HAL_TIM_PWM_Start_IT(&handleTimer4);
    switch(timer)
    {
    case eTimer4:
        HAL_TIM_PWM_ConfigChannel(&handleTimer4, &outputChannelInit, channel);
        HAL_TIM_PWM_Start(&handleTimer4, channel);

        break;
    case eTimer1:
    case eTimer2:
    case eTimer3:
    default:
        break;
    }
    return;
}
开发者ID:Lee-apollo,项目名称:plotter_stm32,代码行数:26,代码来源:hwTimer.c


示例19: MX_TIM5_Init

/* TIM5 init function */
void MX_TIM5_Init(void)
{
  TIM_MasterConfigTypeDef sMasterConfig;
  TIM_IC_InitTypeDef sConfigIC;
  TIM_OC_InitTypeDef sConfigOC;

  htim5.Instance = TIM5;
  htim5.Init.Prescaler = 0;
  htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim5.Init.Period = 8400000 * 5; // 500 ms
  htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  HAL_TIM_IC_Init(&htim5);

  HAL_TIM_PWM_Init(&htim5);

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig);

  sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_BOTHEDGE;
  sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
  sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
  sConfigIC.ICFilter = 0;
  HAL_TIM_IC_ConfigChannel(&htim5, &sConfigIC, TIM_CHANNEL_1);

  sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = 840;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_2);

  HAL_TIM_MspPostInit(&htim5);

}
开发者ID:Vadim-Stupakov,项目名称:ProjectX,代码行数:35,代码来源:tim.c


示例20: vHardwareTimerPwmSetup

void vHardwareTimerPwmSetup(
        TIM_HandleTypeDef* xTimerHandle,
        TIM_OC_InitTypeDef* xTimerPwmConfig,
        uint8_t usChannel,
        uint8_t usPolarity,
        uint32_t ulPulseValue)
{
    /* Configure PWM action */
    xTimerPwmConfig->OCMode     = TIM_OCMODE_PWM1;
    xTimerPwmConfig->OCPolarity = usPolarity;
    xTimerPwmConfig->OCFastMode = TIM_OCFAST_DISABLE;
    xTimerPwmConfig->Pulse      = ulPulseValue;


    /* Configure PWM */
    if(HAL_TIM_PWM_ConfigChannel(xTimerHandle, xTimerPwmConfig, usChannel) != HAL_OK)
    {
        /* Configuration Error */
        vErrorFatal(__LINE__, __FILE__, "Unable to init PWM");
    }

    /* Start PWM generation */
    if(HAL_TIM_PWM_Start(xTimerHandle, usChannel) != HAL_OK)
    {
        /* Configuration Error */
        vErrorFatal(__LINE__, __FILE__, "Unable to init PWM");
    }
}
开发者ID:ccccjason,项目名称:amass,代码行数:28,代码来源:hardware.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ HAL_TIM_PWM_Init函数代码示例发布时间:2022-05-30
下一篇:
C++ HAL_TIM_IRQHandler函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap