cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103VG Use Cubemx to generate TIM1 CH1 PWM output, and use firmware version stm32cube FW_ F1 v1.8.1 has normal PWM output. Use firmware version stm32cube FW_ F1 v1.8.1 ~ v1.8.4 cannot output PWM.

李强.1
Associate

0693W00000D26CsQAJ.png0693W00000D26D2QAJ.png 

void user_pwm_setvalue(uint16_t value)

{

TIM_OC_InitTypeDef sConfigOC;

sConfigOC.OCMode = TIM_OCMODE_PWM1;

sConfigOC.Pulse = value;

sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_1);

HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1);

sConfigOC.Pulse = 95;

HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1);

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);

}

int main(void)

{

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */

SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_TIM4_Init();

MX_TIM1_Init();

/* USER CODE BEGIN 2 */

HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1);

HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);

user_pwm_setvalue(80);

/* USER CODE END 2 */

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */

}

/* USER CODE END 3 */

}

0 REPLIES 0