Skip to content

A simple STM32CubeIDE project for generating and controlling dual-channel PWM signals on STM32F103C8T6 (Blue Pill). Demonstrates increasing duty cycle on one channel while decreasing it on another using TIM2.

Notifications You must be signed in to change notification settings

SanthoshKumar-BE/stm32-pwm-dual-channel-control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

STM32F103C8T6 Dual Channel PWM Control

This project demonstrates how to generate and control two PWM outputs on an STM32F103C8T6 (Blue Pill board) using STM32CubeIDE and HAL libraries.
It uses TIM2 to drive two channels:

  • Channel 1 duty cycle increases gradually from 0 to 255.
  • Channel 2 duty cycle decreases gradually from 255 to 0.

Features

  • Dual PWM output using TIM2 Channel 1 and Channel 2.
  • Dynamic duty cycle adjustment.
  • Uses STM32 HAL functions for portability.
  • Delay-based update for visual testing with LEDs.

Hardware Requirements

  • STM32F103C8T6 board (Blue Pill)
  • Two LEDs (or other PWM-controllable devices)
  • Resistors for LEDs
  • USB to Serial / ST-Link programmer

Pinout (PWM Outputs)

Timer Channel Pin Alternate Function
TIM2_CH1 PA0 PWM Output
TIM2_CH2 PA1 PWM Output

How It Works

  • TIM2 is initialized for PWM mode.
  • The code runs in an infinite loop:
    • pulse_ch1 increments (LED1 gradually brightens).
    • pulse_ch2 decrements (LED2 gradually dims).
    • When pulse_ch1 reaches 255, it resets to 0.
    • When pulse_ch2 reaches 0, it resets to 255.
  • The PWM duty cycle is updated using:
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, pulse_ch1);
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, pulse_ch2);

About

A simple STM32CubeIDE project for generating and controlling dual-channel PWM signals on STM32F103C8T6 (Blue Pill). Demonstrates increasing duty cycle on one channel while decreasing it on another using TIM2.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages