You are on page 1of 13

KJST 1 (1) pp.

59-71 2011

KIST Journal of Science and Technology


Volume 1 Number 1

Microcontroller based motor control system


for the dieless drawing process

Gerard Rushingabigwi*
Department of Electrical & Electronics Engineering, KIST, 1 Av. de laArme P.O.
Box: 3900 Kigali-Rwanda.. E-mail: g.rushingabigwi@kist.ac.rw

Xiaojuan Ban & Dongxing Wang


Department of Computer Science and Technology, University of Science and Technology, Beijing (USTB), Post Code: 100083 Beijing, P.R.China, 30 Xueyuan Road.
ABSTRACT
Problems are encountered in conventional workability such as: long production
circle, high production cost as well as low uniformity and instability of quality
and performance, which require high accuracy. To minimize such problems in
manufacturing engineering, and to experiment the microcontroller as a control
tool having advantages of high accuracy, programmability, low cost and small
size, this research work was carried out to simulate a control work on the dieless
drawing system.The dieless drawing is a method of metal processing, which does
not draw using mould like the traditional method, but which, by induction heating
is used to partially heat up the metal wires to a higher temperature (Pan and
Fan, 2002. By giving the work piece a constant drawing speed, the metal wire
will come into deformation at the heated area. Through cool water, the partial
deformation can be controlled to obtain the desirable cross-section. During this
microcontroller based control work, the user gives digital control commands to
the microcontroller which controls the step motor according to the given commands, thus controlling the cooling systems gap against the work piece. The
microcontroller must return the control information to the user who, according
to that feedback, readjusts the next inputs issued to the microcontroller.Through
repetitive inputs by the user and readjustments of the control instructions, the
precise positioning of the cooling system is successfully realized to simulate the
dieless drawing process. The experiments for this work show that the microcontroller is good at controlling the step motor when the problems of overshooting
and step loosing are properly solved. The gap between the cooling system and
the heated work piece was accurately adjusted in such a way that the cooling
system run by the step motor is positioned accordingly by manipulating the speed
of the motor during coding.
*Corresponding author

Cellophone: +250785469187 or 0725032674. E-mail: g.rushingabigwi@kist.ac.rw


59

KEYWORDS
Microcontroller,
dieless drawing
system, 2-phase
step motor,
embedded
systems

Gerard Rushingabigwi, Xiaojuan Ban & Dongxing Wang

INTRODUCTION
Microcontrollers are found in almost all smart
electronic devices. From microwaves to automotive braking systems, they are doing jobs that
make peoples lives more convenient and safer.
Microcontrollers are essentially small computers. Unlike the desktop computer, microcontrollers interact with other machines rather
than humans. A microcontroller might be used
to control the temperature of a toast at breakfast and when the temperature reaches a predetermined measure, the toaster could be automatically turned off. A microcontroller could
also be used to count the number of customers
entering the ball park through a turnstile, thereby keeping track of ticket sales (Martin, 2002).
The microcontroller is utilized in this work to
control the speed of a hybrid step motor because the gap between the step motor-driven
cooling system and the work piece needs to
be precisely controlled. During dieless drawing
process, a tube is fixed at one end, heated and
cooled at a part. It is then pulled at the other
end with a certain tensile force, allowing the
heater and cooler to move in the opposite direction, with all movements being motivated by
the step motor.

METHODOLOGY
Different control methods were reviewed such
as intelligent control method, microcontroller
control method, etc. Finally a microcontroller
control method was chosen to be utilized in this
work after assessing different process control
modes and finding that On/Off process control
mode is suitable for the microcontroller based
on the control of the step motor.
Intelligent control method is any system that is
able to effectively access, transmit, process, recycle and use information, in any given environment to successfully achieve the intended purpose. The intelligent core is a thinking activity
based on whats known as inference engine.With
the inference engine or simply if .. then statement while programming, the purpose of intelligent technologies is to design and manufacture
the high level of artificial intelligence systems to
serve the community according to the needs.
Such systems can be used to carry out various
tasks even more accurately than human beings
(Michael, 2005; Cai, 2003, 2002).

A microcontroller is a miniature computer that


can be found in all kinds of controllable devices.
As examples, peoples everyday materials like miThrough repetitive inputs and readjustments of crowave ovens, digital radio sets, mobile phones,
the control instructions, the accurate position- etc have inbuilt microcontrollers. If the device
ing of the cooling system is successfully realized. has buttons and a digital display, chances are that
The microcontroller commands the running of it also has a programmable microcontroller.
the step motor, the communication being made Loading a program into a microcontroller
through the proper motor drive. On the other
side, the microcontroller communicates with a This is to demonstrate how programs are loaded
computer through the RS232 serial ports (Zhou, into a microcontrollers memory as shown in Fig.
2009).

Fig. 1. The flowchart of a program into a microcontroller


60

Microcontroller based motor control system for the dieless drawing process

1.The microcontroller being set to communicate


with the personal computer as the first step, a
microcontroller program is written and saved
as ASCII text, then saved with any name ending
with dot c. The written and saved program is
compiled to check for errors and if there are no
errors, it is translated into microcontroller machine language by the C-programming language
known as a compiler. Finally, the program is loaded by the programmer into a microcontroller
which is an integrated circuit on a breadboard;
thats when the program loading takes effects
and the desired actions are observed on the microcontroller that performs the wanted tasks.
After choosing STC89C51/RD+Series Microcontroller, the manufacturers recommended
users to program this in C language under the
environment of Keil Micro vision, or simply Keil
Vision IDE (Beijing blue ocean micro-chip technology, 2009).The Vision IDE is the easiest current way for most developers to create embedded applications in C language.
Survey across the process control modes
The Process Control is an act of measuring inputs and taking action based on those inputs.
The type of reaction that takes place upon evaluation of the inputs during such an act defines the
process control mode.

Five common process control modes as mentioned in the Table 1 are On/Off, Differential
Gap, Proportional, Integral, and Derivative; while
for the PID is a combination of the three modes
(Proportional-integral-Derivative).
On-Off control
On/Off control is the simplest of the five control modes. Full output action is taken based on
whether the measured value is above or below
the desired value. As a result, the output action
drives the measurement back towards the set
point. When the measured value passes the set
point, the error polarity changes and the output is driven fully to the opposite direction. The
process cycles back and forth past the set point
based on this action. At an incubator for example, it needs to maintain the temperature between 100C and 110C. To get a median value,
a set point of 105C may be used. If temperature
falls below 105C, the heater will turn on. At
105C or above, the heater will shut off.
On/Off control is suitable for processes that
have large capacity, sluggish response, and a relatively constant level of disturbance.
Differential-gap control
Differential-gap control is similar to On/Off
control in that only full output action is taken.
Differential gap control does not take this ac-

Table1. The fundamental characteristic of the process control modes

61

Gerard Rushingabigwi, Xiaojuan Ban & Dongxing Wang

tion based on a single desired set point. Instead,


it defines an upper and lower tolerable limit.
When the measured value goes beyond a limit,
full appropriate action is taken and maintained
until the measured value is driven to the opposite limit. Full opposite action is then taken
to drive the process back to the other limit.
Therefore, the process is cycled between the
upper and lower limit. The rate of this cycling is
determined by the overall speed of response of
the process. The differential-gap mode of control is appropriate when the process is large
and sluggish.
To demonstrate differential gap control in the
same incubator example, if a desired set point
of 105 2C is defined, the heater will energize when temperature drops to 103C and
turn off when temperature exceeds 107C
Derivative & integral control
Derivative control adjusts the drive based on
the rate of change of the error. For the above
example, the faster the temperature drops, the
greater the amount of drive. Or conversely, the
faster it rises the more the drive will be reduced.
Derivative control by itself is not useful because
output drive is only determined by the rate of
error signal, but when combined with proportional control the combination can be effective

at quickly compensating for a disturbance. This


is known as proportional plus derivative control
(PD control). PD control mode is effective for
small capacity, rapidly changing processes where
disturbances happen quickly and at high magnitudes. A rapidly decreasing temperature in the
incubator would indicate that the door may have
been opened. Derivative control would drive the
heater hard in an effort to compensate for the
anticipated further drop in temperature.
As a programmer, a method must be developed
to evaluate the derivative or rate of change of
the error signal. This rate is then taken into account in the control evaluation (Carbondale,
1999, 2000). After surveying five common process control modes, the on-off process control
method is suitable for this work.
The dieless drawing system
Dieless drawing forming process is a frictionless
thermal processing technology that aims at getting enough cross-section shrinkage. This forming process is suitable for high-friction, hard materials and wire forming (Kawaguchi, 1991).
Looking at an example of optical fiber manufacturing as illustrated in Fig.2, the process is
so complex that it is done into two steps: making the preform, then drawing (Shotwell, 1999).
The size of the fiber is monitored as it is pulled
through the neck, and adjustments are made to

Fig.2. Optical fibers drawing process


62

Microcontroller based motor control system for the dieless drawing process

the temperature of the preform and the speed


of the drawing so that the size of the fiber is
constant.

In this work, the two phase hybrid step motor


is utilized for the intelligent dieless drawing system, and Fig.3 shows how the cooling system
shall be moved from one place to another. The
Industrial application of the step motor in cold water that is contained in an elevated water
the dieless drawing process.
source is pumped down and this pumped water
is stored into a container that will be moving
The step motors have found their place in many towards and backwards to the heated part of
different applications such as printers, plotters, the work piece. The heating source generates
hard disk drives, medical equipment, fax ma- the heat energy transmitted by a heating resistchines, automotive and many more. Before dis- ance (heater) surrounding the rod to be drawn
cussing the role of the step motor for the die- or pulled.As the heat energy and the cooling waless drawing system, it is important to look at ter are both needed for the quality of the work
some characteristics of step motors. These in- piece (rod), the gap of about 10 to 20mm must
clude step motors are constant power devices; be maintained and this is the core of this work.
as motor speed increases, torque decreases; the
torque curve may be extended by using current Design of a precise positioning system
limiting drivers and increasing the driving voltage; step motors exhibit more vibration than The main objective of this design is to utilize a
other motor types, as the discrete step tends microcontroller to drive a hybrid step motor
to snap the rotor from one position to another, that will move forward and backward accordalthough this vibration can become very bad at ing to the needs. The pulses of this motor must
some speeds causing the motor to lose torque; be controlled in terms of rotational frequency
and, a step motor is a good choice when con- versus time, and finally the instructions given to
trolled movements are required.

Fig.3. Image of the dieless drawing water cooling system.


63

Gerard Rushingabigwi, Xiaojuan Ban & Dongxing Wang

the microcontroller must be adjusted in order


to maintain the wanted gap between the cooler
and the work piece.
It is a simulation control whereby the upper machine of the dieless drawing system is mimicked
by the user who gives the hexadecimal digital
instruction to the lower system made of the
microcontroller system; and the lower machine
must process the given instruction to run the
motor, then it reports back the results to the
user.

controller is on electronic breadboard or simply


the printed circuit that facilitates the connection
with the step motor through the motor drive.
Very quickly as the microcontroller receives
the programs instructions, it executes these instructions by running the step motor and simultaneously returns the feedback to the user who
stands for the upper dieless drawing system
during this simulation work. The supervisory
computer is there to for modifications of the
microcontroller program and for other simulation manipulations.

The role of this system is to accurately position


the cooling device that needs to be dynamic during the dieless drawing process and this is done
by controlling a step motor. The design of a precise positioning system is shown in Fig.4 where
the microcontroller known as lower machine
receives programmed instructions and notifies
back to the user to have received and processed
the offered instructions. Of course the micro-

Through repetitive inputs by the user and readjustments of the control instructions, the
accurate positioning of the cooling system is
successfully realized to simulate the dieless
drawing process. From the users inputs, the upper machine structure or dieless drawing system which is a constructed intelligent control
system, must give the relevant instructions (to
run or stop) to the lower machine system, as

Fig.4. A simulative design of a precise positioning system.


64

Microcontroller based motor control system for the dieless drawing process

well as the rotation parameters (rotational or


angular direction). The upper-to-lower machine
data is always exchanged through the RS232 serial port of a PC. The upper machine structure
will receive the control instructions and running
parameters transmitted by the lower machine
structure. After the lower machine structure
executes instructions, the feedback information
will be given to the upper machine or dieless
drawing system.
Experimental work
Firstly there is need to select the electric current of 2.4A as specified by manufacturers of
the step motor. After setting the rated electric
current on the motor drive (Chawakorn, 2008),
the switches on this motor drive must be set as
off-on-off as shown by Fig. 5

Fig. 5. Setting of the motor drive


The program allowing communication of the microcontroller with the step motor through the
motor drive is simplified by the flow diagram
shown in Fig. 6. The connection of the micro-

Fig. 6. The flow diagram for the communication of the microcontroller with the step motor
65

Gerard Rushingabigwi, Xiaojuan Ban & Dongxing Wang

Fig. 7 Results displayed


controller to the computer is done through the
RS232 serial port. When the program is compiled and run with the command of 2F given
into the command window, the instruction is
processed by the microcontroller and a backreport is displayed to the user as 2F (same as
the input) followed by 00 to mean the success
of a command.
It is of great importance to show how the microcontrollers programs are coded. This is shown
by a code put in appendix; the program cannot
run unless some bugs are removed.
The motor starts accelerating from the initial
frequency f0, the current frequency changes
once for each pulse in accordance with the
frequency-dependent function, until it reaches a
stable operating specified frequency which is the
end of acceleration process.

notably when 2 is followed by a hexadecimal digit put in the command window, 2F for example.
3) case 0x3: runFlag = 0; break; // The motor
stops, notably when 3 is followed by a hexadecimal digit put in the command window, 3F for
example.
The pictured window in Fig. 7 shows the results
displayed to the user when the instructions 1),
2) and 3) are respectively given to the microcontroller. The target is to attain a high speed and
a quick response for the basic requirements of
On/Off control mode; this is attained when F is
given as hexadecimal digit.

