Vous êtes sur la page 1sur 102

0

Abstract

The rise of virtual reality and augmented reality provides brand new way of
interaction with digital information. However, virtual reality immerses the users in
simulated world with scarce connection with the real one. Augmented reality
merely overlays virtual objects over real ones with no specific concern about the
interaction in between. By understanding the environment, mixed reality is capable
of blending the virtual objects with the real world. This project proposes a mixed
reality system with multiplayer engagement based on Microsoft HoloLens and
Google Tango tablet. Several innovative applications for creation works, such as
painting in 3-dimensional space and 3D reconstruction, are introduced to
appreciate the interaction and collaboration with the concept of mixed reality. In
terms of technical objectives, the main focus will be put on the implementation of
spatial mapping, Gaze-Gesture-Voice (GGV) input. Up to this point, all the mixed
reality applications on both HoloLens and Tango have been implemented and
tested. The cross-platform multiplayer is also finished and the whole system is now
ready for demonstration.

INTRODUCTION

Since the year of 2013, a collection of virtual reality (VR) headsets including
Oculus Rift and HTC Vive have been introduced to the public. The common point
of VR headsets is that they display the software-generated images to replicate a
virtual world setting. Although such synthetic environments may possess the
properties of the real ones, there can also be no connection between the physical
and virtual world. For example, the basic physical laws may no longer hold.

1
On the other hand, the concept of augmented reality (AR) introduces a real-time
view of the physical world with supplemented elements generated by the computer.
For instance, the mobile game Pokémon GO by Nintendo enable players to catch
pocket monsters that do not really exist. Nevertheless, most implementations of
augmented reality simply overlay the images and information on the physical
world. This makes it more stiff and less interactive if a virtual object and a real one
overlap unnaturally.

2
Mixed reality (MR) shares the same characteristic with augmented reality. Both the
virtual and physical objects are combined. However, in mixed reality, the spatial
mapping of the real environment is perceptible by the computer. Then the objects,
including the real and virtual ones, can have interactions at a level of visual
verisimilitude (see Figure 1). Thus there is enhanced illusion of having both
aspects in the same reality.

Figure 1. Virtual objects are displayed as if they are


placed on table or projected on wall with the correct
perspective in real world. This makes the combination of
two environments true to life. (image source: Microsoft)

Thanks to the introduction of HoloLens by Microsoft in 2015, developers can


implement more immersive and interactive mixed reality applications. Applications
targeted for this device such as HoloBlocks and HoloAnatomy can now be
downloaded from Windows Store. However, most of them exhibit limited
3
functionalities and no multiplayer support. For example, HoloBlocks has the sole
functionality of generating and placing objects (i.e. cubes and spheres) on detected
surfaces. In this project, a mixed reality system with multiplayer engagement will
be built with HoloLens and other hardwares. Several innovative scenarios
including interior design and 3D painting will be implemented to demonstrate a
more natural way to create and collaborate.

2. Objective
The objective of the project is to build a workable demo of mixed reality. The
demo should have the capability of observing the spatial mapping. In other words,
this system is able to recognizing the surface of ceiling, walls, table and floor. In
addition, the demo is planned to take the GazeGesture-Voice (GGV) input as
controlling methods. Multiple users can interact with both the physical and virtual
environment and also collaborate with each other. The scenarios for creation works
as well as their main technical focus include but not limited to:

• Setting up an art gallery — spatial mapping

• Designing the interior setting (painting viewer) — spatial mapping; GGV


(particularly gaze input); spatial sound
• Drawing in three-dimensional space — GGV (particularly manipulation
gesture)

• 3D reconstruction (object scanning) — surface observer; computer


vision

• Viewing and interacting with objects — GGV (particularly navigation


gesture)

4
• Complementary application (focus point stabilizer) — GGV (particularly
gaze input)

• Cross-platform multiplayer synchronization — coordinate calibration

All the works above are projected at the same place of the physical world.
Therefore users may have better experience in collaboration. With the HoloLens,
anyone can easily participate in this process and realize his or her own design in a
more natural and interactive way than the approach of augmented reality. In the
meantime, the work done is shared among all the other users in realtime.

3. System Details
In this section, the infrastructure of the whole mixed reality system will be
introduced. Reasons will be provided for the choices of hardware and software
platforms. In the second subsection, the scope of the project will follow. The 5-
stage approach for building the system will be explained as the last part of this
section.

Infrastructure
The hardware for the mixed reality system includes two kinds of devices,
Microsoft HoloLens and Google Tango tablets. HoloLens is a head-mounted
display (see Figure 2a) equipped with an inertial measurement unit (IMU), four
environment understanding sensors and a depth camera. It can map the
5
surroundings in a short time with relatively high precision. This provides users
with the most interactive demonstration of the mixed reality and thus makes
HoloLens our first choice.

Figure 2a. Microsoft HoloLens is a headset with Figure 2b. Google Tango tablet
is an Android various sensors and depth cameras for perception based device with
depth sensor. It provides spatial of the surroundings at a relatively high precision.
mapping without extra setups at a more affordable
(image source: Microsoft) price. (image source: Google)
However, the number of HoloLens is limited due to the high price (US$3000).
Since we want more users to get involved, the more affordable Google Tango
tablets (US$512) are used as supplementary devices. They are Android based
devices with a touchscreen, cameras for motion tracking and depth sensing (see
Figure 2b). No extra setup is necessary for new users to participate in the
collaboration. However, the other smart devices such as tablets and mobile phones
with ordinary touchscreen and cameras are ruled out as complex calibration is
necessary before they can be used. All the devices within the mixed reality system
are connected via LAN/WiFi so that the status of the demo can be shared.

The scenarios and features will be implemented with the Unity 3D game
development platform. This is a generally free-to-use software kit for developing

6
games and demos. It has a well written documentation and an active supporting
community. In addition, Unity supports multiple platforms so that little works are
needed to build applications for different devices. Moreover, Photon Unity 3D
Networking Framework SDK is used for realization of multiplayer support. These
are the general practices in individual gaming development and thus we will adopt
them over other choices.

Scope
One of aims of this project is to demonstrate the advantages of mixed reality over
augmented reality and virtual reality in terms of interactiveness in creative works.
Therefore, more attention are paid to the innovation of various demos within the
system. In other words, the system is supposed to include a collection of innovative
scenarios such as painting in three-dimensional space featuring mixed reality,
namely spatial mapping and GGV input. The complexity of a particular
functionality is not within scope. As an example, the implementation of 3D
drawing should not focus on the diversity of pen tools. Although the details will be
refined, this will never be comparable to professional software for digital painting.
The accuracy and level of details of 3D reconstruction will be subject to the actual
performance of the devices. In building this system, an uninterrupted user
experience is preferred over finer details with less consistent performance.

Approach
Figure 3 shows the main flow for building the mixed reality system. Basically five
steps are involved in the procedure.

Review on Prototyping Multiplayer Refinement Testing and


platforms scenarios Support of details modifications

7
Figure 3. The 5-step approach of building the mixed reality system.
I. Review on hardwares and softwares to be used within this project.

For the first stage, research works has been done on the developing platforms
including hardwares and softwares. As most of them are still under beta testing
and not finalized yet, there may be unforeseen bugs and disfunction.
Furthermore, the limitation of the hardware have been found so that
unrealizable functionalities can be eliminated from the project scope at the
early stage.

II. Implementation of prototypes for the mixed reality system.

Prototypes of scenarios will be implemented within this stage. Possible ones


include building of a scaled virtual city, designing of interior setting,
interacting with virtual models placed in physical world, painting using
gestures in three-dimensional space and 3D reconstruction using stereo vision.
More scenarios may be added to the system as long as they demonstrate the
innovative usage of mixed reality.

III. Integration of multiplayer support.

Works will be done on support for multiplayer engagement. We will try to


share the spatial mapping and the coordinates among different devices. The
origin of world coordinate is supposed to be calibrated using Vuforia
Augmented Reality SDK and cross-platform synchronization is to be archived
utilizing Photon Unity Networking framework. In this way, multiple users can
see others’ works at the same location of the physical environment so that they
can collaborate in a natural manner.

8
IV. Refinement of functionalities.

The details of each scenario built in previous stages is to be refined. Possible


refinement includes enhancing stability of user input. For example, the
precision of hand tracking can be improved. Rendering performance can be
improved by optimizing the number of triangles used for representing the
spatial mapping. Complementary applications for graphics stabilization is to be
implemented to archive consistent visual experience.

V. Testing and modification.

The system as a whole will be setup in an indoor environment for robustness


testing. Further modifications will be carried out to improve the performance
under unexpected situations. For example, simplification of spatial mapping
may be applied if the environment is more complicated than what the hardware
can handle.

The mixed reality system proposed in the project is supposed to be a experimental


and developmental implementation of mixed reality. As stated in previous section,
the objective is to build a system to demonstrate the possible application of mixed
reality. We will regard a working demonstration in a simplified space as the
baseline for this project. The space setup will be limited to 3-meter by 3-meter with
no complicated structure, subject to further changes. Each scenario of a workable
demo should have appropriate integration of spatial mapping and GGV input
respectively. Graphic performance will also be considered as part of the pass-fail
criteria. Lags in rendering virtual objects will have negative effect on user
experience. A system with unfavorable performance should not be qualified for
successful implementation. From the users’ prospective, positive feedback in terms

9
of interaction and collaboration will be regarded as the indication of pass for the
project.

4. Project Status
Results — HoloLens Platform

At this time, I have finished all the prototypes of scenarios as stated in previous
sections as well as the complementary parts for the mixed reality system. The
applications are implemented based on the review of the developing platforms
including hardwares and softwares. I have take into consideration of the
recommendations on hologram stabilization and performance by Microsoft in the
course of application design. Furthermore, a number of preliminary testings based
on these prototypes were done to help make clear of the hardware capability.
Certain refinements and adjustments have been carried out to make the system
work with satisfying performance.

I. Setup of art gallery


