You are on page 1of 96

CLOSED LOOP CONTROL OF A BLDC MOTOR TO RUN

AT A EXACTLY ENTERED SPEED

A PROJECT REPORT

Submitted by

BITTU GOSWAMI (112713105008)

N.KARTHIK RAJA (112713105022)

P.NAVEEN KUMAR (112713105034)

A.SANDEEP RAJ (112713105046)

in partial fulfillment for the award of the degree


of
BACHELOR OF ENGINEERING
in
ELECTRICAL AND ELECTRONICS ENGINEERING
ST.PETERS COLLEGE OF ENGINEERING AND TECHNOLOGY, CHENNAI

ANNA UNIVERSITY:: CHENNAI 600 025

APRIL 2017

1
ANNA UNIVERSITY::CHENNAI 600 025
BONAFIDE CERTIFICATE
Certified that this project report CLOSED LOOP CONTROL OF A BLDC MOTOR TO
RUN AT ENTERED SPEED is the bonafide work of the following students.
BITTU GOSWAMI (112713105008)
N.KARTHIK RAJA (112713105022)
P.NAVEEN KUMAR (112713105034)
A.SANDEEP RAJ (112713105046)

SIGNATURE SIGNATURE
Dr.J.JasperGnanaChandran, M.E., Ph.D. Mrs. C. Subha, M.E

(HEAD OF THE DEPARTMENT) (SUPERVISOR)

Professor Assistant Professor

Electrical and Electronics Engineering Electrical and Electronics Engineering

St. Peters college of Engineering and St. Peters college of Engineering and

Technology, Avadi, Chennai-600 054. Technology, Avadi, Chennai-600 054.

The project of CLOSED LOOP CONTROL OF A BLDC MOTOR TO RUN AT A


EXACTLY ENTERED SPEED is submitted on..

INTERNAL EXAMINER EXTERNAL EXAMINER

2
ACKNOWLEDGEMENT

First of all, we are grateful to the Almighty God for establishing us to complete this
project.

It is our immense pleasure to express our deep sense of gratitude to our honourable
Chairperson Dr. BANUMATHI THAMBIDURAI for providing such an excellent lab
facility. We are extremely thankful to our Principal Dr.S.SELVAN, M.E.., Ph.D., for
the facilities provided to us during the project.

We thank our honourable Head of the Department of Electrical and Electronics


Engineering Dr.J. JASPER GNANACHANDRAN, M.E.., Ph.D., for the necessary
help in rescheduling the lab timing and giving enough time, so that we could make use
of the available resources optimally.

We owe our profound gratitude to our Project Coordinator and Project Internal
Guide Mrs. C.SUBHA, M.E for their exemplary guidance, suggestions, monitoring
and constant encouragement throughout the course. Their Blessing, motivation and
guidance which have been given by them has made us to complete our journey.

We are thankful and fortunate enough to get the constant encouragement, support and
guidance from all Staff of the Department of Electrical and Electronics Engineering
which helped us in successful completion of this project work.

Last but not the least, we are very grateful to our parents and our well-wishers for their
constant support and encouragement during the project.

3
TABLE OF CONTENTS

CHAPTER NO. TITLE PAGE NO

ABSTRACT

LIST OF TABLES

LIST OF FIGURES

LIST OF SYMBOLS

1 INTRODUCTION 11

2 BLOCK DIAGRAM 15

3 HARDWARE REQUIREMENT 16

3.1 Transformers 17

3.2 Voltage Regulator 19

3.3 Rectifier 21

3.4 Filter 21

3.5 Microcontroller (AT89S52) 22

3.6 Liquid Crystal Display 29

3.7 Key Pad 32

3.8 Optoisolator 34

3.9 MOSFET 37

3.10 DC Motor 39

3.11 IR Led (BC547) 43

3.12 Photodiode (IN4007) 44

3.13 PWM 45

4
4 SOFTWARE REQUIREMENTS 49

4.1 IDE 49

4.2 Concept of Compiler 49

4.3 Concept of Cross Compiler 50

4.4 Keil C Cross Compiler 50

4.5 Building an Application 51

In Uvision2

4.6 Creating Your Own 51

Application in Uvision2

4.7 Debugging an Application 51

Inuvision2

4.8 Starting Uvision2 & 52

Creating a Project

4.9 Windows_ Files 52

4.10 Building Projects & 52

Creating Hex Files

4.11 CPU Simulation 53

4.12 Database Selection 53

4.13 Start Debugging 53

4.14 Disassembly Window 54

4.15 Embedded C 54

5 SCHEMATIC DIAGRAM 56

5.1 Description 57

6 CODING 67

5
7.1 Compiler 67

7.2 Source Code 74

7 HARDWARE TESTING 95

8.1 Continuity Test 95

8.2 Power on Test 95

8 RESULTS 97

9 CONCLUSION 99

10 BIBLIOGRAPHY

6
LIST OF FIGURES

FIGURE NO TITLE PAGE NO

1(a) Embedded Design Cycle 10

2.1 Block Diagram of the Project 13

3.1(b) A Typical Transformer 15

3.2(a) A Ideal Transformer 16

3.2(b) Voltage Regulator 17

3.2(c) Block Diagram of Voltage Regulator 18

3.3 Full Wave Bridge Rectifier 19

3.4 Performance Characteristics 20

3.5(a) Block Diagram Of AT89S52 22

3.5(b) Pin Diagram of AT89S52 23

3.5(c) Oscillator Connections 26

3.5(d) External Clock Drive Configuration 27

3.6(a) Liquid Crystal Display 29

3.6(b) Schematic Diagram of LCD 29

3.7(a) Keypad 30

3.7(a) Matrix Keypad 31

3.8 Schematic Diagram of Optocoupler 33

3.9(a) Pin Diagram of MOSFET 36

3.9(b) MOSFET as a Switch 37

3.10(a) BLDC Motor 38

3.10 (b) Brushless DC Electric Motor 39

5.1 Schematic Diagram 54


5.2 MOSFET as Switch 58

5.3 Transistor as a Switch 59

5.4 Speed Sensor 61


ABSTRACT

The project is designed to control the speed of a BLDC motor using closed loop

control technique. BLDC motor has various application used in industries like in

drilling, lathes, spinning, elevators, electric bikes etc. The speed control of the DC

motors is very essential. This proposed system provides a very precise and effective

speed control system. The user can enter the desired speed and the motor will run at

that exact speed.

Based on the principle of PWM speed can be controlled. This is achieved by keeping

BLDC motor on closed loop feedback by giving RPM reference to the microcontroller

upon a shaft mounted IR reflection arrangement. An LCD duly interfaced to the

microcontroller to display the running speed. The desired speed in percentage of full

speed is fed with the help of keypad. The controller delivers desired pulse width to

automatically adjust the DC power to the motor for required speed. The above

operation is carried out by using one opto-isolator and a MOSFET for driving the

BLDC motor with IR sensing for getting the speed reference to the microcontroller.

Further the project can be enhanced to a fully-fledged fuzzy logic control of a BLDC

motor for industrial applications. It can also be developed for an intelligent cruise

control used in modern automobiles these days.


CHAPTER 1

INTRODUCTION

1.1 What is Embedded system?


An Embedded System is a combination of computer hardware and software, and
perhaps additional mechanical or other parts, designed to perform a specific function.
An embedded system is a microcontroller-based, software driven, reliable, real-time
control system, autonomous, or human or network interactive, operating on diverse
physical variables and in diverse environments and sold into a competitive and cost
conscious market.
An embedded system is not a computer system that is used primarily for processing,
not a software system on PC or UNIX, not a traditional business or scientific
application. High-end embedded & lower end embedded systems. High-end embedded
system - Generally 32, 64 Bit Controllers used with OS. Examples Personal Digital
Assistant and Mobile phones etc. Lower end embedded systems - Generally 8,16 Bit
Controllers used with an minimal operating systems and hardware layout designed for
the specific purpose. Examples Small controllers and devices in our everyday life like
Washing Machine, Microwave Ovens, where they are embedded in.
System
System
Definitio
Testing
n
Hardwar
Rapid e-in-the-
Prototyping Loop
Testing

Targeting

Figure 1(a):Embedded System Design Cycle


1.2 Characteristics of Embedded System
An embedded system is any computer system hidden inside a product other than a
computer.
They will encounter a number of difficulties when writing embedded system
software in addition to those we encounter when we write applications
Throughput Our system may need to handle a lot of data in a short period of
time.
ResponseOur system may need to react to events quickly
TestabilitySetting up equipment to test embedded software can be difficult
DebugabilityWithout a screen or a keyboard, finding out what the software is
doing wrong (other than not working) is a troublesome problem
Reliability embedded systems must be able to handle any situation without
human intervention
Memory space Memory is limited on embedded systems, and you must make the
software and the data fit into whatever memory exists
Program installation you will need special tools to get your software into
embedded systems
Power consumption Portable systems must run on battery power, and the
software in these systems must conserve power
Processor hogs computing that requires large amounts of CPU time can
complicate the response problem
Cost Reducing the cost of the hardware is a concern in many embedded system
projects; software often operates on hardware that is barely adequate for the job.
Embedded systems have a microprocessor/ microcontroller and a memory.
Some have a serial port or a network connection. They usually do not have keyboards,
screens or disk drives.
1.3 APPLICATIONS
Military and aerospace embedded software applications
Communication Applications
Industrial automation and process control software
Mastering the complexity of applications.
Reduction of product design time.
Real time processing of ever increasing amounts of data.
Intelligent, autonomous sensors.

1.4 CLASSIFICATION
Real Time Systems.
RTS is one which has to respond to events within a specified deadline.
A right answer after the dead line is a wrong answer

1.4.1 RTS CLASSIFICATION


Hard Real Time Systems
Soft Real Time System

1.4.1.1 HARD REAL TIME SYSTEM


"Hard" real-time systems have very narrow response time.
Example: Nuclear power system, Cardiac pacemaker.

1.4.1.2 SOFT REAL TIME SYSTEM


"Soft" real-time systems have reduced constrains on "lateness" but still must
operate very quickly and repeatable.
Example: Railway reservation system takes a few extra seconds the data
remains valid.

