51
CHAPTER 1 INTRODUCTION 1.1 OBJECTIVE: The aim of this project is to design an dc motor speed and direction by using the pwm and H-bridge which are built with micro controller, IR sensors ,and an Infra red LED. 1.2 HARDWARE COMPONENTS: Microcontroller (AT89S52) Power supply IR sensors (Transmitter & Receiver) Opt coupler MOC 3021 Buffer IC 4050 TRIAC BTA 12 600 AC Motor (230 v) 1.3 SOFTWARE TOOLS: KEIL µvision Embedded-C 1

3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

Embed Size (px)

DESCRIPTION

mini project doc

Citation preview

Page 1: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

CHAPTER 1

INTRODUCTION

1.1 OBJECTIVE:

The aim of this project is to design an dc motor speed and direction by using the

pwm and H-bridge which are built with micro controller, IR sensors ,and an Infra red

LED.

1.2 HARDWARE COMPONENTS:

Microcontroller (AT89S52)

Power supply

IR sensors (Transmitter & Receiver)

Opt coupler MOC 3021

Buffer IC 4050

TRIAC BTA 12 600

AC Motor (230 v)

1.3 SOFTWARE TOOLS:

KEIL µvision

Embedded-C

1

Page 2: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

1.4 BLOCK DIAGRAM:

2

Page 3: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

CHAPTER 2

MICRO CONTROLLER

2.1 GENERAL DESCRIPTION:

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 amount of

memory and the number of timers.

In the concerned project 8052 microcontroller is used. Here microcontroller used

is AT89S52, which is manufactured by ATMEL laboratories.

2.2 INTRODUCTION TO AT89S52:

AT89S52 has 8KB Flash and 256 bytes of data RAM32 I/O lines, three 16-bit

timer/counters, an Eight-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 hardware reset. The Flash

program memory supports both parallel programming and in Serial In-system

Programming (ISP). The 89S52 is also In-Application Programmable (IAP), allowing the

Flash program memory to be reconfigured even while the application is running.

By combining a versatile 8-bit CPU with Flash on a monolithic chip. The ATMEL

AT89S52 is a powerful microcomputer which provides a highly flexible and cost

effective solution to many embedded control applications.

3

Page 4: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

2.2.1 FEATURES:

Compatible with MCS-51 Products

8K bytes of In-System Programmable(ISP) Flash Memory

Endurance: 1000 Write/Erase cycles.

4V 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

4

Page 5: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

2.2.2 PIN DIAGRAM:

Fig 2.2.2 Pin Diagram Of AT89S52 IC

5

Page 6: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

2.3 PIN DESCRIPTIONS:

VCC: Supply voltage

GND: Ground

PORT0:

PORT0 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 PORT0 pins, the pins can be used as high-

impedance inputs. PORT0 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. PORT0 also receives the code bytes during Flash programming and

outputs the code bytes during program verification. External pull-ups are required during

program verification.

When used for interfacing with the external memory, the lower byte of address is first

sent via PORT0, latched using address latch enable (ALE) pulse and then the bus is

turned around to become the data bus for external memory.

PORT1:

PORT1 is exclusively used for input/output operations. PORT1 pin have no dual function.

When a pin is to be configured as input. 1 is to be written into the corresponding PORT1

latch. PORT1 also receives the low-order address bytes during Flash programming and

verification.

Table 2.30 Port Pin Details

6

Page 7: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

PORT2:

PORT2 may be used as an input/output port. It may also be used to supply a high-

order address byte in conjunction with PORT0 low-order byte to address external

memory. PORT2 pins are momentarily changed by the address control signals when

supplying the high byte a 16-bit address. PORT2 latches remain stable when external

memory is addressed, as they do not have to be turned around (set to 1) for data input as

in the case for PORT0. PORT2 also receives the high-order address bits and some control

signals during Flash programming and verification.

PORT3:

PORT3 may be used to input/output port. The input and output functions can be

programmed under the control of the P3 latches or under the control of various special

function registers. Unlike PORT0 and PORT2, which can have external addressing

functions and change all eight-port b se, each pin of PORT3 may be individually

programmed to be used as I/O or as one of the alternate functions.

Table 2.31 Port 3 Pin Details

RST:

The reset pin. A high on this pin for two machine cycles while the oscillator is

running resets the device.

7

Page 8: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

ALE:

Address latch enable is an output pulse for latching the low byte of address during

access to external memory this pin is also the program pulse input (PROG) during Flash

programming.

2.3.1 ARCHITECTURE OF MICRO CONTROLLER:

Fig 2.3.1 Architecture of micro controller

8

Page 9: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

2.3.2 FUNCTIONAL BLOCK DIAGRAM OF MICROCONTROLLER

Fig 2.3.2 Functional Block Diagram of micro controller

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 memory.

9

Page 10: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

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.

2.4 MEMORIES&INTERRUPTS

2.4.1 SPECIAL FUNCTION REGISTERS:

A map of the on-chip memory area called the Special Function Register (SFR) space is

shown in Table. Note that not all of the addresses are occupied, and unoccupied addresses

may not be implemented on the chip. Read accesses to these addresses will in general

return random data, and write accesses will have an indeterminate effect. User software

should not write 1s to these unlisted locations, since they may be used in future products

to invoke new features. In that case, the reset or inactive values of the new bits will

always be 0.

TIMER 2 REGISTERS:

Control and status bits are contained in registers T2CON (shown in Table) and T2MOD

(shown in Table) for TIMER2. The register pair (RCAP2H, RCAP2L) is the

Capture/Reload registers for TIMER2 in 16-bit capture mode or 16-bit auto-reload mode.

10

Page 11: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

2.4.2 INTERRUPT REGISTERS:

The individual interrupt enable bits are in the IE register. Two priorities can be set

for each of the six interrupt sources in the IP register.

T2CON – TIMER/COUNTER 2 CONTROL REGISTER:

Table 2.4.20 T2con Details

T2MOD – TIMER 2 MODE CONTROL REGISTER:

11

Page 12: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

Table 2.4.21 T2mod Details

CHAPTER 3

CRYSTAL OSCILLATOR

3.1 OVERVIEW:

The H8/532 chip has a built-in clock pulse generator (CPG) consisting of an oscillator

circuit, a system (ø) clock divider, an E clock divider, and a group of presales. The

presales generate clock signals for the on-chip supporting modules.

BLOCK DIAGRAM:

Fig 3.1: Block Diagram Of Clock Pulse Generator

CRYSTAL OSCILLATOR:

12

Page 13: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

If an external crystal is connected across the EXTAL and XTAL pins, the on-chip

oscillator circuit generates a clock signal for the system clock divider. Alternatively, an

external clock signal can be applied to the EXTAL pin.

The external crystal should have the characteristics listed in table.

3.2 EXTERNAL CRYSTAL PARAMETERS:

Table 3.2 External Crystal Parameters

Fig 3.2: Crystal Oscillator Equivalent Circuit

3.2.1 NOTE ON BOARD DESIGN:

When an external crystal is connected, other signal lines should be kept away

from the crystal circuit to prevent induction from interfering with correct oscillation.

When the board is designed, the crystal and its load capacitors should be placed as close

as possible to the XTAL and EXTAL pins.

Fig 3.2.1. Diagram Of Note On Board Design

3.2.2 SYSTEM CLOCK DIVIDER:

13

Page 14: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

The system clock divider divides the crystal oscillator or external clock frequency by 2 to

create the ø clock. An E clock signal is created by dividing the ø clock by 8. The E clock

is used for interfacing to E clock based devices.

Fig

3.2.2 Phase Relationship Of Ø Clock And E Clock

CHAPTER 4

DC MOTOR

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).

Fig 4.1 DC Motor

14

Page 15: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

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) rotate 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, driving it to continue rotating.

Fig 4.2 Working of DC Motor

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

15

Page 16: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

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 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).

CHAPTER 5

PULSE WIDTH MODULATION

5.1 DC Motor Bidirectional Speed Control Using PWM:

This mini-project explains the use of PIC16F877A internal PWM module to control the

speed of a DC motor, it also describes the use of H-Bridge circuit to control the direction

of rotation.

The Concept of Pulse-Width-Modulation (PWM) :

a square wave signal is described by three parameters, amplitude, frequency and duty

cycle (AKA pulse width).

The term "duty cycle" describes the ratio of the ON state of the signal to the period of that

signal,

i.e. Duty=TON/T=TON/(TON+TOFF)