There are six main scenarios of the HoloLens part of the mixed reality system. The
first one is setup of the art gallery with spatial mapping. The raw information of
spatial mapping is stored as meshes and is to be used in the following applications.
Surface meshes are categorized into major groups such as walls, floors and
ceilings. Equipped with a depth camera, Microsoft HoloLens is capable of
perceiving the geometry of the surroundings within about 3.1 meters. With the
mesh caching strategy, the device can store, update and discard the information of
spatial surfaces for a whole room. There was no significant decline in performance
of mapping surroundings when around 2500 square foot area and over 500,000
triangles were cached. This suggests that if the dimensional scale of the system is
restricted to indoor level, the application should have no pitfall for performance.
10
Nevertheless, because of limitation on the density of mesh triangles, only the
simple surface like tables, walls and shelves were detected. The device showed no
capability of processing complicated surfaces such as creased fabric. It is unlikely
that we should consider such condition for building the system.

II. Interior design


The second scenario is designing the interior setting, namely the painting viewer
(see Figure 4). The prototype utilizing the spatial mapping and gaze-gesture-voice
input was implemented. The user is able to choose from the loaded paintings and
posters and stick to a suitable surface. In addition, the description using spatial
sound can be played as user’s need. This can serve as the guidance in the art
gallery.

Figure 4. The prototype of poster viewer for


interior design was implemented. The user can
stick, move and delete a chosen poster. The

11
application mainly utilizes spatial mapping and
GGV input.

III. 3D painting with gestures

The third scenario is drawing in three-dimensional space. This application enable


the user to paint 3D space with hands. The user input is called manipulation
gesture, which keeps track of the position of hands. This is used as mock
handwriting procedure. However, there is a known issue that hands to be tracked
need to be within the field of view (FOV) of the integrated cameras. Since the FOV
of cameras is limited, the user wearing the device is required to focus on the hand
holding the virtual paint brush.

The rendering capability of HoloLens is around 80,000 triangles at more than 30


frames per seconds. As it is a mobile head-mounted display with limited
computational power compared to desktop PCs, two rendering techniques were
introduced to increase performance and reduce latency while maintaining
acceptable quality of graphics.

The pen strokes are represented by segments consisting of pairs of lines and dots.
One trivial way of assembling the segments is to use Unity primitive objects. One
cylinder (88 vertices, 80 triangles) is to be used as the line and one sphere (515
vertices, 768 triangles) is to be used as the dot. However, as the number of
segments needed for a single pen stroke will be normally at the level of around 102,
this will result in low frame rate and cause discomfort for users. Therefore I
adopted the usage of quads with billboard rendering. Each pair is made up of one
quad (4 vertices, 2 triangles) as rectangle and another one as circle. Both quads will

12
reorient the rotation to face the user if the threshold of user movement is reached.
This radically decreases the number of vertices and triangles to be rendered.

The other feature is GPU instancing recommended by Unity. The adoption of a


instanced shader and texture atlas (see Figure 5) can reduce the draw calls and then
the overhead for the CPU. There are still other choices of advanced rendering such
as static batching and dynamic batching. The combination of the two techniques
above demonstrated good graphics quality and acceptable frame rate in the tests.

Figure 5. The quad for line and the quad for


dot are combined as a whole to utilize the
feature of texture atlas and GPU instancing.

IV. 3D reconstruction
The fourth scenario is 3D reconstruction. This application is capable of scanning
the real objects placed on surfaces such as floors, walls and ceilings and making
virtual replicates. It is also a mock stamping procedure using mixed reality. This
prototype was implemented with surface observer, the Unity API portal for spatial
mapping functionality. This is originally used for understanding the surroundings
and thus the observation volume can not be set to a small value to tightly fit the
object to be scanned. The results of testing during the implementation showed that
a value less than 1 by 1 by 1 cubic meter will cause unexpected exceptions and

13
system halt. Then there will be fallback that the whole room is to be scanned
before the necessary part of mesh is picked.

The reconstruction procedure includes three steps. First, three or more landmarks
are picked for setting up the normal vector, origin plane and clipping volume. Then
the surface observer starts scanning. Finally the object mesh within the clipping
volume will be taken via a multi-threaded post-processing step.

In order to achieve a well balanced performance between latency and quality, the
scanning parameters is set to a medium preset. The precision is 1500 triangles per
cubic meter against the ordinary 500 triangles/m 3 used for spatial mapping. The
theoretic maximum value is 6000 triangles/m 3 but a test has shown that there will
be no notable increase in scanning quality beyond 1500 triangles/m 3. The time
interval between mapping updates is 0.5 second. Smaller interval caused
exceptions in the same test.

Another optimization is the usage of wireframe in rendering the object meshes (see
Figure 6). The main reason is that the meshes got from surface observer API has no
uv information for applying complex textures. On the other hand, the wireframe is
a good-cheap-fast alternative for simple demonstration like the one in this mixed
reality system.

14
Figure 6. The ball is scanned by the 3D
reconstruction application and wireframe is
used to render the mesh for a balance between
latency and quality.

One originally planned feature of the 3D reconstruction function is the usage of


render texture. In other words, HoloLens does not only reconstruct the shape of
objects but also takes pictures of the real objects during the scanning procedure.
The set of pictures captured is fit to the mesh of the object with the help of camera
calibration matrices so that they can be used as textures in replacement of the
wireframe material. However, the operating memory (RAM) for applications on
HoloLens is bounded to no more than 800 megabytes so that the number of
pictures is also limited. In addition, the fitting process is compute-bounded since
the shader needs to fit the texture coordinates for every vertices of the object mesh.
In the preliminary tests, this plan resulted in unfavorable graphics performance and
even occasional system crash. Therefore, I took the wireframe as the fallback
option.

15
V. Interaction with objects
The next scenario is about interaction with objects in scene including paintings,
posters, drawings, reconstructed 3D objects as well as other objects in the future
implementations. At this stage, preliminary interactions such as initialization,
movement and deletion has been implemented. All of these use the integrated user
input of HoloLens. Two main input for HoloLens are voice input and gesture input.
HoloLens showed capability of recognizing voice commands almost instantly
when we tried out the demos. This is also mentioned by the documentation that
processing voice input is hardware accelerated. Therefore, since I have followed
the guidelines of creating concise commands, voice will be a handy input method.
The core interaction includes press, release and bloom (see Figure 7a and 7b).
Moreover, HoloLens can track the movement of user’s hand. Then complex
gestures such as holding, manipulation (1:1 movement) and navigation (like
joystick) can be recognized by combining individual presses and releases.

Figure 7a. Flexing the index finger down (press) Figure 7b. Bloom is to hold
out the hand, palm and then back up (release) makes an air-tap for up, with
fingertips together and then open the selection. (image source: Microsoft) hand.
This gesture is reserved for HoloLens

16
system and thus can not be used for
our own application. (image source:
Microsoft)
In the prototype application, three basic gestures were well recognized. Holding
and navigation worked with high accuracy as well. However, the manipulation
gesture performed below expectation. The virtual object was moved only for a
short distance before the gesture source was lost. It is likely that HoloLens has a
rather limited area for gesture recognition unlike VR devices with external cameras
(see Figure 8). One of our proposed scenarios, painting in threedimensional,
requires such gestures (see Figure 8). The unexpected performance indicate that
there can be difficulties in implementing this functionality. Overall, the user input
offered by this mixed reality system is handy and lightweight. It is supposed to be
extensible for future usage but diversity of gestures is still limited if no external
controllers like Leap Motion is to be officially supported in the near future.

Figure 8. Tilt Brush by Google makes use of


HTC Vive. This virtual reality device has two
‘Lighthouse’ external sensors and is thus able
to capture extensive movements. However, the
recognition area is limited for HoloLens and it

17
is more difficult to develop such painting
application.

VI. Graphics stabilization


The last application is a complementary one to achieve better hologram
stabilization and graphics quality. Among all the quality metrics mentioned in the
official guideline by Microsoft, jitters and color separation are the two which were
identified during the preliminary tests. Jitter is high frequency shaking of virtual
objects and it is generally caused by low frame rate and bad sensor tuning. Color
separation is the rainbow effect where graphics is separated into red-green-
bluegreen patterns. Both problems will have a negative effect on user experience
and are supposed to be reduced to a minimum level.

Figure 9. The objects passing through the


stabilization plane will have minimum number
of jitters, color separation and other graphics
problems. The focus point manager is a
complementary application to assist the
HoloLens to choose a suitable plane in various
scenes.

18
HoloLens has its default choices of stabilization plane. All the virtual objects
passing through the plane will have best rendering quality (see Figure 9). However
in this mixed reality system, there is a variety of virtual objects attached to
different surfaces in the same 3D space. The choice of focused object will also be
different in various scenarios. For example, the user will probably want to focus on
the pen strokes when drawing. The last application, namely the focus point
manager, was implemented with a custom strategy of choice. A focus point along
with a normal vector is chosen to set up the stabilization plane. At the same time it
has a cache strategy which checks the cached objects to increase efficiency. With
the help of focus point manager, hologram stabilization and user experience are
improved to an acceptable level even if there is a low frame rate.

Results — Cross-Platform Multiplayer


In order to archive the cross-platform multiplayer feature between HoloLens and
Tango tablets, two external development frameworks are used, namely Photon
Unity Network (PUN) framework and Vuforia AR SDK.

I. Vuforia Augmented Reality SDK


Due to the different definition of world coordinate on HoloLens and Tango,
location of the origin point, orientation and scale of coordinate system require to be
calibrated before the holograms can be projected at the identical physical location.

Fortunately, both HoloLens and Tango take the unit length in Unity editor as one
meter in real. Then the only calibration work that remains is location of origin
point and orientation. Since the origin is defined as the spawning point of the
devices, there is possibility that a physical calibration can be archived by matching
the origin and forward vector of HoloLens and Tango when launching the

19
applications. However, this option is rejected since it may cause inconvenience that
conflicts with a favorable user experience.

For the reason above, we embraced the Vuforia SDK for coordinate calibration. In
general, it is an multi-platform library that can recognize specific images, objects
and markers. One image is printed and prepared at a fixed location for each
instance of the mixed reality system. In this way, both HoloLens and Tango are
capable of figure out the origin location and orientation. In the tests, Vuforia
demonstrated satisfying recognition speed and accuracy and precision of
coordinate calibration was better than the physical method in real-life usage.

II. Photon Unity Network framework


PUN is a free-to-use Unity package for multiplayer games on all platforms. It
offers a plug-andplay solution for creating cross-platform system like our case.
PUN makes use of Photon Cloud, a cloud service provided by Exit Games and
requires no master server setup. The location and orientation of game objects
instantiated with Photon will be automatically synchronized at the frequency of 10
times per second. PUN has been adopted by a wide range of developers from
indies to AAA studios. In addition, there is a well maintained documentation and
therefore we decided to take it as the major option for multiplayer support.

