Sie sind auf Seite 1von 17

Mechatronics Laboratory

ENGR 3390U
Lab # 4
Open-Loop Control of a DC Motor System
Surname

Name

Student Number

100503517
Edu, Rose

Fracz, Melissa

100487042
100432341

Lalwani, Karan
100457114
Omole, Olutope

Signature

Table of Contents

Executive Summary..........................................................................................................3
Project Definition.............................................................................................................3
Requirements...................................................................................................................3
Engineering Specifications................................................................................................3
Concept Generation..........................................................................................................3
Test Plan..........................................................................................................................6
Discussion and Analysis....................................................................................................8
Conclusions......................................................................................................................9
References.......................................................................................................................9
Appendix.........................................................................................................................9

Executive Summary
This mini project entailed programming a microcontroller DC motor system in an open loop
control. The project was about demonstrating an experiment that required the movement of a cart

mounted on a rack and pinion from one of the racks end to the other end in a specified manner,
timing and order as will be explained further in the report. The code used in performing this tasks
was generated by the students and was designed so that all the tasks were carried out by the same
code. The project definition and engineering specifications as well as the test plan and concept
generated while working on the project will be further discussed in the report.

Project Definition
The main objective of this lab is to learn how to control a DC motor in an open loop by
programming a microcontroller. The microcontroller is an integrated circuit that is made up of a
small central processing unit as well as input and output ports. In this lab, we used a HC (12)
commercial microcontroller made by Freescale. Also this lab would enable the understanding
and demonstration of programming an IR sensor to prevent the cart from going beyond its limit
of travel. The basic task of this project was to move the cart from one end to the other with two
different types of delays on both sides. The cart was to come to a complete stop after completion
of 4 rounds. The coding in this lab requires the use of CodeWarrior CW12 as that is where all
coding would be done. The following is a list of hardware to be used for the mini project:
1) Custom Built Bi-directional motor speed controller (3959 Motor Control IC)
2) Freescale (formerly Motorola) HC(S) 12 Microcontroller Board (MC68EVB912DP256) with
Microcontroller Chip MC9S12DP256BCPV
3) USB Interface and Cable
4) Custom Built Cart System:
Pinion: SI Precision Component S1086Z-024DS024
Rack: WM Berg R4-5 or R4-6
Motor: MicroMo 2224U012SR with Gearbox Series 23/1 (3.71:1 Reduction) and Encoder IE2512
5) Omron IR Sensors (2X)
6) Custom Built Power Conditioning Circuit with Power Supply

Fig 1: Custom built cart System

Fig 2: Mechatronics board with microcontroller, USB interface, power supply and motor
controller

Fig 3 : IR sensor

Requirements
This lab requires two program codes to be made. The first part must stop the cart in
motion, by having the IR sensor detect and be triggered, by programming the HC(S)12
microcontroller. The second part builds off of this first program code. The cart must be able to
move in two directions and stop. Its required to start in the middle and go right, once hitting the
IR sensor the cart must stop for 5 seconds. The cart then must move to the left side of the track at
a constant speed and once again, stop once reaching the IR sensor, but for 10 seconds on this side

of the track. This cart must make a total of four round trips of this track, doing the same stop and
go motions as stated before.

Engineering Specifications
The signals from PB0 and PP0, which are present on the HC(S) 12 microcontroller, control
the DC motor and the TTL signal sent out from the Digital Output port PB0 controls the
direction of the motor rotation. The PP0 port controls the Pulse Width Modulation (PWM)
signal, which in turn controls the speed of the motor. For the DC system,
1. A low TTL signal, containing a value of 0 moves the cart from right to left.
2. A high TTL signal, containing a value of 1 moves the cart from left to right.
Switching these values through digital output port PB0, will change the direction of the
motor, and therefore it could be controlled accordingly. For the PWM motor speed control, the
actual speed of the motor is determined by the Duty Cycle (sometimes expressed in %, or, in
CodeWarrior expressed either as a number from 0 to 255, or as a combination of two numbers in
milliseconds). In the case of the hardware in this lab, the lower the value the duty cycle, the
higher the speed the motor rotates. A duty cycle of 0% results in full motor angular speed, while
a 100% duty cycle results in the zero motor speed. On each end of the cart system, two sets of IR
Sensors (Figure 4), are used to control the travelling bounds of the cart. Port A2 controls the left
IR Sensors output, while PORT A3 controls the right IR Sensors output.