Duty cycle has no unit, its represented by percentage with 100% describing the fully ON

state and 0% describing the fully OFF state.

16

Page 17: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

PWM concerns about the duty cycle of a square wave signal, it's the technique in which

we change the pulse width to get the desired duty cycle.

5.2 Speed Control Using PWM:

The idea of speed control is to switch the motor ON and OFF at varying speeds, let

us say we have a 12V DC motor and we applied a constant 12V signal to that motor, the

motor would run in its full power (full speed).

Now assume we apply a 50% duty cycle signal to the motor (at several KHz frequency),

the motor will turn ON and OFF continuously and the effective voltage applied to the

motor is 6V, this would decrease the  motor speed by the half, and the motor would be

running at 50% of it's full power.

Varying the duty cycle of the applied signal would cause the speed to vary, a 0%

duty cycle signal would turn OFF the motor, and a 100% one would run the motor at it's

full speed.

5.3 The PIC16F877A PWM Module:

16F877a includes two PWM modules included in the CCP1,CCP2 modules (CCP

stands for Capture-Compare-PWM), and there are 3 steps for using those modules:

Set the desired CCP module to PWM mode.

17

Page 18: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

Setup the TIMER2 module, which controls the frequency and the base of your PWM

signal.

Set your duty cycle; rely on the equations below to select it properly.

We'll be using CCS PIC-C compiler to explain those steps, if you have a question on

using other compilers to set it, post a comment.

To set The CCP1 module to PWM mode, we'll use the code line:

setup_ccp1(CCP_PWM);

 and the first step is done.

Now setting up Timer2 module using PIC-C is a bit easy, use the code line:

setup_timer_2(divider,preload,postscalar).

the divider and the preload values determines the frequency of the PWM signal by the

following function:

Signal Frequency = (Crystal/4) / (divider * (preload+1))

The divider takes the values : T2_DIV_BY_1, T2_DIV_BY_4, T2_DIV_BY_16.

the preload is 8Bits and takes the values 0-255

So let us say we have 4MHz crystal and we set Timer2 like this:

setup_timer_2( T2_DIV_BY_1, 255, 1);

thus, our signal frequency is (4MHz/1)/(4 * 256) =  3.9KHz

Now the final step is to set your duty cycle using the function: set_pwm1_duty(duty

parameter);

to get the duty parameter of your desired duty cycle, note the following:

the maximum value of duty_paramter (MAX) = ((preload+1)*4) -1

so in our case the maximum value is ((255+1)*4)-1 = 1023 and it represents a 100% duty

cycle.

now if we need a duty cycle of 50% it would be 1023*0.5 = 512, and a duty cycle of 25%

would be 1023*0.25 = 256, thus,

set_pwm1_duty(1023L); ---> 100% duty (Full Speed)

set_pwm1_duty(512L);  ----> 50% duty

set_pwm1_duty(256L);  ----> 25% duty

set_pwm1_duty(0);        ----> 0% duty (OFF)

18

Page 19: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

CHAPTER 6

H- BRIDGE & LCD

6.1 The H-Bridge and the Direction of Rotation: L298 is a dual H-Bridge transistor circuitry used to isolate and control DC Motors,

Micrcontrollers has current limitations so it can't drive a high power element such as a

motor, the H-Bridge solves the problem by providing a different power supply for driving

the motors.

For a single motor connected to OUT1,OUT2 respectively, the inputs IN1,IN2 controls

the direction of rotation, setting IN1=1 IN2=0 would rotate the motor clockwise, while

setting IN1=0 IN2=1 would rotate it counter clockwise, and the setting IN1=0 IN2=0

would turn it OFF.

The pin ENA (Enable motor A) is used turn ON/OFF the motor regardless of the inputs

IN1 IN2, thus, our PWM signal could be connected to ENA to control the speed of the

motor.

19

Page 20: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

The Schematic Design:

Fig 6.1 Schematic Design

6.2 LCD

Fig 6.20 LCD Diagram

LCDs can add a lot to your application in terms of providing a useful interface for the

user, debugging an application or just giving it a "professional" look. The most common

type of LCD controller is the Hitachi 44780, which provides a relatively simple interface

between a processor and an LCD. Inexperienced designers do often not attempt using this

interface and programmers because it is difficult to find good documentation on the