CHAPTER 2
BLOCK DIAGRAM

Fig 2.1: Block Diagram of Project

2.1 Explanation

The speed of the motor is sensed by an IR pair and is displayed on LCD and is also
fed to the microcontroller. The required speed is entered using a keypad which is
interfaced with microcontroller. The motor is interfaced to the MC through an
optocoupler & a MOSFET which drives the motor. PWM pulses are generated from
MC according to the entered speed and the motor is adjusted to that speed and
maintained at that speed.

CHAPTER 3
HARDWARE REQUIREMENTS

HARDWARE COMPONENTS:

1. Transformer (230 12 V Ac)

2. Voltage Regulator (LM 7805)

3. Rectifier

4. Filter

5. Microcontroller (AT89S52/AT89C51)

6. LCD Display

7. Keypad

8. LM358

9. MCT2E

10. MOSFET

11. IR Led

12. Photodiode

13. BLDC Motor

14. BC547

15. BC557

16. 1N4007

17. LED

18. Resistor

19. Capacitor

3.1 TRANSFORMER
Transformers convert AC electricity from one voltage to another with a little loss of
power. Step-up transformers increase voltage, step-down transformers reduce voltage.
Most power supplies use a step-down transformer to reduce the dangerously high
voltage to a safer low voltage.

Fig 3.1(A): A Typical Transformer

The input coil is called the primary and the output coil is called the secondary. There is
no electrical connection between the two coils; instead they are linked by an
alternating magnetic field created in the soft-iron core of the transformer. The two lines
in the middle of the circuit symbol represent the core. Transformers waste very little
power so the power out is (almost) equal to the power in. Note that as voltage is
stepped down and current is stepped up.
The ratio of the number of turns on each coil, called the turns ratio, determines the
ratio of the voltages. A step-down transformer has a large number of turns on its
primary (input) coil which is connected to the high voltage mains supply, and a small
number of turns on its secondary (output) coil to give a low output voltage.
TURNS RATIO = (Vp /Vs) = ( Np / Ns )
Where,
Vp = primary (input) voltage.
Vs = secondary (output) voltage
Np = number of turns on primary coil
Ns = number of turns on secondary coil
Ip = primary (input) current
Is = secondary (output) current.

Ideal power equation

Fig 3.1(B)The ideal transformer as a circuit element

If the secondary coil is attached to a load that allows current to flow, electrical power
is transmitted from the primary circuit to the secondary circuit. Ideally, the transformer
is perfectly efficient; all the incoming energy is transformed from the primary circuit
to the magnetic field and into the secondary circuit. If this condition is met, the
incoming electric power must equal the outgoing power:

Giving the ideal transformer equation

Transformers normally have high efficiency, so this formula is a reasonable


approximation.

If the voltage is increased, then the current is decreased by the same factor. The
impedance in one circuit is transformed by the square of the turns ratio.For example, if
an impedance Zs is attached across the terminals of the secondary coil, it appears to the
primary circuit to have an impedance of (Np/Ns)2Zs. This relationship is reciprocal, so
that the impedance Zp of the primary circuit appears to the secondary to be (Ns/Np)2Zp.

3.2 VOLTAGE REGULATOR 7805

Features
Output Current up to 1A.
Output Voltages of 5, 6, 8, 9, 10, 12, 15, 18, 24V.
Thermal Overload Protection.
Short Circuit Protection.
Output Transistor Safe Operating Area Protection.

Fig 3.2(a): Voltage Regulator

Description
The LM78XX/LM78XXA series of three-terminal positive regulators are available in
the TO-220/D-PAK package and with several fixed output voltages, making them
useful in a wide range of applications. Each type employs internal current limiting,
thermal shutdown and safe operating area protection, making it essentially
indestructible. If adequate heat sinking is provided, they can deliver over 1A output
Current. Although designed primarily as fixed voltage regulators, these devices can be
used with external components to obtain adjustable voltages and currents.
Internal Block Diagram

Fig
3.2(b):
Block
Diagram of Voltage Regulator

3.3 RECTIFIER
A rectifier is an electrical device that converts alternating current (AC), which
periodically reverses direction, to direct current (DC), current that flows in only one
direction, a process known as rectification. Rectifiers have many uses including as
components of power supplies and as detectors of radio signals. Rectifiers may be
made of state diodes, vacuum tube diodes, mercury arc valves, and other components.
The output from the transformer is fed to the rectifier. It converts A.C. into pulsating
D.C. The rectifier may be a half wave or a full wave rectifier. In this project, a bridge
rectifier is used because of its merits like good stability and full wave rectification. In
positive half cycle only two diodes (1 set of parallel diodes) will conduct, in negative
half cycle remaining two diodes will conduct and they will conduct only in forward
bias only.

FIG 3.3 Full Wave Bridge Rectifier

3.4 FILTER
Capacitive filter is used in this project. It removes the ripples from the output of
rectifier and smoothens the D.C. Output received from this filter is constant until the
mains voltage and load is maintained constant. However, if either of the two is varied,
D.C. voltage received at this point changes. Therefore a regulator is applied at the
output stage.
The simple capacitor filter is the most basic type of power supply filter. The use of this
filter is very limited. It is sometimes used on extremely high-voltage, low-current
power supplies for cathode-ray and similar electron tubes that require very little load
current from the supply. This filter is also used in circuits where the power-supply
ripple frequency is not critical and can be relatively high. Below figure can show how
the capacitor changes and discharges.
Fig 3.4 Performance Characteristics of Voltage Regulator

3.5 MICROCONTROLLER AT89S52

The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8K


bytes of in-system programmable Flash memory. The device is manufactured using
Atmels high-density non-volatile memory technology and is compatible with the
industry standard 80C51 instruction set and pin out. The on-chip Flash allows the
program memory to be reprogrammed in-system or by a conventional non-volatile
memory programmer.

By combining a versatile 8-bit CPU with in-system programmable Flash on a


monolithic chip, the Atmel AT89S52 is a powerful microcontroller which provides a
highly-flexible and cost-effective solution to many embedded control applications. The
AT89S52 provides the following standard features: 8K bytes of Flash, 256 bytes of
RAM, 32 I/O lines, Watchdog timer, two data pointers, 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 AT89S52 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
interrupt or hardware reset.

Features:

Compatible with MCS-51 Products


8K Bytes of In-System Programmable (ISP) Flash Memory
Endurance: 10,000 Write/Erase Cycles
4.0V to 5.5V Operating Range
Fully Static Operation: 0 Hz to 33 MHz
Three-level Program Memory Lock
256 x 8-bit Internal RAM
32 Programmable I/O Lines
Three 16-bit Timer/Counters
Eight Interrupt Sources
Full Duplex UART Serial Channel
Low-power Idle and Power-down Modes
Interrupt Recovery from Power-down Mode
Watchdog Timer
Dual Data Pointer
Power-off Flag
Fast Programming Time
Flexible ISP Programming (Byte and Page Mode)
Block Diagram of AT89S52:

Fig 3.5(a): Block Diagram of AT89S52


Pin Configurations of AT89S52

Fig 3.5(b): Pin Diagram of AT89S52

Pin Description:

VCC:
Supply voltage.

GND:
Ground.

Port 0:
Port 0 is an 8-bit open drain bidirectional I/O port. 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 can 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. 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.
In addition, P1.0 and P1.1 can be configured to be the timer/counter 2 external count
input (P1.0/T2) and the timer/counter 2 trigger input (P1.1/T2EX).

Port 2:
Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. 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
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 uses 16-bit addresses (MOVX @
DPTR). In this application, Port 2 uses strong internal pull-ups when emitting 1s.
During accesses to external data memory that uses 8-bit addresses (MOVX @ RI),
Port 2 emits the contents of the P2 Special Function Register.

Port 3:
Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. 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.

RST:
Reset input. A high on this pin for two machine cycles while the oscillator is running
resets the device. This pin drives high for 98 oscillator periods after the Watchdog
times out. The DISRTO bit in SFR AUXR (address 8EH) can be used to disable this
feature. In the default state of bit DISRTO, the RESET HIGH out feature is enabled.

ALE/PROG:
Address Latch Enable (ALE) is an 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.

PSEN:
Program Store Enable (PSEN) is the read strobe to external program memory. When
the AT89S52 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 will be 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.

XTAL1:
Input to the inverting oscillator amplifier and input to the internal clock operating
circuit.

XTAL2:
Output from the inverting oscillator amplifier.

Oscillator Characteristics:
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
1. 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 6.2. 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-
flop, but minimum and maximum voltage high and low time specifications must be
observed.

Fig 3.5(c): Oscillator Connections


Fig 3.5(d): External Clock Drive Configuration

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.

Power down Mode


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.

3.6 LIQUID CRYSTAL DISPLAY

Description:
This is the example for the Parallel Port. This example doesn't use the Bi-directional
feature found on newer ports, thus it should work with most, if not all Parallel Ports. It
however doesn't show the use of the Status Port as an input for a 16 Character x 2 Line
LCD Module to the Parallel Port. These LCD Modules are very common these days,
and are quite simple to work with, as all the logic required running them is on board.

Pros:

Very compact and light


Low power consumption

No geometric distortion

Little or no flicker depending on backlight technology

Not affected by screen burn-in

No high voltage or other hazards present during repair/service

Can be made in almost any size or shape

LCD Background:
Frequently, an 8051 program must interact with the outside world using input and
output devices that communicate directly with a human being. One of the most
common devices attached to an 8051 is an LCD display. Some of the most common
LCDs connected to the 8051 are 16x2 and 20x2 displays. This means 16 characters per
line by 2 lines and 20 characters per line by 2 lines, respectively.
Fortunately, a very popular standard exists which allows us to communicate with the
vast majority of LCDs regardless of their manufacturer. The standard is referred to as
HD44780U, which refers to the controller chip which receives data from an external
source (in this case, the 8051) and communicates directly with the LCD.
Fig 3.6(a): LCD

44780 LCD BACKGROUND

