修改led占空比范围为0~255

This commit is contained in:
EN 2024-07-12 21:17:48 +08:00
parent d66db6572b
commit 117afd6bbe
2 changed files with 22 additions and 22 deletions

View File

@ -11,7 +11,7 @@
void LED_Start(uint8_t led); void LED_Start(uint8_t led);
void LED_Stop(uint8_t led); void LED_Stop(uint8_t led);
// duty in [0, 100] // duty in [0, 255]
void LED_SetDuty(uint8_t r, uint8_t g, uint8_t b); void LED_SetDuty(uint8_t r, uint8_t g, uint8_t b);
#endif #endif

View File

@ -1,21 +1,21 @@
/* USER CODE BEGIN Header */ /* USER CODE BEGIN Header */
/** /**
****************************************************************************** ******************************************************************************
* @file tim.c * @file tim.c
* @brief This file provides code for the configuration * @brief This file provides code for the configuration
* of the TIM instances. * of the TIM instances.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* Copyright (c) 2024 STMicroelectronics. * Copyright (c) 2024 STMicroelectronics.
* All rights reserved. * All rights reserved.
* *
* This software is licensed under terms that can be found in the LICENSE file * This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component. * in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS. * If no LICENSE file comes with this software, it is provided AS-IS.
* *
****************************************************************************** ******************************************************************************
*/ */
/* USER CODE END Header */ /* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "tim.h" #include "tim.h"
@ -43,9 +43,9 @@ void MX_TIM2_Init(void)
/* USER CODE END TIM2_Init 1 */ /* USER CODE END TIM2_Init 1 */
htim2.Instance = TIM2; htim2.Instance = TIM2;
htim2.Init.Prescaler = 72 - 1; htim2.Init.Prescaler = 0;
htim2.Init.CounterMode = TIM_COUNTERMODE_UP; htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = 1 - 1; htim2.Init.Period = 72 - 1;
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim2) != HAL_OK) if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
@ -84,9 +84,9 @@ void MX_TIM3_Init(void)
/* USER CODE END TIM3_Init 1 */ /* USER CODE END TIM3_Init 1 */
htim3.Instance = TIM3; htim3.Instance = TIM3;
htim3.Init.Prescaler = 72 - 1; htim3.Init.Prescaler = 720 - 1;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP; htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 100 - 1; htim3.Init.Period = 256 - 1;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim3) != HAL_OK) if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
@ -109,7 +109,7 @@ void MX_TIM3_Init(void)
Error_Handler(); Error_Handler();
} }
sConfigOC.OCMode = TIM_OCMODE_PWM1; sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 10000 - 1; sConfigOC.Pulse = 255;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2) != HAL_OK) if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)