This document was last modified:
Lab 2: Finding DC Motor Constant Values
Table of contents
- Lab Objective
- Deliverables
- General Steps for Completion of Lab
- Step 1 - Prep the DC Motor Wire Harness.
- Step 2 - Overview of the DC Motor
- Step 3 - Assembling the DC Motor for the Lab
- Step 4 - Setting Up the Motor Encoder in PSoC Creator
- Step 5 - Find Your Count Per Revolution (CPR)
- Step 6 - Controlling DC Motor Speed
- Step 7 - Find the Velocity Constant (KV) Via a Single Reading
- Step 8 - Find the Velocity Constant Via a Linear Trendline Fit
- Step 9 - Compare Predicted Motor Speed to Achieved Speed for a Given Torque Load
Lab Objective
Ensure that you can control a DC motor speed and reinforce the subject matter covered in the lecture on “DC Motors and Encoders.”
Deliverables
-
In-class demonstration with the LCD screen displaying a reading of the RPM/speed from one of the many runs used in finding the motor velocity constant (KV).
-
In-class demonstration with the LCD screen displaying the RPM/actual speed for your torque load and being able to tell what your predicted speed for that torque rating.
-
A Canvas submitted document that contains the following items:
-
The calculation and result for figuring out your Count Per Revolution (CPR).
-
The steps for finding the motor velocity constant (KV) via a single reading.
- Table and graph for finding the KV via a linear trendline fit.
- Table has a Title.
- The table`s columns are labeled.
- Graph has a Title.
- Both graph axes are labeled, and unit values are given as needed.
- A trendline that was formed from the points on the graph.
- The trendline formula is shown along with the fit value of r2.
- The method used to determine the linear line equation for Torque vs Speed.
- If by equation, show the steps to calculate the equation.
- If by trendline, show the graph for the Torque vs Speed along with the Table used to generate the graph.
- The graph should include the title.
- Both graph axes are labeled, and unit values are given as needed.
- The trendline formula is shown along with the fit value of r2.
- Show the reworked equation to have Torque as the input.
- The mass or torque used to determine the predicted motor speed.
- Compare the predicted and resulting motor speed for that torque load.
-
Credit for Submitted Files
To receive the credit for the submitted file(s), you must receive demonstration credit.
General Steps for Completion of Lab
Step 1 - Prep the DC Motor Wire Harness.
To Hide Details
To make it easier to connect the motor and encoder wires to the controller, it is strongly suggested that you solder six of your jumper wires to each of the wires of the motor wire harness, similar to what is shown in Figure 1:.
NOTE
- It would suggest using either the Male-to-Female or Female-to-Female jumper wires.
- Cut off the the Female connector and stripe the the end.
- If using heat-shirk to protect the wire connection, make sure it is on the wire before soldewring the wirwes together.
- To avoid confusion later, use jumper wires that have the same color.

Step 2 - Overview of the DC Motor
To Hide Details

WIRING NOTES
- Power + and Power - goes directly to the motor, and the way the polarity is connected determines the direction of rotation.
- Encoder Power + and Encoder Power - is for the encoder and is powered by the controller.
- The two feedback wires are the two channels of signal.
Encoders use a magnetic disc and hall effect sensors to provide 12 counts per revolution of the motor shaft. The sensors operate from 2.7 V to 18 V and provide digital outputs that can be connected directly to a microcontroller or other digital circuit.
Specifications (Motors labled 150)
6V 100-1 Micro Metal Gearmotor w/ Encoder & Cable, 150 rpm
- Model: 12SG-N20VA-100-EN
- Rating Voltage: 6 V DC
- Operation Voltage: 1.5 to 12 V DC
- Gear Ratio: 1/100
- No Load Speed: 150 RPM
- No Load Current: 40 mA
- Rated Speed: 120 RPM
- Rated Torque: 0.35 Kg.cm
- Rated Current: 155 mA
- Stall Torque: 1.75 Kg.cm
- Stall Current: 0.55 A
Motor Source: https://www.robotshop.com/products/e-s-motor-6v-1001-micro-metal-gearmotor-w-encoder-cable-150rpm
Specifications (Motors labled 100)
6V 150-1 Micro Metal Gearmotor w/ Encoder & Cable, 100 rpm
- Model: 12SG-N20VA-150-EN
- Rating Voltage: 6 V DC
- Operation Voltage: 1.5 to 12 V DC
- Gear Ratio: 1/150
- No Load Speed: 100 RPM
- No Load Current: 40 mA
- Rated Speed: 80 RPM
- Rated Torque: 0.55 Kg.cm
- Rated Current: 150 mA
- Stall Torque: 2.75 Kg.cm
- Stall Current: 0.55 A
Motor Source: https://www.robotshop.com/products/e-s-motor-6v-1501-micro-metal-gearmotor-w-encoder-cable-100rpm
Step 3 - Assembling the DC Motor for the Lab
DC Motor Assembly
To keep the your student kit cost down, the assembly of the DC motor with mounting hub and 3D printed parts needed for this lab is something that you get and return.
Please, Do Not Disassemble
You will need to use the DC motor wire harness that is included in your kit.
Extend for Details
Attach the DC motor to the torque lab bracket with two of the Pan-Head, Phillips Screws M1.6 x 0.35mm Thread, 4mm Long as shown in Figure 3.

Now, before attaching the mounting hub to the torque lab spool, position the non-looped side of the string so that the knot is either:
- Inside the recessed notch, as shown in Figure 4. (It will be fine if the knot is slightly above the surface.)
- Or going across the area where the mounting hub will be attached as shown in Figure 5.


Suggestion
Before mounting the hub, it will be easier if you start threading one of the 4-40 set screws in the side threaded hole.
Attach the mounting hub to the torque spool with two to four Pan-Head, 2-56 Thread, 1/4 inch long, slotted screws. Figure 6 shows the positioning of the mounting hub capturing the torque string, and Figure 7 shows that you will have to tighten the screws by passing the screwdriver through the holes.


With the mounting hub attached to the spool, you now need to attach it to the shaft of the DC motor. To do this, align the flat section of the “D” part of the shaft with the #4-40 set screw. With the mounting hub clear of the DC motor screws, tighten the set screw onto the flat section with the included Allen wrench. This is what is being attempted to be shown in Figure 8.

The last few things you will need to do will be to:
- Align and insert the motor wire harness into the socket on the motor.
- Connect the other ends for the encoder to the EGR "controller" per the way you assigned the pins in the upcoming steps.
- Consider winding the torque string around the spool so it is out of the way till later.
Your DC motor setup for this lab should look something like Figure 9.

Step 4 - Setting Up the Motor Encoder in PSoC Creator
Setup and Component Module Setup
To Hide Details
- In your Robotic I workspace, create a new project for this lab.
- Add the “Quadrature Decoder” and “Character LCD” component modules to the “TopDesign.” Figure 10 shows the placing of these modules into the “Topdesign” area.

- Figure 11 shows the settings inside the “Quadrature Decoder” component module on the "Counter Size" tab. The follow are the different settings on the differnt tabs.
- Counter Size tab: select 32 bit because we have lots of memory space to hold a large count values.
- Counter Resolution tab: select “4x” because it will give a count for each change in state in any combination for both hall effector sensors.
- Use Index Input tab: make sure the “Use index input” is unselected because this encoder does not have a indexing signal.
- Enable Glitch Filtering tab: turn on/check.
- Built-in tab: there is nothing to add or select.

- Add two digital input pins, one for each encoder output to go into “quad_A” and “quad_B.”
- Name each pin to a helpful value (i.e. C1 and C2 or A and B)
- The default settings remain.
- Drive mode: “High impedance digital”
- Initial drive state: “Low (0)”
- “HW connection”
- Add a clock pin to the “QuadDec” clock.
- With the component module placed, the pins can be assigned. For the LCD component module, you will select an array of 7 pins (P2[6:0]). For the encoder`s first counter switch, C1, select P1[5], and for the second counter switch, C2, select P1[6], as shown in Figure 12.
- Connect the encoder`s ground line (“blue”) to the PSoC ground.
- Connect the encoder`s power line Vcc (“black”) to the the PSoC Vdd power.