Concept Generation
Flow Chart

Pseudo Code
Part 1
-

Send a low TTL signal for cart to move in a certain direction (left and right)

Duty Cycle controls the carts speed


If the signal sent is of 0 Volts to completely stop the cart

Part 2
-

Send a High TTLsignal to move in a direction (left and right)


Duty Cycle controls the cart speed
PA3 send a low TTL signal of 0 volts to stop the cart
Cart will stop for 5 seconds (sends a low TTL signal from PA3)
Low TTL signal sent to move the cart in a reverse direction (right to left)
Duty Cyle moves the cart at a moderate speed
PA2 sends a low TTL signal of zero to stop the cart
Cart will stop for 10 seconds (continues to send a low signal from PA2)
TTL high signal sent to move the cart in the opposite direction (left to right)
Duty Cycle moves the cart at a moderate speed
PA3 send a Low TTL signal of 0 Volts used to stop the cart
Cart will stop for 5 seconds (continue to send a low signal from PA3)

Set up of program to equipment

Test Plan
We first started by figuring out how the track and sensors run, which are controlled by the
codes in the program. We know there will be two outputs values, one which controls the motor
direction and one which controls the motor speed. When something goes between the two slots
of the IR sensor, it will be triggered, if not a high signal will be sent.

The PBO port controls the direction of the cart, while the PPO controls the location by
the PWM channel. The IR sensors are on PA2 and PA3. When sending a 0 to the PBO the cart
will change directions and go from right to left. When sending a 1 to the PBO the cart will
change directions to go from left to right.
In order to figure out the period the cart was tested at different frequencies. If it was to
high there would be a humming noise from the motor and if it was too low the motor speed
wont speed up. The best frequency ended up being between 1-2 KHz. The period was calculated
by:
1 1
Period= = =1
f 1
This also allowed the starting pulse to be determined by the following calculation:
Starting Pulse=

1
1
= =1
period 1

To set up the code three Bits were used and one PWM. Bit 1 and Bit 2 are both inputs
which controls the Left and right IR sensors at PA2 and PA3 respectively. Bit 3 was an output
controlling the PBO.
Since Bit 1 controls the input, the Get Val function was used as seen below and setting it
to zero makes the IR sensor trigger shown below:
Bit1_GetVal() == 0
The same function was used to for Bit 2, the other IR sensor:
Bit2_GetVal() == 0
Since Bit 3 control the output, and will be the direction of the cart Put Val ( ) was used. 0
was used to move the cart from the right to left, outputting a low value signal.
Bit3_PutVal(0)
1 was used to make to cart go from left to right, outputting a high signal.
Bit3_PutVal(1)
PWM was the other output, controlling the speed of the cart, using SetRatio8, where the
speeds are defined by 0-255, 0 being full speed and 255 being a complete stop. In order to make
the cart fully stop the following was used:
PWM8_SetRatio8(255)

The cart was never needed at full speed, but in order for the cart to move, some speed is
needed. A middle speed was used in order to move the cart along the track:
PWM8_SetRatio8(180)
Once the cart is stopped, we must set the time for the cart to stop on each side. We had to
test the cart and the delay to find the closest time to get to 5 seconds and 10 seconds. For the
right side we use the following, which stops the cart from moving for 5 seconds:
for (i=0; i < 200000; i++)
For the left side we used a different time, in order to keep the cart from moving for 10 seconds:
for (i=0; i < 500000; i++)
In order for this to continuously run, but for 4 round trips only, the code must be within a
while loop and have set criteria to do so. Since 4 loops will mean the cart will trigger the IR
sensors for a total of 9 times, we used the following:
while (x <= 9) {
x++;
}
Two if statements were also included, which allowed the cart to change directions, move
to the other side and stop at the other side for a different amount of time.
If ( ) {
}
The initial speed and direction were also set:
PWM8_SetRatio8(180);
Bit3_PutVal(1);