The 44780 standard requires 3 control lines as well as either 4 or 8 I/O lines for the
data bus. The user may select whether the LCD is to operate with a 4-bit data bus or an
8-bit data bus. If a 4-bit data bus is used the LCD will require a total of 7 data lines (3
control lines plus the 4 lines for the data bus). If an 8-bit data bus is used the LCD will
require a total of 11 data lines (3 control lines plus the 8 lines for the data bus).

Fig 3.6(b) Schematic Diagram of LCD

The three control lines are referred to as EN, RS, and RW.

The EN line is called "Enable." This control line is used to tell the LCD that you are
sending it data. To send data to the LCD, your program should make sure this line is
low (0) and then set the other two control lines and/or put data on the data bus. When
the other lines are completely ready, bring EN high (1) and wait for the minimum
amount of time required by the LCD datasheet (this varies from LCD to LCD), and
end by bringing it low (0) again.
The RS line is the "Register Select" line. When RS is low (0), the data is to be treated
as a command or special instruction (such as clear screen, position cursor, etc.). When
RS is high (1), the data being sent is text data which should be displayed on the screen.
For example, to display the letter "T" on the screen you would set RS high.
The RW line is the "Read/Write" control line. When RW is low (0), the information on
the data bus is being written to the LCD. When RW is high (1), the program is
effectively querying (or reading) the LCD. Only one instruction ("Get LCD status") is
a read command. All others are write commands--so RW will almost always be low
.Finally, the data bus consists of 4 or 8 lines (depending on the mode of operation
selected by the user). In the case of an 8-bit data bus, the lines are referred to as DB0,
DB1, DB2, DB3, DB4, DB5, DB6, and DB7.

3.7 KEYPAD

Fig 3.7(a): Keypad


A keypad is a set of buttons arranged in a block or "pad" which usually bear digits,
symbols and usually a complete set of alphabetical letters. If it mostly contains
numbers then it can also be called a numeric keypad. Keypads are found on many
alphanumeric keyboards and on other devices such as calculators, push-button
telephones, combination locks, and digital door locks, which require mainly numeric
input.
Keypads are a part of HMI or Human Machine Interface and play really important role
in a small embedded system where human interaction or human input is needed.
Matrix keypads are well known for their simple architecture and ease of interfacing
with any microcontroller.

Fig 3.7(b): Matrix Keypad

3.7.1 SCANNING OF MATRIX KEYPAD:


There are many methods depending on the connection keypad with micro controller,
but the basic logic is same the columns are made as input and drive the rows making
them as output; this whole procedure of reading the keyboard is called scanning. In
order to detect which key is pressed from the matrix, the row lines are to be made low
one by one and read the columns. Assume that if Row1 is made low, then read the
columns. If any of the key in row1 is pressed then correspondingly the column 1will
give low that is if second key is pressed in Row1, then column2 will give low. This is
how Scanning is done. So to scan the keypad completely, we need to make rows low
one by one and read the columns. If any of the buttons are pressed in a row, it will take
the corresponding column to a low state which shows that a key is pressed in that row.
If button 1 of a row is pressed then Column 1 will become low, if button 2 then
column2 and so on...this is the way of working by a keypad.

3.8 OPTOISOLATOR (MCT2E)

Opto-isolators, or Opto-couplers, are made up of a light emitting device, and a light


sensitive device, all wrapped up in one package, but with no electrical connection
between the two, just a beam of light. The light emitter is nearly always an LED. The
light sensitive device may be a photodiode, phototransistor, or more esoteric devices
such as thyristors, triacs e.t.c.

A lot of electronic equipment nowadays is using optocoupler in the circuit. An


optocoupler or sometimes refer to as optoisolator allows two circuits to exchange
signals yet remain electrically isolated. This is usually accomplished by using light to
relay the signal. The standard optocoupler circuits design uses a LED shining on a
phototransistor-usually it is a npn transistor and not PNP. The signal is applied to the
LED, which then shines on the transistor in the IC.

The light is proportional to the signal, so the signal is thus transferred to the
phototransistor. Optocouplers may also come in few module such as the SCR,
photodiodes, TRIAC of other semiconductor switch as an output, and incandescent
lamps, neon bulbs or other light source.
The optocoupler usually found in switch mode power supply circuit in many
electronic equipment. It is connected in between the primary and secondary section of
power supplies. The optocoupler application or function in the circuit is to:
Monitor high voltage
Output voltage sampling for regulation
System control micro for power ON/OFF
Ground isolation
If the optocoupler IC breakdown, it will cause the equipment to have low power, blink,
no power, erratic power and even power shut down once switch on the equipment.
Many technicians and engineers do not know that they can actually test the
optocoupler with their analog multimeter. Most of them thought that there is no way of
testing an IC with an analog meter.
This is the principle used in OptoTriacs and optoSCRs, which are readily available
in Integrated circuit (I.C.) form, and do not need very complex circuitry to make them
work. Simply provide a small pulse at the right time to the Light Emitting Diode in the
package. The light produced by the LED activates the light sensitive properties of the
Triac or Thyristor gate and the power is switched on. The isolation between the low
power and high power circuits in these optically connected devices is typically several
thousand volts

Fig: 3.8 Schematic Diagram of


Optocoupler
OPTO-ISOLATOR PARAMETERS

Collector-emitter voltage
This is the maximum voltage that can be present from the collector to the emitter of
the receiving phototransistor (when it is turned off no light) before it may break-
down.
Cree page distance
This is physically how far a spark would have to travel around the outside of the
package to get from one side to the other. If the package has contaminants on it, solder
flux, or dampness, then a lower-resistance path can be created for noise signals to
travel along.
Forward current
This is the current passing through the sending LED. Typically, an Opto-isolator will
require about 5mA to turn the output transistor on.
Forward voltage
This is the voltage that is dropped across the LED when it is turned on. Most normal
diodes drop about 0.7v, but with LEDs it is typically 1 2 volts.
Collector dark current
This is the current that can flow through the output phototransistor when it is turned
off.
Collector-emitter saturation voltage
When the output transistor is fully turned on (saturated), this is the voltage there will
be between the collector and emitter.
Isolation resistance
This is the resistance from a pin in the input side to a pin on the output side. It should
be very high.
Response time
The rise and fall times are the times that the output voltage takes to get from zero to
maximum. The rise time is very much dependent on the load resistor, since it is this
that is pulling the output up. Therefore this value is always quoted with a fixed load
resistance. Note however that the value, 100 Ohms, is much less than you are likely to
use in practice. This is another of the manufacturers attempts to make the product look
better than it is.

Cutoff frequency
This is effectively the highest frequency of square wave that can be sent through the
Opto-isolator. It is actually the frequency at which the output voltage is only swinging
half the amplitude than at DC levels (-3Db = half). It is therefore linked with the rise
and fall times.

Current Transfer Ratio (CTR)


This is the ratio of how much collector current in the output transistor that you get
given a certain amount of forward current in the input side LED. It is affected by how
close the LED and phototransistor are inside the device, how efficient they both are,
and many other factors. In fact it is not a constant but varies wildly with LED forward
current.

3.9 MOSFET

The metaloxidesemiconductor field-effect transistor (MOSFET, MOS-FET, or MOS


FET) is a device used for amplifying or switching electronic signals. The basic
principle of the device was first proposed by Julius Edgar Lilienfeld in 1925. In
MOSFETs, a voltage on the oxide-insulated gate electrode can induce a conducting
channel between the two other contacts called source and drain. The channel can be of
n-type or p-type and is accordingly called an nMOSFET or a pMOSFET. It is by far
the most common transistor in both digital and analog circuits, though the bipolar
junction transistor was at one time much more common.
A variety of symbols are used for the MOSFET. The basic design is generally a line for
the channel with the source and drain leaving it at right angles and then bending back
at right angles into the same direction as the channel. Sometimes three line segments
are used for enhancement mode and a solid line for depletion mode.
Comparison of enhancement-mode and depletion-mode MOSFET symbols, along with
JFET symbols (drawn with source and drain ordered such that higher voltages appear
higher on the page than lower voltages).

Fig 3.9(a): Pin Diagram of MOSFET

Fig 3.9(b): MOSFET as Switch


In this circuit arrangement an Enhancement-mode N-channel MOSFET is being used
to switch a simple lamp "ON" and "OFF" (could also be an LED). The gate input
voltage VGS is taken to an appropriate positive voltage level to turn the device and the
lamp either fully "ON", (VGS = +ve) or a zero voltage level to turn the device fully
"OFF", (VGS = 0).
If the resistive load of the lamp was to be replaced by an inductive load such as a coil
or solenoid, a "Flywheel" diode would be required in parallel with the load to protect
the MOSFET from any back-emf. Above shows a very simple circuit for switching a
resistive load such as a lamp or LED. But when using power MOSFET's to switch
either inductive or capacitive loads some form of protection is required to prevent the
MOSFET device from becoming damaged.
Driving an inductive load has the opposite effect from driving a capacitive load. For
example, a capacitor without an electrical charge is a short circuit, resulting in a high
"inrush" of current and when we remove the voltage from an inductive load we have a
large reverse voltage build up as the magnetic field collapses, resulting in an induced
back-emf in the windings of the inductor.
For the power MOSFET to operate as an analogue switching device, it needs to be
switched between its "Cut-off Region" where V GS = 0 and its "Saturation Region"
where VGS (on) = +ve. The power dissipated in the MOSFET (P D) depends upon the
current flowing through the channel ID at saturation and also the "ON-resistance" of the
channel given as RDS (on).

3.10 BRUSHLESS DC MOTOR

Brushless DC motors (BLDC motors, BL motors) also known as electronically


commutated motors (ECMs, EC motors) are synchronous electric motors powered by
direct-current (DC) electricity and having electronic commutation systems, rather than
mechanical commutators and brushes. The current-to-torque and frequency-to-speed
relationships of BLDC motors are linear.

Fig 3.10(a): BLDC Motor

BLDC motors may be described as stepper motors, with fixed permanent magnets and
possibly more poles on the rotor than the stator, or reluctance motors. The latter may
be without permanent magnets, just poles that are induced on the rotor then pulled into
alignment by timed stator windings. However, the term stepper motor tends to be used
for motors that are designed specifically to be operated in a mode where they are
frequently stopped with the rotor in a defined angular position; this page describes
more general BLDC motor principles, though there is overlap.