20
Limitations
The main limitations encountered is due to the specification and characteristics of
the hardware. First, the limited number of mesh triangles makes it impossible to
deal with complicated surface. It is likely to be avoided if the precision is still
acceptable and we focus on innovation rather than the complexity of the demos.
Second, HoloLens sacrifices the tracking range in order to get extra portability.
Extensive movements can not be captured without external sensor. Therefore we
find it difficult to implement the painter application for HoloLens. This will
possibly have a negative on the user experience but it is likely that this will be
enough in terms of a demonstration instead of a product for marketing.

Another limitation comes from the fact that we are still trying to exploit creative
usage of mixed reality other than those specified in this report. Such scenarios
should also be realizable under the restrictions of the current developing platform.
Although we have already had a few ideas of utilizing mixed reality, it will always
be better if we can come up with more innovation applications.

Finally, the project faces the difficulty of lack of official multi-platform support.
Microsoft has published an open source package called HoloToolkit to simplify the
developing procedure within Unity. The latest release included the updated APIs
for recognizing user input as well as sharing coordinates among HoloLens devices.
It is likely that multiplayer support between HoloLens can be integrated with less
effort. However, the collaborative work using both HoloLens and Tango tablets
receives no official support. We have adopted Vuforia to calibrate the coordinate
system between different devices and then Photon PUN to archive cross-platform

21
synchronization. However, it still breaks our original design principle of building a
“join and play” mixed reality system in any physical environment without
additional setup.

HARDWARE DESIGN

The system hardware of automatic border crossing detection consists of Power


supply unit, RF Transmitter, RF Receiver Transmitting and Receiving Antenna,
Microcontroller, Relay, Buzzer and DC Motor as shown in Figure.1 and Figure.2.

RECEIVER A. Block Diagram:


22
Micro Controller:

A micro controller is a true computer on a chip. The design incorporates all the
features found in a microprocessor such as CPU, ALU,PC, SP and registers. It also
has some added features needed to make a complete computer ROM, RAM,
parallel I/o, serial I/o, counters and clock circuit. The prime use of a micro
controller is to control the operation of a machine using a fixed program that is
stored in ROM and that does not change over the life time of the system. The areas
if applications of micro controllers include control process, manufacturing process,
medicine, instrumentation etc.

PIC MICROCONTROLLER

PIC is a family of Harvard architecture microcontrollers made by Microchip


Technology, derived from the PIC1650 originally developed by General
Instrument's Microelectronics Division. The name PIC initially referred to
"Peripheral Interface Controller".

23
PICs are popular with both industrial developers and hobbyists alike due to their
low cost, wide availability, large user base, extensive collection of application
notes, availability of low cost or free development tools, and serial programming
(and re-programming with flash memory) capability.

HIGH-PERFORMANCE RISC CPU:

 Only 35-75 single-word instructions to learn


 All single-cycle instructions except for program branches, which are two-
cycle
 Operating speed: DC – 20 MHz clock input
 DC – 200 ns instruction cycle
 Up to 8K x 14 words of Flash Program Memory,
 Up to 368 x 8 bytes of Data Memory (RAM),
 Up to 256 x 8 bytes of EEPROM Data Memory
 Pin out compatible to other 28-pin or 40/44-pin PIC16CXXX and
PIC16FXXX microcontrollers

PERIPHERAL FEATURES:

 Timer0: 8-bit timer/counter with 8-bit prescaler


 Timer1: 16-bit timer/counter with prescaler, can be incremented
during Sleep via external crystal/clock
 Timer2: 8-bit timer/counter with 8-bit period register, prescaler and
postscaler
 Two Capture, Compare, PWM modules
 Capture is 16-bit, max. Resolution is 12.5 ns
 Compare is 16-bit, max. Resolution is 200 ns
 PWM max. Resolution is 10-bit
 Synchronous Serial Port (SSP) with SPI™ (Master mode) and I2C™
(Master/Slave)
 Universal Synchronous Asynchronous Receiver Transmitter
(USART/SCI) with 9-bit address detection

24
 Parallel Slave Port (PSP) – 8 bits wide with external RD, WR and CS
controls (40/44-pin only)
 Brown-out detection circuitry for Brown-out Reset (BOR)

ANALOG FEATURES:

 10-bit, up to 8-channel Analog-to-Digital Converter (A/D)


 Brown-out Reset (BOR)
 Analog Comparator module with:
- Two analog comparators
- Programmable on-chip voltage reference (VREF) module
- Programmable input multiplexing from device inputs and internal
voltage reference
- Comparator outputs are externally accessible

SPECIAL MICROCONTROLLER FEATURES:

 100,000 erase/write cycle Enhanced Flash program memory typical


 1,000,000 erase/write cycle Data EEPROM memory typical
 Data EEPROM Retention > 40 years
 Self-reprogrammable under software control
 In-Circuit Serial Programming™ (ICSP™) via two pins
 Single-supply 5V In-Circuit Serial Programming
 Watchdog Timer (WDT) with its own on-chip RC oscillator for reliable
operation
 Programmable code protection
 Power saving Sleep mode
 Selectable oscillator options
 In-Circuit Debug (ICD) via two pins

CMOS TECHNOLOGY:

 Low-power, high-speed Flash/EEPROM technology


 Fully static design
 Wide operating voltage range (2.0V to 5.5V)
 Commercial and Industrial temperature ranges
25
 Low-power consumption

PIN DIAGRAMS

26
QFN- QUAD-FLAT NO-LEADS PACKAGE

PDIP- PLASTIC DUAL-IN-LINE PACKAGE

PLCC- PLASTIC LEADED CHIP CARRIER

TQFP- THIN QUAD FLAT PACK PACKAGES

27
28
DEVICE OVERVIEW
This document contains device specific information about the following devices:
PIC16F877A
PIC16F873A/876A devices are available only in 28-pin packages, while
PIC16F874A/877A devices are available in 40-pin and 44-pin packages. All
devices in the PIC16F87XA family share common architecture with the following
differences:
• The PIC16F873A and PIC16F874A have one-half of the total on-chip memory of
the PIC16F876A and PIC16F877A
• The 28-pin devices have three I/O ports, while the 40/44-pin devices have five
• The 28-pin devices have fourteen interrupts, while the 40/44-pin devices have
fifteen
• The 28-pin devices have five A/D input channels, while the 40/44-pin devices
have eight
• The Parallel Slave Port is implemented only on the 40/44-pin devices

PIC16F87XA DEVICE FEATURES

Key Features PIC16F877A


Operating Frequency DC – 20 MHz
Resets (and Delays) POR, BOR
(PWRT, OST)
Flash Program Memory 8K
(14-bit words)
Data Memory (bytes) 368
EEPROM Data Memory (bytes) 256
Interrupts 15
I/O Ports Ports A, B, C, D, E
Timers 3
29
Capture/Compare/PWM modules 2
Serial Communications MSSP, USART
Parallel Communications PSP
10-bit Analog-to-Digital Module 8 input channels
Analog Comparators 2
Instruction Set 35 Instructions
Packages 40-pin PDIP
44-pin PLCC
44-pin TQFP
44-pin QFN

PIC16F874A/877A BLOCK DIAGRAM

30
PIC16F877A PINOUT DESCRIPTION

31
PIN-1 - MCLR/VPP

Master Clear (input) or programming voltage (output).Master Clear (Reset) input.


This pin is an active low Reset to the device. Programming voltage input.

PORT-A (PIN OUT IS 2 TO 7)

PORT-A is a bidirectional I/O port

PIN-2- RA0/AN0

Digital I/O. Analog input 0.

PIN-3-RA1/AN1

Digital I/O. Analog input 1.

PIN-4- RA2/AN2/VREF-/CVREF

Digital I/O. Analog input 2.

A/D reference voltage (Low) input.

Comparator VREF output

PIN-5-RA3/AN3 /VREF+

Digital I/O. Analog input 3.

A/D reference voltage (High) input.

PIN-6- RA4/T0CKI/C1OUT

Digital I/O – Open-drain when configured as output.

Timer0 external clock input. Comparator 1 output.

32
PIN-7- RA5/AN4/SS/C2OUT

Digital I/O. Analog input 4. SPI slave select input. Comparator 2 output.

PORT-E (PINOUT IS 8 TO 10)

PORT-E is a bidirectional I/O port

PIN-8-RE0/RD/AN5

Digital I/O. Read control for Parallel Slave Port. Analog input 5.

PIN-9- RE1/WR/AN6

Digital I/O. Write control for Parallel Slave Port. Analog input 6.

PIN-10- RE2/CS/AN7

Digital I/O. Chip select control for Parallel Slave Port. Analog input 7.

POWER PIN

PIN-11 AND 32-VDD

Positive supply for logic and I/O pins

PIN-12 AND 31-VSS

Ground reference for logic and I/O pins.

PIN-13- OSC1/CLKI

33
Oscillator crystal or external clock input. Oscillator crystal input or external clock
source input. ST buffer when configured in RC mode; otherwise CMOS. External
clock source input. Always associated with pin function OSC1 (see OSC1/CLKI,
OSC2/CLKO pins)

PIN-14- OSC2/CLKO

Oscillator crystal or clock output. Oscillator crystal output. Connects to crystal or


resonator in Crystal Oscillator mode. In RC mode, OSC2 pin outputs CLKO,
which has 1/4 the frequency of OSC1 and denotes the instruction cycle rate.

PORT-C (PIN OUT IS 15 TO 18 & 23 TO 26)

PORTC is a bidirectional I/O port.

PIN-15- RC0/T1OSO/T1CKI

Digital I/O. Timer1 oscillator output. Timer1 external clock input

PIN-16- RC1/T1OSI/CCP2

Digital I/O. Timer1 oscillator input. Capture2 input, Compare2 output, PWM2
output.

PIN-17- RC2/CCP1

Digital I/O. Capture1 input, Compare1 output, PWM1 output

PIN-18- RC3/SCK/SCL

Digital I/O. Synchronous serial clock input/output for SPI mode.

Synchronous serial clock input/output for I2C mode.


34
PIN-23- RC4/SDI/SDA

Digital I/O. SPI data in. I2C data I/O.