Discussion and Analysis


The testing of the prototype went well. We followed the instructions provided by the Lab TA and
we began the model compilation. In terms of the stopping of the cart, we programmed the cart to
_____.

Conclusions
The lab was successfully completely. The cart was first able to move and once hitting the
IR sensor, completely stop. From this an open-loop circuit was created which allowed the cart to
move in one direction stop for a certain amount of time and continue to move in the opposite
direction to stop once again for a different amount of time and continue this for 4 cycles in total.
From the movement of the cart it could also be said that the IR sensor was triggered and
functioning properly. The cart we programmed delayed the procedure for 5 seconds when it got
to the right end of the rack and delayed 10 seconds at the left end. Hence the requirement tasks of
the project were met and the main objectives met.

References
1. Mechatronics Lab Manual. Open-Loop Control of a DC Motor System. S. Nokleby, C. Chan,
D. Fischer

Appendix
Part 1

/** ###################################################################
**

Filename : Lab4.c

**

Project : Lab4

**

Processor : MC9S12DT256BCPV

**

Version : Driver 01.14

**

Compiler : CodeWarrior HC12 C Compiler

**

Date/Time : 04/03/2015, 2:41 PM

**

Abstract :

**

Main module.

**

This module contains user's application code.

**

Settings :

**

Contents :

**

No public methods

**
** ###################################################################*/
/* MODULE Lab4 */
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "Bit1.h"
#include "Bit2.h"
#include "Bit3.h"
#include "PWM8.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
/* User includes (#include below this line is not maintained by Processor Expert) */

void main(void)
{
/* Write your local variable definition here */
long i;
int x = 1;
int Direction=1;

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization.

***/

/* Write your code here */


PWM8_SetRatio8(180);
Bit3_PutVal(1);
while (x <= 9) {
if (Bit2_GetVal()== 0 && Direction == 1 ) {
PWM8_SetRatio8(255);
for (i=0; i < 200000; i++) {
}
PWM8_SetRatio8(180);
Direction = 0;
Bit3_PutVal(0);
x++;
}
}
PWM8_SetRatio8(255); // stop the cart

/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;){}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* END Lab4 */
/*
** ###################################################################

**
**

This file was created by Processor Expert 3.02 [04.44]

**

for the Freescale HCS12 series of microcontrollers.

**
** ###################################################################
*/

Part 2

/** ###################################################################
**

Filename : Lab4.c

**

Project : Lab4

**

Processor : MC9S12DT256BCPV

**

Version : Driver 01.14

**

Compiler : CodeWarrior HC12 C Compiler

**

Date/Time : 04/03/2015, 2:41 PM

**

Abstract :

**

Main module.

**

This module contains user's application code.

**

Settings :

**

Contents :

**

No public methods

**
** ###################################################################*/
/* MODULE Lab4 */

/* Including needed modules to compile this module/procedure */

#include "Cpu.h"
#include "Events.h"
#include "Bit1.h"
#include "Bit2.h"
#include "Bit3.h"
#include "PWM8.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"

/* User includes (#include below this line is not maintained by Processor Expert) */
void main(void)
{
/* Write your local variable definition here */

long i;
int x = 1;
int Direction=1;
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization.
/* Write your code here */

PWM8_SetRatio8(180);
Bit3_PutVal(1);

***/

while (x <= 9) {
if (Bit2_GetVal()== 0 && Direction == 1 ) {
PWM8_SetRatio8(255);
for (i=0; i < 200000; i++) {
}
PWM8_SetRatio8(180);
Direction = 0;
Bit3_PutVal(0);
x++;
}
if (Bit1_GetVal()== 0 && Direction == 0) {
PWM8_SetRatio8(255); // cart stops
for (i=0; i < 500000; i++){

//for 5 seconds

}
PWM8_SetRatio8(180);
Direction = 1;
Bit3_PutVal(1);
x++;
}
}
PWM8_SetRatio8(255); // stop the cart

/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;){}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* END Lab4 */

/*
** ###################################################################
**
**

This file was created by Processor Expert 3.02 [04.44]

**

for the Freescale HCS12 series of microcontrollers.

**
** ###################################################################

*/