Brushless Versus Brushed Motor:

Limitations of brushed DC motors overcome by BLDC motors include lower


efficiency and susceptibility of the commutator assembly to mechanical wear and
consequent need for servicing, at the cost of potentially less rugged and more complex
and expensive control electronics. BLDC motors develop maximum torque when
stationary and have linearly decreasing torque with increasing speed as shown in the
adjacent figure.
Fig 3.10 (b): Brushless DC Electric Motor Torque-Speed Characteristics
A BLDC motor has permanent magnets which rotate and a fixed armature, eliminating
the problems of connecting current to the moving armature. An electronic controller
replaces the brush/commutator assembly of the brushed DC motor, which continually
switches the phase to the windings to keep the motor turning. The controller performs
similar timed power distribution by using a solid-state circuit rather than the
brush/commutator system.

BLDC motors offer several advantages over brushed DC motors, including more
torque per weight and efficiency, reliability, reduced noise, longer lifetime (no brush
and commutator erosion), elimination of ionizing sparks from the commutator, more
power, and overall reduction of electromagnetic interference (EMI). With no windings
on the rotor, they are not subjected to centrifugal forces, and because the windings are
supported by the housing, they can be cooled by conduction, requiring no airflow
inside the motor for cooling. This in turn means that the motor's internals can be
entirely enclosed and protected from dirt or other foreign matter.
The maximum power that can be applied to a BLDC motor is exceptionally high,
limited almost exclusively by heat, which can weaken the magnets. (Magnets
demagnetize at high temperatures, the Curie point, and for neodymium-iron-boron
magnets this temperature is lower than for other types.) A BLDC motor's main
disadvantage is higher cost, which arises from two issues. First, BLDC motors require
complex electronic speed controllers to run. Brushed DC motors can be regulated by a
comparatively simple controller, such as a rheostat (variable resistor). However, this
reduces efficiency because power is wasted in the rheostat. Second, some practical
uses have not been well developed in the commercial sector. For example, in the Radio
Control (RC) hobby, even commercial brushless motors are often hand-wound while
brushed motors use armature coils which can be inexpensively machine-wound.
(Nevertheless, see "Applications", below.)

BLDC motors are often more efficient at converting electricity into mechanical power
than brushed DC motors. This improvement is largely due to the absence of electrical
and friction losses due to brushes. The enhanced efficiency is greatest in the no-load
and low-load region of the motor's performance curve. Under high mechanical loads,
BLDC motors and high-quality brushed motors are comparable in efficiency.

AC induction motors require induction of magnetic field in the rotor by the rotating
field of the stator; this results in the magnetic and electric fields being out of phase.
The phase difference requires greater current and current losses to achieve power.
BLDC motors are microprocessor-controlled to keep the stator current in phase with
the permanent magnets of the rotor, requiring less current for the same effect and
therefore resulting in greater efficiency.

In general, manufacturers use brush-type DC motors when low system cost is a


priority but brushless motors to fulfill requirements such as maintenance-free
operation, high speeds, and operation in explosive environments where sparking could
be hazardous.
Applications:

Consumer electronics

Transport

Heating and ventilation

Industrial engineering

Model engineering

3.11 IR LED

An IR LED, also known as IR transmitter, is a special purpose LED that transmits


infrared rays in the range of 760 nm wavelength. Such LEDs are usually made of
gallium arsenide or aluminum gallium arsenide. They, along with IR receivers, are
commonly used as sensors.

The appearance is same as a common LED. Since the human eye cannot see the
infrared radiations, it is not possible for a person to identify whether the IR LED is
working or not, unlike a common LED. To overcome this problem, the camera on a
cell phone can be used. The camera can show us the IR rays being emanated from the
IR LED in a circuit.

Features

Extra high radiant power


low forward voltage
suitable for high pulse current operation intensity
high reliability

Chip Materials

Dice Material : GaA1As/GaAs


Lens Color : Water Clear

3.12 PHOTODIODE

A photodiode is a type of photo detector capable of converting light into either current
or voltage, depending upon the mode of operation. Photodiodes are similar to regular
semiconductor diodes except that they may be either exposed (to detect vacuum UV or
X-rays) or packaged with a window or optical fibre connection to allow light to reach
the sensitive part of the device. Many diodes designed for use specifically as a
photodiode will also use a PIN junction rather than the typical PN junction.

Principle of operation
A photodiode is a PN junction or PIN structure. When a photon of sufficient energy
strikes the diode, it excites an electron, thereby creating a mobile electron and a
positively charged electron hole. If the absorption occurs in the junction's depletion
region, or one diffusion length away from it, these carriers are swept from the junction
by the built-in field of the depletion region. Thus holes move toward the anode, and
electrons toward the cathode, and a photocurrent is produced.

Photovoltaic mode
When used in zero bias or photovoltaic mode, the flow of photocurrent out of the
device is restricted and a voltage builds up. The diode becomes forward biased and
"dark current" begins to flow across the junction in the direction opposite to the
photocurrent. This mode is responsible for the photovoltaic effect, which is the basis
for solar cellsin fact, a solar cell is just a large area photodiode.

Photoconductive mode

In this mode the diode is often reverse biased, dramatically reducing the response time
at the expense of increased noise. This increases the width of the depletion layer,
which decreases the junction's capacitance resulting in faster response times. The
reverse bias induces only a small amount of current (known as saturation or back
current) along its direction while the photocurrent remains virtually the same. The
photocurrent is linearly proportional to the luminance
Although this mode is faster, the photoconductive mode tends to exhibit more
electronic noise. The leakage current of a good PIN diode is so low (< 1nA) that the
JohnsonNyquist noise of the load resistance in a typical circuit often dominates.

3.13 PWM
Pulse-width modulation (PWM) is a commonly used technique for controlling power
to an electrical device, made practical by modern electronic power switches. The
average value of voltage (and current) fed to the load is controlled by turning the
switch between supply and load on and off at a fast pace. The longer the switch is on
compared to the off periods, the higher the power supplied to the load is.
The PWM switching frequency has to be much faster than what would affect the load,
which is to say the device that uses the power. Typically switchings have to be done
several times a minute in an electric stove, 120 Hz in a lamp dimmer, from few
kilohertz (kHz) to tens of kHz for a motor drive and well into the tens or hundreds of
kHz in audio amplifiers and computer power supplies.
The term duty cycle describes the proportion of on time to the regular interval or
period of time; a low duty cycle corresponds to low power, because the power is off
for most of the time. Duty cycle is expressed in percent, 100% being fully on.
The main advantage of PWM is that power loss in the switching devices is very low.
When a switch is off there is practically no current, and when it is on, there is almost
no voltage drop across the switch. Power loss, being the product of voltage and
current, is thus in both cases close to zero. PWM works also well with digital controls,
which, because of their on/off nature, can easily set the needed duty cycle.
PWM has also been used in certain communication systems where its duty cycle has
been used to convey information over a communications channel.

Power delivery
PWM can be used to adjust the total amount of power delivered to a load without
losses normally incurred when a power transfer is limited by resistive means. The
drawbacks are the pulsations defined by the duty cycle, switching frequency and
properties of the load. With a sufficiently high switching frequency and, when
necessary, using additional passive electronic filters the pulse train can be smoothed
and average analog waveform recovered.
High frequency PWM power control systems are easily realisable with semiconductor
switches. As has been already stated above almost no power is dissipated by the switch
in either on or off state. However, during the transitions between on and off states both
voltage and current are non-zero and thus considerable power is dissipated in the
switches. Luckily, the change of state between fully on and fully off is quite rapid
(typically less than 100 nanoseconds) relative to typical on or off times, and so the
average power dissipation is quite low compared to the power being delivered even
when high switching frequencies are used.
Modern semiconductor switches such as MOSFETs or Insulated-gate bipolar
transistors (IGBTs) are quite ideal components. Thus high efficiency controllers can be
built. Typically frequency converters used to control AC motors have efficiency that is
better than 98 %. Switching power supplies have lower efficiency due to low output
voltage levels (often even less than 2 V for microprocessors are needed) but still more
than 70-80 % efficiency can be achieved.
Variable-speed fan controllers for computers usually use PWM, as it is far more
efficient when compared to a potentiometer or rheostat. (Neither of the latter is
practical to operate electronically; they would require a small drive motor).
Light dimmers for home use employ a specific type of PWM control. Home use light
dimmers typically include electronic circuitry which suppresses current flow during
defined portions of each cycle of the AC line voltage. Adjusting the brightness of light
emitted by a light source is then merely a matter of setting at what voltage (or phase)
in the AC half cycle the dimmer begins to provide electrical current to the light source
(e.g. by using an electronic switch such as a triac). In this case the PWM duty cycle is
the ratio of the conduction time to the duration of the half AC cycle defined by the
frequency of the AC line voltage (50 Hz or 60 Hz depending on the country).
These rather simple types of dimmers can be effectively used with inert (or relatively
slow reacting) light sources such as incandescent lamps, for example, for which the
additional modulation in supplied electrical energy which is caused by the dimmer
causes only negligible additional fluctuations in the emitted light. Some other types of
light sources such as light-emitting diodes (LEDs), however, turn on and off extremely
rapidly and would perceivably flicker if supplied with low frequency drive voltages.
Perceivable flicker effects from such rapid response light sources can be reduced by
increasing the PWM frequency. If the light fluctuations are sufficiently rapid, the
human visual system can no longer resolve them and the eye perceives the time
average intensity without flicker (see flicker fusion threshold).
In electric cookers, continuously-variable power is applied to the heating elements
such as the hob or the grill using a device known as a Simmertat. This consists of a
thermal oscillator running at approximately two cycles per minute and the mechanism
varies the duty cycle according to the knob setting. The thermal time constant of the
heating elements is several minutes, so that the temperature fluctuations are too small
to matter in practice.
Applications
Telecommunications
Power delivery
Voltage regulation
Audio effects and amplification.
CHAPTER 4
SOFTWARE REQUIREMENTS

4.1 INTRODUCTION TO KEIL MICRO VISION (IDE)

