You can access the source code files via this link.
This project focuses on the seamless integration of STM32 microcontrollers with DC motors, utilizing advanced techniques such as timers, PWM, ADC, and popular motor driver ICs including L289n and L293D.
The L289n, a dual H-bridge motor driver IC, empowers independent control over two DC motors or a single stepper motor. With a maximum current rating of approximately 1A per motor channel, it proves suitable for driving small to medium-sized DC motors. External control logic, such as microcontrollers or discrete logic circuits, is necessary to provide signals for motor direction and enable functions. Additionally, an external power supply ranging from 4.5V to 36V is required for proper motor operation.
Similarly, the L293D, another dual H-bridge motor driver IC, excels in independent control of two DC motors or a single stepper motor. It boasts a maximum current rating of around 600mA per motor channel, making it well-suited for low to medium power motors. Notably, the L293D features built-in control logic, enabling direct interfacing with TTL or CMOS logic levels. This streamlines the control circuitry by eliminating the need for additional external logic components. Furthermore, the L293D incorporates an internal voltage regulator, eliminating the requirement for a separate voltage regulator and allowing operation at lower voltage levels (typically 4.5V to 36V).
Significantly, PWM assumes a critical role in optimizing the performance of the L298N and L293D motor driver ICs. PWM facilitates precise motor speed control, enhances power efficiency, reduces motor vibrations, and ensures compatibility. The modulation of the PWM signal enables smooth and accurate adjustments to the motor's speed, maximizing energy efficiency and prolonging the motor's lifespan. By minimizing motor vibrations through PWM modulation, stable and reliable motor operation is achieved. As the L298N and L293D motor driver ICs are designed to effectively work with PWM signals, integrating PWM is imperative to harness the full potential of these motor driver ICs.
By skillfully incorporating timers, PWM, ADC, and the L289n and L293D motor driver ICs, this project unlocks a comprehensive approach to integrating STM32 microcontrollers with DC motors. The result is a precise motor control, efficient power utilization, minimized vibrations, and seamless compatibility, empowering a wide range of applications requiring optimal motor performance.
Step One:Open CubeMX & Create New Project Choose The Target MCU STM32F103C6 & Double-Click Its Name
- Go To The Clock Configuration & Set The System Clock To 8MHz
GPIO Configuration:
- Configure The GPIO Pin PA6 (slection pin)
- Configure The GPIO Pins [PB6..PB11] (Control Buttons)
- Configure The GPIO Pins [PB14, PB15] and PA3 (L298 Motor Driver)
- Configure The GPIO Pins [PB12, PB13] and PA2 (L293D Motor Driver)
TIMER Configuration:
- In the Categories tab, select the TIM2 then (enable Internal Clock & PWM Generation channel 3 and channel 4)
- In the Parameter settings tab, set the (Prescaler = 800 & Counter Peroid = 1000)
- set the Pulse to 500 & enable the output compare preload for (PWM Generation ch3 and ch4)
ADC Configuration:
- In the Categories tab, select the ADC1 & enable IN9
- In the Parameter settings tab, Enable the Continuous Conversion Mode
UART Configuration:
- Enable USART1 Module (Asynchronous Mode)
- Set the USART1 communication parameters (baud rate = 9600, parity=NON, stop bits =1, and word length =8bits)
- Generate The Initialization Code & Open The Project In CubeIDE
- Open Proteus & Create New Project and click next
- Click on Pick Device
- Search for STM32F103C6 & L298 & L293D & Motor & Button & Pot & RES & SW-SPDT
- Click on Virtual Instruments Mode then choose (VIRTUALTERMINAL&OSCILLOSCOPE)
- Click on Terminal Mode then choose (DEFAULT & POWER &GROUND)
- finally make the circuit below and start the simulation
If you have any questions or suggestions don't hesitate to leave a comment below
Comments