In this project, we’ll explore how to interface an STM32F103C6 microcontroller with the L298N motor driver, allowing control over the speed and direction of two DC motors. The L298N is a versatile H-Bridge driver, making it ideal for projects involving motor control with STM32. We’ll walk through its pin configuration, key features, and how to integrate it into a real-world embedded system for controlling motor movement using PWM signals from the STM32.
L298N OverviewThe L298N is a dual H-Bridge motor driver module designed to control two DC motors simultaneously. It can handle voltages between 5V and 35V, with a peak current of up to 2A.
Key Features:
- Motor Power Supply (VCC): Provides power to the motors.
- Onboard 5V Regulator: Can be enabled (for motor voltages ≤12V) or disabled (for higher voltages) using a jumper.
- Logic Control Inputs (IN1, IN2, IN3, IN4): Control motor direction by switching the H-Bridge transistors.
- Enable Pins (ENA, ENB): Enable and control the speed of the motors using PWM signals.
Pinout and Functionality:
- ENA and ENB (Enable Pins): Enable motor A and B, respectively. When a jumper is present, the motor runs at full speed. Connect these to PWM pins from the STM32 to control motor speed.
- IN1 and IN2 (Motor A Direction): Control rotation direction of motor A. IN1 = HIGH, IN2 = LOW → forward. Reversing logic → reverse.
- IN3 and IN4 (Motor B Direction): Control rotation direction of motor B, same principle as motor A.
- MCU Selection: STM32F103C6 (16 MHz clock)
- TIM3 Configuration:
-
Channel 1 (PA6) & Channel 3 (PA0): PWM Generation
-
Prescaler: 0
-
Counter Period: 65535
-
PWM Mode: Mode 1
- GPIO Configuration:
-
PB12, PB13, PA8, PA9
→ Outputs (Direction control)
- UART1 Configuration:
-
Baud Rate: 115200
-
Word Length: 8 bits
-
Parity: None
-
Stop Bits: 1
- Generate initialization code in STM32CubeIDE.
Key Functions
Motor Direction Control
→ void checkKeys(void);PWM Speed Adjustment
→ void updateMotors(void);UART Status Feedback
→ void printSpeeds(void);
Components:
- STM32F103C6
- L298N Motor Driver
- DC Motors (x2)
- Virtual Terminal (UART)
Connections:
- Match GPIO/PWM pins (PA0, PA6, PB12, PB13, PA8, PA9)
- Connect UART1 TX (PA9) → Virtual Terminal
Steps:
- Load the.hex file into STM32 in Proteus.
- Use UART terminal to monitor motor speed/direction.
- Adjust PWM signals to vary motor speed.
If you have any questions or suggestions don't hesitate to leave a comment below
Comments