Basic Motor Control Application Using PWM Input
This program demonstrates a fundamental motor control application, where the motor’s behavior is controlled through Pulse Width Modulation (PWM) input specified by the user. The script sets up the motor, establishes communication, and allows the user to input a PWM value to control the motor's rotation speed and direction. PWM is a common method to adjust motor speed in motor control applications.
About Tools and Materials:
SMD USB Gateway (Purchase Here)
Arduino Gateway Module (Purchase Here)
Step 1: Hardware & Software Overview
Project Key Components
SMD The SMD acts as a bridge between the script and the modules. It is responsible for interpreting the commands sent by the script and translating them into actions that read input from the Button Module and actuate the BDC motor, the RGB LED Module and the Buzzer Module.
BDC Motor The motor is controlled using velocity commands, allowing for smooth acceleration and deceleration.
Project Key Features
USB Port Detection:
The script first identifies and connects to the appropriate USB serial port based on the operating system. It uses the
serial
module to scan for connected serial devices.The program is compatible with Windows, Linux, and macOS, using different naming conventions for the USB port depending on the OS.
Motor Initialization and Configuration:
The
Master
andRed
objects from thesmd.red
library are used to set up the motor and establish communication.The motor's essential parameters are initialized, such as counts per revolution (
set_shaft_cpr
) and shaft RPM (set_shaft_rpm
).
PWM Input for Motor Control:
After configuring the motor, the program prompts the user to input a PWM value, which will control the motor’s rotation speed and direction.
PWM values can vary, with positive values for one direction and negative values for the opposite. This input is passed to the motor using
m.set_duty_cycle(0, -int(pwm))
.By inputting a PWM value, the user directly controls the motor’s duty cycle, affecting both the speed and direction.
User Feedback:
After setting the PWM, the program prints a confirmation message indicating that the motor is running at the specified PWM level.
Step 2: Assemble
Getting Started
Hardware Setup
Connect the SMD to the PC or Arduino board using USB Gateway Module or Arduino Gateway Module.
Connect the 100 RPM BDC Motor with Encoder to the motor ports of the SMD using an RJ-45 cable.
Make sure that the SMD is powered and all connections are correct.
Project Wiring diagram
Step 3: Run & Test
Run the Script
• Execute the script to initiate the Basic Motor Control Application Using PWM Input.
• The script will automatically detect the USB port and establish communication with the SMD Master Controller.
• Enter a PWM value (0 to 255) when prompted to adjust the motor speed.
Experience PWM-Based Motor Control
• Observe how the motor speed increases as the PWM value increases.
• Enter zero (0) to stop the motor completely.
• Notice how the PWM signal directly influences the motor speed, providing smooth and efficient control.
Codes
Last updated