PIN-24- RC5/SDO

Digital I/O. SPI data out.

PIN-25- RC6/TX/CK

Digital I/O. USART asynchronous transmit. USART1 synchronous clock.

PIN-26- RC7/RX/DT

Digital I/O. USART asynchronous receive. USART synchronous data.

PORT-D (PINOUT IS 19 TO 22 & 27 TO 30)

PORTD is a bidirectional I/O port or Parallel Slave Port when interfacing to a


microprocessor bus.

PIN-19- RD0/PSP0

Digital I/O. Parallel Slave Port data.

PIN-20- RD1/PSP1

Digital I/O. Parallel Slave Port data.

PIN-21- RD2/PSP2

Digital I/O. Parallel Slave Port data.

PIN-22- RD3/PSP3

Digital I/O. Parallel Slave Port data.

35
PIN-27- RD4/PSP4

Digital I/O. Parallel Slave Port data.

PIN-28- RD5/PSP5

Digital I/O. Parallel Slave Port data.

PIN-29- RD6/PSP6

Digital I/O. Parallel Slave Port data.

PIN-30- RD7/PSP7

Digital I/O. Parallel Slave Port data.

PORT-B(PIN OUT IS 33 TO 40)

PORTB is a bidirectional I/O port. PORTB can be software programmed for


internal weak pull-up on all inputs.

PIN-33- RB0/INT

Digital I/O. External interrupt

PIN-34- RB1

Digital I/O.

PIN-35- RB2

Digital I/O.

PIN-36- RB3/PGM

36
Digital I/O. Low-voltage ICSP programming enable pin.

PIN-37- RB4

Digital I/O.

PIN-38- RB5

Digital I/O.

PIN-39- RB6/PGC

Digital I/O. In-circuit debugger and ICSP programming clock.

PIN-40- RB7/PGD

Digital I/O. In-circuit debugger and ICSP programming data.

MEMORY ORGANIZATION

There are three memory blocks in each of the PIC16F87XA devices. The program
memory and data memory have separate buses so that concurrent access can occur
and is detailed in this section. The EEPROM data memory block is detailed in
“Data EEPROM and Flash Program Memory”.

Additional information on device memory may be found in the PICmicro® Mid-


Range MCU Family Reference Manual (DS33023).

Program Memory Organization

The PIC16F87XA devices have a 13-bit program counter capable of addressing an


8K word x 14 bit program memory space. The PIC16F876A/877A devices have

37
8K words x 14 bits of Flash program memory. Accessing a location above the
physically implemented address will cause a wraparound.

The Reset vector is at 0000h and the interrupt vector is at 0004h.

PIC16F877A PROGRAM MEMORY MAP AND STACK

Data Memory Organization

The data memory is partitioned into multiple banks which contain the General Purpose Registers and the
Special Function Registers. Bits RP1 (Status<6>) and RP0 (Status<5>) are the bank select bits.

RP1:RP0 Bank
00 0
01 1
10 2
11 3
38
Each bank extends up to 7Fh (128 bytes). The lower locations of each bank are
reserved for the Special Function Registers. Above the Special Function Registers
are General Purpose Registers, implemented as static RAM. All implemented
banks contain Special Function Registers. Some frequently used Special Function
Registers from one bank may be mirrored in another bank for code reduction and
quicker access.

GENERAL PURPOSE REGISTER FILE


The register file can be accessed either directly, or indirectly, through the File
Select Register (FSR).

PIC16F876A/877A REGISTER FILE MAP

39
DATA EEPROM AND FLASH PROGRAM MEMORY

40
The data EEPROM and Flash program memory is readable and writable during
normal operation (over the full VDD range). This memory is not directly mapped
in the register file space. Instead, it is indirectly addressed through the Special
Function Registers. There are six
SFRs used to read and write this memory:
• EECON1
• EECON2
• EEDATA
• EEDATH
• EEADR
• EEADRH
When interfacing to the data memory block, EEDATA holds the 8-bit data for
read/write and EEADR holds the address of the EEPROM location being accessed.
These devices have 128 or 256 bytes of data EEPROM (depending on the device),
with an address range from 00h to FFh. On devices with 128 bytes, addresses from
80h to FFh are unimplemented and will wraparound to the beginning of data
EEPROM memory. When writing to unimplemented locations, the on-chip charge
pump will be turned off. When interfacing the program memory block, the
EEDATA and EEDATH registers form a two-byte word that holds the 14-bit data
for read/write and the EEADR and EEADRH registers form a two-byte word that
holds the 13-bit address of the program memory location being accessed. These
devices have 4 or 8K words of program Flash, with an address range from 0000h
to 0FFFh for the PIC16F873A/874A and 0000h to 1FFFh for the
PIC16F876A/877A. Addresses above the range of the respective device will
wraparound to the beginning of program memory. The EEPROM data memory
allows single-byte read and write. The Flash program memory allows single-word
41
reads and four-word block writes. Program memory write operations automatically
perform an erase-before write on blocks of four words. A byte write in data
EEPROM memory automatically erases the location and writes the new data
(erase-before-write). The write time is controlled by an on-chip timer. The
write/erase voltages are generated by an on-chip charge pump, rated to operate
over the voltage range of the device for byte or word operations. When the device
is code-protected, the CPU may continue to read and write the data EEPROM
memory. Depending on the settings of the write-protect bits, the device may or
may not be able to write certain blocks of the program memory; however, reads of
the program memory are allowed. When code-protected, the device programmer
can no longer access data or program memory; this does NOT inhibit internal reads
or writes.

EEADR and EEADRH


The EEADRH: EEADR register pair can address up to a maximum of 256 bytes of
data EEPROM or up to a maximum of 8K words of program EEPROM. When
selecting a data address value, only the LSByte of the address is written to the
EEADR register. When selecting a program address value, the MSByte of the
address is written to the EEADRH register and the LSByte is written to the
EEADR register. If the device contains less memory than the full address reach of
the address register pair, the Most Significant bits of the registers are not
implemented. For example, if the device has 128 bytes of data EEPROM, the Most
Significant bit of EEADR is not implemented on access to data EEPROM.

EECON1 and EECON2 Registers

42
EECON1 is the control register for memory accesses. Control bit, EEPGD,
determines if the access will be a program or data memory access. When clear, as it
is when reset, any subsequent operations will operate on the data memory. When
set, any subsequent operations will operate on the program memory. Control bits,
RD and WR, initiate read and write or erase, respectively. These bits cannot be
cleared, only set, in software. They are cleared in hardware at completion
of the read or write operation. The inability to clear the WR bit in software
prevents the accidental, premature termination of a write operation. The WREN
bit, when set, will allow a write or erase operation. On power-up, the WREN bit is
clear. The WRERR bit is set when a write (or erase) operation is interrupted by a
MCLR or a WDT Time-out Reset during normal operation. In these situations,
following Reset, the user can check the WRERR bit and rewrite the location. The
data and address will be unchanged in the EEDATA and EEADR registers.
Interrupt flag bit, EEIF in the PIR2 register, is set when the write is complete. It
must be cleared in software.EECON2 is not a physical register. Reading
EECON2will read all ‘0’s. The EECON2 register is used exclusively in the
EEPROM write sequence.

Reading Data EEPROM Memory


To read a data memory location, the user must write the address to the EEADR
register, clear the EEPGD control bit (EECON1<7>) and then set control bit RD
(EECON1<0>). The data is available in the very next cycle in the EEDATA
register; therefore, it can be read in the next instruction (see Example 3-1).
EEDATA will hold this value until another read or until it is written to by the user
(during a write operation).

The steps to reading the EEPROM data memory are:


43
1. Write the address to EEADR. Make sure that the address is not larger than the
memory size of the device.
2. Clear the EEPGD bit to point to EEPROM data memory.
3. Set the RD bit to start the read operation.
4. Read the data from the EEDATA register.

Writing to Data EEPROM Memory


To write an EEPROM data location, the user must first write the address to the
EEADR register and the data to the EEDATA register. Then the user must follow a
specific write sequence to initiate the write for each byte. The write will not initiate
if the write sequence is not exactly followed (write 55h to EECON2, write AAh to
EECON2, then set WR bit) for each byte. We strongly recommend that interrupts
be disabled during this code segment (see Example 3-2).
Additionally, the WREN bit in EECON1 must be set to enable write. This
mechanism prevents accidental writes to data EEPROM due to errant (unexpected)
code execution (i.e., lost programs). The user should keep the WREN bit clear at
all times, except when updating EEPROM. The WREN bit is not cleared by
hardware after a write sequence has been initiated, clearing the WREN bit will not
affect this write cycle. The WR bit will be inhibited from being set unless the
WREN bit is set. At the completion of the write cycle, the WR bit is cleared in
hardware and the EE Write Complete Interrupt Flag bit (EEIF) is set. The user can
either enable this interrupt or poll this bit. EEIF must be cleared by software.

The steps to write to EEPROM data memory are:


1. If step 10 is not implemented, check the WR bit to see if a write is in progress.

44
2. Write the address to EEADR. Make sure that the address is not larger than the
memory size of the device.
3. Write the 8-bit data value to be programmed in the EEDATA register.
4. Clear the EEPGD bit to point to EEPROM data memory.
5. Set the WREN bit to enable program operations.
6. Disable interrupts (if enabled).
7. Execute the special five instruction sequence:
• Write 55h to EECON2 in two steps (first to W, then to EECON2)
• Write AAh to EECON2 in two steps (first to W, then to EECON2)
• Set the WR bit
8. Enable interrupts (if using interrupts).
9. Clear the WREN bit to disable program operations.
10. At the completion of the write cycle, the WR bit is cleared and the EEIF
interrupt flag bit is set. (EEIF must be cleared by firmware.) If step 1 is not
implemented, then firmware should check for EEIF to be set, or WR to clear, to
indicate the end of the program cycle.

TIMER0 MODULE

The Timer0 module timer/counter has the following features:


• 8-bit timer/counter
• Readable and writable
• 8-bit software programmable prescaler
• Internal or external clock select
• Interrupt on overflow from FFh to 00h
• Edge select for external clock

