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.
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
PORT2: PORT2 may be used as an input/output port. It may also be used to supply a highorder 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.
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.
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.
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.
10
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:
11
BLOCK DIAGRAM:
CRYSTAL OSCILLATOR:
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.
12
Fig 3.2.1. Diagram Of Note On Board Design 3.2.2 SYSTEM CLOCK DIVIDER: 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.
13
CHAPTER 4 DC MOTOR
In any electric motor, operation is based on simple electromagnetism. A currentcarrying 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 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
14
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.
In real life, though, DC motors will always have more than two poles (three is a very common number). In particular, this avoids "dead spots" in the commutator. You can imagine how with our example two-pole motor, if the rotor is exactly at the middle of its rotation (perfectly aligned with the field magnets), it will get "stuck" there. Meanwhile, with a two-pole motor, there is a moment where the commutator shorts out the power supply (i.e., both brushes touch both commutator contacts simultaneously). This would be
15
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).
16
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.
17
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
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
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
Pins 1 2 3 4 5 6 7 14
Description Ground VCC Contrast Voltage "R/S" _Instruction/Register Select "R/W" _Read/Write LCD Registers "E" Clock Data I/O Pins Table 6.2 LCD Pin Description
21
TYPE OF COLORS:
1. RED 2. GREEN 3. YELLOW
22
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
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
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
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, stepdown 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 turns ratio, determines the ratio of the voltages. A step-down transformer has a large number of turns on its primary
26
(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.
27
withstand the peak voltages). Please see the Diodes page for more details, including pictures of bridge rectifiers.
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
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.
29
30
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; TH0 = 0x3C; TL0 = 0xB0; IE = 0x83; IP=0X04; // Enable interrupt // Mode1 of Timer0 // Initial values loaded to Timer
IT0=1;
");
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
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
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 ");
} void MSDelay (unsigned int value) { unsigned int x,y; for (x=0;x<value;x++) for (y=0;y<200;y++); }
35
ADVANTAGES:
APLLICATONS:
36
CHAPTER 11 CONCLUSION
37
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 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 Mazidi
38
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.
39
40