1. INTRODUCTION Radio-frequency Identification (RFID) is an automatic identification method, relying/storing and remotely retrieving data using called RFID tags (Transporters). An RFID tag is an object that can imbibe into a product, animal, or person for the purpose of identification using radio waves. Some tags can be read from several meters and also can be used beyond the line of sight of the reader. The model developed uses an active RFID technology and wireless communicator as it helps to improve data transfer between the tag and the host database over a long distance. The main objective of this module development is to implement an automated check in and checkout in Electronic Toll collection system. Electronic toll collection system (ETC) is one of the means that have been adopted by all developed countries to solve jam problem by parking charge and improve service quality. However the system can also be used in car alarms, warehouse inventory, security access control, personnel access & tracking without the need to swipe each item individually. 1
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1. INTRODUCTION
Radio-frequency Identification (RFID) is an automatic identification method,
relying/storing and remotely retrieving data using called RFID tags (Transporters). An
RFID tag is an object that can imbibe into a product, animal, or person for the purpose of
identification using radio waves. Some tags can be read from several meters and also can
be used beyond the line of sight of the reader. The model developed uses an active RFID
technology and wireless communicator as it helps to improve data transfer between the tag
and the host database over a long distance.
The main objective of this module development is to implement an automated
check in and checkout in Electronic Toll collection system. Electronic toll collection
system (ETC) is one of the means that have been adopted by all developed countries to
solve jam problem by parking charge and improve service quality. However the system can
also be used in car alarms, warehouse inventory, security access control, personnel access
& tracking without the need to swipe each item individually.
1
ABSTRACT:
Electronic Toll Collection (ETC), an adaptation of military "identification friend or
foe" technology, aims to eliminate the delay on toll roads by collecting tolls electronically. It is thus
a technological implementation of a road pricing concept. It determines whether the cars passing
are enrolled in the program, alerts enforcers for those that are not, and electronically debits the
accounts of registered car owners without requiring them to stop. The major advantage of ETC is
that users are able to drive through the toll plaza at highway speeds without having to slow down to
pay the toll. In some installations, ETC may also reduce congestion at the plazas by allowing more
vehicles per hour/per lane
2
BLOCK DIAGRAM:
Block Diagram:
PIC
Micro
Controller
PIC
Micro
Controller
RFIDREADER
RFIDREADER
LCDLCD
Relay with ULN2003Relay with ULN2003
Gate ModelGate Model
Vehicle with RFID Tag
Power SupplyPower Supply
Recharge Keys
Recharge Keys
3
BLOCK DIAGRAM DESCRIPTION
The purpose of the project is to provide a fast and safe environment for toll
collection and to automatically control the vehicle movements at the toll stations by
providing individual identities to each user with the help of RFID technology. This project is
going to deal with the Toll gate collection and payment calculations, in order to make the
posting toll transactions and customer payments to the accounts, and handling customer inquiries.
whenever the vehicle comes the driver will access his cards and only the authorized person can enter
and pass out if the card is valid and also if enough amount is present in the card. The card will be
placed in front of the reader and the card is checked for validation then the concerned amount will be
reduced and then the gate will be opened and the vehicle will be allowed.
4
CIRCUIT DIAGRAM
5
CIRCUIT DIAGRAM DESCRIPTION
Presently toll collection system is mainly depend on the men. that means it is
depending on human effort so in this proposal to reduce human effort and the security is
improved and avoiding jam at toll center.
This system working like shown figure, here we are using AT89S52 microcontroller
it is interfaced with lcd, steeper motor, RFID. Here microcontroller is totally 40 pins .here
display purpose microcontroller is interred faced with LCD.
In LCD 8 pins are a data pin that is 7 to 14 are connected to port0 of microcontroller.
These 8 pins are data pins. These are used to send information to lcd or read contents what
data in register that display on the LCD.
Pin 4 in lcd to port 3.5 pin of micro controller pin 4 LCD is called register select pin.
This is used to select the internal register of LCD, this pin made low then the instruction
command code reregister is selected. if this pin is made high then the data register is selected.
Pin 5is connected to pin 3.6 in micro controller. Pin5 of LCD is called read/write pin.
If this pin is made high then the user is allowed to read information from it. If this pin is
made low then the user is allowed to write the information to it.
Pin 6 is connected to port3.7 pin of micro controller. This is used by the LCD to latch
information presented to its data pins.
In the system is another important section is there that is UART serial
communication. microcontroller interfaced with MAX232.this is inner facing micro
controller is inter faced with MAX 232 because it is modifying version of RS232.we need
line driver to convert the RS232 signals to TTL voltage levels that will be acceptable to
micro controller .in micro controller is inter facing pins TXD,RXD pins. One example of
such a convert is MAX 232 from maximum crop. The MAX232 converts from rs232 voltage
level to TTL levels, and vice versa. One advantage of MAX232 chip is that is uses a 5v
power supply, we need dual power supplies that are common in many older system.
MAX232 requires 4 capacitors ranging from 1 to 22 micro farad.
6
After MAX 232 inter faced is communicated with serial communication process that
with help of modem it can link with RFID reader .in this system is main module is RFID.
System having tags given that’s having small micro chip that’s working when it face before
of the reader. RFID reads information of tag detects and display on the controller side. If any
invalid tag that time display.RFID is mainly reads data from tag and send information
controller it is main part of etc.
In the system another module is mechanical part is there that steeper motor is inter
facing with micro controller with help of ULN 2003. Here 16 pin chip. Pin 3 and pins 4 are
linked with micro controller. ULN chip pin 12 to pin 16 are out put pins that are link with
steeper motor.remainig are connected with resistors.
7
HARDWARE REQUIREMENTS:
POWER SUPPLY
RFID TAG
LCD,
PIC 16F877A MICROCONTROLLER.
SOFTWARE REQUIREMENTS:
CCS OR MPLAB
EMBEDDED ‘C’
8
HARDWARE REQUIREMENTS:
Processor : intel Core
RAM :
Hard Disk :
Input Device :
Output Device :
SOFTWARE REQIREMENTS:
Operating Systems :
Front End :
Language :
9
OBJECTIVES OF THE STUDY
The main objective of this project is to ELECTRONIC TOLL COLLECTION
SYSTEM to ease the collecting toll and reduce traffic and improve service. The
RFID card will be given to the user which contains the digital code, which have to the
corresponding details stored in the centralized database system which can be accessed
in the relevant office as and when required.
Radio-frequency Identification (RFID) is an automatic identification method,
relying/storing and remotely retrieving data using called RFID tags (Transporters). An
RFID tag is an object that can imbibe into a product, animal, or person for the purpose of
identification using radio waves. Some tags can be read from several meters and also can
be used beyond the line of sight of the reader. The model developed uses an active RFID
technology and wireless communicator as it helps to improve data transfer between the tag
and the host database over a long distance.
The main objective of this module development is to implement an automated
check in and checkout in Electronic Toll collection system. Electronic toll collection
system (ETC) is one of the means that have been adopted by all developed countries to
solve jam problem by parking charge and improve service quality. However the system can
also be used in car alarms, warehouse inventory, security access control, personnel access
& tracking without the need to swipe each item individually.
10
RFID
As an evolutionary automatic identification technology, RFID was considered a
niche technology a few years ago. As the costs associated with RFID hardware have
decreased, and standards defined for managing data, RFID has gone main stream. It has the
potential of powering business systems such that they become the competitive backbone of
organizations. Radio-frequency identification (RFID) is an automatic identification
method, relying on storing and remotely retrieving data using devices called RFID tags or
transponders.
An RFID tag is an object that can be applied to or incorporated into a product,
animal, or person for the purpose of identification using radio waves. Some tags can be
read from several meters away and beyond the line of sight of the reader.
Most RFID tags contain at least two parts. One is an integrated circuit for
storing and processing information, modulating and demodulating a (RF) signal and
can also be used for other specialized functions. The second is an antenna for receiving
and transmitting the signal. A technology called chip less RFID allows for discrete
identification of tags without an integrated circuit, thereby allowing tags to be printed
directly onto assets at lower cost than traditional tags.
Today, a significant thrust in RFID use is in enterprise supply chain
management, improving the efficiency of inventory tracking and management.
However, a threat is looming that the current growth and adoption in enterprise supply
chain market will not be sustainable.
A fair cost-sharing mechanism, rational motives and justified returns from
RFID technology investments are the key ingredients to achieve long-term and
sustainable RFID technology adoption.
EMBEDDEDSYSTEMS
Embedded System is a combination of hardware and software used to achieve a
single specific task. An embedded system is a microcontroller-based, software driven,
11
reliable, real-time control system, autonomous, or human or network interactive, operating
on diverse physical variables and in diverse environments and sold into a competitive and
cost conscious market.
An embedded system is not a computer system that is used primarily for
processing, not a software system on PC or UNIX, not a traditional business or scientific
application. High-end embedded & lower end embedded systems. High-end embedded
system - Generally 32, 64 Bit Controllers used with OS. Examples Personal Digital
Assistant and Mobile phones etc .Lower end embedded systems - Generally 8,16 Bit
Controllers used with an minimal operating systems and hardware layout designed for the
specific purpose. Examples Small controllers and devices in our everyday life like Washing
Machine, Microwave Ovens, where they are embedded in.
Fig 1.1“V Diagram”
In this place we need to discuss the role of simulation software, real-time systems
and data acquisition in dynamic test applications. Traditional testing is referred to as
“static” testing where functionality of components is tested by providing known inputs and
12
measuring outputs. Today there is more pressure to get products to market faster and
reducedesigncycletimes.
This has led to a need for “dynamic” testing where components are tested while in
use with the entire system – either real or simulated. Because of cost and safety concerns,
simulating the rest of the the system with real-time hardware is preferred to testing
components in the actual real system.
The diagram shown on this slide is the “V Diagram” that is often used to describe
the development cycle. Originally developed to encapsulate the design process of software
applications, many different versions of this diagram can be found to describe different
product design cycles. Here we have shown one example of such a diagram representing
the design cycle of embedded control applications common to automotive, aerospace and
defense applications.
In this diagram the general progression in time of the development stages is shown
from left to right. Note however that this is often an iterative process and the actual
development will not proceed linearly through these steps. The goal of rapid development
is to make this cycle as efficient as possible by minimizing the iterations required for a
design. If the x-axis of the diagram is thought of as time, the goal is to narrow the “V” as
much as possible and thereby reduce development time
The y-axis of this diagram can be thought of as the level at which the system
components are considered. Early on in the development, the requirements of the overall
system must be considered.
As the system is divided into sub-systems and components, the process becomes
very low-level down to the point of loading code onto individual processors. Afterwards
components are integrated and tested together until such time that the entire system can
enter final production testing. Therefore the top of the diagram represents the high-level
system view and the bottom of the diagram represents a very low-level view.
Characteristics of Embedded System:
13
• An embedded system is any computer system hidden inside a product other than a
computer
• There will encounter a number of difficulties when writing embedded system
software in addition to those we encounter when we write applications
1. Throughput – Our system may need to handle a lot of data in a
short period of time.
2. Response–Our system may need to react to events quickly
3. Testability–Setting up equipment to test embedded software can
be difficult
4. Debugability–Without a screen or a keyboard, finding out what
the software is doing wrong (other than not working) is a
troublesome problem
5. Reliability – embedded systems must be able to handle any
situation without human intervention
6. Memory space – Memory is limited on embedded systems, and
you must make the software and the data fit into whatever
memory exists
7. Program installation – you will need special tools to get your
software into embedded systems
8. Power consumption – Portable systems must run on battery
power, and the software in these systems must conserve power
9. Processor hogs – computing that requires large amounts of CPU
time can complicate the response problem
10. Cost – Reducing the cost of the hardware is a concern in many
embedded system projects; software often operates on hardware
that is barely adequate for the job.
14
• Embedded systems have a microprocessor/ microcontroller and a memory. Some
have a serial port or a network connection. They usually do not have keyboards,
screens or disk drives.
Applications
1. Military and aerospace embedded software applications
2. Communicat ion Appl ica t ions
3. Industrial automation and process control software.
Power supply
The Entire Project needs power for its operation. However, from the study of this
project it comes to know that we supposed to design 5v and 12v dc power supply. So by
utilizing the following power supply components, required power has been gained.
(230/12v (1A and 500mA) – Step down transformers, Bridge rectifier to converter ac to dc,
booster capacitor and +5v (7805) and +12v (7812) regulator to maintain constant 5v & 12
supply for the controller circuit and RFID Reader).
15
RFID Reader Details
The DLP-RFID1 is a low-cost, USB-powered module for reading from and writing
to ISO 15693, ISO 18000-3, and Tag-it™ intelligent RFID transponder tags. It has the
ability to both read and write up to 256 bytes of data in addition to reading the unique
identifier (UID/SID). All of the DLP-RFID1’s electronics and antenna reside within the
compact unit, and all operational power is taken from the host PC via the USB interface.
The range of the internal antenna is up to 4 inches depending upon the size of the tag being
read.
RFID stands for Radio Frequency Identification. It is an electronic technology
whereby digital data encoded in an RFID Tag (or transponder) is retrieved utilizing a
reader. In contrast to bar code technology, RFID systems do not require line-of-sight access
to the tag in order to retrieve the tag’s data, and they are well suited to harsh environments.
An RFID tag consists of an integrated circuit attached to an antenna. In the case of
the tags used with the DLP-RFID1, the antenna is in the form of conductive ink “printed”
on a material that allows for connection to the integrated circuit. This type of passive
(battery-free) tag is commonly referred to as an “inlay”.
The RFID reader (or “interrogator”) is typically a microcontroller-based radio
transceiver that powers the tag with a time-varying electromagnetic radio frequency (RF)
field. When the RF field passes through the tag’s antenna, AC voltage is generated in the
antenna and rectified to supply power to the tag. Once powered, the tag can receive
commands from the reader. The information stored in the tag can then be read by the reader
and sent back to the host PC for processing.
The data in the tag consists of a hard-coded, permanent serial number (or UID) and
user memory that can be written to, read from and locked if desired. Once locked, user data
can still be read but not changed.
LCD MODULE
A liquid crystal is a material (normally organic for LCDs) that will flow like a liquid
but whose molecular structure has some properties normally associated with solids. The
16
Liquid Crystal Display (LCD) is a low power device. The power requirement is typically in
the order of microwatts for the LCD. However, an LCD requires an external or internal light
source. It is limited to a temperature range of about 0C to 60C and lifetime is an area of
concern, because LCDs can chemically degrade
There are two major types of LCDs which are:
1. Dynamic-scattering LCDs
2. Field-effect LCDs
Field-effect LCDs are normally used in such applications where source of energy is
a prime factor (e.g., watches, portable instrumentation etc.).They absorb considerably less
power than the light-scattering type. However, the cost for field-effect units is typically
higher, and their hoight is limited to 2 inches. On the other hand, light-scattering units are
available up to 8 inches in height. Field-effect LCD is used in the project for displaying the
appropriate information.
The turn-on and turn-off time is an important consideration in all displays. The
response time of LCDs is in the range of 100 to 300ms.The lifetime of LCDs is steadily
increasing beyond 10,000+hours limit. Since the color generated by LCD units is dependent
on the source of illumination, there is a wide range of color choice.
STEPPER MOTORS
These motors are also called stepping motors or step motors. This name is used
because this motor rotates trough a fixed angular step in response to each input current pulse
received by its controller. In the recent years, there has been wide demand of stepping motors
because of the explosive growth of the computer industry. This popularity is due to the fact
that they can be directly controlled by computers, microprocessors and programmable
controllers.
17
As we know industrial motors are used to convert electric into mechanical energy
but they cannot be used for precision positioning of an object. These stepper motors are
ideally suited for situations where precise positioning is required.
When a command pulse is received each time the output shaft rotates in a series
of discrete angular intervals. When number of pulses supplied are definite then shaft of the
stepper motor turns through definite known angle. This makes stepper motor suited for open
loop position control because no feedback need to be taken from the shaft.
Such motors develop some torques ranging from 1Mn-m. In a tiny wristwatch motor of 3mm
diameter, up to 40N-M in a motor of 15cm diameter suitable for machine tool applications.
Power output ranges from 1Wto a max of 2500W. The only moving party in a stepper motor
is its rotor, which has no windings, commutator or brushes. This feature makes it quite robust
and reliable.
Step Angle The angle through which motor shaft rotates for each command is
called the step angle. Smaller the stepper angle, greater the no. of steps for revolution and
higher the resolution or accuracy of positioning obtained. The step angle can be as small as
0.72 degrees as large as 90 degrees. But most common step sizes are 1.8, 2.5, 7.5 and 15.
Resolution is given by the number of steps needed to complete one revolution of
the rotor shaft. Higher the resolution greater the extraordinary ability to operate at very high
stepping rates up to (20,000 steps 1 second)Operation at high speeds is called slewing.
Stepping motors come in two varieties, permanent magnet and variable
reluctance (there are also hybrid motors, which are indistinguishable from permanent magnet
motors from the controller's point of view). Lacking a label on the motor, you can generally
tell the two apart by feel when no power is applied. Permanent magnet motors tend to "cog"
as you twist the rotor with your fingers, while variable reluctance motors almost spin freely
(although they may cog slightly because of residual magnetization in the rotor). You can also
distinguish between the two varieties with an ohmmeter. Variable reluctance motors usually
have three (sometimes four) windings, with a common return, while permanent magnet
motors usually have two independent windings, with or without center taps. Center-tapped
windings are used in unipolar permanent magnet motors.
18
Working System of ETC
FIG 3.1 system of ETC
Electron toll collection system working like shown in figure. In the system is mainly
depending on microcontroller and RFID. Vehicle owner contain tag when ever vehicle
19
coming into toll center .in toll center RFID reader is road side I center. Here we used low
frequency RFID so that frequency is 125 KHz, when vehicle man his tag before on reader it
immediately working the tag information and content of data and every thing is display on
controller side. Tag have correct information that time we can pay money and alternately
gate is working and gate opened or closed with in time . time is depending on code.
Tag if any defaults we can reset the system. and tag is invalid that time toll center
having some toll center personalities and enquiry the every thing and any defaults thy can
take immediately action.In the system everything on control of toll center.
20
4. HARDWARE REQUIREMENTS
MICROCONTROLLER PIC16F877A
INTRODUCTION
The PIC16F877A CMOS FLASH-based 8-bit microcontroller is upward compatible with the PIC16C5x, PIC12Cxxx and PIC16C7x devices. It features 200 ns instruction execution, 256 bytes of EEPROM data memory, self programming, an ICD, 2 Comparators, 8 channels of 10-bit Analog-to-Digital (A/D) converter, 2 capture/compare/PWM functions, a synchronous serial port that can be configured as either 3-wire SPI or 2-wire I2C bus, a USART, and a Parallel Slave Port.
HIGH-PERFORMANCE RISC CPU
Lead-free; RoHS-compliant
Operating speed: 20 MHz, 200 ns instruction cycle
Operating voltage: 4.0-5.5V
Industrial temperature range (-40° to +85°C)
15 Interrupt Sources
35 single-word instructions
All single-cycle instructions except for program branches (two-cycle)
SPECIAL MICROCONTROLLER FEATURES
Flash Memory: 14.3 Kbytes (8192 words)
Data SRAM: 368 bytes
Data EEPROM: 256 bytes
Self-reprogrammable under software control
In-Circuit Serial Programming via two pins (5V)
Watchdog Timer with on-chip RC oscillator
Programmable code protection
Power-saving Sleep mode
Selectable oscillator options
In-Circuit Debug via two pins
21
PERIPHERAL FEATURES
33 I/O pins; 5 I/O ports
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
16-bit Capture input; max resolution 12.5 ns
16-bit Compare; max resolution 200 ns
10-bit PWM
Synchronous Serial Port with two modes:
SPI Master
I2C Master and Slave
USART/SCI with 9-bit address detection
Parallel Slave Port (PSP)
8 bits wide with external RD, WR and CS controls
Brown-out detection circuitry for Brown-Out Reset
Analog Features
10-bit, 8-channel A/D Converter
Brown-Out Reset
ANALOG COMPARATOR MODULE
2 analog comparators
Programmable on-chip voltage reference module
Programmable input multiplexing from device inputs and internal VREF
Comparator outputs are externally accessible
Program memory (FLASH) is used for storing a written program. Since memory made in FLASH technology can be programmed and cleared more than once, it makes this microcontroller suitable for device development.
EEPROM - data memory that needs to be saved when there is no supply.It is usually used for storing important data that must not be lost if power supply suddenly stops. For instance, one such data is an assigned temperature in temperature regulators. If during a loss of power
22
supply this data was lost, we would have to make the adjustment once again upon return of supply. Thus our device looses on self-reliance.
RAM - Data memory used by a program during its execution.
In RAM are stored all inter-results or temporary data during run-time.
PORTS are physical connections between the microcontroller and the outside world. PIC16F877A has five I/O Ports and 33 pins in all 5 ports.
FREE-RUN TIMER is an 8-bit register inside a microcontroller that works independently of the program. On every fourth clock of the oscillator it increments its value until it reaches the maximum (255), and then it starts counting over again from zero. As we know the exact timing between each two increments of the timer contents, timer can be used for measuring time which is very useful with some devices.
CENTRAL PROCESSING UNIT has a role of connective element between other blocks in the microcontroller. It coordinates the work of other blocks and executes the user program.
Fig.3.1 Architectures of the System.
CISC, RISC
It has already been said that PIC16F877A has a RISC architecture. This term is often found in computer literature, and it needs to be explained here in more detail. Harvard architecture is a newer concept than von-Neumann's. It rose out of the need to speed up the work of a microcontroller. In Harvard architecture, data bus and address bus are separate. Thus a greater flow of data is possible through the central processing unit, and of course, a greater speed of work. Separating a program from data memory makes it further possible for instructions not to have to be 8-bit words. PIC16F877A uses 14 bits for instructions which allows for all instructions to be one word
23
instructions. It is also typical for Harvard architecture to have fewer instructions than von-Neumann's, and to have instructions usually executed in one cycle.
Microcontrollers with Harvard architecture are also called "RISC microcontrollers". RISC stands for Reduced Instruction Set Computer. Microcontrollers with von-Neumann's architecture are called 'CISC microcontrollers'. Title CISC stands for Complex Instruction Set Computer.
Since PIC16F877A is a RISC microcontroller, that means that it has a reduced set of instructions, more precisely 35 instructions. (Ex. Intel's and Motorola's microcontrollers have over hundred instructions) All of these instructions are executed in one cycle except for jump and branch instructions. According to what its maker says, PIC16F877A usually reaches results of 2:1 in code compression and 4:1 in speed in relation to other 8-bit microcontrollers in its class.
APPLICATIONS
PIC16F877A perfectly fits many uses, from automotive industries and controlling home appliances to industrial instruments, remote sensors, electrical door locks and safety devices. It is also ideal for smart cards as well as for battery supplied devices because of its low consumption.
EEPROM memory makes it easier to apply microcontrollers to devices where permanent storage of various parameters is needed (codes for transmitters, motor speed, receiver frequencies, etc.). Low cost, low consumption, easy handling and flexibility make PIC16F877A applicable even in areas where microcontrollers had not previously been considered (example: timer functions, interface replacement in larger systems, coprocessor applications, etc.).
System Programmability of this chip (along with using only two pins in data transfer) makes possible the flexibility of a product, after assembling and testing have been completed. This capability can be used to create assembly-line production, to store calibration data available only after final testing, or it can be used to improve programs on finished products.
CLOCK / INSTRUCTION CYCLE
Clock is microcontroller's main starter, and is obtained from an external component called an "oscillator". If we want to compare a microcontroller with a time clock, our "clock" would then be a ticking sound we hear from the time clock. In that case, oscillator could be compared to a spring that is wound so time clock can run. Execution of instruction starts by calling an instruction that is next in string. Instruction is called from program memory on every Q1 and is written in instruction register on Q4. Decoding and execution of instruction are done between the next Q1 and Q4 cycles. On the following diagram we can see the relationship between instruction cycle and clock of the oscillator (OSC1) as well as that of internal clocks Q1-Q4. Program counter (PC) holds information about the address of the next instruction.
24
Fig 3.2 Clock/Instruction Cycle
PIPELINING
Instruction cycle consists of cycles Q1, Q2, Q3 and Q4. Cycles of calling and executing instructions are connected in such a way that in order to make a call, one instruction cycle is needed, and one more is needed for decoding and execution. However, due to pipelining, each instruction is effectively executed in one cycle. If instruction causes a change on program counter, and PC doesn't point to the following but to some other address (which can be the case with jumps or with calling subprograms), two cycles are needed for executing an instruction. This is so because instruction must be processed again, but this time from the right address. Cycle of calling begins with Q1 clock, by writing into instruction register (IR). Decoding and executing begins with Q2, Q3 and Q4 clocks.
Fig 3.3 Instruction Pipeline Flow
TCY0 reads in instruction MOVLW 55h (it doesn't matter to us what instruction was executed, because there is no rectangle pictured on the bottom).TCY1 executes instruction MOVLW 55h and reads in MOVWF PORTB.TCY2 executes MOVWF PORTB and reads in CALL SUB_1.TCY3 executes a call of a subprogram CALL SUB_1, and reads in instruction BSF PORTA,
25
BIT3. As this instruction is not the one we need, or is not the first instruction of a subprogram SUB_1 whose execution is next in order, instruction must be read in again. This is a good example of an instruction needing more than one cycle. TCY4 instruction cycle is totally used up for reading in the first instruction from a subprogram at address SUB_1.TCY5 executes the first instruction from a subprogram SUB_1 and reads in the next one.
PIN DESCRIPTION
PIC16F877A has a total of 40 pins. It is most frequently found in a DIP40 type of case but can also be found in SMD case which is smaller from a DIP. DIP is an abbreviation for Dual In Package. SMD is an abbreviation for Surface Mount Devices suggesting that holes for pins to go through when mounting aren't necessary in soldering this type of a component.
Fig.3.4 Pin Diagram of PIC16F877A
Pins on PIC16F877A microcontroller have the following meaning:
There are 40 pins on PIC16F877A. Most of them can be used as an IO pin. Others are already for specific functions. These are the pin functions.1. MCLR – to reset the PIC2. RA0 – port A pin 03. RA1 – port A pin 14. RA2 – port A pin 25. RA3 – port A pin 3
26
6. RA4 – port A pin 47. RA5 – port A pin 58. RE0 – port E pin 09. RE1 - port E pin 110. RE2 – port E pin 211. VDD – power supply12. VSS – ground13. OSC1 – connect to oscillator14. OSC2 – connect to oscillator15. RC0 – port C pin 016. RC1 – port C pin 017. RC2 – port C pin 018. RC3 – port C pin 019. RD0 - port D pin 020. RD1 - port D pin 121. RD2 - port D pin 222. RD3 - port D pin 323. RC4 - port C pin 424. RC5 - port C pin 525. RC6 - port C pin 626. RC7 - port C pin 727. RD4 - port D pin 428. RD5 - port D pin 529. RD6 - port D pin 630. RD7 - port D pin 731. VSS - ground32. VDD – power supply33. RB0 - port B pin 034. RB1 - port B pin 135. RB2 - port B pin 236. RB3 - port B pin 337. RB4 - port B pin 438. RB5 - port B pin 539. RB6 - port B pin 640. RB7 - port B pin 7
By utilizing all of this pin so many application can be done such as:1. LCD – connect to Port B pin.2. LED – connect to any pin declared as output.3. Relay and Motor - connect to any pin declared as output.4. External EEPROM – connect to I2C interface pin – RC3 and RC4 (SCL and SDA) 5. LDR, Potentiometer and sensor – connect to analogue input pin such as RA0.6. GSM modem dial up modem – connect to RC6 and RC7 – the serial communication interface using RS232 protocol.
27
For more detail function for each specific pin please refer to the device datasheet from Microchip.
CLOCK GENERATOR – OSCILLATOR
Oscillator circuit is used for providing a microcontroller with a clock. Clock is needed so that microcontroller could execute a program or program instructions.
TYPES OF OSCILLATORS
PIC16F877A can work with four different configurations of an oscillator. Since configurations with crystal oscillator and resistor-capacitor (RC) are the ones that are used most frequently, these are the only ones we will mention here. Microcontroller type with a crystal oscillator has in its designation XT, and a microcontroller with resistor-capacitor pair has a designation RC. This is important because you need to mention the type of oscillator when buying a microcontroller.
XT OSCILLATOR
Crystal oscillator is kept in metal housing with two pins where you have written down the frequency at which crystal oscillates. One ceramic capacitor of 30pF whose other end is connected to the ground needs to be connected with each pin.
Oscillator and capacitors can be packed in joint case with three pins. Such element is called ceramic resonator and is represented in charts like the one below. Center pins of the element is the ground, while end pins are connected with OSC1 and OSC2 pins on the microcontroller. When designing a device, the rule is to place an oscillator nearer a microcontroller, so as to avoid any interference on lines on which microcontroller is receiving a clock.RC Oscillator.
In applications where great time precision is not necessary, RC oscillator offers additional savings during purchase. Resonant frequency of RC oscillator depends on supply voltage rate, resistance R, capacity C and working temperature. It should be mentioned here that resonant frequency is also influenced by normal variations in process parameters, by tolerance of external R and C components, etc.
Above diagram shows how RC oscillator is connected with PIC16F877A. With value of resistor R being below 2.2k, oscillator can become unstable, or it can even stop the oscillation. With very high value of R (ex.1M) oscillator becomes very sensitive to noise and humidity. It is recommended that value of resistor R should be between 3 and 100k. Even though oscillator will work without an external capacitor (C=0pF), capacitor above 20pF should still be used for noise and stability. No matter which oscillator is being used, in order to get a clock that microcontroller works upon, a clock of the oscillator must be divided by 4. Oscillator clock divided by 4 can also be obtained on OSC2/CLKOUT pin, and can be used for testing or synchronizing other logical circuits.
28
Fig 3.5 Clock and Instruction Cycles
Following a supply, oscillator starts oscillating. Oscillation at first has an unstable period and amplitude, but after some period of time it becomes stabilized.
To prevent such inaccurate clock from influencing microcontroller's performance, we need to keep the microcontroller in reset state during stabilization of oscillator's clock. Diagram above shows a typical shape of a signal which microcontroller gets from the quartz oscillator.
RESET
Reset is used for putting the microcontroller into a 'known' condition. That practically means that microcontroller can behave rather inaccurately under certain undesirable conditions. In order to continue its proper functioning it has to be reset, meaning all registers would be placed in a starting position. Reset is not only used when microcontroller doesn't behave the way we want it to, but can also be used when trying out a device as an interrupt in program execution, or to get a microcontroller ready when loading a program.
In order to prevent from bringing a logical zero to MCLR pin accidentally (line above it means that reset is activated by a logical zero), MCLR has to be connected via resistor to the positive supply pole. Resistor should be between 5 and 10K. This kind of resistor, whose function is to keep a certain line on a logical one as a preventive, is called a pull up.
Microcontroller PIC16F877A knows several sources of resets:
a) Reset during power on, POR (Power-On Reset)b) Reset during regular work by bringing logical zero to MCLR microcontroller's pin.c) Reset during SLEEP regimed) Reset at watchdog timer (WDT) overflowe) Reset during at WDT overflow during SLEEP work regime.
The most important reset sources are a) and b). The first one occurs each time a power supply is brought to the microcontroller and serves to bring all registers to a starting position initial state. The second one is a product of purposeful bringing in of a logical zero to MCLR pin during normal operation of the microcontroller. This second one is often used in program development.
During a reset, RAM memory locations are not being reset. They are unknown during a power up and are not changed at any reset. Unlike these, SFR registers are reset to a starting position
29
initial state. One of the most important effects of a reset is setting a program counter (PC) to zero (0000h) , which enables the program to start executing from the first written instruction.
Reset at supply voltage drop below the permissible (Brown-out Reset) Impulse for resetting during voltage voltage-up is generated by microcontroller itself when it detects an increase in supply Vdd (in a range from 1.2V to 1.8V). That impulse lasts 72ms which is enough time for an oscillator to get stabilized. These 72ms are provided by an internal PWRT timer which has its own RC oscillator. Microcontroller is in a reset mode as long as PWRT is active. However, as device is working, problem arises when supply doesn't drop to zero but falls below the limit that guarantees microcontroller's proper functioning. This is a likely case in practice, especially in industrial environment where disturbances and instability of supply are an everyday occurrence. To solve this problem we need to make sure that microcontroller is in a reset state each time supply falls below the approved limit.
Fig.3.6 Voltage Drop Below the Proper Level
If, according to electrical specification, internal reset circuit of a microcontroller can not satisfy the needs, special electronic components can be used which are capable of generating the desired reset signal. Beside this function, they can also function in watching over supply voltage. If voltage drops below specified level, a logical zero would appear on MCLR pin which holds the microcontroller in reset state until voltage is not within limits that guarantee accurate performance.
CENTRAL PROCESSING UNIT
Central processing unit (CPU) is the brain of a microcontroller. This part is responsible for finding and fetching the right instruction which needs to be executed, for decoding that instruction, and finally for its execution. Central processing unit connects all parts of the microcontroller into one whole. Surely, its most important function is to decode program instructions.
When programmer writes a program, instructions have a clear form like MOVLW 0x20. However, in order for a microcontroller to understand that, this 'letter' form of an instruction must be translated into a series of zeros and ones which is called an 'opcode'. This transition from a letter to
30
binary form is done by translators such as assembler translator (also known as an assembler). Instruction thus fetched from program memory must be decoded by a central processing unit. We can then select from the table of all the instructions a set of actions which execute a assigned task defined by instruction. As instructions may within themselves contain assignments which require different transfers of data from one memory into another, from memory onto ports, or some other calculations, CPU must be connected with all parts of the microcontroller. This is made possible through a data bus and an address bus.
Arithmetic logic unit is responsible for performing operations of adding, subtracting, moving (left or right within a register) and logic operations. Moving data inside a register is also known as 'shifting'. PIC16F877A contains an 8-bit arithmetic logic unit and 8-bit work registers.
Fig 3.7 STATUS Register format
In instructions with two operands, ordinarily one operand is in work register (W register), and the other is one of the registers or a constant. By operand we mean the contents on which some operation is being done, and a register is any one of the GPR or SFR registers. GPR is an abbreviation for 'General Purposes Registers', and SFR for 'Special Function Registers'. In instructions with one operand, an operand is either W register or one of the registers. As an addition in doing operations in arithmetic and logic, ALU controls status bits (bits found in STATUS register). Execution of some instructions affects status bits, which depends on the result itself. Depending on which instruction is being executed, ALU can affect values of Carry (C), Digit Carry (DC), and Zero (Z) bits in STATUS register.
PORTS
Term "port" refers to a group of pins on a microcontroller which can be accessed simultaneously, or on which we can set the desired combination of zeros and ones, or read from them an existing status. Physically, port is a register inside a microcontroller which is connected by wires to the pins of a microcontroller. Microcontroller uses them in order to monitor or control other components or devices. Due to functionality, some pins have twofold roles like PA4/TOCKI for instance, which is in the same time the fourth bit of port A and an external input for free-run counter. Selection of one of these two pin functions is done in one of the configuration registers. An illustration of this is the fifth bit T0CS in OPTION register. By selecting one of the functions the other one is disabled.
31
All port pins can be designated as input or output, according to the needs of a device that's
being developed. In order to define a pin as input or output pin, the right combination of
zeros and ones must be written in TRIS register. If the appropriate bit of TRIS register
contains logical "1", then that pin is an input pin, and if the opposite is true, it's an output
pin. Every port has its proper TRIS register. Thus, port A has TRISA, and port B has
TRISB. Pin direction can be changed during the course of work which is particularly fitting
for one-line communication where data flow constantly changes direction. PORTA and
PORTB state registers are located in bank 0, while TRISA and TRISB pin direction
registers are located in bank 1.
MEMORY ORGANIZATION
PIC16F877A has two separate memory blocks, one for data and the other for program.
EEPROM memory with GPR and SFR registers in RAM memory make up the data block,
while FLASH memory makes up the program block.
PROGRAM MEMORY
Program memory has been carried out in FLASH technology which makes it possible to
program a microcontroller many times before it's installed into a device, and even after its
installment if eventual changes in program or process parameters should occur. The size of
program memory is 1024 locations with 14 bits width where locations zero and four are
reserved for reset and interrupt vector.
DATA MEMORY
Data memory consists of EEPROM and RAM memories. EEPROM memory consists of
256 eight bit locations whose contents is not lost during loosing of power supply.
EEPROM is not directly addressable, but is accessed indirectly through EEADR and
EEDATA registers. As EEPROM memory usually serves for storing important parameters
(for example, of a given temperature in temperature regulators) , there is a strict procedure
for writing in EEPROM which must be followed in order to avoid accidental writing. RAM
memory for data occupies space on a memory map from location 0x0C to 0x4F which
32
comes to 68 locations. Locations of RAM memory are also called GPR registers which is
an abbreviation for General Purpose Registers. GPR registers can be accessed regardless
of which bank is selected at the moment.
MEMORY BANKS
Beside this 'length' division to SFR and GPR registers, memory map is also divided in
'width' (see preceding map) to two areas called 'banks'. Selecting one of the banks is done
via RP0 bit in STATUS register.
EXAMPLE:
bcf STATUS, RP0
Instruction BCF clears bit RP0 (RP0=0) in STATUS register and thus sets up bank 0.
bsf STATUS, RP0
Instruction BSF sets the bit RP0 (RP0=1) in STATUS register and thus sets up bank1.
It is useful to consider what would happen if the wrong bank was selected. Let's assume
that we have selected bank 0 at the beginning of the program, and that we now want to
write to certain register located in bank 1, say TRISB. Although we specified the name of
the register TRISB, data will be actually stored to a bank 0 register at the appropriate
address, which is PORTB in our example.
BANK0 macro
Bcf STATUS, RP0 ;Select memory bank 0
endm
BANK1 macro
Bsf STATUS, RP0 ;Select memory bank 1
endm
Bank selection can be also made via directive banksel after which name of the register
to be accessed is specified. In this manner, there is no need to memorize which register is
in which bank.
PROGRAM COUNTER
33
Program counter (PC) is a 13-bit register that contains the address of the instruction being
executed. It is physically carried out as a combination of a 5-bit register PCLATH for the
five higher bits of the address, and the 8-bit register PCL for the lower 8 bits of the address.
By its incrementing or change (i.e. in case of jumps) microcontroller executes program
instructions step-by-step.
STACK
PIC16F877A has a 13-bit stack with 8 levels, or in other words, a group of 8 memory
locations, 13 bits wide, with special purpose. Its basic role is to keep the value of program
counter after a jump from the main program to an address of a subprogram . In order for a
program to know how to go back to the point where it started from, it has to return the
value of a program counter from a stack. When moving from a program to a subprogram,
program counter is being pushed onto a stack (example of this is CALL instruction). When
executing instructions such as RETURN, RETLW or RETFIE which were executed at the
end of a subprogram, program counter was taken from a stack so that program could
continue where was stopped before it was interrupted. These operations of placing on and
taking off from a program counter stack are called PUSH and POP, and are named
according to similar instructions on some bigger microcontrollers.
IN SYSTEM PROGRAMMING
In order to program a program memory, microcontroller must be set to special working
mode by bringing up MCLR pin to 13.5V, and supply voltage Vdd has to be stabilized
between 4.5V to 5.5V. Program memory can be programmed serially using two 'data/clock'
pins which must previously be separated from device lines, so that errors wouldn't come up
during programming.
34
Fig 3.8 Direct addressing format
INDIRECT ADDRESSING
Indirect unlike direct addressing does not take an address from an instruction but
derives it from IRP bit of STATUS and FSR registers. Addressed location is accessed via
INDF register which in fact holds the address indicated by a FSR. In other words, any
instruction which uses INDF as its register in reality accesses data indicated by a FSR
register. Let's say, for instance, that one general purpose register (GPR) at address 0Fh
contains a value of 20. By writing a value of 0Fh in FSR register we will get a register
indicator at address 0Fh, and by reading from INDF register, we will get a value of 20,
which means that we have read from the first register its value without accessing it directly
(but via FSR and INDF). It appears that this type of addressing does not have any
advantages over direct addressing, but certain needs do exist during programming which
can be solved smoothly only through indirect addressing.
35
Indirect addressing is very convenient for manipulating data arrays located in GPR
registers. In this case, it is necessary to initialize FSR register with a starting address of the
array, and the rest of the data can be accessed by incrementing the FSR register.
Fig 3.9 Indirect addressing format
Such examples include sending a set of data via serial communication, working with
buffers and indicators (which will be discussed further in a chapter with examples), or
erasing a part of RAM memory (16 locations) as in the following instance.
Reading data from INDF register when the contents of FSR register is equal to zero returns
the value of zero, and writing to it results in NOP operation (no operation).
INTERRUPTS
Interrupts are a mechanism of a microcontroller which enables it to respond to some
events at the moment they occur, regardless of what microcontroller is doing at the time.
This is a very important part, because it provides connection between a microcontroller and
environment which surrounds it. Generally, each interrupt changes the program flow,
interrupts it and after executing an interrupt subprogram (interrupt routine) it continues
from that same point on.
36
Control register of an interrupt is called INTCON and can be accessed regardless of
the bank selected. Its role is to allow or disallowed interrupts, and in case they are not
allowed, it registers single interrupt requests through its own bits.
INTCON REGISTER
Fig 3.10 INTCON register Format
Bit 7 GIE (Global Interrupt Enable bit) Bit which enables or disables all interrupts.
1 = all interrupts are enabled
0 = all interrupts are disabled
Bit 6 EEIE (EEPROM Write Complete Interrupt Enable bit) Bit which enables an interrupt
at the end of a writing routine to EEPROM
1 = interrupt enabled
0 = interrupt disabled
If EEIE and EEIF (which is in EECON1 register) are set simultaneously , an interrupt will
occur.
bit 5 T0IE (TMR0 Overflow Interrupt Enable bit) Bit which enables interrupts during
counter TMR0 overflow.
1 = interrupt enabled
0 = interrupt disabled
If T0IE and T0IF are set simultaneously, interrupt will occur.
bit 4 INTE (INT External Interrupt Enable bit) Bit which enables external interrupt from
pin RB0/INT.
1 = external interrupt enabled
37
0 = external interrupt disabled
If INTE and INTF are set simultaneously, an interrupt will occur.
bit 3 RBIE (RB port change Interrupt Enable bit) Enables interrupts to occur at the change
of status of pins 4, 5, 6, and 7 of port B.
1 = enables interrupts at the change of status
0 =interrupts disabled at the change of status
If RBIE and RBIF are simultaneously set, an interrupt will occur.
bit 2 T0IF (TMR0 Overflow Interrupt Flag bit) Overflow of counter TMR0.
1 = counter changed its status from FFh to 00h
0 = overflow did not occur
Bit must be cleared in program in order for an interrupt to be detected.
bit 1 INTF (INT External Interrupt Flag bit) External interrupt occurred.
1 = interrupt occurred
0 = interrupt did not occur
If a rising or falling edge was detected on pin RB0/INT, (which is defined with bit
INTEDG in OPTION register), bit INTF is set.
bit 0 RBIF (RB Port Change Interrupt Flag bit) Bit which informs about changes on pins
4, 5, 6 and 7 of port B.
1 = at least one pin has changed its status
0 = no change occurred on any of the pins
Bit has to be cleared in an interrupt subroutine to be able to detect further interrupts.
PIC16F877A has four interrupt sources:
1. Termination of writing data to EEPROM
2. TMR0 interrupt caused by timer overflow.
3. Interrupt during alteration on RB4, RB5, RB6 and RB7 pins of port B.
4. External interrupt from RB0/INT pin of microcontroller
Generally speaking, each interrupt source has two bits joined to it. One enables
interrupts, and the other detects when interrupts occur. There is one common bit called GIE
38
which can be used to disallow or enable all interrupts simultaneously. This bit is very
useful when writing a program because it allows for all interrupts to be disabled for a
period of time, so that execution of some important part of a program would not be
interrupted. When instruction which resets GIE bit was executed (GIE=0, all interrupts
disallowed), any interrupt that remained unsolved should be ignored.
Interrupts which remained unsolved and were ignored, are processed when GIE bit
(GIE=1, all interrupts allowed) would be cleared. When interrupt was answered, GIE bit
was cleared so that any additional interrupts would be disabled, return address was pushed
onto stack and address 0004h was written in program counter - only after this does replying
to an interrupt begin! After interrupt is processed, bit whose setting caused an interrupt
must be cleared, or interrupt routine would automatically be processed over again during a
return to the main program.
KEEPING THE CONTENTS OF IMPORTANT REGISTERS
Only return value of program counter is stored on a stack during an interrupt (by
return value of program counter we mean the address of the instruction which was to be
executed, but wasn't because interrupt occurred). Keeping only the value of program
counter is often not enough. Some registers which are already in use in the main program
can also be in use in interrupt routine. If they were not retained, main program would
during a return from an interrupt routine get completely different values in those registers,
which would cause an error in the program. One example for such a case is contents of the
work register W. If we suppose that main program was using work register W for some of
its operations, and if it had stored in it some value that's important for the following
instruction, then an interrupt which occurs before that instruction would change the value
of work register W which would directly be influenced the main program.
Procedure of recording important registers before going to an interrupt routine is
called PUSH, while the procedure which brings recorded values back, is called POP.
PUSH and POP are instructions with some other microcontrollers (Intel), but are so widely
accepted that a whole operation is named after them. PIC16F877A does not have
instructions like PUSH and POP, and they have to be programmed.
39
Fig 3.11 Common error: saving the value wasn't done before entering the interrupt routine
Due to simplicity and frequent usage, these parts of the program can be made as macros.
The concept of a Macro is explained in "Program assembly language". In the following
example, contents of W and STATUS registers are stored in W_TEMP and
STATUS_TEMP variables prior to interrupt routine. At the beginning of PUSH routine we
need to check presently selected bank because W_TEMP and STATUS_TEMP are found
in bank 0. For exchange of data between these registers, SWAPF instruction is used instead
of MOVF because it does not affect the STATUS register bits.
Example is an assembler program for following steps:
1. Testing the current bank
2. Storing register regardless of the current bank
3. Storing STATUS register in bank 0.
4. Executing interrupt routine for interrupt processing (ISR)
5. Restores STATUS register
40
6. Restores W register
If there are some more variables or registers that need to be stored, then they need to
be kept after storing STATUS register (step 3), and brought back before STATUS register
is restored (step 5). The same example can be carried out using macros, thus getting a more
legible program. Macros that are already defined can be used for writing new macros.
Macros BANK1 and BANK0 which are explained in "Memory organization" chapter are
used with macros 'push' and 'pop'.
FREE-RUN TIMER TMR0
Timers are usually the most complicated parts of a microcontroller, so it is necessary to set
aside more time for understanding them thoroughly. Through their application it is possible
to establish relations between a real dimension such as "time" and a variable which
represents status of a timer within a microcontroller. Physically, timer is a register whose
value is continually increasing to 255, and then it starts all over again: 0, 1, 2, 3,
4...255....0,1, 2, 3......etc.
This incrementing is done in the background of everything a microcontroller does. It is
up to programmer to think up a way how he will take advantage of this characteristic for
his needs. One of the ways is increasing some variable on each timer overflow. If we know
how much time a timer needs to make one complete round, then multiplying the value of a
variable by that time will yield the total amount of elapsed time.
EEPROM DATA MEMORY
PIC16F877A has 256 bytes of EEPROM memory locations on addresses from 00h to 63h
that can be written to or read from. The most important characteristic of this memory is
that it does not lose its contents with the loss of power supply. Data can be retained in
EEPROM without power supply for up to 40 years (as manufacturer of PIC16F877A
microcontroller states), and up to 1 million cycles of writing can be executed.
41
In practice, EEPROM memory is used for storing important data or process
parameters. One such parameter is a given temperature, assigned when setting up a
temperature regulator to some process. If that data wasn't retained, it would be necessary to
adjust a given temperature after each loss of supply. Since this is very impractical (and
even dangerous), manufacturers of microcontrollers have began installing one smaller type
of EEPROM memory.
MODULE 2
4.2 RFID MODULE
Radio-frequency identification (RFID) is an automatic identification method,
relying on storing and remotely retrieving data using devices called RFID tags or
42
transponders. The technology requires some extent of cooperation of an RFID reader and
an RFID tag.
An RFID tag is an object that can be applied to or incorporated into a product,
animal, or person for the purpose of identification and tracking using radio waves. Some
tags can be read from several meters away and beyond the line of sight of the reader.
Most RFID tags contain at least two parts. One is an integrated circuit for storing
and processing information, modulating and demodulating a radio-frequency (RF) signal,
and other specialized functions. The second is an antenna for receiving and transmitting the
signal.
There are generally two types of RFID tags:
Active RFID tags, which contain a battery, and
Passive RFID tags, which have no battery.
Future Chip less RFID allows for discrete identification of tags without an integrated
circuit, thereby allowing tags to be printed directly onto assets at a lower cost than
traditional tags.
VARIETIES OF RFID TAGS
RFID tags come in three general varieties passive, active, or semi-passive (also
known as battery-assisted or semi-active) and beacon types. Passive tags require no internal
power source, thus being pure passive devices (they are only active when a reader is nearby
to power them by wireless illumination), whereas semi-passive and active tags require a
power source, usually a small battery. Beacon tags transmit autonomously with a certain
blink pattern and do not respond to interrogation.
Passive
43
Passive RFID tags have no internal power supply. The minute electrical current
induced in the antenna by the incoming radio frequency signal provides just enough power
for the CMOS integrated circuit in the tag to power up and transmit a response. Most
passive tags signal by backscattering the carrier wave from the reader. This means that the
antenna has to be designed both to collect power from the incoming signal and also to
transmit the outbound backscatter signal. The response of a passive RFID tag is not
necessarily just an ID number; the tag chip can contain non-volatile data, possibly writable
EEPROM for storing data.
Active
Unlike passive RFID tags, active RFID tags have their own internal power source,
which is used to power the integrated circuits and to broadcast the response signal to the
reader. Communications from active tags to readers is typically much more reliable (i.e.
fewer errors) than those from passive tags due to the ability for active tags to conduct a
"session" with a reader.
Active tags, due to their onboard power supply, also may transmit at higher power
levels than passive tags, allowing them to be more robust in "RF challenged" environments
with humidity and spray or with RF-dampening targets (including humans and cattle,
which contain mostly water), reflective targets from metal (shipping containers, vehicles),
or at longer distances. In turn, active tags can be larger (due to battery size) and more
expensive to manufacture (due to price of the battery). However, the potential shelf life of
an active tag can be many years.
Many active tags today have operational ranges of hundreds of meters, and a battery
life from several months to 10 years. Active tags may include larger memories than passive
tags, and may include the ability to store additional information received from the reader.
Special active RFID tags may include specialized sensors. For example, a
temperature sensor can be used to record the temperature profile during the transportation
and storage of perishable goods. Other sensor types used include humidity, shock/vibration,
light, nuclear radiation, pressure and concentrations of gases such as ethylene.
The Filter circuit is often fixed after the Regulator circuit. Capacitor is most often
used as filter. The principle of the capacitor is to charge and discharge. It charges during
the positive half cycle of the AC voltage and discharges during the negative half cycle. So
it allows only AC voltage and does not allow the DC voltage. This filter is fixed after the
Regulator circuit to filter any of the possibly found ripples in the output received finally.
Here we used 0.1µF capacitor. The output at this stage is 5V and is given to the
Microcontroller. The output voltage overshoots when the load is removed or a short clears.
When the load is removing from a switching mode power supply with a LC low-pass
output filter, the only thing the control loop can do is stop the switching action so no more
energy is taken from the source. The energy that is stored in the output filter inductor is
dumped into the output capacitor causing a voltage overshoot.
The magnitude of the overshoot is the vector sum of two orthogonal voltages, the
output voltage before the load is removed and the current through the inductor times the
characteristic impedance of the output filter, Zo = (L/C)^1/2. This can be derived from
conservation of energy considerations.
The two energies are equal when the load is removed, since the load is no longer
taking energy from the system. Equating the two energies, substituting zero current for the
final inductor current, then the solution for the final voltage Vf is:
This is the orthogonal vector sum of the output voltage and the load current times
the characteristic impedance and is illustrated in Figure .The problem becomes worse if the
current in the inductor is established by a short circuit on the output and the short circuit
clears. In this case, the initial voltage is zero (short circuit) and the overshoot is I*Zo,
where I can be very large, resulting in a ruinous overshoot.
4.4 UART
52
SERIAL COMMUNICATION
A serial port sends and receives data one bit at a time over one wire. While it takes
eight times as long as to transfer each byte of data this way, only a few wires are required.
In fact, two-way (full duplex) communications is possible with only three separate wires-
one to send, one to receive, and a common signal ground wire.
Bi-directional communications
Communicating by wires
The Parity Bit
Cable lengths
MAX-232C
DCE And DTE devices
Synchronous and Asynchronous Communications
Bi-directional Communications
The serial port on your PC is a full-duplex device meaning that it can send and
receive data at the same time. In order to be able to do this, it uses separate lines for
transmitting and receiving data. Some types of serial devices support only one-way
communications and therefore use only two-wires in the cable – the transmit line and the
signal ground.
Communicating by bits
Once the start bit has been sent, the transmitter sends the actual data bits. There may
either be 5,6,7, or 8 data bits, depending on the number you have selected. Both receiver
and the transmitter must agree on the number of data bits, as well as the baud rate. Almost
all devices transmit data using either 7 or 8 data bits. Notice that when only 7 data bits are
employed, you cannot send ASCII values greater than 127. Likewise, using 5 bits limits the
highest possible value to 31. After the data has been transmitted, a stop bit is sent. A stop
bit has a value of 1- or a mark state- and it can be detected correctly even if the previous
data bit also had a value of 1. This is accomplished by the stop bit’s duration.
The Parity Bit
53
Besides the synchronization provided by the use of start and stop bits, an additional
bit called a parity bit may optionally be transmitted along with the data. A parity bit affords
a small amount of error checking, to help detect data corruption that might occur during
transmission.
Cable Lengths
The MAX-232 standard imposes a cable length limit of 50 feet. You can usually
ignore this “standard”, since a cable can be as long as 10000 feet at baud rates up to 19200
if you use a high quality, well shielded cable. The external environment has a large effect
on lengths for unshielded cables.
MAX232 (Voltage Converter)
Since the RS232 is not compatible with today microprocessors and micro
controller, we need line driver to convert the RS232 signals to TTL voltage levels that will
be acceptable to the 8051’s TXD and RXD pins. One example of such a converter is MAX
232 from maxim corp. The MAX 232 converts from RS232 voltage levels to TTL voltage
levels, and vice versa. One advantage of MAX232 chip is that it uses a +5V power source,
which is the same as the source voltage for the at89s52 micro controller. In other words,
with a single +5v power supply we can power both the PIC and MAX 232, with no need of
for the dual power supplies that are common in many older systems. The MAX 232
requires four capacitors ranging from 1 to 22 microfarad. The most widely used value for
this capacitor is 22microfarad.
The MAX232 is a dual driver/receiver that includes a capacitive voltage generator
to supply TIA/EIA-232-Fvoltage levels from a single 5-V supply. Each receiver converts
TIA/EIA-232-F inputs to 5-V TTL/CMOS levels. These receivers have a typical threshold
of 1.3 V, a typical hysterias is of 0.5 V, and can accept ±30-V inputs. Each driver converts
TTL/CMOS input levels into TIA/EIA-232-F levels.
PIN DIAGRAM OF MAX232
54
Fig 4.5 max232 pin diagram
DCE and DTE devices
Two terms you should be familiar with are DTE and DCE. DTE stands for Data
Terminal Equipment, and DCE stands for Data Communication Equipment. These terms
are used to indicate the pin-out for the connectors on a device and the direction of the
signals on the pins. Your computer is a DTE device, while most other devices are usually
DCE devices. If you have trouble keeping the two straight then replace the term “DTE
device” with your PC and the term DCE device with “remote Device” in the following
discussion. The RS-232 standard states that DTE devices use a 25-pin male connector, and
DCE devices use a 25-pin female connector. You can therefore connect a DTE device to a
DCE using a straight pin-for-pin connection. However, to connect two like devices, you
must instead use a null modem cable. Null modem cables cross the transmit and receive
lines in the cable.
The DTE device puts this line in a mark condition to tell the remote device that it
is ready and able to receive data. If the DTE device is not able to receive data (typically
because its receive buffer is almost full), it will put this line in the space condition as a
signal to the DCE to stop sending data. When the DTE device is ready to receive more data
it will place this line back in the mark condition. The complement of the RTS wire is CTS,
which stands for Clear to Send. The DCE device puts this line in a mark condition to tell
55
the DTE device that it is ready to receive the data. Likewise, if the DCE device is unable to
receive data, it will place this line in the space condition. Together, these two lines make up
what is called RTS/CTS or “hardware” flow control. The software wedge supports this type
of flow control as well as Xon/Xoff or “software” flow control. Software flow control uses
special control characters transmitted from one device to another to tell the other device to
stop or start sending data. With software flow control the RTS and CTS lines are not used.
DTR stands for Data Terminal Ready. Its intended function is very similar to the
RTS line. DSR (Data Set Ready) is the companion to DTR in the same way that CTS is to
RTS. Some serial devices use DTR and DSR as signals to simplify confirm that a device is
connected and turned on. The software wedge sets DTR to the mark state when the serial
port is opened and leaves it in that state until the port is closed. The DTR and DSR lines
were originally designed to provide an alternate method of hardware handshaking. It would
be pointless to use both RTS/CTS and DTR/DSR for flow control signals at the same time.
Because of this DTR and DSR are rarely used for flow control.
Synchronous and Asynchronous Communications
There are two basic types of serial communications, synchronous and
asynchronous. With synchronous communications, the two devices initially synchronize
themselves to each other, and then continually send characters to stay in sync. Even when
the data is not really being sent, a constant flow of bits allows each device to know where
the other is at any given time. That is, each character that is sent is either actual data or an
idle character. Synchronous communications allows faster data transfer rates than
asynchronous methods, because additional bits to mark the beginning and end of each data
byte are not required. The serial ports on IBM style PCs are asynchronous devices and
therefore only support asynchronous serial communications. Asynchronous means no
“synchronization”, and thus does not require sending and receiving idle characters.
However, the beginning and end of each byte of data must be identified by start and stop
bits. The start bit indicates when the data byte is about to begin and the stop bit signals
when it ends.
4.5 LCD DISPLAY
56
Liquid crystal display (LCD) has material which combines the properties of both
liquid and crystals. They have a temperature range within which the molecules are almost
as mobile as they would be in a liquid, but are grouped together in an order form similar to
a crystal.
LCD DISPLAY
Fig 4.6 lcd module
More microcontroller devices are using 'smart LCD' displays to output visual
information. The following discussion covers the connection of a Hitachi LCD display to a
PIC microcontroller. LCD displays designed around Hitachi's LCD HD44780 module, are
inexpensive, easy to use, and it is even possible to produce a readout using the 8 x 80 pixels
of the display. Hitachi LCD displays have a standard ASCII set of characters plus Japanese,
Greek and mathematical symbols.
HARDWARE DIAGRAM
57
Fig 4.7 lcd pin configuration
For an 8-bit data bus, the display requires a +5V supply plus 11 I/O lines. For a 4-
bit data bus it only requires the supply lines plus seven extra lines. When the LCD display
is not enabled, data lines are tri-state which means they are in a state of high impedance (as
though they are disconnected) and this means they do not interfere with the operation of the
microcontroller when the display is not being addressed. The LCD also requires 3 "control"
lines from the microcontroller.
When the LCD is initialized, it is ready to continue receiving data or instructions. If
it receives a character, it will write it on the display and move the cursor one space to the
right. The Cursor marks the next location where a character will be written. When we want
to write a string of characters, first we need to set up the starting address, and then send one
character at a time.
58
Pins description
Table 4.3 pins for lcd
Logic status on control lines
RS (Command / Data):
This bit is to specify weather received byte is command or data. So that LCD can recognize the operation to be performed based on the bit status.
RS = 0 => Command
RS = 1 => Data
RW (Read / Write)
RW bit is to specify weather controller wants READ from LCD or WRITE to LCD. The READ operation here is just ACK bit to know weather LCD is free or not.
RW = 0 => Write
RW = 1 => Read
EN (Enable LCD)
EN bit is to ENABLE or DISABLE the LCD. When ever controller wants to write some thing into LCD or READ acknowledgment from LCD it needs to enable the LCD.
59
EN = 0 => High Impedance
EN = 1 => Low Impedance
ACK (LCD Ready)
ACK bit is to acknowledge the MCU that LCD is free so that it can send new command or data to be stored in its internal Ram locations.
ACK = 1 => Not ACK
ACK = 0 => ACK
Reading data from the LCD is done in the same way, but control line R/W has to
be high. When we send a high to the LCD, it will reset and wait for instructions. Typical
instructions sent to LCD display after a reset are: turning on a display, turning on a cursor
and writing characters from left to right. Characters that can be shown on the display are
stored in data display (DD) RAM. The size of DDRAM is 80 bytes.
Before we access DD RAM after defining a special character, the program must set
the DD RAM address. Writing and reading data from any LCD memory is done from the
last address which was set up using set-address instruction. Once the address of DD RAM
is set, a new written character will be displayed at the appropriate place on the screen. Until
now we discussed the operation of writing and reading to an LCD as if it were an ordinary
memory. But this is not so. The LCD controller needs 40 to 120 microseconds (uS) for
writing and reading. Other operations can take up to 5 mS. During that time, the
microcontroller can not access the LCD, so a program needs to know when the LCD is
busy. We can solve this in two ways.One way is to check the BUSY bit found on data line
D7. This is not the best method because LCD's can get stuck, and program will then stay
forever in a loop checking the BUSY bit. The other way is to introduce a delay in the
program. The delay has to be long enough for the LCD to finish the operation in process.
At the beginning we mentioned that we needed 11 I/O lines to communicate with an
LCD. However, we can communicate with an LCD through a 4-bit data bus. Thus we can
reduce the total number of communication lines to seven.
60
4.6 Stepper Motor
A stepper motor is an electromechanical evince which converts electrical pulses
into discrete mechanical movements. The shaft or spindle of a stepper motor rotates
indiscrete step increments when electrical command pulses are applied to it in the proper
sequence. The motors rotation has several direct relationships to these applied input pulses.
The sequence of the applied pulses is directly related to the direction of motor shafts
rotation. The speed of the motor shafts rotation is directly related to the frequency of the
input pulses and the length of rotation is directly related to the number of input pulses
applied.
Stepper motors operate differently from DC brush motors, which rotate when
voltage applied to their terminals. Stepper motors, on the other hand, effectively have
multiple "toothed" electromagnets arranged around a central gear-shaped piece of iron. The
electromagnets are energized by an external control circuit, such as a microcontroller. To
make the motor shaft turn, first one electromagnet is given power, which makes the gear's
teeth magnetically attracted to the electromagnet's teeth. When the gear's teeth are thus
aligned to the first electromagnet, they are slightly offset from the next electromagnet. So
when the next electromagnet is turned on and the first is turned off, the gear rotates slightly
to align with the next one, and from there the process is repeated. Each of those slight
rotations is called a "step," with an integer number of steps making a full rotation. In that
way, the motor can be turned by a precise angle.
Stepper motors nameplates typically give only the winding current and occasionally
the voltage and winding resistance. The rated voltage will produce the rated winding current
at DC: but this is mostly a meaningless rating, as all modern drivers are current limiting and
the drive voltages greatly exceed the motor rated voltage.
A stepper's low speed torque will vary directly with current. How quickly the torque
falls off at faster speeds depends on the winding inductance and the drive circuitry it is
attached to, especially the driving voltage.
Steppers should be sized according to published torque curve, which is specified by the
manufacturer at particular drive voltages and/or using their own drive circuitry. It is not