45
Figure 5-1 is a block diagram of the Timer0 module and the prescaler shared with
the WDT.
Additional information on the Timer0 module is available in the PICmicro® Mid-
Range MCU Family Reference Manual (DS33023).
Timer mode is selected by clearing bit T0CS (OPTION_REG<5>). In Timer mode,
the Timer0 module will increment every instruction cycle (without prescaler). If
the TMR0 register is written, the increment is inhibited for the following two
instruction cycles. The user can work around this by writing an adjusted value to
the TMR0 register
Counter mode is selected by setting bit T0CS (OPTION_REG<5>). In Counter
mode, Timer0 will increment either on every rising or falling edge of pin
RA4/T0CKI. The incrementing edge is determined by the Timer0 Source Edge
Select bit, T0SE (OPTION_REG<4>). Clearing bit T0SE selects the rising edge.

TIMER1 MODULE

The Timer1 module is a 16-bit timer/counter consisting of two 8-bit registers


(TMR1H and TMR1L) which are readable and writable. The TMR1 register pair
(TMR1H:TMR1L) increments from 0000h to FFFFh and rolls over to 0000h. The
TMR1 interrupt, if enabled, is generated on overflow which is latched in interrupt
flag bit, TMR1IF (PIR1<0>). This interrupt can be enabled/disabled by
setting/clearing TMR1 interrupt enable bit, TMR1IE (PIE1<0>). Timer1 can
operate in one of two modes:
• As a Timer
• As a Counter

46
The operating mode is determined by the clock select bit, TMR1CS (T1CON<1>).
In Timer mode, Timer1 increments every instruction cycle. In Counter mode, it
increments on every rising
edge of the external clock input. Timer1 can be enabled/disabled by
setting/clearing control bit, TMR1ON (T1CON<0>). Timer1 also has an internal
“Reset input”. This Reset can be generated by either of the two CCP modules
(Section 8.0 “Capture/Compare/PWM Modules”). Register 6-1 shows the Timer1
Control register. When the Timer1 oscillator is enabled (T1OSCEN is set), the
RC1/T1OSI/CCP2 and RC0/T1OSO/T1CKI pins become inputs. That is, the
TRISC<1:0> value is ignored and these pins read as ‘0’. Additional information on
timer modules is available in the PICmicro® Mid-Range MCU Family Reference
Manual (DS33023).

TIMER2 MODULE

Timer2 is an 8-bit timer with a prescaler and a postscaler. It can be used as the
PWM time base for the PWM mode of the CCP module(s). The TMR2 register is
readable and writable and is cleared on any device Reset. The input clock
(FOSC/4) has a prescale option of 1:1, 1:4 or 1:16, selected by control bits
T2CKPS1:T2CKPS0 (T2CON<1:0>). The Timer2 module has an 8-bit period
register, PR2. A Timer2 increment from 00h until it matches PR2 and then resets to
00h on the next increment cycle. PR2 is a readable and writable register. The PR2
register is initialized to FFh upon Reset. The match output of TMR2 goes through
a 4-bit postscaler (which gives a 1:1 to 1:16 scaling inclusive) to generate a TMR2
interrupt (latched in flag bit, TMR2IF (PIR1<1>)). Timer2 can be shut-off by
clearing control bit, TMR2ON (T2CON<2>), to minimize power consumption.

47
POWER SUPPLIES

There are many types of power supply. Most are designed to convert high voltage
AC mains electricity to a suitable low voltage supply for electronics’ circuits and
other devices. A power supply can by broken down into a series of blocks, each of
which performs a particular function.

For example a 5V regulated supply:

Each of the blocks is described in more detail below:

TRANSFORMER

Steps down high voltage AC mains to low voltage AC.

Transformers convert AC electricity from one voltage to another with little loss of
power. Transformers work only with AC and this is one of the reasons why mains
electricity is AC.

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 in UK) 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

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

Transformer
circuit symbol

turns ratio = Vp = Np and power out = power in


Vs Ns Vs × Is = Vp × Ip
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

RECTIFIER

Converts AC to DC, but the DC output is varying.

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

SINGLE DIODE RECTIFIER

A single diode can be used as a rectifier but this produces half-wave varying DC which
has gaps when the AC is negative. It is hard to smooth this sufficiently well to supply electronic circuits
unless they require a very small current so the smoothing capacitor does not significantly discharge
during the gaps. Please see the Diodes page for some examples of rectifier diodes.

Output: half-wave varying DC


Single diode rectifier
(using only half the AC wave)

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 all the 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 withstand the
peak voltages). Please see the Diodes page for more details, including pictures of bridge rectifiers.

50
Bridge rectifier Output: full-wave varying DC
(using all the AC wave)

SMOOTHING (FILTER)

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.

51
Note that smoothing significantly increases the average DC voltage to almost the
peak value (1.4 × RMS value). For example 6V RMS AC is rectified to full wave
DC of about 4.6V RMS (1.4V is lost in the bridge rectifier), with smoothing this
increases to almost the peak value giving 1.4 × 4.6 = 6.4V smooth DC.

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.

5 × Io
Smoothing capacitor for 10% ripple, C =
Vs × f

C= smoothing capacitance in farads (F)


Io = output current from the supply in amps (A)
Vs = supply voltage in volts (V), this is the peak value of the unsmoothed DC
f = frequency of the AC supply in hertz (Hz), 50Hz in the UK
52
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 VO

To make things really simple let’s start with a simple power supply and it is also
the one they usually give you in your first electronics project. Well the reason is
quite obvious because all electronics circuits require a DC power supply to work.
You really do plug in the wires of your electronic items in AC mains supply but
they do have AC to DC converters too provide DC to the circuits. All this is done
with a power supply in the right place.

Pin diagram for 7805

 1. Unregulated voltage in
 2. Ground

 3. Regulated voltage out

53
Voltage regulator

This circuit is a small +5V power supply. The circuit will provide a regulated
voltage to the external circuit which may also I am required in any part of the
external circuit or the whole external circuit. The best part is that you can also use
it to convert AC voltage to DC and then regulate it ,simply You need a transformer
to make the AC main drop down to a safe value i.e 12-15 volts and then us a
rectifier to convert AC into DC.

54
This circuit can give +5V output at about 150 mA current, but it can be increased
to 1 A when good cooling is added to 7805 regulator chip. The circuit has over
overload and terminal protection. The capacitors must have enough high voltage
rating to safely handle the input voltage feed to circuit. The circuit is very easy to
build for example into a piece of overboard.

If you need other voltages than +5V, you can modify the circuit by replacing the
7805 chips with another regulator with different output voltage from regulator
78xx chip family. The last numbers in the chip code tells the output voltage.
Remember that the input voltage must be at least 3V greater than regulator output
voltage to otherwise the regulator does not work well. Don’t forget to check the pin
diagram before connecting the IC.

TRANSFORMER ONLY

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.

55
TRANSFORMER + RECTIFIER

The varying DC output is suitable for lamps, heaters and standard motors. It is not
suitable for electronic circuits unless they include a smoothing capacitor.

TRANSFORMER + RECTIFIER + SMOOTHING (FILTER)

The smooth DC output has a small ripple. It is suitable for most electronic circuits.

TRANSFORMER + RECTIFIER + SMOOTHING + REGULATOR

56
The regulated DC output is very smooth with no ripple. It is suitable for all
electronic circuits.

Circuit Diagram:

Circuit Description:

The 230/240VAC line voltage is applied to the transformer primary. Step down
transformer is used to convert 230VAC to 12V/1A output voltage in the
transformer secondary. This 12VAC supply is applied to the bridge rectifier. The
bridge rectifier voltage rating should be double the Vrms of secondary AC and
higher forward current rating. The bridge rectifier has four diodes in that, available

57
as singular. This is the most important and it produces full-wave varying DC or
pulsating DC. This rectified output is smoothed by using shunt capacitor filter
(C1). The larger the filter capacitor lowers the ripple. The larger capacitor C1
across the input bypasses AC ripples to ground. The pure DC output reaches the
regulator IC. The 7805 Voltage regulator IC (U1) gives 5V /1A regulated output.
The capacitor (C2) across the output improves transient response. Low power red
LED is used in the output for power indication. It has voltage drop of 1.8V and
gives brightness at 20 mA. This is done by current limiting resistor (R1).

R = (Vout – Vf) / I

Where, Vout –output voltage; Vf- led voltage drop; I- led forward current.

From this we get R as 160E. We use the standard value of 220E. The higher value
of limiting resistor gives low brightness but longer life time. So, here 470E is used.

RELAY

A relay is an electrically operated switch. Many relays use an electromagnet to


operate a switching mechanism mechanically, but other operating principles are
also used. Relays are used where it is necessary to control a circuit by a low-power
signal (with complete electrical isolation between control and controlled circuits),
or where several circuits must be controlled by one signal. The first relays were
used in long distance telegraph circuits, repeating the signal coming in from one
circuit and re-transmitting it to another. Relays were used extensively in telephone
exchanges and early computers to perform logical operations.

A type of relay that can handle the high power required to directly control an
electric motor or other loads is called a contactor. Solid-state relays control power

58
circuits with no moving parts, instead using a semiconductor device to perform
switching. Relays with calibrated operating characteristics and sometimes multiple
operating coils are used to protect electrical circuits from overload or faults; in
modern electric power systems these functions are performed by digital
instruments still called "protective relays".

Relay Working Principle:

When a coil of wire is wound on a non magnetic material such as plastic, paper
etc., it is called a air-core solenoid or simply a solenoid .if a soft iron core is
inserted into the coil, it becomes an electromagnet. This electromagnet is the basic
component for relay and many other electromechanical devices such as electric
bell, circuit breaker etc,.

Operation
59
When a current flows through the coil, the resulting magnetic field attracts an
armature that is mechanically linked to a moving contact. The movement either
makes or breaks a connection with a fixed contact. When the current to the coil is
switched off, the armature is returned by a force approximately half as strong as
the magnetic force to its relaxed position. Usually this is a spring, but gravity is
also used commonly in industrial motor starters. Most relays are manufactured to
operate quickly. In a low voltage application, this is to reduce noise. In a high
voltage or high current application, this is to reduce arcing.

If the coil is energized with DC, a diode is frequently installed across the coil, to
dissipate the energy from the collapsing magnetic field at deactivation, which
would otherwise generate a spike of voltage and might cause damage to circuit
components. Some automotive relays already include that diode inside the relay
case. If the coil is designed to be energized with AC, a small copper ring can be
crimped to the end of the solenoid. This “shading ring” creates a small out-of-
phase current, which increases the minimum pull on the armature during the AC
cycle by analogy with the functions of the original electromagnetic device; a solid-
state relay is made with a thyristor or other solid-state switching device. To achieve
electrical isolation, a light-emitting diode (LED) is used with a photo transistor.