The encountered problems and solutions


During the running of the step motor, so as to
position the cooling system very well, two problems were encountered. These were: overshooting or vibration as the motor starts or stops;
and step-loosing. To solve the problems two
The code running and explanations
methods were utilized: the motor drive microWhen the written code is debugged and run, stepping technology; and the coding method.
hexadecimal instructions are given to the microcontroller into the command window. The A. The motor drive micro-stepping technology
microcontroller must process the commands One eighth (1/8) micro-stepping was chosen acand in a short while send the feed-back informa- cording to the motors specifications in order
tion to the user; these instructions are the same to reduce the step motors stepping angle, thus
as those it would communicate with the upper reducing the vibration, with the basic concept
control machine (Carbondale, 1999, 2000).
of step motor drives micro-stepping. The motor
drive micro stepping technology, as shown in Fig.
A small portion taken from the appendix code 8, is just to minimize the overshooting problem
helps to understand the digital instructions given but does not completely remove it. When this
to the microcontroller:
micro-stepping technology is not practiced, the
overshooting becomes so severe that the step
1) case 0x1: P01 = 1; runFlag = 1; break; // The motor looses steps which lead to the unwanted
motor runs in forward direction, notably when stopping of the motor.
1 is followed by a hexadecimal digit put in the
command window, 1F for example.
2) case 0x2: P01 = 0; runFlag = 1; break; // The B. The software method
motor runs in opposite or backward direction, By coding, the non-linear pulse control of the
66