Basic Encoder Code for the “main.c” file.
Follow is the basic code to start working with the encoder.
//Basic code to start working with the encoder.
#include "project.h"
int main(void)
{
int count; //to hold the count value
CyGlobalIntEnable; //This is needed for the QuadDec
QuadDec_1_Start();
LCD_Char_1_Start();
for(;;)
{
count=QuadDec_1_GetCounter();
LCD_Char_1_ClearDisplay();
LCD_Char_1_Position(0,0);
LCD_Char_1_PrintNumber(count);
CyDelay(50);
}
}
Step 5 - Find Your Count Per Revolution (CPR)
To Hide Details
- After writing the code to the PSoC with the PSoC program to display the encoder`s count value, rotate the spindle/hub to determine which way to turn it to get an increasing count value.
- Once you know which way to turn the spindle/hub, press the reset button to zero out the count.
- Now, carefully, and slowly rotate the spindle/hub 8 to 20 rotations.
- To help track the complete revolution of the spool, use the hole that is near one of the corners of the hexagon in relation to a fixed point.
- Your accuracy of the CPR value increases as you increase the number of rotations used to get the CPR value.
- Note the count value and the number of rotations.
- Divide the count value by the number of revolutions to get an average CPR.
Counter Max Count Value
There is a limit to how high the counter value will go before resetting. This value for me was about 65500. So, I would suggest that when the counter value is near 65K, finish that rotation as to be the last one.
Step 6 - Controlling DC Motor Speed
While there are multiple ways of powering and controlling the speed of the DC motor, you are expected to use an H-Bridge/Pulse width method for this lab. This method can provide a maximum voltage level of up to 6 volts with a full amp, which is at the normal operation voltage level.
To Hide Details
Setting up PWM for DC Speed Control
To get a controlled change in measurable voltage levels, you will vary to a Pulse Width Modulator (PWM) signal at an extremely fast rate. The PMW rapidly turns on and off a fixed voltage level so fast that the detectable/perceived voltage level is a percentage of the time the PWM signal is high/on. To be able to program a PWM output signal in PSoC Creator, you need to:
- Add the Pulse Width Modulator (aka PWM [v3.3]) to the TopDesign page.
- Now, you need to open and adjust the configuration file of the PWM module by double-clicking on this module.
- On the “Configure” tab:
- Set the “PWM Mode” to “One Output.”
- Set the “Period” to 100.
- Set the "CMP Value 1" to 100.
- The other tabs are left in their default settings.
- Add a Logic Low pin to reset the connection of the PWM component module.
- Add a Clock component and connect it to the clock of the PWM component module.
- Leave at the highest clock frequency so that the pulse width switching time period is super-fast.
- Add a Digital Output pin and connect it to the pwm1 connection of the PWM module.
- Rename the pin to something helpful (i.e. Motor PWM)
- Make sure the “HW connection” is checked.
- Initial drive state is “Low (0) .”
- Now go to the pins under Design Wide Resources and connect the newly added Output pin to a PSoC controller pin. Something like P1[2].
- Now modify existing code to match or add the following code and change the compare value as needed to change the supplied voltage. (see code below)

// Code to use the PWM and encoder with the DC motor along with displaying speed on the LDC screen.
#include "project.h"
int main(void)
{
int count1; //to hold the count value
int count2;
int countDifference;
float cpr = 4222.0; // This should be your CPR value found earlier
float speed;
int Compare = 10; // 100 == full speed/pulse-wide and 0 == is off
CyGlobalIntEnable; //This is needed for the QuadDec
QuadDec_1_Start();
LCD_Char_1_Start();
PWM_1_Start();
for(;;)
{
PWM_1_WriteCompare(Compare);
QuadDec_1_SetCounter(0); // This resets the Encoder count to zero
CyDelay(1000); // This delay is to allow time for the motor to get up to speed
count1=QuadDec_1_GetCounter(); //Get first count value
CyDelay(1000); //wait a know period of time
count2=QuadDec_1_GetCounter(); //Get second count value
countDifference=count2-count1;
speed = (countDifference*60.0)/cpr; //See lecture notes if more info needed
LCD_Char_1_ClearDisplay();
LCD_Char_1_Position(0,0);
LCD_Char_1_PrintNumber(Compare);
LCD_Char_1_Position(1,0);
LCD_Char_1_PrintNumber(speed);
}
}
Use the following table to connect to the H-Bridge for this Lab setup. For the DC motor, the table indicates one of the motor power lead goes to “1Y.” The other motor lead is connected to ground.
H-Bridge Pin Number | H-Bridge Pin Name | Connection To |
---|---|---|
1 | EN A (1,2) | PSoC PWM Speed Pin (P1[2] was suggested) |
2 | 1A (DIR) | PSoC VDD or a PSoC pin that goes high to turn on the motor and low to turn off the motor. |
3 | 1Y | Motor (One Lead) |
8 | VCC2 | Positive power from DC wall Plug |
4, 5, 12, 13 | Ground | Ground (Done by PCB) |
16 | VCC1 | VDD (Done by PCB) |
9 | EN B (3,4) | Not used in this non-directional example |
6 | 2Y | Not used in this non-directional example |
7 | 2A | Not used in this non-directional example |
10 | 3A | Not used in this non-directional example |
11 | 3Y | Not used in this non-directional example |
14 | 4Y | Not used in this non-directional example |
15 | 4A | Not used in this non-directional example |
H-Bridge Source: https://www.ti.com/lit/ds/symlink/sn754410.pdf?ts=1718345235534&ref_url=https%253A%252F%252Fwww.mouser.com%252F
To determine the DC motor`s voltage level, you convert the “Compare” value into a percentage value. Then, multiply this percentage value by the voltage value supplied to the motor (6 volts). For example, if the compare value was set to 90 with the 6-volt wall wart/power plug, then:
Step 7 - Find the Velocity Constant (KV) Via a Single Reading
Find KV by using the velocity constant formula from the lecture notes, along with a voltage level and the speed that was produced at that voltage level.
Step 8 - Find the Velocity Constant Via a Linear Trendline Fit
Run the DC motor at 9 different voltage levels. During each voltage level, collect three speed values. Then, use the average of those speeds per voltage level to get nine points to create a linear graph, which is Speed vs Voltage.
Step 9 - Compare Predicted Motor Speed to Achieved Speed for a Given Torque Load
Using the Stall torque, No-Load Speed, and voltage rating for the kit`s DC motor found in the Step 2: Overview of the DC Motor section, create a linear equation for Torque versus Speed. The linear equation can be found either:
- Creating a Torque versus Speed scatter plot using only the Stall torque and No-Load Speed from the motor specifications. Then, add a trendline to get a linear sloped equation.
- Use the linear sloped equation to find this equation using only the Stall torque and No-Load Speed from the motor specifications.
This equation will find the torque load the motor can handle at the given speed input. Rearrange the equation so that the Torque load is now the input, and the output is the speed. Use this new formula to predict the speed for a torque load force of your choice. To produce this torque force, use the spool dimension shown in Figure 14 to determine the lever arm length and some weight arrangement that varies somewhere between one kilogram and 100 grams, in increments of 100 grams. You will hook this weight configuration onto the end of the torque string. Run the motor at the rated voltage level and display the speed of the motor under load on the LCD screen.
LIMITED WEIGHT SETS
There is a limited number of One kilogram weight sets that has to be shared.
- Please only take a set when you are ready to use it.
- Do not remove from classroom. There are multiply class section.