Keil an ARM Company makes C compilers, macro assemblers, real-time kernels,


debuggers, simulators, integrated environments, evaluation boards, and emulators for
ARM7/ARM9/Cortex-M3, XC16x/C16x/ST10, 251, and 8051 MCU families.
Keil development tools for the 8051 Microcontroller Architecture support every level
of software developer from the professional applications engineer to the student just
learning about embedded software development. When starting a new project, simply
select the microcontroller you use from the Device Database and the Vision IDE sets
all compiler, assembler, linker, and memory options for you.
Keil is a cross compiler. So first we have to understand the concept of compilers and
cross compilers. After then we shall learn how to work with keil.

4.2 CONCEPT OF COMPILER


Compilers are programs used to convert a High Level Language to object code.
Desktop compilers produce an output object code for the underlying microprocessor,
but not for other microprocessors. I.E the programs written in one of the HLL like
C will compile the code to run on the system for a particular processor like x86
(underlying microprocessor in the computer). For example compilers for Dos platform
is different from the Compilers for Unix platform So if one wants to define a compiler
then compiler is a program that translates source code into object code.
The compiler derives its name from the way it works, looking at the entire piece of
source code and collecting and reorganizing the instruction. See there is a bit little
difference between compiler and an interpreter. Interpreter just interprets whole
program at a time while compiler analyses and execute each line of source code in
succession, without looking at the entire program.
The advantage of interpreters is that they can execute a program immediately.
Secondly programs produced by compilers run much faster than the same programs
executed by an interpreter. However compilers require some time before an executable
program emerges. Now as compilers translate source code into object code, which is
unique for each type of computer, many compilers are available for the same
language.

4.3 CONCEPT OF CROSS COMPILER


A cross compiler is similar to the compilers but we write a program for the target
processor (like 8051 and its derivatives) on the host processors (like computer of x86).
It means being in one environment you are writing a code for another environment is
called cross development. And the compiler used for cross development is called cross
compiler. So the definition of cross compiler is a compiler that runs on one computer
but produces object code for a different type of computer.

4.4 KEIL C CROSS COMPILER


Keil is a German based Software development company. It provides several
development tools like
IDE (Integrated Development environment)
Project Manager
Simulator
Debugger
C Cross Compiler, Cross Assembler, Locator/Linker
The Keil ARM tool kit includes three main tools, assembler, compiler and linker. An
assembler is used to assemble the ARM assembly program. A compiler is used to
compile the C source code into an object file. A linker is used to create an absolute
object module suitable for our in-circuit emulator.
4.5 Building an Application in Vision2
To build (compile, assemble, and link) an application in Vision2, you must:
1. Select Project -(forexample,166\EXAMPLES\HELLO\HELLO.UV2).
2. Select Project - Rebuild all target files or Build target.Vision2 compiles,
assembles, and links the files in your project.
4.6 Creating Your Own Application in Vision2
To create a new project in Vision2, you must:
1. Select Project - New Project.
2. Select a directory and enter the name of the project file.
3. Select Project - Select Device and select an 8051, 251, or C16x/ST10 device from
the Device Database.
4. Create source files to add to the project.
5. Select Project - Targets, Groups, Files. Add/Files, select Source Group1, and add
the source files to the project.
6. Select Project - Options and set the tool options. Note when you select the target
device from the Device Database all special options are set automatically. You
typically only need to configure the memory map of your target hardware. Default
memory model settings are optimal for most applications.
7. Select Project - Rebuild all target files or Build target.

4.7 Debugging an Application in Vision2


To debug an application created using Vision2, you must:
1. Select Debug - Start/Stop Debug Session.
2. Use the Step toolbar buttons to single-step through your program. You may enter
G, main in the Output Window to execute to the main C function.
3. Open the Serial Window using the Serial #1 button on the toolbar. Debug your
program using standard options like Step, Go, Break, and so on.
4.8 Starting Vision2 and Creating a Project
Vision2 is a standard Windows application and started by clicking on the program
icon. To create a new project file select from the Vision2 menu Project New
Project. This opens a standard Windows dialog that asks you for the new project file
name. We suggest that you use a separate folder for each project. You can simply use
the icon Create New Folder in this dialog to get a new empty folder. Then select this
folder and enter the file name for the new project, i.e. Project1. Vision2 creates a new
project file with the name PROJECT1.UV2 which contains a default target and file
group name. You can see these names in the Project.

4.9 Window Files.


Now use from the menu Project Select Device for Target and select a CPU for your
project. The Select Device dialog box shows the Vision2 device data base. Just select
the microcontroller you use. We are using for our examples the Philips 80C51RD+
CPU. This selection sets necessary tool Options for the 80C51RD+ device and
simplifies in this way the tool Configuration.

4.10 Building Projects and Creating a HEX Files


Typical, the tool settings under Options Target are all you need to start a new
application. You may translate all source files and line the application with a click on
the Build Target toolbar icon. When you build an application with syntax errors,
Vision2 will display errors and warning messages in the Output Window Build
page. A double click on a message line opens the source file on the correct location in
a Vision2 editor window. Once you have successfully generated your application you
can start debugging.
4.11 CPU Simulation
Vision2 simulates up to 16 Mbytes of memory from which areas can be mapped for
read, write, or code execution access. The Vision2 simulator traps and reports illegal
memory accesses. In addition to memory mapping, the simulator also provides support
for the integrated peripherals of the various 8051 derivatives. The on-chip peripherals
of the CPU you have selected are configured from the Device.

4.12 Database selection


You have made when you create your project target. Refer to page 58 for more
Information about selecting a device. You may select and display the on-chip
peripheral components using the Debug menu. You can also change the aspects of each
peripheral using the controls in the dialog boxes.

4.13 Start Debugging


