pc based dc motor speed control1.doc
TRANSCRIPT
-
8/22/2019 PC based DC motor speed control1.doc
1/66
DC MOTOR SPEED CONTROL THROUGH PC
(P.W.M TECHNIQUE)
1.INTRODUCTION
This project mainly deals with the speed control of a
DC Motor using a PC. The type of speed control that has been chosen here is
pulse width modulation PWM. This project deals with development of DC
MOTOR control using PC using PWM. 12V DC Motor drives widely use
Micro controllers and The project detail design and complete hardware based
high performance DC drive control system will be implemented. Most recently
new requirements have arisen. These include faster torque control update with
flexible design capability of motion peripherals for high performance military
drive applications. Pulse width modulation type of speed control is chosen here
because of high accuracy, high reliability, quick response and high efficiency.
Our project deals with the types of problems that we face due to
disturbances in supply voltage or load on the motor and enables us to overcome
these difficulties by helping us with the appropriate software and hardware.
We propose to design an embedded controller that helps us maintain thespeed of the DC machine within the specific limits and a remote operate the
embedded controller. Here, the pulses from the remote are sensed by sensor and
are transmitted to the embedded controller. This controller contains a
programmable PWM port. The output of this PWM port is used to control
power delivered by a power regulating device
1
-
8/22/2019 PC based DC motor speed control1.doc
2/66
1:2 HARDWARE COMPONENTS:
1. POWERSUPPLY UNIT
(TRANSFORMER, 7805 & 7812 REGULATORS, CAPACITOR 1000mf)
2. 89C52 MICROCONTROLLER
3. DC MOTOR
4. ULN 2803 DRIVER IC
5. DB 9 CONNECTOR
6. MAX 232 IC
7. Voltage regulator 7805.
8. Diode IN4007
9. Serial communication used for downloading the hex code.
10 .16X2 LCD interfacing
1:3 SOFTWARE:
Soft Ware developed for this project in Embedded C using KEIL-3.
A KEIL Cross compiler for compiling and linking the code written for
AT89C52.
Serial communication software for downloading code to AT89C52.
Operating system: Windows XP
2. EMBEDDED SYSTEMS
2
-
8/22/2019 PC based DC motor speed control1.doc
3/66
2.1 DEFINITIONS:
Embedded system is a combination of hardware and software, it is
also named as Firm ware.
An embedded system is a special purpose computer system, which
is completely encapsulated by the device it controls. It is a computer-
controlled system
An embedded system is a specialized system that is a part of a
larger system or machine. As a part of a larger system it largely
determines its functionality. Embedded systems are electronic devices
that incorporate microprocessors with in their implementations. The main
purpose of the microprocessors are simplify the system design and
improve flexibility. In the embedded systems, the software is often stored
in a read only memory (RAM) chip.
Embedded systems provide several major functions including
monitoring of the analog environment by reading data from sensors and
controlling actuators.
Inputs (sensor) Outputs
(actuator)
Figure 2.1 A real time system interacts with environment
2.2 EXAMPLES OF EMBEDDED SYSTEMS:
3
EmbeddedSystem
-
8/22/2019 PC based DC motor speed control1.doc
4/66
Embedded systems are found in wide range of application areas.
Originally they were used only for expensive industrial control
applications, but as technology brought down the cost of dedicated
processors, they began to appear in moderately expensive applications
such as automobiles, communication and office equipments and
television Today's embedded systems are so inexpensive that they are
used in almost every electronic product in our life. Embedded systems are
often designed for mass production.
Some examples of embedded systems:
Automatic Teller Machines
Cellular telephone and telephone switches
Computer network equipment
Computer printers
Disk drives
Engine controllers and antilock break controllers for
automobiles
Home automation products
Handheld calculators
Household appliances
Medical equipment
Measurement equipment
Multifunction wrist watches
Multifunction printers
Mobile phones with additional capabilities
Programmable Logic Controllers
4
-
8/22/2019 PC based DC motor speed control1.doc
5/66
2.3 MICROPROCESSOR AND MICROCONTROLLER:
Microprocessors and microcontrollers are used in embedded
system products. An embedded product uses a microprocessor (or
microcontroller) to do one task and one task only.
Microprocessor as the term come to be known is a general purpose
digital computer central processing unit. Although popularly known as a
"computer on chip", the microprocessor is in no sense a complete digital
computer.
Microprocessor CPU contains Arithmetic Logical Unit, a program
counter, a stack pointer, some working registers, a clock timing circuits
and interrupt circuit.
To make complete microcomputer memory must add, usually Read
Only Memory, Random Access Memory, memory decoders and an
Input/Output devices. In addition special purpose devices such as
interrupts, counters may be added to relieve the CPU from time
consuming counting or timing chores.
The hardware design of microprocessor CPU is arranged so that a
small or very large system can be configured around the CPU as the
application demands. The internal CPU architecture as well as the
resultant machine level code that operates that architecture is
comprehensive but as flexible as possible.
The prime use of microprocessor is to read data perform extensive
calculations on that data and store those calculations in mass storage
5
-
8/22/2019 PC based DC motor speed control1.doc
6/66
devices or display the results for user use. The program is used by
microprocessor are stored in the mass storage devices and loaded into
RAM as the user directs.
A microcontrollers is a computer on a single chip .Micro suggest
that the device is small and controller tells that the device is used to
control objects, process or events
Microcontroller is a highly integrated chip that contains all the
devices comprising a computer. Typically this includes a CPU, RAM,
Input/ Output ports, timers, interrupts. So microcontroller is also called as
"true computer on a chip". Unlike a general purpose computer which also
includes all of these devices. A microcontroller is designed for a very
specific task to control a particular system.
A microcontroller is a general purpose device but one that is meant
to read data, perform limited calculations on that data and control its
environment based on those calculations.
The prime use of microcontroller is to control the operation of
machine using a fixed program that is stored in ROM that does not
change over the life time of the system.
The advantages of microcontroller over microprocessor are cost is less
speed is more
power consumption is less
compact device
external components are minimum
6
-
8/22/2019 PC based DC motor speed control1.doc
7/66
2.4 MICROPROCESSOR VERSES MICROCONTROLLER:
The contrast between microprocessor and microcontroller is best
exemplified by the fact that:
Most microprocessor have operational codes for moving
data from external memory to CPU, microcontroller may have
one or two.
Microprocessor may have one or two types of bit handling
instructions microcontroller will have many.
Microprocessor concerned with rapid movement of code and
data from external address to the chip, microcontroller is
concerned with rapid data movement of bits with in chip.
Microcontroller can function as a computer with out addition
of external devices, but microprocessor must have many
additions to operate a computer.
7
-
8/22/2019 PC based DC motor speed control1.doc
8/66
3. PC BASED DC MOTOR SPEED CONTROL
BLOCK DIAGRAM
8
0
5
2
MAX
232
PC
ULN
2803
Driver
Dc motor
8
-
8/22/2019 PC based DC motor speed control1.doc
9/66
4.MICROCONTROLLER
4:1 A BRIEF HISTORY OF 8051:
In 1981, Intel Corporation introduced an 8 bit microcontroller called
8051. this microcontroller had 128 bytes of RAM, 4K bytes of chip
ROM, two timers, one serial port, and four ports all on a single chip. At
the time it was also referred as A SYSTEM ON A CHIP
The 8051 is an 8-bit processor meaning that the CPU can work only
on 8 bits data at a time. Data larger than 8 bits has to be broken into 8 bits
pieces to be processed by the CPU. The 8051 has a total of four I\O ports
each 8 bit wide.
There are many versions of 8051 with different speeds and amount of on-
chip ROM and they are all compatible with the original 8051. this means
that if you write a program for one it will run on any of them.
The 8051 is an original member of the 8051 family. There are two
other members in the 8051 family of microcontrollers. They are 8052 and
8031. All the three microcontrollers will have the same internal
architecture, but they differ in the following aspects.
8031 has 128 bytes of RAM, two timers and 6 interrupts.
8051 has 4K ROM, 128 bytes of RAM, two timers and 6 interrupts.
8052 has 8K ROM, 128 bytes of RAM, three timers and 8
interrupts.
Of the three microcontrollers, 8051 is the most preferable.
Microcontroller supports both serial and parallel communication.
9
-
8/22/2019 PC based DC motor speed control1.doc
10/66
In the concerned project 8052 microcontroller is used. Here
microcontroller used is AT89C52, which is manufactured by ATMEL
laboratories.
4:2 Description of 89C52 Microcontroller:
The AT89C52 provides the following standard features: 8Kbytes
of Flash, 256 bytes of RAM, 32 I/O lines, three 16-bit timer/counters, a
six-vector two-level interrupt architecture, a full duplex serial port, on-
chip oscillator, and clock circuitry. In addition, the AT89C52 is designed
with static logic for operation down to zero frequency and supports two
software selectable power saving modes. The Idle Mode stops the CPU
while allowing the RAM, timer/counters, serial port, and interrupt system
to continue functioning. The Power down Mode saves the RAM contents
but freezes the oscillator, disabling all other chip functions until the next
hardware reset.
By combining a versatile 8-bit CPU with Flash on a monolithic
chip, the Atmel AT89C52 is a powerful microcomputer which provides a
highly flexible and cost effective solution to many embedded control
applications.
4:3 Features of Microcontroller (8052):
Compatible with MCS-51 Products
8 Kbytes of In-System Reprogrammable Flash Memory
10
-
8/22/2019 PC based DC motor speed control1.doc
11/66
Endurance: 1,000 Write/Erase Cycles
Fully Static Operation: 0 Hz to 24 MHz
Three-Level Program Memory Lock
256 x 8-Bit Internal RAM
32 Programmable I/O Lines
Three 16-Bit Timer/Counters
Eight vector two level Interrupt Sources
Programmable Serial Channel
Low Power Idle and Power Down Modes
In addition, the AT89C52 is designed with static logic for operation down
to zero frequency and supports two software selectable power saving modes.
The Idle Mode stops the CPU while allowing the RAM, timer/counters,
serial port and interrupt system to continue functioning. The Power Down Mode
saves the RAM contents but freezes the oscillator disabling all other chip
functions until the next hardware reset.
11
-
8/22/2019 PC based DC motor speed control1.doc
12/66
4:4 Block Diagram of Microcontroller:
Figure 4.1 Block Diagram Of 8052
12
-
8/22/2019 PC based DC motor speed control1.doc
13/66
4.5 Pin Configurations:
Figure 4.2 Pin Diagram of 8952
4.6 Pin Description:
VCC :
Pin 40 provides Supply voltage to the chip. The voltage
source is +5v
GND :
Pin 20 is the grounded
13
-
8/22/2019 PC based DC motor speed control1.doc
14/66
Port 0:
Port 0 is an 8-bit open drain bidirectional I/O port from pin 32 to
39. As an output port each pin can sink eight TTL inputs. When 1s are
written to port 0 pins, the pins can be used as high-impedance inputs. Port
0 may also be configured to be the multiplexed low-order address/data
bus during accesses to external program and data memory. In this mode
P0 has internal pull-ups.
Port 0 also receives the code bytes during Flash programming, and
outputs the code bytes during program verification. External pull-ups are
required during program verification.
Port 1:
Port 1 is an 8-bit bidirectional I/O port with internal pull-ups from
pin 1 to 8. The Port 1 output buffers can sink/source four TTL inputs.
When 1s are written to Port 1 pins they are pulled high by the internal
pull-ups and can be used as inputs. As inputs, Port 1 pins that are
externally being pulled low will source current (IIL) because of the
internal pull-ups. Port 1 also receives the low-order address bytes during
Flash programming and program verification.
Port 2:
Port 2 is an 8-bit bidirectional I/O port with internal pull-ups from
pin 21 to 28. The Port 2 output buffers can sink / source four TTL inputs.
When 1s are written to Port 2 pins they are pulled high by the internal
pull-ups and can be used as inputs. As inputs, Port 2 pins that are
14
-
8/22/2019 PC based DC motor speed control1.doc
15/66
externally being pulled low will source current (IIL) because of the
internal pull-ups.
Port 2 emits the high-order address byte during fetches from
external program memory and during accesses to external data memory
that use 16-bit addresses (MOVX @ DPTR). In this application it uses
strong internal pull-ups when emitting 1s. During accesses to external
data memory that use 8-bit addresses (MOVX @ RI), Port 2 emits the
contents of the P2 Special Function Register. Port 2 also receives the
high-order address bits and some control signals during Flash
programming and verification.
Port 3:
Port 3 is an 8-bit bidirectional I/O port with internal pull-ups from pin
10 to 17. The Port 3 output buffers can sink / source four TTL inputs. When
1s are written to Port 3 pins they are pulled high by the internal pull-ups and
can be used as inputs. As inputs, Port 3 pins that are externally being pulled
low will source current (IIL) because of the pull-ups.
Port 3 also serves the functions of various special features of the
AT89C51 as listed below:
15
-
8/22/2019 PC based DC motor speed control1.doc
16/66
Table 4.1 Special Features of 89C52
Port 3 also receives some control signals for Flash programming and
programming verification.
RST:
Pin 9 is the Reset input. It is active high. Upon applying a high pulse to
this pin, the microcontroller will reset and terminate all activities. A high on this
pin for two machine cycles while the oscillator is running resets the device.
ALE/PROG:
Address Latch is an output pin and is active high. Address Latch Enable
output pulse for latching the low byte of the address during accesses to external
memory. This pin is also the program pulse input (PROG) during Flash
programming. In normal operation ALE is emitted at a constant rate of 1/6 the
oscillator frequency, and may be used for external timing or clocking purposes.
Note, however, that one ALE pulse is skipped during each access to external
Data Memory. If desired, ALE operation can be disabled by setting bit 0 of SFR
location 8EH. With the bit set, ALE is active only during a MOVX or MOVC
16
-
8/22/2019 PC based DC motor speed control1.doc
17/66
instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-disable
bit has no effect if the microcontroller is in external execution mode.
PSEN:
Program Store Enable is the read strobe to external program memory.
When the AT89C52 is executing code from external program memory, PSEN is
activated twice each machine cycle, except that two PSEN activations are
skipped during each access to external data memory.
EA/VPP:
External Access Enable. EA must be strapped to GND in order to enable
the device to fetch code from external program memory locations starting at
0000H up to FFFFH. Note, however, that if lock bit 1 is programmed, EA willbe internally latched on reset. EA should be strapped to VCC for internal
program executions. This pin also receives the 12-volt programming enable
voltage (VPP) during Flash programming, for parts that require 12-volt VPP.
XTAL1:
Input to the inverting oscillator amplifier and input to the internal clock
operating circuit.
XTAL2:
Output from the inverting oscillator amplifier.
4.7 Oscillator Characteristics:
17
-
8/22/2019 PC based DC motor speed control1.doc
18/66
XTAL1 and XTAL2 are the input and output, respectively, of an
inverting amplifier which can be configured for use as an on chip oscillator, as
shown in Figure 5.3. Either a quartz crystal or ceramic resonator may be used.
To drive the device from an external clock source, XTAL2 should be left
unconnected while XTAL1 is driven as shown in Figure.4.1
Figure: crystal connections
Figure: 4.3 External Clock Drive Configuration
There are no requirements on the duty cycle of the external clock signal,
since the input to the internal clocking circuitry is through a divide-by two flip-
18
-
8/22/2019 PC based DC motor speed control1.doc
19/66
flop, but minimum and maximum voltage high and low time specifications must
be observed.
4.8 TIMERS:
Timer 0 and 1:
Timer 0 and Timer 1 in the AT89C52 operate the same way as Timer 0
and Timer 1 in the AT89C51.
Timer 2:Timer 2 is a 16-bit Timer/Counter that can operate as either a timer or an
event counter. The type of operation is selected by bit C/T2 in the SFR T2CON.
Timer 2 has three operating modes: capture, auto-reload (up or down counting),
and baud rate generator. The modes are selected by bits in T2CON, as shown in
Table 5.2. Timer 2 consists of two 8-bit registers, TH2 and TL2. In the Timer
function, the TL2 register is incremented every machine cycle. Since a machinecycle consists of 12 oscillator periods, the count rate is 1/12 of the oscillator
frequency.
Table: 4.8.1 Timer 2 Operating Modes
In the Counter function, the register is incremented in response to a 1-to-0
transition at its corresponding external input pin, T2. In this function, the
external input is sampled during S5P2 of every machine cycle. When the
19
-
8/22/2019 PC based DC motor speed control1.doc
20/66
samples show a high in one cycle and a low in the next cycle, the count is
incremented. The new count value appears in the register during S3P1 of the
cycle following the one in which the transition was detected. Since two machine
cycles (24 oscillator periods) are required to recognize a 1-to-0 transition, the
maximum count rate is 1/24 of the oscillator frequency. To ensure that a given
level is sampled at least once before it changes, the level should be held for at
least one full machine cycle.
There are no restrictions on the duty cycle of external input signal, but it
should for at least one full machine to ensure that a given level is sampled at
least once before it changes
Interrupts:
The AT89C52 has a total of six interrupt vectors: two external interrupts
(INT0 and INT1), three timer interrupts (Timers 0, 1, and 2), and the serial port
interrupt. These interrupts are all shown in Figure.
Figure: 4.4 Interrupts source
20
-
8/22/2019 PC based DC motor speed control1.doc
21/66
Each of these interrupt sources can be individually enabled or disabled by
setting or clearing a bit in Special Function Register IE. IE also contains a
global disable bit, EA, which disables all interrupts at once.
Note that Table 3 shows that bit position IE.6 is unimplemented. In the
AT89C51, bit position IE.5 is also unimplemented. User software should not
write 1s to these bit positions, since they may be used in future AT89 products.
4.8.2 Table 3 Interrupts Enable Register:
Timer 2 interrupt is generated by the logical OR of bits TF2 and EXF2 in
register T2CON. Neither of these flags is cleared by hardware when the service
routine is vectored
21
-
8/22/2019 PC based DC motor speed control1.doc
22/66
to. In fact, the service routine may have to determine whether it was TF2 or
EXF2 that generated the interrupt, and that bit will have to be cleared in
software.
The Timer 0 and Timer 1 flags, TF0 and TF1, are set at S5P2 of the cycle
in which the timers overflow. The values are then polled by the circuitry in the
next cycle. However, the Timer 2 flag, TF2, is set at S2P2 and is polled in the
same cycle in which the timer overflows.
Idle Mode:
In idle mode, the CPU puts itself to sleep while all the on-chip
peripherals remain active. The mode is invoked by software. The content of the
on-chip RAM and all the special functions registers remain unchanged during
this mode. The idle mode can be terminated by any enabled interrupt or by a
hardware reset. It should be noted that when idle is terminated by a hardware
reset, the device normally resumes program execution, from where it left off, up
to two machine cycles before the internal reset algorithm takes control.
On-chip hardware inhibits access to internal RAM in this event, but
access to the port pins is not inhibited. To eliminate the possibility of anunexpected write to a port pin when Idle is terminated by reset, the instruction
following the one that invokes Idle should not be one that writes to a port pin or
to external memory.
Power down Mode:
22
-
8/22/2019 PC based DC motor speed control1.doc
23/66
In the power down mode the oscillator is stopped, and the instruction that
invokes power down is the last instruction executed. The on-chip RAM and
Special Function Registers retain their values until the power down mode is
terminated. The only exit from power down is a hardware reset. Reset redefines
the SFRs but does not change the on-chip RAM. The reset should not be
activated before VCC is restored to its normal operating level and must be held
active long enough to allow the oscillator to restart and stabilize.
Table 4.8.3 Status of External Pins during Idle and Power down Mode
Program Memory Lock Bits:
On the chip are three lock bits which can be left unprogrammed (U) orcan be programmed (P) to obtain the additional features listed in the table 4.8.3
When lock bit 1 is programmed, the logic level at the EA pin is sampled and
latched during reset. If the device is powered up without a reset, the latch
initializes to a random value, and holds that value until reset is activated. It is
necessary that the latched value of EA be in agreement with the current logic
level at that pin in order for the device to function properly.
23
-
8/22/2019 PC based DC motor speed control1.doc
24/66
Table 4.8.4 Lock Bit Protection Modes
Programming the Flash:
The AT89C51 is normally shipped with the on-chip Flash memory array
in the erased state (that is, contents = FFH) and ready to be programmed. The
programming interface accepts either a high-voltage (12-volt) or a low-voltage
(VCC) program enable signal. The low voltage programming mode provides a
convenient way to program the AT89C51 inside the users system, while the
high-voltage programming mode is compatible with conventional third party
Flash or EPROM programmers.
The AT89C51 is shipped with either the high-voltage or low voltage
programming mode enabled. The respective top-side marking and device
signature codes are listed in the following table.
Table: 4.8.5 5 Top side marking and Device Signature Codes
24
-
8/22/2019 PC based DC motor speed control1.doc
25/66
The AT89C52 code memory array is programmed byte-by-byte in either
programming mode. To program any non-blank byte in the on-chip Flash
Memory, theentire memory must be erased using the Chip Erase Mode.
Programming Algorithm:
Before programming the AT89C52, the address, data and control signals
should be set up according to the Flash programming mode table and Figures 3
and 4. To program the AT89C52, take the following steps.
1. Input the desired memory location on the address lines.
2. Input the appropriate data byte on the data lines.
3. Activate the correct combination of control signals.
4. Raise EA/VPP to 12 V for the high-voltage programming mode.
5. Pulse ALE/PROG once to program a byte in the Flash array or the lock bits.
The byte-write cycle is self-timed and typically takes no more than 1.5 ms.
Repeat steps 1 through 5, changing the address and data for the entire array or
until the end of the object file is reached.
Data Polling:
The AT89C52 features Data Polling to indicate the end of a write cycle.
During a write cycle, an attempted read of the last byte written will result in the
complement of the written datum on PO.7. Once the write cycle has been
completed, true data are valid on all outputs, and the next cycle may begin. Data
Polling may begin any time after a write cycle has been initiated.
25
-
8/22/2019 PC based DC motor speed control1.doc
26/66
Ready/Busy:
The progress of byte programming can also be monitored by theRDY/BSY output signal. P3.4 is pulled low after ALE goes high during
programming to indicate BUSY. P3.4 is pulled high again when programming
is done to indicate READY.
Program Verify:
If lock bits LB1 and LB2 have not been programmed, the programmed
code data can be read back via the address and data lines for verification. The
lock bits cannot be verified directly. Verification of the lock bits is achieved by
observing that their features are enabled.
Chip Erase:
The entire Flash array is erased electrically by using the proper
combination of control signals and by holding ALE/PROG low for 10 ms. The
code array is written with all "1"s. The chip erase operation must be executed
before the code memory can be re-programmed.
Reading the Signature Bytes:
The signature bytes are read by the same procedure as a normal
verification of locations 030H, 031H, and 032H, except that P3.6 and P3.7 must
be pulled to a
logic low. The values returned are as follows.
(030H) = 1EH indicates manufactured by Atmel
(031H) = 51H indicates 89C51
26
-
8/22/2019 PC based DC motor speed control1.doc
27/66
(032H) = FFH indicates 12 V programming
(032H) = 05H indicates 5 V programming
Programming Interface:
Every code byte in the Flash array can be written and the entire array canbe erased by using the appropriate combination of control signals. The write
operation cycle is self-timed and once initiated, will automatically time itself to
completion.
4.8.6 Flash programming modes
27
-
8/22/2019 PC based DC motor speed control1.doc
28/66
5. POWER SUPPLY UNIT
DC power supply is the soul of electronic circuits,
so we should be very cautious while designing power supply. For that
we have chosen fixed IC voltage regulators to maintain constant voltage
with out any fluctuations to convert A.C into D.C we are using step
down transformer of 12v.In our system we need two separate voltages
i.e. +5V and +12V. So to get such voltages we ate going for the fixed
IC voltage regulators. We are using IC 7805 and IC 7812 with properly
designed filter circuit. These are versatile, relatively inexpensive and
are available with features such as programmable o/p, current/voltage
boosting and floating operation for high voltage application.
IC 78XX:
These are fixed voltage regulators, which are having three
terminals, positive voltage regulators; its having the o/p voltage
options such as 5, 6, 8,12,15,18 and 24V.
In 78XX, the last two numbers (XX) indicate the o/p voltage. The
standard 78XX is also called as monolithic voltage regulators.
28
-
8/22/2019 PC based DC motor speed control1.doc
29/66
78XX
1 2
C1 C2
Where input capacitor C1 is used to cancel the inductive effects due to
long distribution leads and the o/p capacitor C2 improves the transient
response.
It is intended for use as fixed voltage-regulator in a wide range
of applications
FEATURES:
1. Maximum current output: 0.8 Amps.
2 .No external components are required.
3. Internal thermal over load protection.
4. Internal short circuit current limiting.
ABSOLUTE MAXIMUM RATINGS:
1. Input voltage: Max-35V OC
2. Operating Temperature: -20 c to 80 c
3. Internal power dissipation: Internally limited.
Power supply:
29
-
8/22/2019 PC based DC motor speed control1.doc
30/66
There are many types of power supply. Most are designed to
convert high voltage AC mains electricity to a suitable low voltage
supply for electronics circuits and other devices. A power supply can by
broken down into a series of blocks, each of which performs a particular
function.
For example a 5V regulated supply can be shown as below
Fig:5.1 Block Diagram of a Regulated Power Supply System
Similarly, 12v regulated supply can also be produced by suitable
selection of the individual elements. Each of the blocks is described in
detail below and the power supplies made from these blocks are
described below with a circuit diagram and a graph of their output:
Transformer:
A transformer steps down high voltage AC mains to low voltage
AC. Here we are using a center-tap transformer whose output will be
sinusoidal with 36volts peak to peak value.
30
-
8/22/2019 PC based DC motor speed control1.doc
31/66
Fig: Output Waveform of transformer
The low voltage AC output is suitable for lamps, heaters and
special AC motors. It is not suitable for electronic circuits unless they
include a rectifier and a smoothing capacitor. The transformer output is
given to the rectifier circuit.
Rectifier:
A rectifier converts AC to DC, but the DC output is varying. There
are several types of rectifiers; here we use a bridge rectifier.
The Bridge rectifier is a circuit, which converts an ac voltage
to dc voltage using both half cycles of the input ac voltage. The Bridge
rectifier circuit is shown in the figure. The circuit has four diodes
connected to form a bridge. The ac input voltage is applied to the
diagonally opposite ends of the bridge. The load resistance is connected
between the other two ends of the bridge.
For the positive half cycle of the input ac voltage, diodes D1 and D3
conduct, whereas diodes D2 and D4 remain in the OFF state. The
conducting diodes will be in series with the load resistance RL and hence
the load current flows through RL. For the negative half cycle of the input
ac voltage, diodes D2 and D4 conduct whereas, D1 and D3 remain OFF.
The conducting diodes D2 and D4 will be in series with the load
resistance RL and hence the current flows through RL in the same
direction as in the previous half cycle. Thus a bi-directional wave is
converted into unidirectional.
31
-
8/22/2019 PC based DC motor speed control1.doc
32/66
5.2 Fig the output waveform of the rectifier is shown as below
The varying DC output is suitable for lamps, heaters and standard
motors. It is not suitable for electronic circuits unless they include a
smoothing capacitor.
Smoothing:
The smoothing block smoothes the DC from varying greatly to a
small ripple. The ripple voltage is defined as the deviation of the load
voltage from its DC value. Smoothing is also named as filtering.
Filtering is frequently effected by shunting the load with a
capacitor. The action of this system depends on the fact that the capacitor
32
-
8/22/2019 PC based DC motor speed control1.doc
33/66
stores energy during the conduction period and delivers this energy to the
loads during the no conducting period. In this way, the time during which
the current passes through the load is prolonging Ted, and the ripple is
considerably decreased. The action of the capacitor is shown with the
help of waveform.
Fig: 5.3 The waveform of the rectified output after smoothing is given
below:
Regulator:
33
-
8/22/2019 PC based DC motor speed control1.doc
34/66
Regulator eliminates ripple by setting DC output to a fixed
voltage.Voltage regulator ICs are available with fixed (typically 5, 12 and
15V) or variable output voltages. Negative voltage regulators are also
available
Many of the fixed voltage regulator ICs has 3 leads (input, output and
high impedance). They include a hole for attaching a heat sink if
necessary. Zener diode is an example of fixed regulator which is shown
here.
REGULATOR
34
-
8/22/2019 PC based DC motor speed control1.doc
35/66
Transformer + Rectifier + Smoothing + Regulator:
6. PWM THE TECHNIQUE
PWM is a way of digitally encoding analog signal levels.
Through the use of high-resolution counters, the duty cycle of a square
wave is modulated to encode a specific analog signal level. The PWM
signal is still digital because, at any given instant of time, the full DC
supply is either fully on or fully off. The voltage or current source is
supplied to the analog load by means of a repeating series of and off
pulse.
The on time is the time during which the DC supply is applied to the load
and the off time is the period during which that supplies is switched off.
Given a sufficient bandwidth, any analog value can be encoded with
PWM.
Many micro controllers include PWM controllers. For example,
Microchips PIC16C67 includes two, each of which has a selectable on-
time and period. The duty cycle is the ratio of the on-time to the period.
35
-
8/22/2019 PC based DC motor speed control1.doc
36/66
6.1 ADVANTAGES OF PWM:
PWM is economical, space saving. The signal
remains digital all the way from the processor to the controlled system.
No digital-to analog conversion is necessary. By keeping the signal
digital, noise immunity is yet another benefit of choosing PWM over
analog control and is the principal reason PWM is sometimes used for
communication.
6.2 APPLICATIONS OF PWM:
PWM is employed in a wide variety of applications, ranging from
measurement and communication to power control and conversion. As a
concrete example consider a PWM-controlled brake. To put it simply, a
brake is a device that clamps down hard on something in many brakes,
the amount of clamping pressure is controlled with an analog input
signal. The more voltage or current thats applied to the brake, the more
pressure the brake will exert. The output of a PWM controller could be
connected to a switch between the supply and the brake to produce more
stopping power, the software need only increase the duty cycle of the
PWM output.
36
-
8/22/2019 PC based DC motor speed control1.doc
37/66
7 .Serial communication between PC and Microcontroller
7.1 INTRODUCTION:
When a processor communicates with the outside world, it provides
data in byte sized chunks. Computers transfer data in two ways: parallel and
serial. In parallel data transfers, often more lines are used to transfer data to a
device and 8 bit data path is expensive. The serial communication transfer uses
only a single data line instead of the 8 bit data line of parallel communication
which makes the data transfer not only cheaper but also makes it possible for
two computers located in two different cities to communicate over telephone.
Serial data communication uses two methods, asynchronous and
synchronous. The synchronous method transfers data at a time while the
asynchronous transfers a single byte at a time. There are some special IC chips
made by many manufacturers for data communications. These chips are
commonly referred to as UART (universal asynchronous receiver-transmitter)
and USART (universal synchronous asynchronous receiver transmitter). The
AT89C51 chip has a built in UART.
37
-
8/22/2019 PC based DC motor speed control1.doc
38/66
In asynchronous method, each character is placed between start
and stop bits. This is called framing. In data framing of asynchronous
communications, the data, such as ASCII characters, are packed in between a
start and stop bit. We have a total of 10 bits for a character: 8 bits for the ASCII
code and 1 bit each for the start and stop bits. The rate of serial data transfer
communication is stated in bps or it can be called as baud rate.
To allow the compatibility among data communication equipment
made by various manufacturers, and interfacing standard called RS232 was set
by the Electronics industries Association in 1960. Today RS232 is the most
widely used I/O interfacing standard. This standard is used in PCs and
numerous types of equipment. However, since the standard was set long before
the advent of the TTL logic family, its input and output voltage levels are not
TTL compatible. In RS232, a 1 bit is represented by -3 to -25V, while a 0 bit is
represented +3 to +25 V, making -3 to +3 undefined. For this reason, to connect
any RS232 to a microcontroller system we must use voltage converters such as
MAX232 to connect the TTL logic levels to RS232 voltage levels and vice
versa. MAX232 ICs are commonly referred to as line drivers.
The RS232 cables are generally referred to as DB-9 connector. In
labeling, DB-9P refers to the plug connector (male) and DB-9S is for the socket
38
-
8/22/2019 PC based DC motor speed control1.doc
39/66
connector (female). The simplest connection between a PC and microcontroller
requires a minimum of three pin, TXD, RXD, and ground. Many of the pins of
the RS232 connector are used for handshaking signals. They are bypassed since
they are not supported by the 8051 UART chip.
IBM PC/ compatible computers based on x86(8086, 80286, 386,
486 and Pentium) microprocessors normally have two COM ports. Both COM
ports have RS232 type connectors. Many PCs use one each of the DB-25 and
DB-9 RS232 connectors. The COM ports are designated as COM1 and COM2.
We can connect the serial port to the COM 2 port of a PC for serial
communication experiments. We use a DB9 connector in our arrangement.
The AT89C51 has two pins that are used specifically for transferringand receiving data serially. These two pins are called TXD and RXD and are
part of the port3 (P3.0 and P3.1). These pins are TTL compatible; therefore they
require a line driver to make them RS232 compatible. One such line driver is
the MAX232 chip. One advantage of MAX232 chip is that it uses a +5v power
source which is the same as the source voltage for the at89c51. The MAX232
has two sets of line drivers for receiving and transferring data. The line driversfor TXD are called T1 and T2 while the line drivers for RXD are designated as
R1 and R2. T1 and R1 are used for TXD and RXD of the 89c51 and the second
set is left unused. In MAX232 that the TI line driver has a designation of T1 in
and T1 out on pin numbers 11 and 14, respectively. The T1 in pin is the TTL
side and is connected to TXD of the microcontroller, while TI out is the RS232
side that is connected to the RXD pin of the DB9 connector.
39
-
8/22/2019 PC based DC motor speed control1.doc
40/66
To allow data transfer between PC and the microcontroller system
without any error, we must make sure that the baud rate of the 8051 system
matches the baud rate of the PCs COM port.
8. ULN DC MOTOR DRIVER
ULN is mainly suited for interfacing between low-level
circuits and multiple peripheral power loads, The series ULN20XX high
voltage, high current Darlington arrays feature continuous load current ratings.
The driving circuitry in- turn decodes the coding and conveys the necessary datato the stepper motor, this module aids in the movement of the arm through
steppers.
40
-
8/22/2019 PC based DC motor speed control1.doc
41/66
The driver makes use of the ULN2003 driver IC, which contains an
array of 7 power Darlington arrays, each capable of driving 500mA of
current. At an approximate duty cycle, depending on ambient temperature
and number of drivers turned on, simultaneously typical power loads totaling
over 230w can be controlled.
The device has base resistors, allowing direct connection to any
common logic family. All the emitters are tied together and brought out to a
separate terminal. Output protection diodes are included; hence the device
can drive inductive loads with minimum extra components. Typical loads
include relays, solenoids, stepper motors, magnetic print hammers,
multiplexed LED, incandescent displays and heaters.
41
-
8/22/2019 PC based DC motor speed control1.doc
42/66
8.1.1 The main features of ULN2003 are as follows:
1. Seven Darlington per package
2. Output current 500ma per driver (600ma peak)
Output voltage 50v
3. Integrated suppression diodes for inductive loads
4. Outputs can be paralleled for high current TTL/CMOS/DTL
compatible inputs
5. Inputs pinned opposite outputs to simplify layout.
Transient protected outputs
6. Dual In-Line plastic package or small-Outline IC package.
9. DC MOTOR
DC motors are configured in many types and sizes, including brush less,
servo, and gear motor types. A motorconsists of a rotor and a permanent
magnetic field stator. The magnetic field is maintained using either permanent
magnets or electromagnetic windings. DC motors are most commonly used in
variable speed and torque.
Motion and controls cover a wide range of components that in
42
http://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorhttp://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorhttp://dc-motors.globalspec.com/Industrial-Directory/motors -
8/22/2019 PC based DC motor speed control1.doc
43/66
some way are used to generate and/or control motion. Areas within this
category include bearings and bushings, clutches and brakes, controls and
drives, drive components, encoders and resolves, Integrated motion control,
limit switches, linear actuators, linear and rotary motion components, linear
position sensing, motors (both AC and DC motors), orientation position
sensing, pneumatics and pneumatic components, positioning stages, slides and
guides, power transmission (mechanical), seals, slip rings, solenoids, springs.
Motors are the devices that provide the actual speed and torque
in a drive system. This family includes AC motortypes (single and multiphase
motors, universal, servo motors, induction, synchronous, and gear motor) and
DC motors (brush less, servo motor, and gear motor) as well as linear, stepper
and airmotors, and motorcontactors and starters.
In any electric motor, operation is based on simple
electromagnetism. A current-carrying conductor generates a magnetic field;
when this is then placed in an external magnetic field, it will experience a force
proportional to the current in the conductor, and to the strength of the external
magnetic field. As you are well aware of from playing with magnets as a kid,
opposite (North and South) polarities attract, while like polarities (North and
North, South and South) repel. The internal configuration of a DC motor is
designed to harness the magnetic interaction between a current-carrying
conductor and an external magnetic field to generate rotational motion.Let's start by looking at a simple 2-pole DC electric motor (here red
represents a magnet or winding with a "North" polarization, while green
represents a magnet or winding with a "South" polarization).
43
http://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorhttp://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorhttp://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorhttp://encyclobeamia.solarbotics.net/articles/current.htmlhttp://encyclobeamia.solarbotics.net/articles/current.htmlhttp://encyclobeamia.solarbotics.net/articles/dc.htmlhttp://encyclobeamia.solarbotics.net/articles/current.htmlhttp://encyclobeamia.solarbotics.net/articles/dc.htmlhttp://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorhttp://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorhttp://dc-motors.globalspec.com/Industrial-Directory/motorshttp://dc-motors.globalspec.com/Industrial-Directory/motorhttp://encyclobeamia.solarbotics.net/articles/current.htmlhttp://encyclobeamia.solarbotics.net/articles/current.htmlhttp://encyclobeamia.solarbotics.net/articles/dc.htmlhttp://encyclobeamia.solarbotics.net/articles/current.htmlhttp://encyclobeamia.solarbotics.net/articles/dc.html -
8/22/2019 PC based DC motor speed control1.doc
44/66
Every DC motor has six basic parts -- axle, rotor (a.k.a., armature), stator,
commutator, field magnet(s), and brushes. In most common DC motors (and all
that Beamers will see), the external magnetic field is produced by high-strength
permanent magnets1. The stator is the stationary part of the motor -- this
includes the motor casing, as well as two or more permanent magnet pole
pieces. The rotor (together with the axle and attached commutator) rotates with
respect to the stator. The rotor consists of windings (generally on a core), the
windings being electrically connected to the commutator. The above diagram
shows a common motor layout -- with the rotor inside the stator (field) magnets.
The geometry of the brushes, commutator contacts, and rotor
windings are such that when power is applied, the polarities of the energized
winding and the stator magnet(s) are misaligned, and the rotor will rotate until it
is almost aligned with the stator's field magnets. As the rotor reaches alignment,
the brushes move to the next commutator contacts, and energize the next
winding. Given our example two-pole motor, the rotation reverses the direction
of current through the rotor winding, leading to a "flip" of the rotor's magnetic
field, and driving it to continue rotating.
In real life, though, DC motors will always have more than two
poles (three is a very common number). In particular, this avoids "dead spots" in
the commutator. You can imagine how with our example two-pole motor, if the
rotor is exactly at the middle of its rotation (perfectly aligned with the field
magnets), it will get "stuck" there. Meanwhile, with a two-pole motor, there is a
moment where the commutator shorts out the power supply (i.e., both brushes
44
http://encyclobeamia.solarbotics.net/articles/dc.htmlhttp://encyclobeamia.solarbotics.net/articles/dc.htmlhttp://encyclobeamia.solarbotics.net/articles/dc.htmlhttp://encyclobeamia.solarbotics.net/articles/dc.html -
8/22/2019 PC based DC motor speed control1.doc
45/66
touch both commutator contacts simultaneously). This would be bad for the
power supply, waste energy, and damage motor components as well. Yet
another disadvantage of such a simple motor is that it would exhibit a high
amount of torque ripple" (the amount of torque it could produce is cyclic with
the position of the rotor).
So since most small DC motors are of a three-pole design, let's tinker with the
workings of one via an interactive animation (JavaScript required):
You'll notice a few things from this -- namely, one pole is fully energized at a
time (but two others are "partially" energized). As each brush transitions from
one commutator contact to the next, one coil's field will rapidly collapse, as the
next coil's field will rapidly charge up (this occurs within a few microsecond).
We'll see more about the effects of this later, but in the meantime you can see
that this is a direct result of the coil windings' series wiring:
45
-
8/22/2019 PC based DC motor speed control1.doc
46/66
There's probably no better way to see how an average dc motor is put together,
than by just opening one up. Unfortunately this is tedious work, as well as
requiring the destruction of a perfectly good motor.
This is a basic 3-pole dc motor, with 2 brushes and three commutator contacts.
Furthermore, modular design allows the software designer to limit the required
changes whenever a module needs to be modified or extended. The functional
separation main issue is to isolate as much as possible the application itself from
the user interface and the underlying hardware. The user interface is the set of
functions that allow the interaction between the user and the softwareapplication.
The Keil 8051 Development Tools are designed to solve the complex
problems facing embedded software developers. Keil development tools for the
46
-
8/22/2019 PC based DC motor speed control1.doc
47/66
8051 Microcontroller Architecture support every level of software developer
and learning about embedded software development.
keil C is an integrated development system for writing embedded software.
keil C comes with many function libraries, all in source code. It supports real-
time programming, machine level I/O
9.1 Features of keil C:
When starting a new program, simply select the microcontroller
from the Device Database and the Vision sets all compilers, assembler, linker,
and memory options depending on the selections.
The Keil Vision provides Debugger which accurately simulates
on-chip peripherals (UART, SPI, Interrupts, I/O Ports, A/D Converter, D/A
Converter, and PWM Modules) of your 8051 device. Simulation helps in
understanding hardware configurations and avoids time wasted on setup
problems. Additionally, with simulation, we can write and test applications
before target hardware is available.
After compiling and debugging process, the program will execute
in the run state and the result can be observed physically or through the
configurations made depending on selections made.
Numerous example programs are included to help getting started
with the most popular embedded 8051 devices.
47
-
8/22/2019 PC based DC motor speed control1.doc
48/66
Keil development tools for microcontrollers are easy to learn and use, yet
powerful enough for the most demanding embedded applications.
The keil c Vision compiler helps you create robust, sophisticated embedded
applications.
The keilc Vision Debugger accurately simulates a complete microcontroller
including peripherals and enables application testing without target hardware.
9.2 PROGRAMMING THE CHIP:
The chip can be programmed using INTELLIGENT
UNIVERSAL PROGRAMMER from Advantech, which connects to
PCs parallel port. The LabTool-48UXP features a 48-pin universal
pin driver and an expandable TTL pin driver, an on-board processor
lets it handle todays (and tomorrows) complicated DIP-type silicon
PLDs, microprocessors and high density memory chips.
The LabTool-48XP is developed for both laboratory and mass-
production applications. It supports over 7000 different devices,
including PAL, GAL, CPLD, EPLD, PEEL, MAX, MACH, pLSI,
microprocessors, EPROM, series EPROM, PROM and Flash
memory.
The LabTool-48XP performs device insertion and contact checks
before it programs each device. It can detect poor pin contact and
incorrect insertion, thus saving expensive chip damage due to
operator error. Many EPROM and Flash memories have a built-in
device and manufacturer ID. The LabTool-48XP can read this
48
-
8/22/2019 PC based DC motor speed control1.doc
49/66
information, making it useful when working with secondhand chips
and devices that have had their part number removed.
9.2.1 Intelligent Universal Programmer
9.3 FEATURES OF IUP:
High Speed USB port interface.
Supports 5V, 3.3V & 1.8V Devices
Less that 2 seconds per M bit Programming speed
No adapter required for DIL devices up to 48-pin.
48-pin universal pin driver and current limit
Device insertion / continuity check
Supports Windows 95/98, Windows 2000, Windows XP &
NT
3 years hardware warranty.
49
-
8/22/2019 PC based DC motor speed control1.doc
50/66
FREE software updates via the web.
Serialization for Memory and Micro's
Memory buffer H / L byte swap
Project file save and load function
User Selectable verify VCC with one or two-pass verify voltage
Automatic file format detection and conversion
Pin swapping table provided for all adapters
Universal adapters, for example one 44 pin PLCC adapter will
program 44 pin memory and micro devices.
9.4 Driving a dc motor:
1. The four leads of the stator winding are controlled by the four bits of
the 8051 port (p1.0-p1.3). However, since the 8051 lacks sufficient
current to drive the stepper motor windings, we must use a driver such as
uln2003a to energize the stator. Instead of the uln2003a, we could have
used transistors as drivers.
2. However, notice that if transistors are used as drivers, we must also
use diodes to take care of inductive current generated when the coil is
turned off. One reason that the uln2003a is preferable to the use of
transistors as drivers is that the uln2003 has as internal diode to take care
of back emf.
50
-
8/22/2019 PC based DC motor speed control1.doc
51/66
10.LIQUID CRYSTAL DISPLAY UNIT (LCD)
Introduction: -
Liquid Crystal Displays are created by sandwiching a thin (10-12 micro
mm) layer of a liquid crystal fluid between two glass plates. A
transparent, electrically conductive film or back plane is put up on the
rear glass sheet. The transparent sections of the conductive film in the
shape of the desired characters are coated on the front glass plate. When a
voltage is applied between a segment and the back plane, an electric field
is created in the region under the segment.
The is electric field changes the transmission of light through the region
under the segment film.
10.1 Liquid Crystal Display Description: -
In this project, JHD 162A Liquid Crystal Display (16x2), which is shown
in Figure 3.9, is interfaced with the CPU.
Figure 10.1.1 JHD 162A Liquid Crystal Display
The features of JHD 162A LCD is as follows: -
16 Characters x 2 Lines
51
-
8/22/2019 PC based DC motor speed control1.doc
52/66
5x7DotswithCursor
Built-in controller
+5v Power Supply
1/16 Duty Circle.
The pin description of the JHD 162A LCD without backlight is as shown in
Table 2.13. If the LCD is having Backlight, then it will have two more pins with
pin numbers 15 & 16 connected to VCC and GND respectively.
Pin
numberSymbol Level I/O Function
1 Vss - - Power supply (GND)
2 Vcc - - Power supply (+5V)
3 Vee - - Contrast adjust
4 RS 0/1 I0= Instruction input
1 = Data input
5 R/W 0/1 I0 = Write to LCD module
1 = Read from LCD module
6 E 1, 1->0 I Enable signal
7 DB0 0/1 I/O Data bus line 0 (LSB)
8 DB1 0/1 I/O Data bus line 1
9 DB2 0/1 I/O Data bus line 2
10 DB3 0/1 I/O Data bus line 3
11 DB4 0/1 I/O Data bus line 412 DB5 0/1 I/O Data bus line 5
13 DB6 0/1 I/O Data bus line 6
14 DB7 0/1 I/O Data bus line 7 (MSB)
Table 10.1.2 Pin assignment for
-
8/22/2019 PC based DC motor speed control1.doc
53/66
information during application debug. ASCII-input LCDs even though
they have these advantages, they have a reputation of being difficult to
hook up and get to work. Most alphanumeric LCD's use a common
controller chip and a common connector interface. Both of these actions
have resulted in alphanumeric LCDs that range in size from 8 characters
to 80 (arranged as 40 b 2 or 20 b 4) and are interchangeable, without
requiring hardware or software changes.
The ASCII code to be displayed is 8 bits long and is sent to the LCD
either 4 or 8 bits at time. If the 4-bit mode is used, two nibbles of data
(sent high 4 bits then low 4 bits with an E clock pulse with each nibble)
are sent to make up a full 8-bit transfer. The "E" clock is used to initiate
the data transfer within the LCD. In the LCD there is a cursor,
This specifies where the next data character is to be written. This cursor
can be moved or be made invisible to blink. The blinking function is very
rarely used because it is pretty obnoxious.
Sending parallel data either as 4 or 8 bits are the two primary
modes of operation. While there are secondary considerations and modes
deciding how to send the data to the LCD is more critical decision to be
made for an LCD interface application. 4-bit mode is best used when the
speed required in an application and at least 10 I/O pins are available. 4-
bit mode requires minimum 6 bits. To wire a Microcontroller to an LCD4-bit mode, just the top 4-bits (DB4-7) are written as shown in the Figure
10.1.3 below:
53
-
8/22/2019 PC based DC motor speed control1.doc
54/66
Figure 10.1.3 Data Transfer using a 4-Bit Interface
Using a shift register so that a minimum of three I/O pins is required can
further reduce this. 8-bit mode could be used with a shift register, but a
ninth bit (which will be used as R/S) will be required.
The display contains two internal byte-wide registers, one for command
(RS=0) and the second for the characters to be displayed (RS=1). The R/S
bit is used to select whether data or an instruction is being transferred
between the Microcontroller and the LCD. If the bit is set, the byte at the
current LCD cursor position can be read or written When the bit is reset,
either an instruction is being sent to the LCD or the execution status of
the last instruction is read back (whether it has completed or not).
The display contains two internal byte-wide registers, one for command
(RS=0) and the second for characters to be displayed (RS=1). It also
contains a user programmed RAM area (the character RAM) that can be
programmed to generate a desired character that can be formed using adot matrix.
54
-
8/22/2019 PC based DC motor speed control1.doc
55/66
To distinguish between these two data areas, the hex command byte 80
will be used to signify that the display RAM address 00h is chosen.
Port 1 is used to furnish the commands or data byte and ports 3.2 to 3.4
furnish register select and read/write levels. The display takes varying
amounts of time to accomplish the functions. LCD bit 7 is monitored for a long
high (bus) to ensure the display is not over written. A slightly more
complicated LCD display (4 lines* 40 characters) is currently being used in
medical diagnostic systems to run a very familiar program.
10.2 Getting The LCD To Display Text: -After successfully initializing the LCD and turning the display ON,one can
begin to display messages on the LCD by sending the correct instructions to
it. Getting the LCD to display text is a two-step process. First, the LCD's
cursor must be moved to the LCD address where the character is to be
displayed. This is done with the "DDRAM Address Set" command. Second,
the actual character must be written to the cursor in order to store it in the
DDRAM at the cursor's location. This is performed with the "CGRAM/DDRAM
Data Write" command.
10.3 LCD Busy Flag Polling: -
The LCD will not accept new commands while it is busy with some internal
operation. This condition must be tested before sending a new command to
the LCD. The "Busy Flag/Address Read" instruction should be used for this
purpose. The BF bit in this
instruction is the busy flag. When this bit is 1, LCD controller is busy. When
BF is 0, LCD is ready for the next command. In addition to busy flag polling,
this instruction is used to determine where the address of the LCD cursor is.
Examples for Busy Flag testing using both 4-bit and 8-bit interfaces are shown
in figures 10.3.1 and 10.3.2 respectively.
55
-
8/22/2019 PC based DC motor speed control1.doc
56/66
Figure 10.3.1 Example of busy flag testing using a 4-bit interface.
Figure 10.3.2 Example of busy flag testing using an 8-bit interface.
56
-
8/22/2019 PC based DC motor speed control1.doc
57/66
10.4 Defining LCD Custom Characters: -
One of the nice features of the LCD is that it allows for the creation and use of
up to eight unique, user-defined characters. Character Generator RAM
(CGRAM) has been added to the LCD for this purpose. Before a customcharacter can be used it must be created. Each character that can be
displayed by the LCD is composed of a 5 x 8 grid of pixels or dots. Each of
these dots can be turned either ON or OFF when a character is being
displayed. Therefore, in order for the LCD controller to display a character, it
must have a definition of which of the character dots need to be turned ON.
10.5 Interfacing of LCD with 89s52 Microcontroller: -In this project, the JHD 162ALCD is interfaced with the 89s52 Microcontroller.
Port1 pins of 89s52 are used to read and write the data from LCD by
interfacing P0.0 - P0.7 lines to D0-D7 lines of LCD. Similarly Port3 pins (P3.2-
P3.4) are connected to control pins of LCD i.e. E, R/W and RS pins
respectively.
57
-
8/22/2019 PC based DC motor speed control1.doc
58/66
11. PROJECT CODE
#include
#include ////////////////////////////////////////////////#define lcd P0/////////////////////////////////////////////////void init_lcd(void);void cmd_lcd(unsigned char);void lcd_data(unsigned char);void display_lcd(unsigned char *);void delay_ms(unsigned int);bit receive=0;unsigned char flag;
void pwm(unsigned int);void config(unsigned int value);sbit motor12=P2^7;unsigned char vall;///////////////////////////////////////////////////////////////////////////unsigned char a;unsigned int keypress;
void serial_int(void)interrupt 4{if(RI){
RI = 0;vall = SBUF;
if(vall == 'A'){flag=0;keypress=1;
}if(vall == 'B'){flag=0;keypress=2;}if(vall == 'C'){flag=0;keypress=3;}
if(vall == 'D')
{flag=0;
58
-
8/22/2019 PC based DC motor speed control1.doc
59/66
keypress=4;
}if(vall == 'E'){
flag=0;keypress=5;}if(vall == 'F'){flag=0;keypress=6;}
}}
void main(void){
motor12=0;
TMOD = 0x20;SCON = 0x50;TH1 = 0xFD;TR1 = 1;TH0=0x00;TL0=0x00;IE = 0x92;motor12=0;
init_lcd();init_lcd();init_lcd();
cmd_lcd(0x80);display_lcd("PC BASED DC MOTOR");cmd_lcd(0xC0);display_lcd("SPEED CONTROLLING ");
delay_ms(1000);//cmd_lcd(0x01);
59
-
8/22/2019 PC based DC motor speed control1.doc
60/66
while(1){//delay_ms(100);pwm(keypress);}}void pwm(unsigned int d){switch (d){
case 1:motor12=1;config(100);motor12=0;config(1);if(flag==0){cmd_lcd(0x01);cmd_lcd(0x80);display_lcd("Motor rotating");cmd_lcd(0xc0);display_lcd("with max speed");flag++;d=0;}break;
case 2:motor12=1;config(30);motor12=0;
config(70);if(flag==0){cmd_lcd(0x01);cmd_lcd(0x80);display_lcd("Motor rotating");cmd_lcd(0xc0);display_lcd("with Med speed");flag++;d=0;}break;
case 3:
60
-
8/22/2019 PC based DC motor speed control1.doc
61/66
motor12=1;config(40);motor12=0;config(60);if(flag==0)
{cmd_lcd(0x01);cmd_lcd(0x80);display_lcd("Motor rotating");cmd_lcd(0xc0);display_lcd("with Low 1 speed");flag++;d=0;}break;
case 4:motor12=1;config(60);motor12=0;config(40);if(flag==0){cmd_lcd(0x01);cmd_lcd(0x80);display_lcd("Motor rotating");cmd_lcd(0xc0);display_lcd("with Low 2speed");flag++;d=0;}break;
case 5:motor12=1;config(80);
motor12=0;config(20);if(flag==0){cmd_lcd(0x01);cmd_lcd(0x80);display_lcd("Motor rotating");cmd_lcd(0xc0);display_lcd("with Low 3speed");flag++;d=0;}
break;
61
-
8/22/2019 PC based DC motor speed control1.doc
62/66
case 6:motor12=0;config(00);motor12=0;config(00);
if(flag==0){cmd_lcd(0x01);cmd_lcd(0x80);display_lcd("Motor stop");//cmd_lcd(0xc0);//display_lcd("with Low 3speed");flag++;d=0;}break;
break;default:break;}}void config(unsigned int value ){unsigned int I ;while(value) {I = 115;while(I >0) I -- ;value--;}}
///////////////////////////////////////////////////////////////void init_lcd(void){
cmd_lcd(0x28);cmd_lcd(0x0c);cmd_lcd(0x06);cmd_lcd(0x01);delay_ms(10);}void cmd_lcd(unsigned char c){lcd = ((c & 0xf0) | 0x08);lcd = 0;lcd = ((c
-
8/22/2019 PC based DC motor speed control1.doc
63/66
}void lcd_data(unsigned char c){lcd = ((c&0xf0)|0x0a);lcd = 0;
lcd = ((c
-
8/22/2019 PC based DC motor speed control1.doc
64/66
PROJECT CIRCUIT DIAGRAM:
64
-
8/22/2019 PC based DC motor speed control1.doc
65/66
13.BIBILIOGRAPHY
REFERENCES:
BOOKS:
65
-
8/22/2019 PC based DC motor speed control1.doc
66/66
1. MICRO CONTROLLERS BYRAMESH.S.GAONKR
2. DATA SHEETS OF VARIOUS ICS
3 .The 8051 Microcontroller Architecture, Programming &Applications
Kenneth J Ayala4. 8051 MANUAL
WEB SITE:
1. WWW.CHIP.COM
2. WWW.GOOGLEARCH.COM
3. WWW.EMBEDDEDSYSTEMS.COM
4. WWW.VISUALBASIC.COM
5. www.8051 free projectsinfo.com
LIST OF FIGURES
http://www.chip.com/http://www.googlearch.com/http://www.embeddedsystems.com/http://www.visualbasic.com/http://www.chip.com/http://www.googlearch.com/http://www.embeddedsystems.com/http://www.visualbasic.com/