Types

Latching relay

60
Latching relay with permanent magnet

A latching relay has two relaxed states (bi-stable). These are also called "impulse",
"keep", or "stay" relays. When the current is switched off, the relay remains in its
last state. This is achieved with a solenoid operating a ratchet and cam mechanism,
or by having two opposing coils with an over-center spring or permanent magnet to
hold the armature and contacts in position while the coil is relaxed, or with a
remanent core. In the ratchet and cam example, the first pulse to the coil turns the
relay on and the second pulse turns it off. In the two coil example, a pulse to one
coil turns the relay on and a pulse to the opposite coil turns the relay off. This type
of relay has the advantage that one coil consumes power only for an instant, while
it is being switched, and the relay contacts retain this setting across a power
outage. A remanent core latching relay requires a current pulse of opposite polarity
to make it change state.

Reed relay

A reed relay is a reed switch enclosed in a solenoid. The switch has a set of
contacts inside an evacuated or inert gas-filled glass tube which protects the
contacts against atmospheric corrosion; the contacts are made of magnetic material
that makes them move under the influence of the field of the enclosing solenoid.
Reed relays can switch faster than larger relays, require only little power from the
control circuit, but have low switching current and voltage ratings. In addition, the
reeds can become magnetized over time, which makes them stick 'on' even when
no current is present; changing the orientation of the reeds with respect to the
solenoid's magnetic field will fix the problem.

61
Top, middle: reed switches, bottom: reed relay

Mercury-wetted relay

A mercury-wetted reed relay is a form of reed relay in which the contacts are
wetted with mercury. Such relays are used to switch low-voltage signals (one volt
or less) where the mercury reduces the contact resistance and associated voltage
drop, for low-current signals where surface contamination may make for a poor
contact, or for high-speed applications where the mercury eliminates contact
bounce. Mercury wetted relays are position-sensitive and must be mounted
vertically to work properly. Because of the toxicity and expense of liquid mercury,
these relays are now rarely used. See also mercury switch.

Polarized relay

A polarized relay placed the armature between the poles of a permanent magnet to
increase sensitivity. Polarized relays were used in middle 20th Century telephone
exchanges to detect faint pulses and correct telegraphic distortion. The poles were
on screws, so a technician could first adjust them for maximum sensitivity and then
apply a bias spring to set the critical current that would operate the relay.

62
Machine tool relay

A machine tool relay is a type standardized for industrial control of machine tools,
transfer machines, and other sequential control. They are characterized by a large
number of contacts (sometimes extendable in the field) which are easily converted
from normally-open to normally-closed status, easily replaceable coils, and a form
factor that allows compactly installing many relays in a control panel. Although
such relays once were the backbone of automation in such industries as automobile
assembly, the programmable logic controller (PLC) mostly displaced the machine
tool relay from sequential control applications.

A relay allows circuits to be switched by electrical equipment: for example, a timer


circuit with a relay could switch power at a preset time. For many years relays
were the standard method of controlling industrial electronic systems. A number of
relays could be used together to carry out complex functions (relay logic). The
principle of relay logic is based on relays which energize and de-energize
associated contacts. Relay logic is the predecessor of ladder logic, which is
commonly used in Programmable logic controllers.

Ratchet relay

This is again a clapper type relay which does not need continuous current through
its coil to retain its operation.

Contactor relay

63
A contactor is a very heavy-duty relay used for switching electric motors and
lighting loads, although contactors are not generally called relays. Continuous
current ratings for common contactors range from 10 amps to several hundred
amps. High-current contacts are made with alloys containing silver. The
unavoidable arcing causes the contacts to oxidize; however, silver oxide is still a
good conductor.[2] Such devices are often used for motor starters. A motor starter is
a contactor with overload protection devices attached. The overload sensing
devices are a form of heat operated relay where a coil heats a bi-metal strip, or
where a solder pot melts, releasing a spring to operate auxiliary contacts. These
auxiliary contacts are in series with the coil. If the overload senses excess current
in the load, the coil is de-energized. Contactor relays can be extremely loud to
operate, making them unfit for use where noise is a chief concern.

Solid-state relay

A solid state relay (SSR) is a solid state electronic component that provides a
similar function to an electromechanical relay but does not have any moving
components, increasing long-term reliability. With early SSR's, the tradeoff came
from the fact that every transistor has a small voltage drop across it. This voltage
drop limited the amount of current a given SSR could handle. The minimum
voltage drop for such a relay is equal to the voltage drop across one transistor
(~0.6-2.0 volts), and is a function of the material used to make the transistor
(typically silicon). As transistors improved, higher current SSR's, able to handle
100 to 1,200 Amperes, have become commercially available. Compared to
electromagnetic relays, they may be falsely triggered by transients.

64
Solid state relay with no moving parts

Solid state contactor relay

A solid state contactor is a heavy-duty solid state relay, including the necessary
heat sink, used for switching electric heaters, small electric motors and lighting
loads; where frequent on/off cycles are required. There are no moving parts to wear
out and there is no contact bounce due to vibration. They are activated by AC
control signals or DC control signals from Programmable logic controller (PLCs),
PCs, Transistor-transistor logic (TTL) sources, or other microprocessor and
microcontroller controls.

25 A or 40 A solid state contactors

65
Buchholz relay

A Buchholz relay is a safety device sensing the accumulation of gas in large oil-
filled transformers, which will alarm on slow accumulation of gas or shut down the
transformer if gas is produced rapidly in the transformer oil. it is connected in
between conservator tank and main tank. it is use in above 750 kva transformer.
This relay is developed by max buchholz

Forced-guided contacts relay

A forced-guided contacts relay has relay contacts that are mechanically linked
together, so that when the relay coil is energized or de-energized, all of the linked
contacts move together. If one set of contacts in the relay becomes immobilized, no
other contact of the same relay will be able to move. The function of forced-guided
contacts is to enable the safety circuit to check the status of the relay. Forced-
guided contacts are also known as "positive-guided contacts", "captive contacts",
"locked contacts", or "safety relays".

Overload protection relay

Electric motors need over current protection to prevent damage from over-loading
the motor, or to protect against short circuits in connecting cables or internal faults
in the motor windings. One type of electric motor overload protection relay is
operated by a heating element in series with the electric motor. The heat generated
66
by the motor current heats a bimetallic strip or melts solder, releasing a spring to
operate contacts. Where the overload relay is exposed to the same environment as
the motor, a useful though crude compensation for motor ambient temperature is
provided.

Pole & Throw

Since relays are switches, the terminology applied to switches is also applied to
relays. A relay will switch one or more poles, each of whose contacts can be
thrown by energizing the coil in one of three ways:

Normally-open (NO) contacts connect the circuit when the relay is activated; the
circuit is disconnected when the relay is inactive. It is also called a Form A contact
or “make” contact.

Normally-closed (NC) contacts disconnect the circuit when the relay is activated;
the circuit is connected when the relay is inactive. It is also called a Form B contact
or “break” contact.

Change-over, or double-throw, contacts control two circuits: one normally-open


contact and one normally-closed contact with a common terminal. It is also called
a Form C contact or “transfer” contact.

The following types of relays are commonly encountered:

SPST – Single Pole Single Throw. These have two terminals which can be
connected or disconnected. Including two for the coil, such a relay has four
terminals in total. It is ambiguous whether the pole is normally open or normally
closed. The terminology “SPNO” and “SPNC” is sometimes used to resolve the
ambiguity.

67
SPDT – Single Pole Double Throw. A common terminal connects to either of two
others. Including two for the coil, such a relay has five terminals in total.

DPST – Double Pole Single Throw. These have two pairs of terminals. Equivalent
to two SPST switches or relays actuated by a single coil. Including two for the coil,
such a relay has six terminals in total. It is ambiguous whether the poles are
normally open, normally closed, or one of each.

DPDT – Double Pole Double Throw. These have two rows of change-over
terminals. Equivalent to two SPDT switches or relays actuated by a single coil.
Such a relay has eight terminals, including the coil.

QPDT - Quadruple Pole Double Throw. Often referred to as Quad Pole Double
Throw, or 4PDT. These have four rows of change-over terminals. Equivalent to
four SPDT switches or relays actuated by a single coil or two DPDT relays. In
total, fourteen terminals including the coil

RELAY DRIVER

A ULN2803 is an Integrated Circuit (IC) chip with a High Voltage/High Current


Darlington Transistor Array. It allows you to interface TTL signals with higher
voltage/current loads. In English, the chip takes low level signals (TLL, CMOS,

68
PMOS, NMOS - which operate at low voltages and low currents) and acts as a
relay of sorts itself, switching on or off a higher level signal on the opposite side.

A TTL signal operates from 0-5V, with everything between 0.0 and 0.8V
considered "low" or off, and 2.2 to 5.0V being considered "high" or on. The
maximum power available on a TTL signal depends on the type, but generally does
not exceed 25mW (~5mA @ 5V), so it is not useful for providing power to
something like a relay coil. Computers and other electronic devices frequently
generate TTL signals. On the output side the ULN2803 is generally rated at
50V/500mA, so it can operate small loads directly. Alternatively, it is frequently
used to power the coil of one or more relays, which in turn allow even higher
voltages/currents to be controlled by the low level signal. In electrical terms, the
ULN2803 uses the low level (TTL) signal to switch on/turn off the higher
voltage/current signal on the output side.

The ULN2803 comes in an 18-pin IC configuration and includes eight (8)


transistors. Pins 1-8 receive the low level signals; pin 9 is grounded (for the low
level signal reference). Pin 10 is the common on the high side and would generally
be connected to the positive of the voltage you are applying to the relay coil. Pins
11-18 are the outputs (Pin 1 drives Pin 18, Pin 2 drives 17, etc.).

ULN2803

The eight NPN Darlington connected transistors in this family of arrays are ideally
suited for interfacing between low logic level digital circuitry (such as TTL,
CMOS or PMOS/NMOS) and the higher current/voltage requirements of lamps,
relays, printer hammers or other similar loads for a broad range of computer,