Microcontroller based motor control system for the dieless drawing process

Fig. 8. The step motor drives 1/8th micro-stepping

Fig. 9. The frequency dependency curve for both speeding up&


speeding down processes.

step motor can be achieved so as to get the


non-linear speed, especially when the step motor is starting and stopping, as shown in the Fig.
9.
67

Here the source code is manipulated, and according to calculations with reference to the
commonly known formula shown in Equation 2
(Hui., 2008; Wang, 2008; Zhou, 2009), the vibration and overshoot problems were completely

Gerard Rushingabigwi, Xiaojuan Ban & Dongxing Wang

Let

Table 2 Data for the step motor speeding up & speeding down processes

solved
The value of 65535 is considered instead of
65536 simply because counting in this work
starts from 0 not from 1. After making a number
of calculations by the formula shown in Equation
2 above, and trying several times running the
motor, a better positioning of the dieless drawings cooler is found. The good rotational moment (torque) is obtained with the nth trial; it is
68

corresponding to the motors frequency of 7.68


KHz that gives the counter of initial value of:
During practices, for example, with the initial
value count of 65229 that corresponds to the
smallest motor frequency of 3 KHz, the rotational speed is so high that the microcontroller
gets confused and doesnt obey the commands,
which leads to errors in the precise positioning
of the cooler especially when the bigger hexa-