interface, initializing the interface can be a problem and the displays themselves are

expensive.

20

Page 21: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

Pins Description

1 Ground

2 VCC

3 Contrast Voltage

4 "R/S" _Instruction/Register Select

5 "R/W" _Read/Write LCD Registers

6 "E" Clock

7 – 14 Data I/O Pins

Table 6.2 LCD Pin Description

Fig 6.21 Block Diagram Of LCD

6.3 LIGHT EMITTING DIODE:

A light-emitting diode (LED) is a semiconductor device that emits incoherent narrow-

spectrum light when electrically biased in the forward direction of the p-n junction. This

effect is a form of electroluminescence.

21

Page 22: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

An LED is usually a small area source, often with extra optics added to the chip to shape

its radiation pattern (10). The colour of the emitted light depends on the composition and

condition of the semiconducting material used, and can be infrared, visible, or near-

ultraviolet.

Fig 6.3: LED Diagram

TYPE OF COLORS:

1. RED

2. GREEN

3. YELLOW

22

Page 23: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

Fig 6.4: Block Diagram Of LED

ADVANTAGES:

Low working voltages and currents

Less power consumption

Very fast action

Small size and weight

Extremely long life

APPLICATIONS:

Textile industries

A/C halls

In school to set time for pumps and bell systems

23

Page 24: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

CHAPTER 7

IR SENSORS

7.1 INTRODUCTION:

A sensor is a device that measures a physical quantity and converts it into a

signal which can be read by an observer or by an instrument. For example, a mercury in

glass thermometer converts the measured temperature into expansion and contraction of a

liquid which can be read on a calibrated glass tube. A thermocoupler converts

temperature to an output voltage which can be read by a voltmeter. For accuracy, most

sensors are calibrated against known standards.

Sensors are used in everyday objects such as touch-sensitive elevator buttons

and lamps which dim or brighten by touching the base. There are also innumerable

applications for sensors of which most people are never aware. Applications include cars,

machines, aerospace, medicine, manufacturing and robotics.

A sensor is a device which receives and responds to a signal. A sensor's

sensitivity indicates how much the sensor's output changes when the measured quantity

changes. For instance, if the mercury in a thermometer moves 1 cm when the temperature

changes by 1 °C, the sensitivity is 1 cm/°C (it is basically the slope Dy/Dx assuming a

linear characteristic). Sensors that measure very small changes must have very high

sensitivities. Sensors also have an impact on what they measure; for instance, a room

temperature thermometer inserted into a hot cup of liquid cools the liquid while the liquid

heats the thermometer. Sensors need to be designed to have a small effect on what is

measured, making the sensor smaller often improves this and may introduce other

advantages. Technological progress allows more and more sensors to be manufactured on

a microscopic scale as microsensors using MEMS technology. In most cases, a

microsensor reaches a significantly higher speed and sensitivity compared with

macroscopic approaches.

7.2 IR SENSORS:

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 LED s are usually made

of gallium arsenide or aluminium gallium arsenide. They, along with IR receivers, are

commonly used as sensors.

24

Page 25: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

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

cellphone can be used. The camera can show us the IR rays being emanated from the IR

LED in a circuit.

Fig-7.1 Fig-7.2

25

Page 26: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

CHAPTER 8

POWER SUPPLY

8.1 INTRODUCTION:

Power supply is a supply of electrical power. A device or system that supplies

electrical or other types of energy to an output load or group of loads is called a power

supply unit or PSU. The term is most commonly applied to electrical energy supplies, less

often to mechanical ones, and rarely to others.

There are many types of power supply. Most are designed to convert high voltage AC

mains electricity to a suitable low voltage supply for electronic circuits and other devices.

FIG. 8.1 Block Diagram of Regulated power supply

8.2 TRANSFORMER:

Transformer is a device which can efficiently transform the electric energy. Major

use of transformer is in power distribution. Which is used in electrical devices, control

systems, communication system devices etc. Step-up transformers increase voltage, step-

down transformers reduce voltage. Most power supplies use a step-down transformer to

reduce the dangerously high mains voltage (230V) to a safer low voltage.

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 current is stepped up.

The ratio of the number of turns on each coil, called the turn’s ratio, determines the ratio

of the voltages. A step-down transformer has a large number of turns on its primary

26

Page 27: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

