Wolfram Language

Closed-Loop Speed Control of a DC Motor

In closed-loop control, a controller essentially compares the desired and actual values of variables of interest and adjusts the control effort such that the actual value matches the desired value.

show complete Wolfram Language input

In this example, a speed controller is deployed to an Arduino Uno microcontroller board. The actual speed of the motor is measured using an encoder. The desired speed is set using a potentiometer. The motor is powered using a motor shield. Finally, the reference and actual speeds are transmitted over a serial RS-232 bus that will be read using the device framework.

The model of the DC motor.

Design a PID controller with sampling period 0.25 seconds.

The encoder gives 12 counts per revolution and the motor's gearbox has a gear ratio of 9.86. Create a model that gets the encoder readings in rpm.

The reference is set by a potentiometer with range 05V. Rescale it to read 0 to 500 rpm.

The comparator to compare the reference speed and the actual encoder speed.

The microcontroller output to the motor is based on the duty cycle of the PWM signal. The actual voltage across the motor comes from the motor shield. The following is the relationship between the voltage and the duty cycle based on a piecewise fit of measured data.

The inverse model of the shield that maps the voltage to the duty cycle.

The block diagram of the Arduino, shield, motor and the input and outputs.

The controller that is to be deployed to the Arduino has 2 inputs and 3 outputs.

The first input is the reference speed that is set by the potentiometer value. The second input is the actual speed that is measured by the encoder.

The first output is the duty cycle of the PWM signal that drives the motor. The other two are the reference and actual speed transmitted over a serial RS-232 connection.

Deploy the code.

Open a serial connection to the target.

Set up a scheduled task to read the values every 0.25 seconds.

show complete Wolfram Language input

Plot the results showing the response to set reference values and disturbances.

Remove the task and close the device connection.

Related Examples