Microcontroller based motor control system for the dieless drawing process

Fig.10. The bad result in case of extra high motor speed.

Fig.11. Good results to control the gap of 10-20mm.

decimal instruction (F) is given.


Observed from data in Fig. 10, the microcontroller
runs the stepper motor twice (1F 1F or 2F 2F) before reporting back (00) to the user. This is bad and
is not recommended for the precise positioning of
the cooler.
Taking the initial value count of 65413, the speed is
moderate: neither low nor high and as the code is
run, instructions given in hexadecimal digits, the good
wanted speed is observed and the desired gap maintained. Fig.11 illustrates 4 trials that are made in one
direction. The direction is shown by the first digit
while for the second digit is talking about the running
speed of the step motor. Results are said to be good
because the motor runs with a moderate speed, this
is testified by the feedback to user given once as 00
by the microcontroller at every offered instruction.
.
These results mean that the initial value count in the
source code must be fixed to 65415 or 65535-120
corresponding to the frequency of 7.68KHz and the
control flags value is fixed to E in both forward and
backward rotation.
RESULTS AND DISCUSSION
A microcontroller is utilized to control the pulses of
a two-phase hybrid step motor which plays the role
of changing positions of the cooling system so as to
ensure efficient operations for the drawing process.
69

This is successfully achieved through simulation performed with a microcontroller and a step motor as
the main materials.The microcontroller is first configured with the personal computer through the RS232
serial ports and then a program is written, compiled
and run in accord with microcontroller to drive the
step motor (Chandy, 2008; Carbondale, 1999, 2000).
The microcontroller communicates with the step motor through the motor drive that is properly micro
stepped to minimize the problem of overshooting.
Though overshooting is normal to the step motors
functioning because of inertia, it causes the step loosing unless minimized.
The big challenge is about the problems of overshooting and vibration which are however solved.The vibration is the inevitable working principle of step motors especially while it is stepping to another pulse.
It means that the stepper motor rotates according
to the initially set angle of rotation. The step-losing
phenomenon occurs when the step motor is not normally started. Normally, the speed of stepper motor
requires the direct starting just because the corresponding frequency must not exceed the utmost limit
of the starting frequency (Hui, 2008). The immediate
motor start up and the final critical stopping point
are the motor running stages certainly characterized
by overshooting phenomenon just because of inertia
reasons (Wang, 2008).
To solve the problems, the motor drives micro stepping technology and coding methods are the two ways

