MEE446 Control Systems Lab ∙ Laboratory Modules
DC motor with encoder
Introduction
In this module, we will be building the circuit of a DC motor with its embedded encoder.
Then, we will use LabVIEW myRIO to create a PID speed controller for the DC motor.
In this sheet we will use Port C of the myRIO.
The items used in this experiment are:
1- DC motor with encoder JGA25-370 (12V)
2- Dual H bridge L298N
3- Power supply (12V)
4- myRIO microcontroller (Port C)
5- Connecting wires
L298N H bridge DC motor pins
Module 9 myRIO
Fallport
2024C Page 1
MEE446 Control Systems Lab ∙ Laboratory Modules
Hardware
Step 1: Power the H bridge
Connect the Vs pin of the H bridge to the positive pin (+) of the power supply.
Connect the GND pin of the H bridge to the negative pin (-) of the power supply.
Step 2: Connect the DC motor to the H bridge
Connect pin 1 (Motor -) and pin 6 (Motor +) of the DC motor to Motor A pins of the H bridge.
Step 3: Power the Encoder
Connect pin 2 (Encoder -) on the DC motor to the DGND pin of the myRIO.
Connect pin 5 (Encoder +) on the DC motor to the +3.3V pin of the myRIO.
Note: Make sure the DGND of the myRIO and the GND of the power supply are connected.
Step 4: Connecting signals to controller
Connect pin 3 (Encoder A Phase) from the DC motor to DIO0 on myRIO port C.
Connect pin 4 (Encoder B Phase) from the DC motor to DIO2 on myRIO port C.
Connect Enable A from the H bridge to pin 14 (DIO3/PWM0) on myRIO port C.
Connect Input 1 from the H bridge to pin 13 (DIO2) on myRIO port C.
Connect Input 2 from the H bridge to pin 15 (DIO4) on myRIO port C.
Module 9 Fall 2024 Page 2
MEE446 Control Systems Lab ∙ Laboratory Modules
Software
Step 1: Reading angle position from Encoder
Create a while loop and add a stop condition.
Add Encoder 0 block from the myRIO library.
Create a case structure and connect i to the selector. The case structure will be used to reset the
counter of the Encoder.
Make 1 the default case and create in it a button controller. Connect the button to Reset
Counter on the Encoder block. In case 0, connect a True constant.
Create indicators for Counter Value and Counter Direction
To calibrate the angle of the motor, rotate your DC motor 10 rotations and check the reading on
the Counter Value. Divide the reading by 10 to get an approximation for the counter value for
one rotation. The DC motor’s encoder we are using should give approximately 905 counts per
revolution.
To convert the reading to an angle we need to divide by 905 to get the number of revolution
and them multiply by 360 to convert the revolutions to an angle. We can simply multiply by
0.39779.
Module 9 Fall 2024 Page 3
MEE446 Control Systems Lab ∙ Laboratory Modules
Step 2: Reading speed from Encoder
Add a tick count (ms) block.
To get the speed, we need to divide the difference in angle by the difference in time. Therefore,
we need 2 shift registers, for angle and time.
After that, we need to convert the signal from degrees per milliseconds to rpm (rounds per
minute) therefore we need to divide by 360 and multiply by 60000.
Bonus: It is preferable to filter the signal, therefore a low pass filter can be added.
Module 9 Fall 2024 Page 4