69
industrial, and consumer applications. All devices feature open–collector outputs
and freewheeling clamp diodes for transient suppression. The ULN2803 is
designed to be compatible with standard TTL families while the ULN2804 is
optimized for 6 to 15 volt high level CMOS or PMOS.

MOTOR

A DC motor is an electric motor that runs on direct current (DC) electricity. DC


motors were used to run machinery, often eliminating the need for a local steam
engine or internal combustion engine. DC motors can operate directly from
rechargeable batteries, providing the motive power for the first electric vehicles.
Today DC motors are still found in applications as small as toys and disk drives, or

70
in large sizes to operate steel rolling mills and paper machines. Modern DC motors
are nearly always operated in conjunction with power electronic devices.

MOTOR PRINCIPLES OF OPERATION

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.

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

Every DC motor has six basic parts -- axle, rotor (a.k.a., armature), stator,
commutator, field magnet(s), and brushes. In most common DC motors (and all
that Beamers’ will see), the external magnetic field is produced by high-strength
permanent magnets1. The stator is the stationary part of the motor -- this includes
the motor casing, as well as two or more permanent magnet pole pieces. The rotor
(together with the axle and attached commutator) rotates with respect to the stator.
The rotor consists of windings (generally on a core), the windings being
electrically connected to the commutator. The above diagram shows a common
motor layout -- with the rotor inside the stator (field) magnets.

The geometry of the brushes, commutator contacts, and rotor windings are such
that when power is applied, the polarities of the energized winding and the stator
magnet(s) are misaligned, and the rotor will rotate until it is almost aligned with
the stator's field magnets. As the rotor reaches alignment, the brushes move to the
next commutator contacts, and energize the next winding. Given our example two-
pole motor, the rotation reverses the direction of current through the rotor winding,
leading to a "flip" of the rotor's magnetic field, driving it to continue rotating.

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

One pole is fully energized at a time (but two others are "partially" energized). As
each brush transitions from one commutator contact to the next, one coil's field
will rapidly collapse, as the next coil's field will rapidly charge up (this occurs
within a few microsecond). We'll see more about the effects of this later, but in the
meantime you can see that this is a direct result of the coil windings' series wiring:

73
There's probably no better way to see how an average DC motor is put together,
than by just opening one up. Unfortunately this is tedious work, as well as
requiring the destruction of a perfectly good motor.

Luckily for you, I've gone ahead and done this in your stead. The guts of a
disassembled Mabuchi FF-030-PN motor (the same model that Solarbotics sells)
are available for you to see here (on 10 lines / cm graph paper). This is a basic 3-
pole DC motor, with 2 brushes and three commutator contacts.

The use of an iron core armature (as in the Mabuchi, above) is quite common, and
has a number of advantages2. First off, the iron core provides a strong, rigid
support for the windings -- a particularly important consideration for high-torque
motors. The core also conducts heat away from the rotor windings, allowing the
motor to be driven harder than might otherwise be the case. Iron core construction
is also relatively inexpensive compared with other construction types.

But iron core construction also has several disadvantages. The iron armature has a
relatively high inertia which limits motor acceleration. This construction also
results in high winding inductances which limit brush and commutator life.

In small motors, an alternative design is often used which features a 'coreless'


armature winding. This design depends upon the coil wire itself for structural
integrity. As a result, the armature is hollow, and the permanent magnet can be
mounted inside the rotor coil. Coreless DC motors have much lower armature
inductance than iron-core motors of comparable size, extending brush and
commutator life.

74
DC MOTOR BEHAVIOR

At a simplistic level, using DC motors is pretty straightforward -- you put power


in, and get rotary motion out. Life, of course, is never this simple -- there are a
number of subtleties of DC motor behavior that should be accounted for in BEAM
bot design.

High-speed output

This is the simplest trait to understand and treat -- most DC motors run at very high
output speeds (generally thousands or tens of thousands of RPM). While this is fine
for some BEAM bots (say, photo poppers or solar rollers), many BEAM bots
(walkers, heads) require lower speeds -- you must put gears on your DC motor's
output for these applications.

Back EMF

Just as putting voltage across a wire in a magnetic field can generate motion,
moving a wire through a magnetic field can generate voltage. This means that as a
DC motor's rotor spins, it generates voltage -- the output voltage is known as back
EMF. Because of back EMF, a spark is created at the commutator as a motor's
brushes switch from contact to contact. Meanwhile, back EMF can damage
sensitive circuits when a motor is stopped suddenly.

Noise (ripple) on power lines

A number of things will cause a DC motor to put noise on its power lines:
commutation noise (a function of brush / commutator design & construction),

75
roughness in bearings (via back EMF), and gearing roughness (via back EMF, if
the motor is part of a gear motor) are three big contributors.

Even without these avoidable factors, any electric motor will put noise on its
power lines by virtue of the fact that its current draw is not constant throughout its
motion. Going back to our example two-pole motor, its current draw will be a
function of the angle between its rotor coil and field magnets:

Since most small DC motors have 3 coils, the coils' current curves will overlay
each other:

Added together, this ideal motor's current will then look something like this:

76
Reality is a bit more complex than this, as even a high-quality motor will display a
current transient at each commutation transition. Since each coil has inductance
(by definition) and some capacitance, there will be a surge of current as the
commentator’s brushes first touch a coil's contact, and another as the brushes leave
the contact (here, there's a slight spark as the coil's magnetic field collapses).

As a good example, consider an oscilloscope trace of the current through a


Mabuchi FF-030PN motor supplied with 2 V (1ms per horizontal division, 0.05
mA per vertical division):

In this case, the peak-to-peak current ripple is approximately 0.29 mA, while the
average motor current is just under 31 mA. So under these conditions, the motor
puts about less than 1% of current ripple onto its power lines (and as you can see
from the "clean" traces, it outputs essentially no high-frequency current noise).
Note that since this is a 3-pole motor, and each coil is energized in both directions
over the course of a rotor rotation, one revolution of the rotor will correspond to
six of the above curves (here, 6 x 2.4 ms = 0.0144 sec, corresponding to a motor
rotation rate of just under 4200 RPM).

Motor power ripple can wreak havoc in Nv nets by destabilizing them


inadvertently. Fortunately, this can be mitigated by putting a small capacitor across
the motor's power lines (you'll only be able to filter out "spikey" transients this
way, though -- you'll always see curves like the ones above being imposed on your
power). On the flip side of this coin, motor power ripple can be put to good use --
as was shown above, ripple frequency can be used to measure motor speed, and its
destabilizing tendencies can be used to reverse a motor without the need for
discrete "back-up" sensors.

77
PARAMETERIZING DC MOTOR PERFORMANCE

as you tinker around with DC motors, you'll start to run across some interesting
relationships. Namely you'll discover that torque and current are linearly
proportional to each other, as are speed and voltage. Under a fixed load (torque),
voltage and current will also be proportional to each other.