Gerard Rushingabigwi, Xiaojuan Ban & Dongxing Wang

utilized and as a result by running and observing the


motor, its clearly found that the vibration phenomenon at the beginning and stopping of the step motor
is alleviated up to 90%. The speed on the step motor
during operation is worthy of discussion: when the
run Flags information (or duration of how long and
how far the step motor must go) is not big enough,
the motor will get so confused that it runs twice,
which is not good for the purpose of the precise positioning of the dieless drawing systems cooling system.
The speed problem is solved by fixing a hexadecimal
digit F to be the runFlag in the coded instructions.
CONCLUSION
In this work, a microcontroller was utilized to control
the pulses of a two-phase hybrid step motor, the big
task being to precisely position the cooling device in
the needed location, near or far away from the heated
work piece.
The STC89C51/RD+ Series microcontroller like all
the other embedded works are recommended to be
programmed in C language under the environment of
Keil Micro vision2 IDE Environment.
The precise positioning system which is designed for
the cooler that needs dynamic operation during the
dieless drawing process is implemented by controlling
pulses of the step motor.The step motor and its drive
communicate with the computer through the RS232
serial ports, and the work here was done by simulation using the Microcontroller. The precise manipulation of the step motor encounters the overshooting
and vibration phenomena which severely affect the
accurate positioning of the cooling system. These
problems were practically solved by both the motor
drives micro-stepping technology and the software
method (coding) to achieve the non-linear pulse control method.
From this work, it is evident that various commands
can be executed by a small control and simulation unit.
As a result, the microcontroller unit can drive a step
motor very well. The microcontroller has been an
excellent tool at the control of the step motor during the simulation work on precise positioning of the
dieless drawing systems cooler, and the problems of
overshooting and step loosing of the step motor due
to inertia were properly solved by the micro-stepping
technique of the motor drive, and by non-linear pulse
70