(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.

Fig 8.2 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.

8.3 RECTIFIER:

There are several ways of connecting diodes to make a rectifier to convert AC to DC. The

bridge rectifier is the most important and it produces full-wave varying DC. A full-wave

rectifier can also be made from just two diodes if a centre-tap transformer is used, but this

method is rarely used now that diodes are cheaper. A single diode can be used as a

rectifier but it only uses the positive (+) parts of the AC wave to produce half-wave

varying DC.

8.3.1 BRIDGE RECTIFIER:

A bridge rectifier can be made using four individual diodes, but it is also available in

special packages containing the four diodes required. It is called a full-wave rectifier

because it uses the entire AC wave (both positive and negative sections). 1.4V is used up

in the bridge rectifier because each diode uses 0.7V when conducting and there are

always two diodes conducting, as shown in the diagram below. Bridge rectifiers are rated

by the maximum current they can pass and the maximum reverse voltage they can

withstand (this must be at least three times the supply RMS voltage so the rectifier can

27

Page 28: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

withstand the peak voltages). Please see the Diodes page for more details, including

pictures of bridge rectifiers.

Fig 8.3.1 Bridge Rectifier

8.3.2 SMOOTHING:

Smoothing is performed by a large value electrolytic capacitor connected across the DC

supply to act as a reservoir, supplying current to the output when the varying DC voltage

from the rectifier is falling. The diagram shows the unsmoothed varying DC dotted line)

and the smoothed DC (solid line). The capacitor charges quickly near the peak of the

varying DC, and then discharges as it supplies current to the output. Smoothing is not

perfect due to the capacitor voltage falling a little as it discharges, giving a small ripple