Digging into the math (and I'll spare you this), it turns out that the current a motor
draws is ultimately determined by the torque the motor produces. The generated
torque is dependent upon the current I, and factors determined by the materials and
internal geometry of the motor. Since the construction of a finished motor will not
(!) change during operation, a constant of proportionality between the motor
current and the materials / geometry dependent factors can be calculated for a
given motor. This constant, the torque constant Kt, describes the torque generated
by the motor for a specific motor current:

Kt = T / I

Or to put it another way,

Current through motor = torque produced / torque constant

I (Amps) = Torque (oz-in) / Kt (oz-in/A) in imperial units

I (Amps) = Torque (N-m) / Kt (N-m/A) in SI units

Because of the interrelationship of torque, speed, current, and voltage, the constant
current operation of a DC motor produces constant output torque regardless of
speed. Given a constant load (i.e. torque) the speed of a motor is solely dependent

78
on the voltage applied to the motor. For DC motors operated at a constant voltage,
the speed and torque produced are inversely related (the higher the torque, the
lower the speed of the motor).

We earlier saw that an EMF will be developed across a motor's brushes when its
coil is rotated by an external torque -- the magnitude of this EMF is dependent
upon materials / geometry factors, and upon the speed at which the coil is rotated.
Once again, there is a constant of proportionality which describes the relationship
between coil rotational speed and materials / geometry factors, commonly known
as the back EMF constant (Ke). The back EMF constant is typically given in volts
per unit of rotational speed (which in turn is generally expressed either in RPM or
radians / second).

If one takes the reciprocal of the back EMF constant, the result is a proportionality
constant which relates the voltage applied to the motor terminals to the rotational
speed of the coil. This version of the motor constant is commonly known as the
velocity constant, Kv. The velocity constant is given in units of rotational speed
(again, either RPM or radians / second) per volt.

Since the motor construction does not change, regardless of what we're measuring,
it turns out that these three constants (Kt, Ke, Kv) are all essentially the same
number. The differences between the torque constant and the back EMF constant
are simply a matter of the units used, while the velocity constant is simply a useful
form of the back EMF constant.

If the torque constant is specified in N-m / A and the back EMF constant in V-sec /
rad, then:

Kt = Ke = 1 / Kv
79
Those of us who live in the U.S., though, are stuck with using more colorful units.
Commonly used units for small motors are oz-in for torque and RPM for rotational
speed. Using these units of measure, torque constants are often given in oz-in / A,
back EMF constants in mV / RPM, and velocity constants in RPM / V. In imperial
units, the relationships between motor constants are then as follows:

With
Kt in units of oz-in / A
Ke in units of mV / RPM
Kv in units of RPM / volt

Then

Kt = 1352.4 / Kv

Ke= Kt / 1.3524

Ke = 1000 / Kv

Kv = 1000 / Ke

So what good is all this? It means that given a source of known rotational speed
(an electric drill, or drill press if you have one), you can compute Ke for a given
motor (clamp the motor shaft in the drill's jaws, measure the resulting open-circuit
voltage, then do the math).

Ke, along with the above information will then give you Kt (so you can compute
your motor's theoretical torque at any given current), and Kv (so you can compute
your motor's maximum speed at any given voltage). If you can measure stall

80
torque, you can then compute motor efficiency (measured torque expressed as a
percentage of the theoretical torque).

MOTOR DRIVER

The L293 and L293D are quadruple high-current half-H drivers. The L293 is
designed to provide bidirectional drive currents of up to 1 A at voltages from 4.5 V
to 36 V. The L293D is designed to provide bidirectional drive currents of up to
600-mA at voltages from 4.5 V to 36 V. Both devices are designed to drive
inductive loads such as relays, solenoids, dc and bipolar stepping motors, as well
as other high-current/high-voltage loads in positive-supply applications. All inputs
are TTL compatible. Each output is a complete totem-pole drive circuit, with a
Darlington transistor sink and a pseudo- Darlington source. Drivers are enabled in
pairs, with drivers 1 and 2 enabled by 1,2EN and drivers 3 and 4 enabled by
3,4EN. When an enable input is high, the associated drivers are enabled, and their
outputs are active and in phase with their inputs. When the enable input is low,
those drivers are disabled, and their outputs are off and in the high-impedance
state. With the proper data inputs, each pair of drivers forms a full-H (or bridge)
reversible drive suitable for solenoid or motor applications.

81
 Featuring Unitrode L293 and L293D

 Products Now From Texas Instruments

 Wide Supply-Voltage Range: 4.5 V to 36 V

 Separate Input-Logic Supply

 Internal ESD Protection

 Thermal Shutdown

 High-Noise-Immunity Inputs

 Functionally Similar to SGS L293 and SGS L293D

 Output Current 1 A per Channel (600 mA for L293D)


82
 Peak Output Current 2 A per Channel (1.2 A for L293D)

 Output Clamp Diodes for Inductive

 Transient Suppression (L293D)

Logic diagram

RF MODULE

The RF module, as the name suggests, operates at Radio Frequency. The


corresponding frequency range varies between 30 kHz & 300 GHz. In this RF

83
system, the digital data is represented as variations in the amplitude of carrier
wave. This kind of modulation is known as Amplitude Shift Keying (ASK).

Figure 4.10 RF module


Transmission through RF is better than IR (infrared) because of many
reasons. Firstly, signals through RF can travel through larger distances making it
suitable for long range applications. Also, while IR mostly operates in line-of-sight
mode, RF signals can travel even when there is an obstruction between transmitter
& receiver. Next, RF transmission is more strong and reliable than IR transmission.
RF communication uses a specific frequency unlike IR signals which are affected
by other IR emitting sources.

This RF module comprises of an RF Transmitter and an RF Receiver. The


transmitter/receiver (Tx/Rx) pair operates at a frequency of 434 MHz an RF
transmitter receives serial data and transmits it wirelessly through RF through its
antenna connected at pin4. The transmission occurs at the rate of 1Kbps -
10Kbps.The transmitted data is received by an RF receiver operating at the same
frequency as that of the transmitter.

84
The RF module is often used along with a pair of encoder/decoder. The
encoder is used for encoding parallel data for transmission feed while reception is
decoded by a decoder. HT12E-HT12D, HT640-HT648, etc. are some commonly
used encoder/decoder pair ICs.

Figure 4.11 RF Transmitter and Receiver

4.4.1 Decoder (HT12D)

4.4.1.1 General Description

The 212 decoders are a series of CMOS LSIs for remote control system
applications. They are paired with Holtek’s 212 series of encoders. For proper
operation, a pair of encoder/decoder with the same number of addresses and data
format should be chosen. The decoders receive serial addresses and data from a
programmed 212 series of encoders that are transmitted by a carrier using an RF or
an IR transmission medium. They compare the serial input data three times
continuously with their local addresses. If no error or unmatched codes are found,
the input data codes are decoded and then transferred to the output pins. The VT
pin also goes high to indicate a valid transmission. The 212 series of decoders are
capable of decoding information’s that consist of N bits of address and 12-N bits of
data. Of this series, the HT12D is arranged to provide 8 address bits and 4 data
bits, and HT12F is used to decode 12 bits of address information.
85
4.4.1.2 Features

 Operating voltage: 2.4V~12V


 Low power and high noise immunity CMOS technology
 Low standby current
 Capable of decoding 12 bits of information
 Binary address setting
 Received codes are checked 3 times
 Address/Data number combination
 HT12D: 8 address bits and 4 data bits
 Built-in oscillator needs only 5% resistor
 Valid transmission indicator
 Easy interface with an RF or an infrared transmission medium
 Minimal external components
 Pair with Holtek’s 212 series of encoders
18-pin DIP, 20-pin SOP package

86
Figure 4.11 Pin Diagram for HT12D

4.4.1.3 Pins description

 A0~A7 (HT12D) - Input pins for address A0~A7 setting these pins can be
externally set to VSS or left open.
 D8~D11 (HT12D) - Output data pins, power-on state is low. CMOS OUT
 DIN- Serial data input pin CMOS IN
 VT - Valid transmission, active high CMOS OUT
 OSC1 - Oscillator input pin
 OSC2 - Oscillator output pin
 VSS - Negative power supply, ground
 VDD- Positive power supply

4.4.2 Encoder (HT12E)

4.4.2.1 General Description

The 212 encoders are a series of CMOS LSIs for remote control system
applications. They are capable of encoding information which consists of N
address bits and 12_N data bits. Each address/data input can be set to one of the
two logic states. The programmed addresses/data are transmitted together with the
header bits via an RF or an infrared transmission medium upon receipt of a trigger
signal. The capability to select a TE trigger on the HT12E or a DATA trigger on the
HT12A further enhances the application flexibility of the 212 series of encoders.
The HT12A additionally provides a 38 kHz carrier for infrared systems.

4.4.2.2 Features
 Operating voltage
o 2.4V~12V for the HT12E
87
 Low power and high noise immunity CMOS technology
 Low standby current: 0.1A (typ.) at VDD=5V
 HT12A with a 38 kHz carrier for infrared transmission medium
 Minimum transmission word: Four words for the HT12E
 Built-in oscillator needs only 5% resistor
 Data code has positive polarity
 Minimal external components
 Pair with Holtek’s 212 series of decoders
 18-pin DIP, 20-pin SOP package

Figure 4.12 Pin Diagram for HT12E

4.4.2.3 Pins description

 A0~A7 (HT12E) - Input pins for address A0~A7 setting these pins can be
externally set to VSS or left open.
 AD8~AD11 (HT12E) - Input pins for data D8~D11 setting and transmission
enable, active low CMOS IN Pull high
 DOUT- Encoder data serial transmission output CMOS OUT
 TE - Transmission enable, active low CMOS IN Pull high
88
 OSC1 - Oscillator input pin
 OSC2 - Oscillator output pin
 VSS - Negative power supply, ground
 VDD- Positive power supply

4.4.3 Flow chart for working of RF module

RF Transmitter RF Receiver
434MHZ Serial data 434MHZ

Serial data Serial data

Encoder Decoder
HT12E HT12D

Parallel data Parallel data

Figure 4.13 Flow chart for working of RF module


Motion Sensors

In this document

Using the Gravity Sensor

Using the Linear Accelerometer

Using the Rotation Vector Sensor

Using the Significant Motion Sensor

89
Using the Step Counter Sensor

Using the Step Detector Sensor

Working with Raw Data

Using the Accelerometer

Using the Gyroscope

Key classes and interfaces

Sensor

SensorEvent

SensorManager

SensorEventListener

Related samples

Accelerometer Play

API Demos (OS - RotationVectorDemo)

API Demos (OS - Sensors)

See also

Sensors

Sensors Overview

Position Sensors

Environment Sensors

90
The Android platform provides several sensors that let you monitor the motion of a
device.

The sensors' possible architectures vary by sensor type:

The gravity, linear acceleration, rotation vector, significant motion, step counter,
and step detector sensors are either hardware-based or software-based.

The accelerometer and gyroscope sensors are always hardware-based.

Most Android-powered devices have an accelerometer, and many now include a


gyroscope. The availability of the software-based sensors is more variable because
they often rely on one or more hardware sensors to derive their data. Depending on
the device, these software-based sensors can derive their data either from the
accelerometer and magnetometer or from the gyroscope.

Motion sensors are useful for monitoring device movement, such as tilt, shake,
rotation, or swing. The movement is usually a reflection of direct user input (for
example, a user steering a car in a game or a user controlling a ball in a game), but
it can also be a reflection of the physical environment in which the device is sitting
(for example, moving with you while you drive your car). In the first case, you are
monitoring motion relative to the device's frame of reference or your application's
frame of reference; in the second case you are monitoring motion relative to the
world's frame of reference. Motion sensors by themselves are not typically used to
monitor device position, but they can be used with other sensors, such as the

91
geomagnetic field sensor, to determine a device's position relative to the world's
frame of reference (see Position Sensors for more information).

All of the motion sensors return multi-dimensional arrays of sensor values for each
SensorEvent. For example, during a single sensor event the accelerometer returns
acceleration force data for the three coordinate axes, and the gyroscope returns rate
of rotation data for the three coordinate axes. These data values are returned in a
float array (values) along with other SensorEvent parameters. Table 1 summarizes
the motion sensors that are available on the Android platform.

The three elements of the rotation vector are expressed as follows:

Where the magnitude of the rotation vector is equal to sin(θ/2), and the direction of the rotation
vector is equal to the direction of the axis of rotation.

92
Figure 1. Coordinate system used by the rotation vector sensor.

The three elements of the rotation vector are equal to the last three components of a
unit quaternion (cos(θ/2), x*sin(θ/2), y*sin(θ/2), z*sin(θ/2)). Elements of the
rotation vector are unitless. The x, y, and z axes are defined in the same way as the
acceleration sensor. The reference coordinate system is defined as a direct
orthonormal basis (see figure 1). This coordinate system has the following
characteristics:
 X is defined as the vector product Y x Z. It is tangential to the ground at the
device's current location and points approximately East.
 Y is tangential to the ground at the device's current location and points
toward the geomagnetic North Pole.
 Z points toward the sky and is perpendicular to the ground plane.
The Android SDK provides a sample application that shows how to use the rotation
vector sensor. The sample application is located in the API Demos code ( OS -
RotationVectorDemo).

9.1 COMPILER

1. Click on the Keil Vision Icon on Desktop

2. The following fig will appear

93
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 u r own folder
sited in either C:\ or D:\

94
6. Then Click on Save button above.

7. Select the component for u r project. i.e. Atmel……

8. Click on the + Symbol beside of Atmel

9. Select AT89C51 as shown below

95
10. Then Click on “OK”

11. The Following fig will appear

12. Then Click either YES or NO………mostly “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.

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

97
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”.

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

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

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

101

Vous aimerez peut-être aussi