Basic Motor Control Application Using PWM Input
Last updated
Last updated
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:
()
()
()
()
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 and actuate the BDC motor, the and the .
The motor is controlled using velocity commands, allowing for smooth acceleration and deceleration.
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
and Red
objects from the smd.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.
Hardware Setup
Make sure that the SMD is powered and all connections are correct.
• 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.
• 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.
Connect the SMD to the PC or Arduino board using or .
Connect the 100 RPM with Encoder to the motor ports of the SMD using an RJ-45 cable.