You start the debug mode of Vision2 with the Debug Start/Stop Debug
Session Command. Depending on the Options for Target Debug Configuration,
Vision2 will load the application program and run the startup code Vision2 saves
the editor screen layout and restores the screen layout of the last debug session. If the
program execution stops, Vision2 opens an editor window with the source text or
shows CPU instructions in the disassembly window. The next executable statement is
marked with a yellow arrow. During debugging, most editor features are still available.
For example, you can use the find command or correct program errors. Program source
text of your application is shown in the same windows. The Vision2 debug mode
differs from the edit mode in the following aspects:
_ The Debug Menu and Debug Commands described on page 28 are available. The
additional debug windows are discussed in the following.
_ The project structure or tool parameters cannot be modified. All build commands are
disabled.
4.14 Disassembly Window
The Disassembly window shows your target program as mixed source and assembly
program or just assembly code. A trace history of previously executed instructions may
be displayed with Debug View Trace Records. To enable the trace history, set Debug
Enable/Disable Trace Recording.
If you select the Disassembly Window as the active window all program step
commands work on CPU instruction level rather than program source lines. You can
select a text line and set or modify code breakpoints using toolbar buttons or the
context menu commands.
1`You may use the dialog Debug Inline Assembly to modify the CPU instructions.
That allows you to correct mistakes or to make temporary changes to the target
program you are debugging. Numerous example programs are included to help you get
started with the most popular embedded 8051 devices.
The Keil Vision Debugger accurately simulates on-chip peripherals (IC, CAN,
UART, SPI, Interrupts, I/O Ports, A/D Converter, D/A Converter, and PWM Modules)
of your 8051 device. Simulation helps you understand hardware configurations and
avoids time wasted on setup problems. Additionally, with simulation, you can write
and test applications before target hardware is available.

4.15 EMBEDDED C
Use of embedded processors in passenger cars, mobile phones, medical equipment,
aerospace systems and defense systems is widespread, and even everyday domestic
appliances such as dish washers, televisions, washing machines and video recorders
now include at least one such device.
CHAPTER 5
SCHEMATIC DIAGRAM

Fig 5.1 Schematic Diagram


5.1 DESCRIPTION

5.1.1 POWER SUPPLY


The circuit uses standard power supply comprising of a step-down transformer from
230Vto 12V and 4 diodes forming a bridge rectifier that delivers pulsating dc which is
then filtered by an electrolytic capacitor of about 470F to 1000F. The filtered dc
being unregulated, IC LM7805 is used to get 5V DC constant at its pin no 3
irrespective of input DC varying from 7V to 15V. The input dc shall be varying in the
event of input ac at 230volts section varies from 160V to 270V in the ratio of the
transformer primary voltage V1 to secondary voltage V2 governed by the formula
V1/V2=N1/N2. As N1/N2 i.e. no. of turns in the primary to the no. of turns in the
secondary remains unchanged V2 is directly proportional to V1.Thus if the
transformer delivers 12V at 220V input it will give 8.72V at 160V.Similarly at 270V it
will give 14.72V.Thus the dc voltage at the input of the regulator changes from about
8V to 15V because of A.C voltage variation from 160V to 270V the regulator output
will remain constant at 5V.
The regulated 5V DC is further filtered by a small electrolytic capacitor of 10F for
any noise so generated by the circuit. One LED is connected of this 5V point in series
with a current limiting resistor of 330 to the ground i.e., negative voltage to indicate
5V power supply availability. The unregulated 12V point is used for other applications
as and when required.

5.2 STANDARD CONNECTIONS TO 8051 SERIES MICRO


CONTROLLER
ATMEL series of 8051 family of micro controllers need certain standard connections.
The actual number of the Microcontroller could be 89C51 , 89C52, 89S51,
89S52, and as regards to 20 pin configuration a number of 89C2051. The 4 set of
I/O ports are used based on the project requirement. Every microcontroller requires a
timing reference for its internal program execution therefore an oscillator needs to be
functional with a desired frequency to obtain the timing reference as t =1/f.
A crystal ranging from 2 to 20 MHz is required to be used at its pin number 18 and 19
for the internal oscillator. It may be noted here the crystal is not to be understood as
crystal oscillator It is just a crystal, while connected to the appropriate pin of the
microcontroller it results in oscillator function inside the microcontroller. Typically
11.0592 MHz crystal is used in general for most of the circuits using 8051 series
microcontroller. Two small value ceramic capacitors of 33pF each is used as a standard
connection for the crystal as shown in the circuit diagram.

RESET

Pin no 9 is provided with an reset arrangement by a combination of an electrolytic


capacitor and a register forming RC time constant. At the time of switch on, the
capacitor gets charged, and it behaves as a full short circuit from the positive to the pin
number 9.After the capacitor gets fully charged the current stops flowing and pin
number 9 goes low which is pulled down by a 10k resistor to the ground. This
arrangement of reset at pin 9 going high initially and then to logic 0 i.e., low helps the
program execution to start from the beginning. In absence of this the program
execution could have taken place arbitrarily anywhere from the program cycle. A
pushbutton switch is connected across the capacitor so that at any given time as
desired it can be pressed such that it discharges the capacitor and while released the
capacitor starts charging again and then pin number 9 goes to high and then back to
low, to enable the program execution from the beginning. This operation of high to low
of the reset pin takes place in fraction of a second as decided by the time constant R
and C.

For example: A 10F capacitor and a 10k resistor would render a 100ms time to pin
number 9 from logic high to low, there after the pin number 9 remains low.
External Access (EA):
Pin no 31 of 40 pin 8051 microcontroller termed as EA is required to be connected to
5V for accessing the program form the on-chip program memory. If it is connected to
ground then the controller accesses the program from external memory. However as
we are using the internal memory it is always connected to +5V.

5.3 OPTOCOUPLER

Opto coupler is a 6 pin IC. It is a combination of 1 LED and a transistor. Pin 6 of


transistor is not generally used and when light falls on the Base-Emitter junction then
it switches and pin5 goes to zero.
If input of the diode is zero and other end of diode is GND then the output is one.
When logic zero is given as input then the light doesnt fall on transistor so it
doesnt conduct which gives logic zero as output.
When logic 1 is given as input then light falls on transistor so that it conducts,
that makes transistor switched ON and it forms short circuit this makes the
output is logic zero as collector of transistor is connected to ground.

Fig 5.2: MOSFET as Switch


In this circuit arrangement an Enhancement-mode N-
channel MOSFET is being used to switch a simple
lamp "ON" and "OFF" (could also be an LED). The
gate input voltage VGS is taken to an appropriate
positive voltage level to turn the device and the lamp either fully "ON", (V GS = +ve) or
a zero voltage level to turn the device fully "OFF", (VGS = 0).

BRIEF DESCRIPTION OF TRANSISOR ACTING AS SWITCH


An NPN transistor is "on" when its base is pulled high relative to the emitter. The

arrow in the NPN transistor symbol is on the emitter leg and points in the direction of

the conventional current flow when the device is in forward active mode. Whenever

base is high, then current starts flowing through base and emitter and after that only

current will pass from collector to emitter

Fig 5.3 Transistor as Switch

OPERATION
CONNECTIONS:
A 230v-12v step down transformer is connected to the bridge rectifier, a blocking
diode is connected at the output of bridge rectifier, a 100 mf capacitor is connected
after blocking diode, a 7805 voltage regulator is connected after 1000mf capacitor, a
10mf capacitor is connected at the output of voltage regulator, a red LED is connected
with a series resistor 330ohms. Now +5v dc is generated at the output of voltage
regulator.
The 40th pin of micro controller is connected to the +5v dc and 20 th pin of controller is
connected to the ground. A crystal oscillator is connected at 18 th and 19th pins of
controller, a push button is connected at 19 th pin of controller, a 10micro farads
capacitor is connected across the push button, a 10k resistor is connected to the 19 th pin
and grounded two 33pf capacitor are connected at the crystal pins.
Keypad is connected to port 1 of micro controller, 3 control pins of LCD are connected
to port 3.5 to 3.7 and 8 data pins of the LCD are connected to port 0. LCD 16 th pin is
GND and 2nd and 15th pins are connected to Vcc.
The anode of IR LED is connected to Vcc via 220ohms resistors, cathode is GND. The
cathode of photo diode is connected to Vcc through 1k resistor, anode is connected to a
variable resistor 1k &third pin of variable resistor is connected to base of an n-p-n
transistor, emitter is grounded and collector is connected to 12 th pin of micro controller,
being pulled up with 2.2k resistor.
The output pin of micro controller i.e. P2.0 is connected to the 2nd pin of opto isolator
&1 pin of the opto is connected to 5volt +ve via a resistor of 330 ohms. Pin 4 & 5 that
works like a switch of the optofeeds a Mosfet that is wired to operate the BLDC motor
as per the circuit.

WORKING:
While logic high during the on time duty cycle is delivered by the microcontroller to
the input of the OPTO U3, The opto led glows to bring the opto transistor pin no 5 and
6 to conduct. Now 12V supply is given at the junction point of R7 and R8 and reaches
the gate of the MOSFET Q1 via D4 for Q1 to conduct thus enabling the motor to get
supply to run. A freewheel diode is used across the motor to conduct the charge stored
in the motor during off period. During off time of the duty cycle the opto transistor
does not conduct and the charge which is stored in the gate of Q1 forces Q3 to conduct
while the motor stops. This ON and OFF the motor reduces the speed. The DC power
is available to the motor via the MOSFET as per the PWM generated by micro
controller depending upon the input given to micro controller from a keypad. As well
as the speed is displayed on a liquid crystal display. To sense the speed of BLDC motor
an IR LED in photo diode arrangement is used. The value of speed is changed in
percentage by using fuzzy logic. Fuzzy logic is something i.e. approximate but not
accurate. So a program is written in to micro controller that uses fuzzy logic due to
which we get the values almost equal to accurate values.
A 230v -12v step down transformer is used to decrease AC supply voltage to 12v, now
this ac voltage is rectified by using a full wave bridge rectifier, a blocking diode is
used before the filter capacitor to get the pulsating D.C. to get the fixed output D.C a
7805 voltage regulator is employed because micro controller fixed +5v pure DC. To
filter pulsating D.C an electrolytic capacitor of value 470 micro farads or 1000micro
farads is connected at the input of 7850. One more electrolytic capacitor is connected
at the output of 7850 to remove complete ripples if there any +5v D.C. A LED with a
series resistors is connected to indicate the power. Micro controller has to generate
PWM pulses as per error signal received from the speed sensing input to match the
keyboard input in order to run the motor at the input RPM.
A push button is connected at the 9th pin of micro controller which is known as reset a
10 micro farads electrolytic capacitor is connected across the button and a 10k resistor
is used to pull down 9th pin of micro controller. When this reset pin is pressed during
the operation, the program written in micro controller starts from beginning. A crystal
across oscillator of value 11.0592 MHz is connected across 18 th& 19th pins of micro
controller with the 33pico farads ceramic capacitors are connected for stabilising it.
Fig 5.4 Speed Sensor
To sense the speed of BLDC motor an infrared (IR) diode and photo diode are used.
When light falls on photo diode the resistance across it decreases and vice versa.
Hence photo diode is employed in a potential divider with a variable resistor. This
potential divider supplies voltage to an N-P-N transistor whose collector is connected
to micro controller input. So, the IR LED and photo diode are placed near the shaft of
BLDC motor and a white spot is made on the shaft infrared light gets reflected by
white colour and the reflected light keeps falling on photo diode, due to which the
voltage across it keeps changing thereafter the voltage at base of transistor also
changes therefore at the collector of transistor a pulse is generated which is given to
micro controller for counting the number of rotations per minute of D.C motor.
This sensed speed is displayed on LCD in rpm. To change the speed a keypad is used
as an input to the micro controller. By using this we can enter how much percentage of
speed would be required for the motor to run.
Pressing # twice the maximum running speed is stored. After which pressing * the
desired percentage of speed is entered. There after pressing # the desired speed is
saved which are displayed on the LCD. There after the on time of the pulse width
progressively goes on reducing to result the speed reduction. Speed sensors
continuously send the error signal to pin 12 of the MC to lock the running speed of the
motor at the desired speed.
Some calculations:
Choosing Capacitor for Bridge rectifier: There is some approximated formula
.Peak to peak ripple voltage =Load current in amps / (2*line frequency in hertz
* capacitance in farads). But as rule of thumb for 1 A current 1000uF is best.
Thus it is load dependent.
Series resistor with LED: When LED (red)conducts the voltage drop across it
will be 1.2V fixed so we have to limit the current of 10 to 20 mA through series
resistor, now voltage drop across series resistor will be 3.8V (5-1.2) and we have
to limit current to 10mA ,so apply Ohms law R=V/I = 3.8/0.01 = 380 330
Same with Opto-isolator MCT2E
Series resistor with IR LED: When LED conducts the voltage drop across it will
be 1.2V fixed, so we have to limit the current of 10-20mA through series resistor
for good IR strength, now voltage drop across series resistor will be 3.8V and
have to limit current 20mA so apply Ohms law R=V/I = 3.8/0.02 = 190
220
Reset Circuit at pin 9 of microcontroller: Reset circuit is a standard circuit
resistor and capacitor but we can calculate the time calculate RC time constant
R*C=10K * 10F 0.1 sec, meaning during the power on time that pin is
driven high for 0.1 sec because of capacitor charging and there after the pin goes
low for the program to get executed from the start.
Photo diode: Resistor with photo diode is variable so you have to adjust for
biasing the NPN transistor by a variable resistor till the transistor starts
conducting upon the reference to IR light falling on photo diode
Crystal is a standard circuit
BC547: Microcontroller understands only logic High and Low i.e., 5V or 0V, thats

why use one BC547 NPN transistor as it has its emitter a ground reference .So when
the IR light is reflecting on photo diode through the white patch on the fan blade its
resistance decreases meaning the voltage drop changes across the photo diode that
results voltage drop across 10k preset ( the variable resistor) increase which goes to
bias the base of NPN transistor and thus make collector point ( as the transistor
conducts) low i.e., this 0V is low logic given to microcontroller. But when IR light is
not reflecting the resistance across photo diode will be high meaning voltage across it
will be high that results voltage across 10k preset will change and this voltage is not
enough to bias the NPN transistor so collector point will be logic High meaning 5V
will go to that point to the microcontroller.
BC557: This is to discharge the in-built capacitor charge of MOSFET as explained in

the documents
Freewheeling diode: We are dealing with DC motor, motor has inductance. The
inductance property is that when a current flow through it, it stores some energy, when
motor supply is cut off this stored energy needs a path to allow flow of that energy in
the same direction as the current was flowing otherwise this energy forcefully goes to
damage the other switching component attachment to it like MOSFET.
MOSFET: Here MOSFET is used as a motor driver switch, which drives the BLDC
motor with reference to the logic coming from the microcontroller .

OPERATION PROCEDURE:
1. Press # once display shows the store Max RPM.
2. Press # again to store Max.RPM.
3. Press * to get the required RPM. Display shows % of Req_RPM:
4. Enter the required percentage using Keypad.
5. Press # to save the required RPM.

CHAPTER 6
CODING
6.1 COMPILER
1. Click on the Keil Vision Icon on Desktop
2. The following fig will appear
3. Click on the Project menu from the title bar
4. Then Click on New Project

5. Save the Project by typing suitable project name with no extension in your own
folder sited in either C:\ or D:\
6. Then Click on save button above.
7. Select the component for your project. I.e. Atmel
8. Click on the + Symbol beside of Atmel

9. Select AT89C51 as shown below


10. Then Click on OK
11. The Following fig will appear
12. Then Click either YES or NOmostly NO.
13. Now your project is ready to USE.
14. Now double click on the Target1, you would get another option Source group 1
as shown in next page.

15. Click on the file option from menu bar and select new.
16. The next screen will be as shown in next page, and just maximize it by double
clicking on its blue boarder.

17. Now start writing program in either in EMBEDDED C or ASM.


18. For a program written in Assembly, then save it with extension . asm and for
EMBEDDED C based program save it with extension .C
19. Now right click on Source group 1 and click on Add files to Group Source.
20. Now you will get another window, on which by default EMBEDDED C files
will appear.

21. Now select as per your file extension given while saving the file
22. Click only one time on option ADD.
23. Now Press function key F7 to compile. Any error will appear if so happen.
24. If the file contains no error, then press Control+F5 simultaneously.
25. The new window is as follows

26. Then Click OK.


27. Now click on the Peripherals from menu bar, and check your required port as
shown in fig below.
28. Drag the port a side and click in the program file.

29. Now keep Pressing function key F11 slowly and observe.
30. You are running your program successfully.
6.2 SOURCE CODE

#include<AT89x52.h> //header file

#define LCDDATA P2

sbit BUSY = P2^7;

sbit RS = P3^7;

sbit RW = P3^6;

sbit en = p3^5;

sbit COL1 = P1^4;

sbit COL2 = p1^5;

sbit COL3 = P1^6;

sbit ROW1 = P1^0

sbit ROW2 = P1^1;

sbit ROW3 = P1^2;

sbit ROW4 = P1^3;

sbit MOUT = P0^7;

sbit D0 = P0^0;

sbit D1 = P0^1;

sbit D2 = P0^2;

sbit D3 = P0^3;
//bit addresable area

bit INTO_Flag = 0x10;

bit time_flag = 0x11;

bit update_flag = 0x12;

bit pulse_flag = 0x13;

bit pulsetime_flag = 0x14;

bit timecount_flag = 0x15;

bit setrpm_flag = 0x09;

unsigned char keypad[4][3] = {{1,2,3},

{4,5,6},

{7,8,9},

{*,0,#}};

unsigned char K_Flag = 0;

unsigned char RPM_Flag = 0,shift_flag = 0;

unsigned char Temp = 0;

unsigned int RPM = 0;

int Temp_count = 0;

unsigned int shift 0,d;

unsigned int Reoshift;


unsigned int PresentRPM = 0,RequiredRPM = 0;

unsigned int MaxRPM = 0;

unsigned int ReqSpeed = 0;

unsigned int time_count;

unsigned char high_count;

unsigned char low_count;

unsigned char imt0_count,COUNT = 0;

unsigned char RPM_ENTERED[5] = {0};

CHAR Temp_buffer[5];

char shift_buf[3];

void LCDData(unsigned char Data);

void T2_Delay(unsigned int msec);

void wait();

void send_to_mem(char s_address, char s_data);

void start_s_eeprom();

void send_byte_s_eeprom(char s_byte);

void acknowledge();

void stop_s_eeprom();

char get_from_mem(char s_address);

char get_byte_s_eeprom();
void delay();

void speed2_bcd(unsigned int rev);

void copy2_speed();

void get_speed();

void rpm2_bcd(unsigned int max);

void copy2_maxrpm();

void copy2_reqrpm();

void get_maxrpm();

void get_reqrpm();

void clear_eeprom();

void copy2_shift();

void shift2_bcd(unsigned int );

void get_shift();

void ISR_INT0() interrupt 0 // interrupt service routine for interrupt 0

if(update_flag == 1) // if update_flag is set

int0_count++; // increment the int0_count

if(int0_count == 2) // if int0_count is equal to 2

TR0 = 0; //stop the timer

high_count = TH0; // copy timer0 high count

low_count = TL0; // copy timer0 low count


update_flag = 0; // clear the update_flag

int0_count = 0; // clear the int0_count

timecount_flag = 1; // set the timecount_flag

else

TR0 = 1; // start the timer0

void timer0_isr() interrupt 1 // ISR for timer0 interrupt

time_count = time_count + 1; // increment the time_count for each overflow of


timer0

void PWM_DELAY()

MOUT = 0; // switch on the motor

T2_Delay (shift);

MOUT = 1; // switch off the motor

T2_Delay(100-shift);
}

/*100usec ZVS Delay*/

void T2_Delay(unsigned int msec) // time delay for 100uS delay

unsigned int i = 0;

for(i = 0; i<msec;i++)

TH2 = 0XFF; // Load the timer2 high count

TL2 = 0XA4; // Load the timer2 low count

T2CON = 0X04; //start the timer2

while(TF2 == 0); // wait here till the timer2 overflows

TF2 = 0; // clear the timer2 overflow flag

T2CON = 0X00; // stop the timer2

void init_T0() // Initialisation of timer0

TMOD l =0x01; // select the timer0 in mode1 mode

TH0 = 0x00; //Load 0x00 into the timer high count

TL0 = 0x00; // Load 0x00 into the timer low count

}
void delay()

unsigned int NUM;

for (NUM=0;NUM<25000:num++);

/*Function to send command to LCD*/

Void LCDCMD(unsigned char CMD)

LCDDATA=CMD; //copy command to the lcd data bus

RS=0; //RS=0 for command

RW=0; //RW=0 for waiting

EN=1; //make enable pin is high

EN=0; //make enable pin is low

/*Function to send data to LCD*/

Void LCDData(unsigned char Data)

LCDDATA=Data; //copy Data to the lcd data bus

RS=1; //RS=1 for data

RW=0; //RW=0 for writing

EN=1; //make enable pin is high

EN=0; //make enable pin is low


}

Void LCDString(unsigned char*str) //Display the string on the LCD

While(*str)

LCDData(*str)

Void LCDNUM(unsigned int NUM)

Unsigned char Buff[5]=(0)=0;

While(NUM)

Buff[i]=(NUM%10)+ 0x30;

NUM=NUM/10;

If(!i)

LCDData(0)
LCDString( );

Else

While(i--)

LCDData(Buff[i]);

LCDString( );

/*Function to initialize LCD*/

Void init_LCD()

/*command to select 2 line , 5x7 matrix mode of LCD */

LCDCMD(0x38);

/*command to shift the cursor to next position when Data is send in LCD */

LCDCMD(0x06);

/*command to ON display, OFF the cursor in LCD */

LCDCMD(0xoc);
/*Return cursor home */

LCDCMD(0x02);

Void Delay(unsigned int time)

Unsigned int i=0;j=0;

for(i=0;i<Time;i++)

for(j=0;j<1000;j++);

Void ReadkeyPad() //keypadfunction

unsigned char posi=0;

If(posi==0)

Col1=0; //make coloumn1 zero

else if(posi == 1)

Col2=0; //make coloumn2 zero

else if(posi == 2)
{

Col3=0; //make coloumn3 zero

If(Row1 == 0) //if row1 is zero

K_Flag = 1;

Temp = keypad[0][posi];

If(Row2 == 0) //if row2 is zero

K_Flag = 1;

Temp = keypad[1][posi];

If(Row3 == 0) //if row3 is zero

K_Flag = 1;

Temp = keypad[2][posi];

If(Row1 == 0) //ifrow1 is zero

K_Flag = 1;

Temp = keypad[3][posi];

}
Posi++; //increment the posi

Void init_EXINT() //initialization of interrupt0

EX0 = 1; //Enable the interrupt0

Unsigned int ASCII_DECIMAL((unsigned char *str)

Unsigned char j =0, k=0,i=0, *ptr;

Unsigned int ten =10,out =0,temp =1;

For(;*ptr!=0;ptr++)

K++;

while(*str)

For(i=k-1;I !=0;i--)

temp *= ten;

out +=(unsigned int)(*str++-0x30)*temp;

temp = 1;

k--;

Return out;
}

Void main()

Unsigned char Buff[10] =0;j=0;k=0;

Unsigned int temp =0; Mode =0,B4 =0;

P2 =0xFF; //set port2 as input/output port

P1 =0xFF; //set port1 as input/output port

P3 =0xFF; //set port3 as input/output port

P0 =0xFF; //set port0 as input/output port

Init_EXINT(); //intialise the interrupt 0

Init_T0(); //intialise the timer0

Init_LCD(); //intialise the LCD

Shift _flag = 0; //clear the shift_flag

Rpm_Flag =0; //clear the RPM_flag

time _count =0; //clear the time_count flag

time_flag= 0; //clear the time_flag

timecount_flag= 0; //clear the time_count flag

setrpm_flag =0; // clear the setrpm_flag

INT0_flag =0; // clear the INT0_flag

Int0_count =0; // clear the Into_count

time_count=0; //clear the time_count

Count=0; //make COUNT is zero

LCDCMD(0x01); //clear the LCD screen


LCDCMD(0x80); //select the lcd 1st line starting position

LCDstring( BLDCMOTOR ); //Display string on the LCD screen

LCDCMD(0xc0); //select the lcd 2nd line starting position

LCDstring( SPEED CONTROL ); //Display string on the LCD screen

Display(100);

LCDCMD(0x01); //clear the LCD screen

LCDCMD(0x80); //select the lcd 1st line starting position

LCDstring(*->Required_RPM); //Display string on the LCD screen

LCDCMD(0xc0); //select the lcd 2nd line starting position

LCDstring( SPEED CONTROL ); //Display string on the LCD screen

While(1)

If(shit_flag == 1)

PWM_DELAY(); //pulse width modulation function

If(timecount_flag == 1)

COUNT = COUNT+1; //increment the count

If(count == 10)

RPM=((60000)/((time_count*71)+((((256*high_count)
+low_count)*1.085))));
If(RPM>MAXRPM) //compare with maximum RPM

RPM = MaxRPM;

if(RPM>RequiredRPM) //if RPM is greater than required RPM

If((RPM-RequiredRPM)<50)

RPM=RequiredRPM;

setrpm_flag=1;

else

Shift--; //decrement pulse width

else

If((RequiredRPM-RPM)<50)

RPM=RequiredRPM;

Setrpm_flag=1;

else
{

shift++; //increment the pulse width

COUNT = 0;

LCDCMD(0Xcb); //select the 2nd line 11th position

LCDNUM(RPM); //Display the RPM

TH0=0X00;

TL0=0X00;

ReadKeypad(); //get the key from keypad

If(K_Flag)

K_Flag=0;

Delay(50);

if(Temp==*) //if key is *

MOUT=0; //switch on the motor

LCDCMD(0x01); //clear the LCD

LCDString(%ofReq_RPM=);//Display the sring on LCD

LCDMCD(0xc0); //select LCD 2nd line starting position

LCDString(Press#toSave);//Display the string on the LCD

LCDCMD(0xBE); //select LCD 1st line 15th position


i=0;

while( Temp!=#) //if key is *

ReadKeyPad(); //get the key from keypad

If(K_Flag)

K_Flag=0;

Delay(50);

if(Temp !=#)

Buff[i++]=Temp;

LCDData(Buff[i-1]);

else

Buff[i]=\0;

ReqShift=ASCII_DECIMAL(Buff); //get the required shift

LCDNUM(ReqShift);

If(ReqShift<=100) //Reduce RPm

Shift=ReqShift;

LCDCMD(0x01); //clear the LCD

LCDString(Duty Cycle:); //Display string on the LCD


LCDNUM(Shift); //Display shift on the LCD

LCDData(%); //Display string on the LCD

LCDMCD(0xC0) //Select the LCD 2nd Line

LCDString(Now=); //Display string on the LCD

RequiredRPM=((MaxRPM/100)*(ReqShift));//calculate Required
RPM

LCDNUM(RequiredRPM); //Display requiredRPM on the LCD

LCCMD(0XC9); //select lcd 2nd line 9th position

LCDString(B4=); //Display string on the LCD

LCDNUM(RPM); //Display RPM on the LCD

Delay(500);

shift_flag=1; //shift_flag set to high

setrpm_flag=0; //clear the setrpm_flag

RPM_flag=0; //clear the RPM_flag

LCDCMD(0x01); //clear thr LCD

LCDString(*->Required_RPM);//Display string on the LCD

LCDCMD(0Xc0); //select theLCD 2nd line

LCDString(MOTOR_RPM=0);//Display string on the LCD

elseif(Temp==#) //if key is #

LCDCMD(0x01); //clear the LCD

LCDString(Store Max RPM);//Dislay string the LCD


LCDCMD(0xC0); //select the LCD 2nd line

LCDString(MOTOR_RPM=0); //Display string on the LCD

MOUT=0; //switch on the motor

delay();

shift_flag=0; //clear the ALL flag

RPM_Flag=0;

time_count=0;

time_flag=0;

update_flag=1;

timecount_flag=0;

setrpm_flag=0;

INT0_Flag=0;

int0_count=0;

time_count=0;

COUNT=0;

TH0=0X00; //clear the timer high value

TL0=0X00; //clear the timer low value

EA=1; //enable all interrupts

while(1)

if(timecount_flag==1)

COUNT=COUNT+1;

if(COUNT==10)
{

RPM=((60000)/((time_count*71)+((((256*high_count)
+low_count)*1.085))));//calculate the RPM

presentRPM=RPM;

COUNT=0;

LCDCMD(0xCB);

LCDNUM(RPM); //display RPM on LCD

TH0=0X00; //clear the timer high value

TL0=0X00; //clear the timer low value

time_count=0; //clear the time_count

timecount_flag=0; //clear the timecount_flag

ReadKeyPad(); //get the key from keypad

if(K_Flag)

K_Flag=0;

Delay(50);

if(Temp==#) //if key is #

MaxRPM=Present RPM;//Get the Max RPM

LCDCMD(0x01); //clear the LCD

LCDCMD(0x80); //select the LCD 1st line

LCDString(MaxRPM=);//Display string on LCD


LCDNUM(MaxRPM);//Display the Max RPM

delay();

break;

delay(); //give some delay

delay();

delay();

LCDCMD(0x01); //clear the LCD

LCDString(->Required_RPM); //display string on LCD

LCDCMD(0xC0); //select the LCD 2nd line

LCDString(MOTOR_RPM=0); //display the string on LCD

time_count=0; //clear the time_count

time_flag=0; //clear the time_flag

update_flag=1; //set update_flag

timecount_flag=0; //clear the timecount_flag

TH0=0X00; //clear thr timer high value

TL0=0X00; //clear the timer low value

}
CHAPTER 7
HARDWARE TESTING

7.1 CONTINUITY TEST:


In electronics, a continuity test is the checking of an electric circuit to see if current
flows (that it is in fact a complete circuit). A continuity test is performed by placing a
small voltage (wired in series with an LED or noise-producing component such as a
piezoelectric speaker) across the chosen path. If electron flow is inhibited by broken
conductors, damaged components, or excessive resistance, the circuit is "open".
Devices that can be used to perform continuity tests include multi meters which
measure current and specialized continuity testers which are cheaper, more basic
devices, generally with a simple light bulb that lights up when current flows.
An important application is the continuity test of a bundle of wires so as to find the
two ends belonging to a particular one of these wires; there will be a negligible
resistance between the "right" ends, and only between the "right" ends.
This test is the performed just after the hardware soldering and configuration has been
completed. This test aims at finding any electrical open paths in the circuit after the
soldering. Many a times, the electrical continuity in the circuit is lost due to improper
soldering, wrong and rough handling of the PCB, improper usage of the soldering iron,
component failures and presence of bugs in the circuit diagram. We use a multi meter
to perform this test. We keep the multi meter in buzzer mode and connect the ground
terminal of the multi meter to the ground. We connect both the terminals across the
path that needs to be checked. If there is continuation then you will hear the beep
sound.
7.2 POWER ON TEST:
This test is performed to check whether the voltage at different terminals is according
to the requirement or not. We take a multi meter and put it in voltage mode. Remember
that this test is performed without microcontroller. Firstly, we check the output of the
transformer, whether we get the required 12 v AC voltage.
Then we apply this voltage to the power supply circuit. Note that we do this test
without microcontroller because if there is any excessive voltage, this may lead to
damaging the controller. We check for the input to the voltage regulator i.e., are we
getting an input of 12v and an output of 5v. This 5v output is given to the
microcontrollers 40th pin. Hence we check for the voltage level at 40 th pin. Similarly,
we check for the other terminals for the required voltage. In this way we can assure
that the voltage at all the terminals is as per the requirement.
CHAPTER 8
RESULTS
PWM Output for 20%

PWM Output for 50%

PWM Output for 80%


OUTPUT RESPONSE

INPUT OUTPUT OUTPUT


DUTY VOLTAGE SPEEDIN
CYCLEIN RPM

25% 3V 650
50% 6V 130
75% 9V 0
195
100% 12V 0
260
0
CHAPTER 9
CONCLUSION
The hardware for closed loop control of BLDC motor using microcontroller is designed. By using the
PWM technique speed of BLDC motor was controlled and it was made to run at exactly entered
speed. In future this hardware will be implemented in various fields due to its advantages over
conventional dc motor and the speed control will be observed. Change in the PWM switching
strategy with in the motor drive promises to eliminate the problem associated with torque ripple.
Another major trend in BLDC motor drive technology is integrating the BLDC motor and drive
electronics into a single package to simplify the system, minimize interconnection cabling, reduce
noise and solve motor-drive compatibility issues.
CHAPTER 10

BIBLIOGRAPHY

1. Kusko, A. & Peeran, S. M. (1987) Brushless DC motor using asymmetrical field


magnetization. IEEE Transactions on Industrial Applications, 23(2):319

2. Bolton, H. R. &Ashen R.A. (1984) Influence of motor design and feed current
wave form on torque ripples in brushless dc motor. IEE Proceeding, 131(3):82-90

3. Duane,H.(2002)Brushless Permanent Magnet Motor Design. University of


Maine, Orno, USA, 2nded.
4. Khader,S.H.(2001)Implementation of an accurate mathematical method for
modeling electromagnetic processes of brushless DC Motor. MESM, Amman,
Jordan, 31-38

5 Miller, T . J. E. (1993) Switched Reluctance Motors and their Control, Oxford, UK,
Magna Phys. Publication andClarendon, 40-90

6. Faiz,J.&Finch,J.W.(1993)Aspects of design optimization for switched


reluctanc emotors, IEEE transactions on Energy
7. Torrey,D.A.,Niu,X.M.& Unkauf,E.J. (1995) Analytical modelling of
variable reluctance machine magnetization characteristics. IEEE Proceedings,
142(1):14-22
8. R.Krishnan,ElectricMotor Drives Modeling, Analysis, and Control,
PrenticeHall InternationaInc.,New Jersey,2001
9. New Approach to Rotor Position Detection and Precision Speed Control of
the BLDC Motor Yong-HoYoonTae- Won Lee Sang-Hun ParkByoung-Kuk
Lee Chung- 1-4244-0136-4/06/$20.00'2006IEEE

You might also like