在int main() { }前面添加自定义改变PWM参数的函数
/* USER CODE BEGIN PV */
uint8_t duty_cycle=0;
/* USER CODE END PV */
/* USER CODE BEGIN 0 */
void Set_PWM_DUTYCYCLE(uint8_t duty_cycle)
{
TIM_OC_InitTypeDef sConfigOC;
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = duty_cycle;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
{
Error_Handler();
}
HAL_TIM_MspPostInit(&htim3);
HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_4);
}
/* USER CODE END 0 */
|