voltage. For many circuits a ripple which is 10% of the supply (voltage is satisfactory and

the equation below gives the required value for the smoothing capacitor. A larger

capacitor will give fewer ripples. The capacitor value must be doubled when smoothing

half-wave DC.

The smoothing block smoothes the DC from varying greatly to a small ripple and 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.

28

Page 29: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

Fig 8.3.2

From figure, we can observe that when waveform is rising it is getting charged and when

it is decaying it will discharge.

8.4 REGULATOR:

Voltage regulator ICs are available with fixed (typically 5, 12 and 15V) or variable output

voltages. They are also rated by the maximum current they can pass. Negative voltage

regulators are available, mainly for use in dual supplies. Most regulators include some

automatic protection from excessive current ('overload protection') and overheating

('thermal protection'). Many of the fixed voltage regulators ICs have 3 leads and look like

power transistors, such as the 7805 +5V, 1A regulator as shown.

Fig 8.4 Three Terminal Of Regulator

29

Page 30: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

CHAPTER 9

SOURCE CODE

#include <reg51.h>

#include <lcd_16x2.h>

sbit clk =P2^3;

sbit aclk =P2^4;

sbit inc =P2^5;

sbit dec =P2^6;

sbit stop =P2^7;

void MSDelay(unsigned int value);

unsigned int s,r,mill_count,sec=0,keyset=0;

unsigned int i,j,open=1,close=1,,i2=0,x;

signed char rpm=0;

unsigned int count=0,set=0,left=0,right=0;

void ext() interrupt 0

{

count++;

}

void Timer(void) interrupt 1 // Interrupt No.1 for Timer 0

{

mill_count++;

if(mill_count>14)

{

sec++;

mill_count=0;

30

Page 31: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

if(sec>=3)

{

lcd_clear();

TR0 = 0;

sec=0;

set=1;

}

}

}

void main(void)

{

P3=4;

P0=0;

P1=0x00;

P2=0;

count=0;

TMOD = 0x01; // Mode1 of Timer0

TH0 = 0x3C; // Initial values loaded to Timer

TL0 = 0xB0;

IE = 0x83; // Enable interrupt

IP=0X04;

IT0=1;

lcd_init();

lcd_loc(0X80);

lcd_string("J.Venkanna ");

lcd_loc(0XC0);

31

Page 32: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

lcd_string("D.Vishnu ");

MSDelay (1250);

lcd_loc(0X80);

lcd_string("G.Srinivasulu");

lcd_loc(0XC0);

lcd_string("B.Venkateswarlu");

MSDelay (1250);

lcd_loc(0X80);

lcd_string("**S.R.T.I.S.T.**");

lcd_loc(0XC0);

lcd_string(" NALGONDA ");

MSDelay (1250);

lcd_clear();

lcd_loc(0X80);

lcd_string("Dir= ");

lcd_loc(0X85);

lcd_string("Not set");

lcd_loc(0Xc0);

lcd_string("RPM=");

lcd_result(countl);

while(1)

{

if(stop==1)

{

P1=0;

right=0;

left=0;

32

Page 33: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

TR0 = 0;

lcd_loc(0X85);

lcd_string("Stopped");

}

if(set==1)

{

countl=count*20;

count=0;

lcd_loc(0Xc0);

lcd_string("RPM=");

lcd_result(countl);

TR0 = 1;

set=0;

}

lcd_loc(0X80);

lcd_string("Dir= ");

lcd_loc(0Xc9);

lcd_string("PWM=");

lcd_result(rpm);

while(clk==1)

{

right=0;

left=1;

TR0 = 1;

}

while(aclk==1)

{

left=0;

right=1;

33

Page 34: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

TR0 = 1;

}

if(left==1)

{

P1=0x01;

MSDelay(rpm);

P1=0x00;

lcd_loc(0X85);

lcd_string("Clock ");

}

if(right==1)

{

P1=0x02;

MSDelay(rpm);

P1=0x00;

lcd_loc(0X85);

lcd_string("Anticlock");

}

if(inc==1)

{

rpm++;

if(rpm>99)

rpm=100;

}

if(dec==1)

{

rpm--;

if(rpm<0)

rpm=0;

}

}

34

Page 35: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

}

void MSDelay (unsigned int value)

{

unsigned int x,y;

for (x=0;x<value;x++)

for (y=0;y<200;y++);

}

35

Page 36: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

CHAPTER 10

RESULT AND APPLICATIONS

RESULT:

ADVANTAGES:

APLLICATONS:

36

Page 37: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

CHAPTER 11

CONCLUSION

37

Page 38: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

BIBILOGRAPHY

WWW.MITEL.DATABOOK.COM

WWW.ATMEL.DATABOOK.COM

WWW.FRANKLIN.COM

WWW.KEIL.COM

REFERENCES

"The 8051 Microcontroller Architecture, Programming & Applications" by

Kenneth J Ayala.

"The 8051 Microcontroller & Embedded Systems” by Mohammed Ali Mazidi

and Janice Gillespie Mazidi

"Power Electronics” by M D Singh and K B Khanchandan

"Linear Integrated Circuits” by D Roy Choudary & Shail Jain

"Electrical Machines” by S K Bhattacharya

"Electrical Machines II” by B L Thereja

www.8051freeprojectsinfo.com

38

Page 39: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

APPENDIX

THEORY OF MICROCONTROLLER:

A microcontroller contains a CPU, clock circuitary, ROM, RAM and input

output circuitary on a single integrated circuit package. The microcontroller is therefore, a

self-contained device, which doesnot require a host of associated support chips for its

operation as conventional microprocessors do. The advantages include cheaper

maintainance, decreased hardware design effort and increased board density, which is

relevant in portable control equipment. The microcontroller that we use in AT89S52.

MEMORY ORGANIZATION OF MICROCONTROLLER:

The total memory of 89S52 system is logically divided in program

memory & data memory. Program memory stores the data like intermediate results,

variables and constants required for the execution of the program. Program memory is

invariable implemented using EPROM, because it stores only program code which is to

be executed and thus it neednot be written into. However the data memory may be read

from or written to and thus it is implemented using RAM. Further, the program memory

& data memory both may be categorized as on-chip(internal) & external memory

depending upon whether the memory physically exists on the chip or it is externally

interfaced. The 89A52 an address 8kbytes of external program memory under the control

of PSEN(low) signal.

The AT89S52 implements 256 bytes of on-chip RAM. The upper 128

bytes occupy a parallel address space to the special function registers. That means the

uppper 128 bytes have the same address as the SFR space but are physically separate

from SFR space. When the CPU accesses the upper 128 bytes of RAM or the SFR space.

Instructions that use direct addressing access SFR space.

39

Page 40: 3. Documdesign an dc motor speed and direction by using the pwm and H-bridge entation

PICTORIAL REPRESENTATION OF THE KIT

40