REFERENCES
Beijing Blue Ocean Microchip Co., Ltd, 2009.
LJD-SY-5100
experimental
development
boards manual to the user. See more
at http://www.bluemcu.com/en/company.asppp.
Cai, Z., 2003, Artificial Intelligence and Applications.
Tsinghua
University
Press, pp. 73-121.
Carbondale,
1999,
2000.
Application
of
microcontrollers. Electronics management labs.
At http://www.technology.heartland.edu/faculty/
chrism/automation
and
control/siulabs.pdf
[Accessed in April 2010]
Chawakorn, Y., 2008. Microstepping Bipolar Drive
of Two-Phase
Hybrid
Stepping
Motor
on TMS320F2808 DSC. Application report.
Dallas,Texas 75265. USA. Available online at http://
www.ti.com. [Lastly accessed on 14 October
2011]
Hui, T. et al., 2008. Microcontroller and Serial ports
communication to drive the step motor.
Jianchuan Science and technology. Hubei,
Wuhan 430064. China
John, A., 2008. Microcontroller Introduction.
University of Connecticut. Available at
http://www.engr.uconn.edu/~chandy/courses/
110s08/L01/Intro ToMicrocontrollers-012408.pdf.
[Lastly accessed on 12 October 2011]
Kawaguchi,Y. et al., 1991. Applications of dieless
drawing to. Ti-Ni wire drawing and tapered steel
wire manufacturing. (Wire Journal International
paper available in the Internet)
Martin, D., 2002. An introduction to PIC
microcontrollers, Available at http://www.
many ppt.com/05/An-Introduction-to-PICMicrocontrollers.html.Spring2002
Michael, N., 2005. Artificial Intelligence Intelligent
System guide, Beijing Electromechanical &
Industrial publisher. Pan, Y. and Fan, L., 2002.
Research on shape memory alloys and
applications, Masters Thesis. Suzhou Universitys
academic journal. China.
Shotwell, A., 1999. An introduction to fiber
optics, New Delhi: Prentice Hall of India.
Wang, Y. et al., 2008. Control System Design of
Acceleration and Deceleration curves of
Stepping
motor
and
its
Applications.
Zhao, H. et al, 2009. Design of Micro stepping of
the Motor Drive by FPGA, Instrument
Technique and Sensor. Available online at
http://g.wanfangdata.com.cn. [lastly accessed
on 14 October 2011]
Zhou, Y., 2009. Research on Step motors
positioning technology, Masters Thesis. Dalian
Jiaotong University. China

Microcontroller based motor control system for the dieless drawing process

APPENDIX:
Coding for microcontroller
The code was written with fixed values of:
Crystal oscillator: 11.0592MHz;
Baud rate 9600.
# Include reg51.h
# Define uchar unsigned char
# Define uint unsigned int
sbit FM = P3 ^ 7;
sbit ch451_din = P1 ^ 0;
sbit ch451_dclk = P1 ^ 1;
sbit ch451_load = P1 ^ 2;
sbit ch451_dout = P3 ^ 3;
sbit P00 = P0 ^ 0;
sbit P01 = P0 ^ 1;
sbit P02 = P0 ^ 2;
sbit P03 = P0 ^ 3;
sbit P04 = P0 ^ 4;
sbit P05 = P0 ^ 5;
sbit P06 = P0 ^ 6;
sbit P07 = P0 ^ 7;
/*
This Program is allowing the communication between
the present microchip and the PC through the motor drive. It stands for the non-linear speeding up and
speeding down process. The timer 0 is a pulse maker.
We need the control flag as value that helps to deal
with conditional expressions; a control flag is used to
determine when the looping process must stop.
*/
void initialization()
{
SCON=0x50;
TMOD = 0x21;
TH0=(65535-120)/256; //set the initial parameter to
timer 0 on the high 8 bit
TL0=(65535-120)%256; //set the initial parameter to
timer 0 on the low 8 bit
TR0=1;
T0=1;
EA = 1;
ES=1;
P00=1; //pulses serial port
P01=0; //directions serial port
P02=1; //out of controls serial port
}
// this is the main function; it is the
systems entrance.
void main()
{
initialization();
while(1)
{
if(RI)
{
RI=0;
varReciever=SBUF;
SBUF=varReciever;
controlFlag=varReciever&0xf0;
controlCounter=varReciever&0x0f;
71

}
switch(controlFlag)
{
case 0x10:P01=1;
runFlag=1;
P02=1;
break;
// forward direction
case 0x20:P01=0;
runFlag=1;
P02=1;
break;
// opposite direction
case 0x30:runFlag=0;
FM=1;
P02=1;
break; //stop the motor
case 0x40:P02=0;
FM=1;
break;
//out of control
default:;
}
controlFlag=0;
if(time>controlCounter*300)
{
time=0;
runFlag=0;
SBUF=0x00;
FM=1;
}
if(TF0==1)
{
TF0=0;
TH0=(65535-120)/256;
TL0=(65535-120)%256;
if(runFlag==1)
{
P00=0;
time++;
FM=0;
}
}
else
{P00=1;
}
}
return;
}

You might also like