Main Project Document Final

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 86

ABSTRACT

Supervisory Control And Data Acquisition (SCADA) is the term used for all Remote
control monitoring of status and fault conditions of an industrial system. This has become
an important factor in the successful deployment of modern industrial process solutions.

This project is mainly useful for industrial monitoring and control and
fault detection. This project uses the AVR microcontroller to acquire the data such as
temperature, voltage and current from each machine in the industry and alert the
authority when any fault occurs in the respective functionality.

By implementing this project, the authority can remotely access the machines
through GSM via simple SMS. This usage of remote connectivity helps controlling and
acknowledgment of the machine status within in seconds of any fault.

1
CHAPTER-1

OVERVIEW

2
1.1 I NTRODUCTION :

Supervisory Control And Data Acquisition is the term used for all Remote control
monitoring of status and fault conditions of an industrial system. This has become an
important factor in the successful deployment of modern industrial process solutions.

This Project presents a miniature robot which is having inbuilt voice commands.
Whatever the operation performing by the robot that we can here as voice command. The
ATMEL (Atmega8) controller is the robot's brain and controls the robot's movements. It's
usually a computer of some type which is used to store information about the robot and the
work environment and to store and execute programs which operate the robot. The control
system contains programs, data algorithms, logic analysis and various other processing
activities which enable the robot to perform.

The DC motors are used, to control the lateral movement of the system on ground.
When the system moves on the ground using the IR, the respective voice commands for robot
will be initially stored in a voice recorder (APR9600) which is interfaced to our ATmega8
microcontroller. That commands will be played according to robot directions.

3
1.2APPLICATION

1. Vehicle Tracking
2. Position Monitoring of Vehicles
3. Vehicle Control System
4. Vehicle Speed/Velocity Monitoring/Controlling

1.3 FUTURE SCOPE

1. If vehicle had an accident, then with the help of vibration sensor we can detect the
accident and can send the location to the owner, hospital and police.
2. If anybody steals our car we can easily find it around the globe.
3. We can reduce the size of the kit by using GPS+GSM on the same module.

1.4 SOFTWARE REQUIREMENTS

1. Windows Xp OS
2. AVR Studio 4.18
3. WinAVR GCC Compiler
4. AT- Prog Serial Programmer
5. GPS DATA Logger

1.5 HARDWARE REQUIREMENT

1. DC power supply 3.5v


2. ATmega162 Microcontroller
3. GPS Module
4. GSM Module
5. Buzzer,MAX-232 IC, LEDs ,Standard Cables

4
CHAPTER-2

INTRODUCTION TO EMBEDDED SYSTEM

5
2.1 INTRODUCTION TO EMBEDDED SYSTEM:

An embedded system is a special-purpose computer system designed to perform one


or a few dedicated functions, sometimes with real-time computing constraints. It is usually
embedded as part of a complete device including hardware and mechanical parts. In
contrast, a general-purpose computer, such as a personal computer, can do many different
tasks depending on programming. Embedded systems have become very important today as
they control many of the common devices we use.

Since the embedded system is dedicated to specific tasks, design engineers can
optimize it, reducing the size and cost of the product, or increasing the reliability and
performance. Some embedded systems are mass-produced, benefiting from economies of
scale.

Physically, embedded systems range from portable devices such as digital watches
and MP3 players, to large stationary installations like traffic lights, factory controllers, or the
systems controlling nuclear power plants. Complexity varies from low, with a single
microcontroller chip, to very high with multiple units, peripherals and networks mounted
inside a large chassis or enclosure.

In general, "embedded system" is not an exactly defined term, as many systems have
some element of programmability. For example, Handheld computers share some elements
with embedded systems — such as the operating systems and microprocessors which power
them — but are not truly embedded systems, because they allow different applications to be
loaded and peripherals to be connected.

An embedded system is some combination of computer hardware and software, either


fixed in capability or programmable, that is specifically designed for a particular kind of
application device. Industrial machines, automobiles, medical equipment, cameras,
household appliances, airplanes, vending machines, and toys (as well as the more obvious
cellular phone and PDA) are among the myriad possible hosts of an embedded system.
Embedded systems that are programmable are provided with a programming interface, and
embedded systems programming is a specialized occupation. Certain operating systems or
language platforms are tailored for the embedded market, such as Embedded Java and
Windows XP Embedded. However, some low-end consumer products use very inexpensive

6
microprocessors and limited storage, with the application and operating system both part of a
single program. The program is written permanently into the system's memory in this case,
rather than being loaded into RAM (random access memory), as programs on a personal
computer are.

2.2 APPLICATIONS OF EMBEDDED SYSTEM

We are living in the Embedded World. You are surrounded with many embedded
products and your daily life largely depends on the proper functioning of these gadgets.
Television, Radio, CD player of your living room, Washing Machine or Microwave Oven in
your kitchen, Card readers, Access Controllers, Palm devices of your work space enable you
to do many of your tasks very effectively. Apart from all these, many controllers embedded
in your car take care of car operations between the bumpers and most of the times you tend to
ignore all these controllers.

In recent days, you are showered with variety of information about these embedded
controllers in many places. All kinds of magazines and journals regularly dish out details
about latest technologies, new devices; fast applications which make you believe that your
basic survival is controlled by these embedded products. Now you can agree to the fact that
these embedded products have successfully invaded into our world. You must be wondering
about these embedded controllers or systems. What is this Embedded System?

The computer you use to compose your mails, or create a document or analyze the
database is known as the standard desktop computer. These desktop computers are
manufactured to serve many purposes and applications.

You need to install the relevant software to get the required processing facility. So,
these desktop computers can do many things. In contrast, embedded controllers carryout a
specific work for which they are designed. Most of the time, engineers design these
embedded controllers with a specific goal in mind. So these controllers cannot be used in any
other place.

Theoretically, an embedded controller is a combination of a piece of microprocessor based


hardware and the suitable software to undertake a specific task.

7
These days designers have many choices in microprocessors/microcontrollers.
Especially, in 8 bit and 32 bit, the available variety really may overwhelm even an
experienced designer. Selecting a right microprocessor may turn out as a most difficult first
step and it is getting complicated as new devices continue to pop-up very often. In the 8 bit
segment, the most popular and used architecture is Intel's 8031. Market acceptance of this
particular family has driven many semiconductor manufacturers to develop something new
based on this particular architecture. Even after 25 years of existence, semiconductor
manufacturers still come out with some kind of device using this 8031 core.

 Military and aerospace software applications

From in-orbit embedded systems to jumbo jets to vital battlefield networks, designers of
mission-critical aerospace and defense systems requiring real-time performance, scalability,
and high-availability facilities consistently turn to the LynxOS® RTOS and the LynxOS-178
RTOS for software certification to DO-178B.

Rich in system resources and networking services, LynxOS provides an off-the-shelf


software platform with hard real-time response backed by powerful distributed computing
(CORBA), high reliability, software certification, and long-term support options.The
LynxOS-178 RTOS for software certification, based on the RTCA DO-178B standard, assists
developers in gaining certification for their mission- and safety-critical systems. Real-time
systems programmers get a boost with LynuxWorks' DO-178B RTOS training
courses.LynxOS-178 is the first DO-178B and EUROCAE/ED-12B certifiable, POSIX®-
compatible RTOS solution.

 Communications applications

"Five-nines" availability, CompactPCI hot swap support, and hard real-time response—
LynxOS delivers on these key requirements and more for today's carrier-class systems.
Scalable kernel configurations, distributed computing capabilities, integrated
communications stacks, and fault-management facilities make LynxOS the ideal choice for
companies looking for a single operating system for all embedded telecommunications
applications—from complex central controllers to simple line/trunk cards.

8
LynuxWorksJumpstarts for Communications package enables OEMs to rapidly develop
mission-critical communications equipment, with pre-integrated, state-of-the-art, data
networking and porting software components—including source code for easy customization.

The Lynx Certifiable Stack (LCS) is a secure TCP/IP protocol stackdesigned especially
for applications where standards certification is required.

 Electronics applications and consumer devices

As the number of powerful embedded processors in consumer devices continues to


rise, the Blue Cat® Linux®operating system provides a highly reliable and royalty-free
option for systems designers.

And as the wireless appliance revolution rolls on, web-enabled navigation systems,
radios, personal communication devices, phones and PDAs all benefit from the cost-effective
dependability, proven stability and full product life-cycle support opportunities associated
with Blue Cat embedded Linux. Blue Cat has teamed up with industry leaders to make it
easier to build Linux mobile phones with Java integration.

For makers of low-cost consumer electronic devices who wish to integrate the LynxOS
real-time operating system into their products, we offer special MSRP-based pricing to
reduce royalty fees to a negligible portion of the device's MSRP.

 Industrial automation and process control software

Designers of industrial and process control systems know from experience that
LynuxWorks operating systems provide the security and reliability that their industrial
applications require.FromISO 9001 certification to fault-tolerance, POSIX conformance,
secure partitioning and high availability, we've got it all. Take advantage of our 20 years of
experience.

9
CHAPTER-3
INTRODUCTION TO MICROCONTROLLER

10
3.1 MICROCONTROLLER VERSUS MICROPROCESSOR

What is the difference between a Microprocessor and Microcontroller? By


microprocessor is meant the general purpose Microprocessors such as Intel's X86 family
(8086, 80286, 80386, 80486, and the Pentium) or Motorola's 680X0 family (68000, 68010,
68020, 68030, 68040, etc). These microprocessors contain no RAM, no ROM, and no I/O
ports on the chip itself. For this reason, they are commonly referred to as general-purpose
Microprocessors.

A system designer using a general-purpose microprocessor such as the Pentium or the


68040 must add RAM, ROM, I/O ports, and timers externally to make them functional.
Although the addition of external RAM, ROM, and I/O ports makes these systems bulkier
and much more expensive, they have the advantage of versatility such that the designer can
decide on the amount of RAM, ROM and I/O ports needed to fit the task at hand. This is not
the case with Microcontrollers.

A Microcontroller has a CPU (a microprocessor) in addition to a fixed amount of


RAM, ROM, I/O ports, and a timer all on a single chip. In other words, the processor, the

11
RAM, ROM, I/O ports and the timer are all embedded together on one chip. In many
applications, for example a TV remote control, there is no need for the computing power of a
486 or even an 8086 microprocessor. These applications most often require some I/O
operations to read signals and turn on and off certain bits.

3.2 MICROCONTROLLERS FOR EMBEDDED SYSTEMS

In the Literature discussing microprocessors, we often see the term Embedded


System. Microprocessors and Microcontrollers are widely used in embedded system
products. An embedded system product uses a microprocessor (or Microcontroller) to do one
task only. A printer is an example of embedded system since the processor inside it performs
one task only; namely getting the data and printing it. Contrast this with a Pentium based PC.
A PC can be used for any number of applications such as word processor, print-server, bank
teller terminal, Video game, network server, or Internet terminal. Software for a variety of
applications can be loaded and run. Of course the reason a pc can perform myriad tasks is
that it has RAM memory and an operating system that loads the application software into
RAM memory and lets the CPU run it.

In an Embedded system, there is only one application software that is typically


burned into ROM. An x86 PC contains or is connected to various embedded products such as
keyboard, printer, modem, disk controller, sound card, CD-ROM drives, mouse, and so on.
Each one of these peripherals has a Microcontroller inside it that performs only one task. For
example, inside every mouse there is a Microcontroller to perform the task of finding the
mouse position and sending it to the PC. Table 1-1 lists some embedded products.

3.3 Typical Microcontroller Architecture and Features

The basic internal designs of microcontrollers are pretty similar. Figure1 shows the
block diagram of a typical microcontroller. All components are connected via an internal bus
and are all integrated on one chip. The modules are connected to the outside world via I/O
pins.

12
F IG 3.3.1: B ASIC L AYOUT OF M ICROCONTROLLER

The following list contains the modules typically found in a microcontroller. You can
find a more detailed description of these components in later sections.

Processor Core: The CPU of the controller. It contains the arithmetic logic unit, the control
unit, and the registers (stack pointer, program counter, accumulator register, register file . . .).

Memory: The memory is sometimes split into program memory and data memory. In larger
controllers, a DMA controller handles data transfers between peripheral components and the
memory.

Interrupt Controller: Interrupts are useful for interrupting the normal program flow in case
of (important) external or internal events. In conjunction with sleep modes, they help to
conserve power.

Timer/Counter: Most controllers have at least one and more likely 2-3 Timer/Counters,
which can be used to timestamp events, measure intervals, or count events. Many controllers
also contain PWM (pulse width modulation) outputs, which can be used to drive motors or
for safe breaking (antilock brake system, ABS). Furthermore the PWM output can, in
conjunction with an external filter, be used to realize a cheap digital/analog converter.

Digital I/O:

13
Parallel digital I/O ports are one of the main features of microcontrollers. The number
of I/O pins varies from 3-4 to over 90, depending on the controller family and the controller
type.

Analog I/O:

Apart from a few small controllers, most microcontrollers have integrated


analog/digital converters, which differ in the number of channels (2-16) and their resolution
(8-12 bits). The analog module also generally features an analog comparator. In some cases,
the microcontroller includes digital/analog converters.

3.4 THE UART: WHAT IT IS AND HOW IT WORKS

The Universal Asynchronous Receiver/Transmitter (UART) controller is the key


component of the serial communications subsystem of a computer. The UART takes bytes of
data and transmits the individual bits in a sequential fashion. At the destination, a second
UART re-assembles the bits into complete bytes.

Serial transmission is commonly used with modems and for non-networked communication
between computers, terminals and other devices. There are two primary forms of serial
transmission: Synchronous and Asynchronous. Depending on the modes that are supported
by the hardware, the name of the communication sub-system will usually include aA if it
supports Asynchronous communications, and a S if it supports Synchronous
communications. Both forms are described below.

 SYNCHRONOUS SERIAL TRANSMISSION

Synchronous serial transmission requires that the sender and receiver share a clock
with one another, or that the sender provide a strobe or other timing signal so that the
receiver knows when to “read” the next bit of the data. In most forms of serial Synchronous
communication, if there is no data available at a given instant to transmit, a fill character
must be sent instead so that data is always being transmitted. Synchronous communication is
usually more efficient because only data bits are transmitted between sender and receiver,
and synchronous communication can be more costly if extra wiring and circuits are required
to share a clock signal between the sender and receiver.

14
A form of Synchronous transmission is used with printers and fixed disk devices in
that the data is sent on one set of wires while a clock or strobe is sent on a different wire.
Printers and fixed disk devices are not normally serial devices because most fixed disk
interface standards send an entire word of data for each clock or strobe signal by using a
separate wire for each bit of the word. In the PC industry, these are known as Parallel
devices. The standard serial communications hardware in the PC does not support
Synchronous operations. This mode is described here for comparison purposes only

 ASYNCHRONOUS SERIAL TRANSMISSION

Asynchronous transmission allows data to be transmitted without the sender having to


send a clock signal to the receiver. Instead, the sender and receiver must agree on timing
parameters in advance and special bits are added to each word which are used to synchronize
the sending and receiving units.

When a word is given to the UART for Asynchronous transmissions, a bit called the
"Start Bit" is added to the beginning of each word that is to be transmitted. The Start Bit is
used to alert the receiver that a word of data is about to be sent, and to force the clock in the
receiver into synchronization with the clock in the transmitter. These two clocks must be
accurate enough to not have the frequency drift by more than 10% during the transmission of
the remaining bits in the word. (This requirement was set in the days of mechanical
teleprinters and is easily met by modern electronic equipment.)

After the Start Bit, the individual bits of the word of data are sent, with the Least
Significant Bit (LSB) being sent first. Each bit in the transmission is transmitted for exactly
the same amount of time as all of the other bits, and the receiver “looks” at the wire at
approximately halfway through the period assigned to each bit to determine if the bit is a 1 or
a 0. For example, if it takes two seconds to send each bit, the receiver will examine the signal
to determine if it is a 1 or a 0 after one second has passed, then it will wait two seconds and
then examine the value of the next bit, and so on.

The sender does not know when the receiver has “looked” at the value of the bit. The
sender only knows when the clock says to begin transmitting the next bit of the word.When

15
the entire data word has been sent, the transmitter may add a Parity Bit that the transmitter
generates. The Parity Bit may be used by the receiver to perform simple error checking. Then
at least one Stop Bit is sent by the transmitter.

When the receiver has received all of the bits in the data word, it may check for the
Parity Bits (both sender and receiver must agree on whether a Parity Bit is to be used), and
then the receiver looks for a Stop Bit. If the Stop Bit does not appear when it is supposed to,
the UART considers the entire word to be garbled and will report a Framing Error to the host
processor when the data word is read. The usual cause of a Framing Error is that the sender
and receiver clocks were not running at the same speed, or that the signal was
interrupted.Regardless of whether the data was received correctly or not, the UART
automatically discards the Start, Parity and Stop bits. If the sender and receiver are
configured identically, these bits are not passed to the host.If another word is ready for
transmission, the Start Bit for the new word can be sent as soon as the Stop Bit for the
previous word has been sent.

Because asynchronous data is “self synchronizing”, if there is no data to transmit, the


transmission line can be idle.

3.5 MICROCONTROLLER
ATmega162

The ATmega162 is a low-power CMOS 8-bit microcontroller, based on


the AVR enhanced RISC architecture. By executing powerful instructions in a single clock

16
cycle, the ATmega162 achieves throughputs approaching 1 MIPS per MHz allowing the
system designer to optimize power consumption versus processing speed.

F IG . 3.5.1 P IN O UT OF AT MEGA 162

AVR core combines a rich instruction set with 32 general-purpose working registers. All the
32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two
independent registers to be accessed in one single instruction executed in one clock cycle.
The resulting architecture is more code efficient while achieving throughputs up to ten times
faster than conventional CISC microcontrollers.

T HE AT MEGA 162 PROVIDES THE FOLLOWING PROMINENT FEATURES

• High-performance, Low-power AVR® 8-bit Microcontroller

17
• Advanced RISC Architecture

 130 Powerful Instructions – Most Single-clock Cycle Execution


 32 x 8 General Purpose Working Registers
 Fully Static Operation
 Up to 16 MIPS Throughput at 16 MHz
 On-chip 2-cycle Multiplier
• High Endurance Non-volatile Memory segments

 8K Bytes of In-System Self-programmable Flash program memory


 512 Bytes EEPROM
 1K Byte Internal SRAM
 Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
 Data retention: 20 years at 85°C/100 years at 25°C
 Optional Boot Code Section with Independent Lock Bits
 In-System Programming by On-chip Boot Program
 True Read-While-Write Operation
 Programming Lock for Software Security
• Peripheral Features

 Two 8-bit Timer/Counters with Separate Prescaler, one Compare Mode


 One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture
Mode

 Real Time Counter with Separate Oscillator


 Three PWM Channels
 8-channel ADC in TQFP and QFN/MLF package
 Eight Channels 10-bit Accuracy
 6-channel ADC in PDIP package
 Six Channels 10-bit Accuracy
 Byte-oriented Two-wire Serial Interface
 Programmable Serial USART
 Master/Slave SPI Serial Interface
 Programmable Watchdog Timer with Separate On-chip Oscillator
 On-chip Analog Comparator
• Special Microcontroller Features

18
 Power-on Reset and Programmable Brown-out Detection
 Internal Calibrated RC Oscillator
 External and Internal Interrupt Sources
 Five Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, and
Standby
• I/O and Packages

 23 Programmable I/O Lines


 28-lead PDIP, 32-lead TQFP, and 32-pad QFN/MLF
• Operating Voltages

 2.7 - 5.5V (ATmega162L)


 4.5 - 5.5V (ATmega162)
• Speed Grades

 0 - 8 MHz (ATmega162L)
 0 - 16 MHz (ATmega162)
• Power Consumption at 4 Mhz, 3V, 25°C

 Active: 3.6 mA
 Idle Mode: 1.0 mA
 Power-down Mode: 0.5 μA

The Idle mode stops the CPU while allowing the USART, Two-wire interface, A/D
Converter, SRAM, Timer/Counters, SPI port, and interrupt system to continue functioning.
The Power-down mode saves the register contents but freezes the Oscillator, disabling all
other chip functions until the next External Interrupt or Hardware Reset.

In Power-save mode, the Asynchronous Timer continues to run, allowing the user to
maintain a timer base while the rest of the device is sleeping. The ADC Noise Reduction
mode stops the CPU and all I/O modules except Asynchronous Timer and ADC, to minimize
switching noise during ADC conversions.

By combining an 8-bit RISC CPU with In-System Self-Programmable Flash on a


monolithic chip, the Atmel ATmega162 is a powerful microcontroller that provides a highly
flexible and cost-effective solution to many embedded control applications.

19
P IN D ESCRIPTIONS

VCC-Digital supply voltage.

GND-Ground.

Port B (PB7..PB0) XTAL1/XTAL2/TOSC1/TOSC2

Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for
each bit). The Port B output buffers have symmetrical drive characteristics with both high
sink and source capability. As inputs, Port B pins that are externally pulled low will source
current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset
condition becomes active, even if the clock is not running. Depending on the clock selection
fuse settings, PB6 can be used as input to the inverting Oscillator amplifier and input to the
internal clock operating circuit. Depending on the clock selection fuse settings, PB7 can be
used as output from the inverting Oscillator amplifier. If the Internal Calibrated RC
Oscillator is used as chip clock source, PB7..6 is used as TOSC2..1 input for the
Asynchronous Timer/Counter2 if the AS2 bit in ASSR is set.

Port C (PC5..PC0)

Port C is an 7-bit bi-directional I/O port with internal pull-up resistors (selected for
each bit). The Port C output buffers have symmetrical drive characteristics with both high
sink and source capability. As inputs, Port C pins that are externally pulled low will source
current if the pull-up resistors are activated. The Port C pins are tri-stated when a reset
condition becomes active, even if the clock is not running.

PC6/RESET

If the RSTDISBL Fuse is programmed, PC6 is used as an I/O pin. Note that the
electrical characteristics of PC6 differ from those of the other pins of Port C. If the

20
RSTDISBL Fuse is unprogrammed, PC6 is used as a Reset input. A low level on this pin for
longer than the minimum pulse length will generate a Reset, even if the clock is not running

Port D (PD7..PD0)

Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for
each bit). The Port D output buffers have symmetrical drive characteristics with both high
sink and source capability. As inputs, Port D pins that are externally pulled low will source
current if the pull-up resistors are activated. The Port D pins are tri-stated when a reset
condition becomes active, even if the clock is not running.

RESET

Reset input. A low level on this pin for longer than the minimum pulse length will
generate a reset, even if the clock is not running. Shorter pulses are not guaranteed to
generate a reset.

AVCC

AVCC is the supply voltage pin for the A/D Converter, Port C (3..0), and ADC (7..6).
It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it
should be connected to VCC through a low-pass filter. Note that Port C (5..4) use digital
supply voltage, VCC.

AREF

AREF is the analog reference pin for the A/D Converter.

ADC7..6 (TQFP and QFN/MLF Package Only)

In the TQFP and QFN/MLF package, ADC7..6 serve as analog inputs to the A/D
converter. These pins are powered from the analog supply and serve as 10-bit ADC channels.

21
F IG 3.6.1 BLOCK DIAGRAM OF AT MEGA 8

The ATmega162 AVR is supported with a full suite of program and system
development tools including: C compilers, macro assemblers, program debugger/simulators,
in-circuit emulators, and evaluation kits.

A flexible interrupt module has its control registers in the I/O space with an additional
global interrupt enable bit in the Status Register. All interrupts have a separate interrupt
vector in the interrupt vector table. The interrupts have priority in accordance with their
interrupt vector position. The lower the interrupt vector address, the higher the priority. The

22
I/O Memory can be accessed directly, or as the Data Space locations following those of the
Register File, 20h - 5Fh

I/O PORTS:

All AVR ports have true Read-Modify-Write functionality when used as general
digital I/O ports. This means that the direction of one port pin can be changed without
unintentionally changing the direction of any other pin with the SBI and CBI instructions.
The same applies when changing drive value (if configured as output) or enabling/disabling
of pull-up resistors (if configured as input). Each output buffer has symmetrical drive
characteristics with both high sink and source capability. The pin driver is strong enough to
drive LED displays directly. All port pins have individually selectable pull-up resistors with a
supply-voltage invariant resistance. All I/O pins have protection diodes to both V CC and
Ground.

All registers and bit references in this section are written in general form. Three I/O
memory address locations are allocated for each port, one each for the Data Register –
PORTx, Data Direction Register – DDRx, and the Port Input Pins – PINx. The Port Input
Pins I/O location is read only, while the Data Register and the Data Direction Register are
read/write. In addition, the Pull-up Disable – PUD bit in SFIOR disables the pull-up function
for all pins in all ports when set.
Most port pins are multiplexed with alternate functions for the peripheral features on
the device. Enabling the alternate function of some of the port pins does not affect the use of
the other pins in the port as general digital I/O.

P O RT S AS G E N E R A L P U R PO SE I/O :

The ports are bi-directional I/O ports with optional internal pull-ups. Each port pin
consists of three register bits: DDxn, PORTxn, and PINxn. The DDxn bits are accessed at the
DDRx I/O address, the PORTxn bits at the PORTx I/O address, and the PINxn bits at the
PINxI/O address. The DDxn bit in the DDRx Register selects the direction of this pin. If
DDxn is written logic one, Pxn is configured as an output pin. If DDxn is written logic zero,
Pxn is configured as an input pin. If PORTxn is written logic one when the pin is configured
as an input pin, the pull-up resistor is activated. To switch the pull-up resistor off, PORTxn

23
has to be written logic zero or the pin has to be configured as an output pin. The port pins are
tri-stated when a reset condition becomes active, even if no clocks are running. If PORTxn is
written logic one when the pin is configured as an output pin, the port pin is driven high
(one). If PORTxn is written logic zero when the pin is configured as an output pin, the port
pin is driven low (zero). Normally, the pull-up enabled state is fully acceptable, as a high-
impedance environment will not notice the difference between a strong high driver and a
pull-up. If this is not the case, the PUD bit in the SFIOR Register can be set to disable all
pull-ups in all ports.

T ABLE 3.6.2 S ELECTION T ABLE

24
F IG 3.6.3 G ENERAL I/O B LOCK DIAGRAM 1

Independent of the setting of Data Direction bit DDxn, the port pin can be read
through the PINxn Register bit. The PINxn Register bit and the preceding latch constitute a
synchronizer. This is needed to avoid meta stability if the physical pin changes value near the
edge of the internal clock, but it also introduces a delay. The maximum and minimum
propagation delays are denoted tpd, max and tpd, min respectively.

25
F IG 3.6.4 T IMING D IAGRAM WHILE R EADING AN 1

Consider the clock period starting shortly after the first falling edge of the system
clock. The latch is closed when the clock is low, and goes transparent when the clock is high,
as indicated by the shaded region of the “SYNC LATCH” signal. The signal value is latched
when the system clock goes low. It is clocked into the PINxn Register at the succeeding
positive clock edge. As indicated by the two arrows tpd, max and tpd, min, a single signal transition
on the pin will be delayed between ½ and 1½ system clock period depending upon the time
of assertion.When reading back a software assigned pin value, a nopinstruction must be
inserted. The out instruction sets the “SYNC LATCH” signal at the positive edge of the
clock. In this case, the delay tpd through the synchronizer is one system clock period.

F IG 3.6.5 T IMING DIAGRAM WHEN R EADING AN

26
3.7 8-BIT TIMER/COUNTER REGISTER DESCRIPTION
Timer/Counter Control Register – TCCR2

FIG 3.7.1. TCCR 1

Bit 7 – FOC2: Force Output Compare

The FOC2 bit is only active when the WGM bits specify a non-PWM mode. However, for
ensuring compatibility with future devices, this bit must be set to zero when TCCR2 is
written when operating in PWM mode. When writing a logical one to the FOC2 bit, an
immediate Compare Match is forced on the waveform generation unit. The OC2 output is
changed according to its COM21:0 bits setting. Note that the FOC2 bit is implemented as a
strobe. Therefore it is the value present in the COM21:0 bits that determines the effect of the
forced compare. A FOC2 strobe will not generate any interrupt, nor will it clear the timer in
CTC mode using OCR2 as TOP. The FOC2 bit is always read as zero.

• Bit 6,3 – WGM21:0: Waveform Generation Mode

These bits control the counting sequence of the counter, the source for the maximum
(TOP) counter value, and what type of waveform generation to be used. Modes of operation
supported by the Timer/Counter unit are: Normal mode, Clear Timer on Compare Match
(CTC) mode, and two types of Pulse Width Modulation (PWM) modes

27
TABLE 3.7.2TCCR MODES

• Bit 5:4 – COM21:0: Compare Match Output Mode

These bits control the Output Compare Pin (OC2) behavior. If one or both of the COM21:0
bits

are set, the OC2 output overrides the normal port functionality of the I/O pin it is connected
to.

However, note that the Data Direction Register (DDR) bit corresponding to OC2 pin must be
set

in order to enable the output driver. When OC2 is connected to the pin, the function of the
COM21:0 bits depends on the WGM21:0 bit setting.

Timer/Counter Register – TCNT2

F IG 3.7.3 TCNT

The Timer/Counter Register gives direct access, both for read and write operations, to
the Timer/Counter unit 8-bit counter. Writing to the TCNT2 Register blocks (removes) the
Compare Match on the following timer clock. Modifying the counter (TCNT2) while the
counter is running, introduces a risk of missing a Compare Match between TCNT2 and the
OCR2 Register.

28
Output Compare Register – OCR2

F IG 3.7.4 OCR2

The Output Compare Register contains an 8-bit value that is continuously compared
with the counter value (TCNT2). A match can be used to generate an Output Compare
interrupt, or togenerate a waveform output on the OC2 pin.

 8-BIT TIMER/COUNTER0

Timer/Counter0 is a general purpose, single channel, 8-bit Timer/Counter module.


The main features are:

• Single Channel Counter

• Frequency Generator

• External Event Counter

• 10-bit Clock Prescaler

Overview

A simplified block diagram of the 8-bit Timer/Counter is shown inFig3.8.1 . For the actual
placement of I/O pinsCPU accessible I/O Registers, including I/O bits and I/O pins, are
shown in bold. The device-specific I/O Register and bit locations are listed in the “8-bit
Timer/Counter Register Description”.

29
F IG 3.7.5 8- BIT T IMER /C OUNTER

Registers

The Timer/Counter (TCNT0) is an 8-bit register. Interrupt request (abbreviated to Int.


Req. in the figure) signals are all visible in the Timer Interrupt Flag Register (TIFR). All
interrupts are individually masked with the Timer Interrupt Mask Register (TIMSK). TIFR
and TIMSK are not shown in the figure since these registers are shared by other timer units.
The Timer/Counter can be clocked internally or via the prescaler, or by an external clock
source on the T0 pin. The Clock Select logic block controls which clock source and edge the
Timer/Counter uses to increment its value. The Timer/Counter is inactive when no clock
source is selected. The output from the clock select logic is referred to as the timer clock
(clkT0).

Definitions

Many register and bit references in this document are written in general form. A
lower case “n” replaces the Timer/Counter number, in this case 0. However, when using the
register or bit defines in a program, the precise form must be used i.e. TCNT0 for accessing
Timer/Counter0 counter value and so on. Timer/Counter Clock Sources

The Timer/Counter can be clocked by an internal or an external clock source. The clock
source is selected by the clock select logic which is controlled by the clock select (CS02:0)
bits located in the Timer/Counter Control Register (TCCR0).

30
Counter Unit.

F IG 3.7.6 C OUNTER U NIT B LOCK D IAGRAM

Operation

The counting direction is always up (incrementing), and no counter clear is


performed. The counter simply overruns when it passes its maximum 8-bit value (MAX =
0xFF) and then restarts from the bottom (0x00). In normal operation the Timer/Counter
Overflow Flag (TOV0) will be set in the same timer clock cycle as the TCNT0 becomes zero.
The TOV0 Flag in this case behaves like a ninth bit, except that it is only set, not cleared.
However, combined with the timer overflow interrupt that automatically clears the TOV0
Flag, the timer resolution can be increased by software. A new counter value can be written
anytime.

Timing Diagrams

The Timer/Counter is a synchronous design and the timer clock (clkT0) is therefore
shown as a clock enable signal in the following figures. The figures include information on
when Interrupt Flags are set. Figure contains timing data for basic Timer/Counter operation.

31
The figure shows the count sequence close to the MAX value.

F IG 3.7.7 TIMING DIAGRAMS 1

F IG 3.7.8 TIMING DIAGRAMS 2

32
CHAPTER-4

POWER SUPPLY

33
4.1 POWER SUPPLY

A variable regulated power supply, also called a variable bench power supply,
is one where you can continuously adjust the output voltage to your requirements.
Varying the output of the power supply is the recommended way to test a project after
having double checked parts placement against circuit drawings and the parts
placement guide.

This type of regulation is ideal for having a simple variable bench power
supply. Actually this is quite important because one of the first projects a hobbyist
should undertake is the construction of a variable regulated power supply. While a
dedicated supply is quite handy e.g. 5V or 12V, it's much handier to have a variable
supply on hand, especially for testing.

Most digital logic circuits and processors need a 5 volt power supply. To use
these parts we need to build a regulated 5 volt source. Usually you start with an
unregulated power To make a 5 volt power supply, we use a LM7805 voltage
regulator IC (Integrated Circuit). The IC is shown below.

F IG 4.1.1 LM7805 VOLTAGE REGULATOR

34
The LM7805 is simple to use. You simply connect the positive lead of your
unregulated DC power supply (anything from 9VDC to 24VDC) to the Input pin.

4.2 CIRCUIT FEATURES

 Brief description of operation: Gives out well regulated +5V output, output
current capability of 100 mA
 Circuit protection: Built-in overheating protection shuts down output when
regulator IC gets too hot
 Circuit complexity: Very simple and easy to build
 Circuit performance: Very stable +5V output voltage, reliable operation
 Availability of components: Easy to get, uses only very common basic
components
 Design testing: Based on datasheet example circuit, I have used this circuit
successfully as part of many electronics projects
 Applications: Part of electronics devices, small laboratory power supply
 Power supply voltage: Unregulated DC 8-18V power supply
 Power supply current: Needed output current + 5 mA
 Component costs: Few dollars for the electronics components + the input
transformer cost

4.3 BLOCK DIAGRAM

35
F IG 4.3.1 BLOCK DIAGRAM OF P OWER SUPPLY

EXAMPLE CIRCUIT DIAGRAM

F IG 4.3.2 C IRCUIT D IAGRAM OF P OWER SUPPLY

36
CHAPTER-5

I NTRODUCTION T O AVR S TUDIO

37
5.1 Introduction To AVR Studio:
Now you havethebasic hardwaretools,itstimetosetupthesoftware
environment.Themain softwaresyou will needare:

• AVRStudio–A GUI IDE


forAVR(www.atmel.com,http://www.atmel.com/dyn/resources/prod_documents/A
VRStudio4.13SP2.exe)
• WinAVR–afreeCcompilerforAVRs (http://winavr.sourceforge.net/download.html)
• PonyProg–SerialDeviceProgrammer (www.lancos.com)

After downloadingtheminstall themin your computer.Itisbetterto installWinAVRin


rootofadrive likec:\winavror d:\winavr. Alsoplease installWinAVRfirstthen
AVRStudiothiswillletAVRStudio detectthe compiler.Nowyou are readyto
writeyoufirstmicrocontrollerprogram!!!

In thistutorial,you willlearn thebasicsteps requiredfor


anymicrocontrollersbasedproject.Wewill
writeabasic“helloworld”project,whichisasimpleLEDblinkerin
MCUempiretodemonstratethese basicsteps.

38
 ENTERING AND COMPILING CODE.
Start“AVRStudio”fromStartMenu->All programs->Atmel AVRTools->AVRStudio4
You will bepresentedwithaProjectwizardasshownbelow.

 AVR STUDIO PROJECTW IZARD

39
 PROJECTDETAILS
SelectAVRGCCin Projecttype then enter asuitableprojectname
say“hello”andselectalocation in you
harddisk.Thenclicknext.Makesurethat“Createinitialfile”and“Createfolder”option ischecked.

 DEVICESELECTION

In thisdialogboxselectAVRSimulatorin“DebugPlatform”listandselectthe
AVRMCUdepending on thetype ofMCUinstalled on yourdevelopmentboard,in
Devicelist.Clickfinish.Afterthat,youwill be presentedwithan
IntegratedDevelopmentEnvironment-IDE. As shownbelow.

40
 AVR STUDIOMAINW INDOW.

This IDEwill helpyou inediting,modifying,and compilesource program.Aftera


projectiscompiledit givesyou a“.hex” filereadytoburn toyour MCU.Themainparts
ofthewindoware
• ProjectArea–displaysall thefilessource andheaderin thecurrentproject.Youcan
addand
removefilesbythe contextmenu of differentgroupslike“sourcefile”, “headerfiles” etc.
Doubleclickafiletoopen itin theeditor.
• Codeeditor– Here youenter and editthefiles.
• MessageArea–HereAVRStudiowill show
errorsandwarninggeneratedbycompilewhenit triesto compileasourcefile.

Now copypastortype thefollowingcode in thecodeeditor.

41
Goto Project->ConfigurationOptionstobringtheProjectoption dialog.

Enter the CPUfrequency.Ifyou areusingxBoard™orxBoard™MINIenter


16Mhzi.e.16000000.In addition,select optimization as-O2.Click ok.

Now you have enteredthecode nowtimetocompileandbuildtheproject.PressF7orselectBuild-


>Build or clickthetoolbarbutton forBuildactiveconfiguration.Ifthe codeiserror
freeAVRstudiowill showyou the followingmessage.

42
“Buildsucceedwith1warning.Don’tworryabouttheone warningitisduetothefactthatANSI
standard suggestthatreturn typeofmain()mustbe one,butfor MCUplatformthereisno
environment oroperatingsystemthatwill receivethisreturnedvalue.So return type
ofmain()isvoid.
Now you have successfullycompiledyou firstproject,whatyou havegotafter compilation
andbuildis “.hexfile”.You canfinditin afoldernamed“default”in you projectfolder.Ithas
samenameasyou project,in thiscase“hello.hex”

 PROGRAMMING THEMCUWITH“HELLO.HEX”.

Nowitstimetoburn thishexfiletoyourMCU.Toknowhowtoburn thehexfiletoyou


MCUreferto you programmers manual.You can
useeXtremeelectronicsUSBAVRProgrammer toburn hexfilesto
youmcu(seeshopsection).Detailedprocedure isgiven in“programmer”folderin
itssupportCD.

Programming UsingPonyProg.

43
Thisistheprogrammer wemadein theprevioustutorial.
Itsuseissimple.StartPonyprog,you will get a screensimilartothis.

44
PonyProgMainWindow.

First,you neetsome setup.Goto menusetup->interface setupand makesettinglikethis.

PonyProgSetup

45
Selectthe serial portinwhichyourprogrammer isconnected.Bewaretheremay be
morethat1 availablecomportshowingthere andusually onlyoneisavailableoutsidethe
PCthe restareinternalandmaybe connectedtoyourmodem.Somakesureyouhaveselecteda
portthatisconnectedtoyour programmer andnottoyourmodem.

Next, go to setupcalibration.Nowyou are done.Connecttheprogrammeryou


havemadeto youPCsserial portandconnectits ISPconnectortothe target you havemade.
Switch on thetarget.Thesoftwareisselfexplanatorywith easytouse GUIin thetoptool
barthere isaselection for type of chip you
wanttoprogram.Select“AVRMicro”andselectthe type ofMicro(likeATmega8)in
boxnext toit.

CHAPTER-6

G LOBAL SYSTEM FOR MOBILE

46
6.1GSM MODEM :

GSM stands for Global System for Mobile Communication. It is a globally


accepted standard for digital cellular communication. GSM is the name of a
standardization group established in 1982 to create a common European mobile
telephone standard that would formulate specifications for a pan-European mobile
cellular radio system operating at 900 MHz.

Functions – GSM Modes

47
The GSM modem basically consists of a

 SIM card holder to hold the activated SIM card for sending and receiving SMS.
 5V AC power supply header to which the 5v ac adapter is connected.
 Power led which gives the indication of modem status that is on or off.
 9 pin female to which the GSM antenna is connected.

6.2Block Diagram of GSM:

48
6.3 GSM Network Setup:

49
TE TA ME

USER & APPLICATIONS NETWORK

GSM setup

This is the basic setup of a GSM. Here ME stands for Mobile Equipment, e.g. a
GSM phone (equal to MS; Mobile Station). TE stands for Terminal Equipment, e.g. a
computer (equal to DTE; Data Terminal Equipment). TA stands for Terminal Adaptor, e.g.
a GSM data card (equal to DCE; Data Circuit Terminating Equipment).

Through the mobile equipment the network messages are sent and received.
These messages are sent to the terminal adapter which is nothing but a GSM data card.
Now if there is some data to be sent to the mobile equipment then the terminal
equipment that is basically a computer or processor sends out AT COMMANDS to the
terminal adapter which in turn sends the mobile equipment the required data

50
Buzzer
TEMPERATURE Sensor
GSM
Module
PT RELAY Device 1
Board
GSM
AT mega 8
Module
CT ADC
MCU Device 2
GSM GPIO’s
Module
Device 3
GSM UART
Module

51
CHAPTER-7
ABOUT SCADA

52
7.1 Supervisory Control and Data Acquisition (SCADA) Networks

Since September 11, 2001 United States agencies involved with national
security have become increasingly concerned about the vulnerability of the North
American power grid, water supply, refining, nuclear facilities and railroads to electronic
intrusions or “cyber attacks”. Several studies have been conducted and have identified
changing socio-economic conditions that increase the probability of such computer-based
attacks. Increased domestic and international terrorism, industry related issues affecting
the utilities job market, the shift to more open standards for interconnection of DCS and
SCADA networks and a growing population of computer-literate people with widely
available hacker tools are factors that contribute greatly to the likelihood of such threats.

In this paper, we will identify and discuss threat origins and how technologies
available today from GDC can mitigate these threats and be part of a comprehensive
network design and security policy to ensure safe and secure communications between
components of DCS and SCADA networks.

7.2 What is a DCS or SCADA network

DCS are used to control large, complex processes such as power plants,
refineries, and chemical plants typically, but not always, at a single site. A DCS is
comprised of a supervisory layer of control and one or more distributed controllers
contained within the same processing plant. The supervisory controller runs on a central
server and communicates with subordinate controllers via some form of peer-to-peer
network. The supervisor sends set points to and requests data from the distributed
controllers. The distributed controllers control their process actuators (switches, valves,
flow controllers, etc) based on requests from the supervisor. These controllers typically
use a local field bus to communicate with the actuators and sensors eliminating the need
for point-to-point wiring to each device. Many times, the distributed controllers in a DCS
have the capability to be accessed via a modem allowing remote diagnostics and servicing
by vendors and plant engineers.

A SCADA network typically consists for a Central Monitoring System (CMS),


contained at a central plant for example and one or more Remote Stations. The CMS
houses the Control Server and the communications access via a peer-to-peer network. The
CMS collects and logs information gathered at the Remote Stations and generates
necessary actions based on the gathered data. A Remote Station consists of either a
Remote Terminal Unit (RTU) or a Programmable Logic Controller (PLC) which controls
actuators and monitors sensors. Remote Stations typically have the capability to be
interfaced by field operators via laptops or other handheld devices to perform diagnostics
and repair operations. information between Remote Stations and the CMS. These facilities
can be telco lines, cable, or RF.

53
7.3 Fieldbus - Ethernet
It is important to understand that DCS and SCADA based industries are
undergoing a change in how these networks are implemented. Controller networks
typically were based on proprietary serial cabling and/or fieldbus architectures (Fieldbus,
Modbus, Profibus) which have upper data limits of about 2Mbps, node limitations, and
distance limitations which all varied from technology to technology. This would all need
to pass through a gateway to get to the internal IT network a very cumbersome
approach. The development of Ethernet-capable controllers and PLCs and the need for
integration of other requirements (security devices, bar code scanners, smart cards, etc) are
helping to drive the industry towards more open and ubiquitous architectures. This shift is
also made apparent by the fact that many vendors are encapsulating the bus protocols into
TCP/IP: Modbus/TCP (Modbus protocol over TCP/IP, EtherNet/IP
(ControlNet/DeviceNet over TCP/IP), Fieldbus High-Speed Ethernet and ProfiNet
(Profibus over Ethenet). Ethernet is quickly becoming a larger part of DCS and SCADA
network implementations, in some cases replacing or augmenting the older bus-type
architectures.

Threats

As demonstrated daily, any TCP/IP based network is subject to intrusion. These


intrusions come from numerous sources including:

Threats from within:


-- Company staff, technician, operators.
-- Security breaches may not be intentional, BUT….
-- Emailed viruses

Threats from the outside:

-- 3rd party support services


-- Communications lines
-- Vandalism/terrorism
Security measures should not be taken lightly. Remember, if your network is easy for your
IT Department to manage, it is most likely easy for an outside party to infiltrate.

54
7.4 How can GDC address security issues with DCS and SCADA
networks?

GDC products should be part of a comprehensive secure network implementation.


Other elements that should be addressed are policies and enforcement, virus detection and
prevention, firewalls, and Intrusion Detection Systems (IDS). GDC’s line of secure
modems and IP access products can be the first line of defense at the most basic levels of
your network – OSI Layers 1 and 2.

As stated earlier, most legacy DCS/SCADA networks have modem access to


some controllers(and potentially elsewhere) for remote maintenance and troubleshooting.
GDC’s family of V.34modems with SteadfastSecurity and additionally RADIUS
authentication can make theseconnections “hack-proof”. GDC’s SteadfastSecurity,
which is a proprietary, handshake-basedexchange requires a GDC modem at both ends. If
the handshake password exchange is notcompleted properly, the call is dropped before
ever being connected to the network. With acommon length password of 6-8
alphanumeric, it would be statistically impossible for any hackerto gain access, assuming
they have a GDC modem Additionally,addingRADIUS authenticationsecurity where
applicable would further enhance the security.With the migration/augmentation of the
DCS and SCADA peer-to-peer networks to 10/100

55
56
Ethernet, GDC’s line of IP access products, SpectraComm IP (SCIP) and
Ethernet switch (SCES) can provide first-line intrusion prevention. All of the
SpectraComm IP and Ethernet switch units implement GDC IronGate Security features.
These features, including port-based shutdown and MAC address filtering, can limit
access only to authorized devices and personnel as designated by the MAC Address tables
configured in the unit by the network administrator. It should be noted that a SCIP unit in
LAN Extension (LAN-X) mode can not only filter MAC addresses on the LAN, but can
also filter on the WAN port as well to ensure that unauthorized access does not occur from
the circuit (Telco facilities). Additionally, the SCIP and SCES implement industry-
standard TACACS+ compatible clients for centralized authentication.

In large-scale processing facilities, the SCIP T1 (1.544 Mbps up to 5000 feet


without repeaters) or SCIP G.S (4 Mbps up to 7000 feet on 1 pair or up to 12,000 feet on 2
pair) in LAN Extension (LANX) mode, can extend the reach between the Central and
Distributed Controller well beyond the 100 meter reach of Ethernet alone. Implementing
the MAC-based filtering and/or TACACS+ in these situations allows maintenance
personnel to attach to the network at the SCIP as determined by the network administrator.

In SCADA RTU applications, the SCIP T1 in LAN-X mode and SCES offer a
compelling andsecure solution where one might typically install a router with its
associated costs. Implementingthe MAC-based filtering and/or TACACS+ allows only
authorized maintenance personnel toaccess the network via the SCIP/SCES as determined
by the network administrator.

Additionally, the Contact Sense feature on the SCIP could be implemented to


alert network monitoring personnel of such things as door opening, high water, high heat,
etc. at the Remote Station if so desired. SCIP and SCES have been independently tested
and certified to stringent NEBS Level 3+ requirements for Telcos and additional testing
have proven them to be consistent with the classification as temperature “hardened” (-40
oC to +70 o C) for deployment in extreme environments.

57
Typical SCADA Applicatio

58
CHAPTER-8
GLOBAL SYSTEM FOR MOBILE COMMUNICATION

59
8.1 GSM

GSM(GLOBAL SYSTEM FOR MOBILE COMMUNICATION) is a digital


mobile telephony system that is widely used in Europe and other parts of the world. GSM
uses a variation of time division multiplexing (TDMA) and is the most widely used of the
three digital wireless telephony technologies (TDMA, GSM, and CDMA). GSM digitizes
and compresses data, thensends it down a channel with two other strams of user data, each
in its own time slot. It operates at either the 900 MHz or 1800 MHz frequency band

 Using the HyperTerminal

Hint :: By developing your AT commands using HyperTerminal, it will be easier for


you to develop your actual program codes in VB, C, Java or other platforms.

Go to START\Programs\Accessories\Communications\HyperTerminal (Win 2000)


to create a new connection, eg. "My USB GSM Modem". Suggested settings ::

 - COM Port :: As indicated in the T-Modem Control Tool 


 - Bits per second :: 9600( or slower )
 - Data Bits : 8
 - Parity : None
 - Stop Bits : 1
 - Flow Control : Hardware

You are now ready to start working with AT commands. Type in "AT" and you should
get a "OK", else you have not setup your HyperTerminal correctly. Check your port
settings and also make sure your GSM modem is properly connected and the drivers
installed.

60
 Initial setup AT commands

We are ready now to start working with AT commands to setup and check the status of
the GSM modem.

AT Returns a "OK" to confirm that modem is working


AT+CPIN="xxxx"   To enter the PIN for your SIM ( if enabled )
AT+CREG? A "0,1" reply confirms your modem is connected to GSM network
AT+CSQ Indicates the signal strength, 31.99 is maximum.

 Sending SMS using AT commands

We suggest try sending a few SMS using the Control Tool above to make sure
your GSM modem can send SMS before proceeding. Let's look at the AT
commands involved ..

AT+CMGF=1 To format SMS as a TEXT message


AT+CSCA="+xxxxx"   Set your SMS center's number. Check with your provider.

To send a SMS, the AT command to use is AT+CMGS ..

AT+CMGS="+yyyyy" <Enter>
> Your SMS text message here <Ctrl-Z>

The "+yyyyy" is your receipent's mobile number. Next, we will look at receiving SMS via
AT commands.

 Receiving SMS using AT commands

The GSM modem can be configured to response in different ways when it receives a
SMS.

61
a) Immediate - when a SMS is received, the SMS's details are immediately sent to the host
computer (DTE) via the +CMT command

AT+CMGF=1 To format SMS as a TEXT message


AT+CNMI=1,2,0,0,0   Set how the modem will response when a SMS is received

When a new SMS is received by the GSM modem, the DTE will receive the following ..

+CMT :  "+61xxxxxxxx" , , "04/08/30,23:20:00+40"


This the text SMS message sent to the modem
Your computer (DTE) will have to continuously monitor the COM serial port, read and
parse the message.

b) Notification - when a SMS is recieved, the host computer ( DTE ) will be notified of the
new message. The computer will then have to read the message from the indicated
memory location and clear the memory location.

AT+CMGF=1 To format SMS as a TEXT message


AT+CNMI=1,1,0,0,0   Set how the modem will response when a SMS is received

When a new SMS is received by the GSM modem, the DTE will receive the following ..

+CMTI: "SM",3 Notification sent to the computer. Location 3 in SIM memory


AT+CMGR=3 <Enter>  AT command to send read the received SMS from modem

The modem will then send to the computer details of the received SMS from the specified
memory location ( eg. 3 ) ..

+CMGR: "REC READ","+61xxxxxx",,"04/08/28,22:26:29+40"


This is the new SMS received by the GSM modem

After reading and parsing the new SMS message, the computer (DTE) should send a AT
command to clear the memory location in the GSM modem ..

AT+CMGD=3 <Enter>   To clear the SMS receive memory location in the GSM modem

62
If the computer tries to read a empty/cleared memory location, a +CMS ERROR : 321 will
be sent to the computer.

Using a computer program to send and receive SMS

Once we are able to work the modem using AT commands, we can use high-level
programming ( eg. VB, C, Java ) to send the AT ASCII commands to and read messages
from the COM serial port that the GSM modem is attached to.

8.2 GSM MODULE PICTURE:

63
64
8.3 GSM FLOW CHART:

65
CHAPTER-9

INRODUCTION TO UART

66
9.1 SERIAL COMMUNICATION

The Universal Asynchronous Receiver/Transmitter (UART) controller is the key


component of the serial communications subsystem of a computer. The UART takes bytes
of data and transmits the individual bits in a sequential fashion. At the destination, a
second UART re-assembles the bits into complete bytes.

Serial transmission is commonly used with modems and for non-networked


communication between computers, terminals and other devices.

There are two primary forms of serial transmission: Synchronous and


Asynchronous. Depending on the modes that are supported by the hardware, the name of
the communication sub-system will usually include aA if it supports Asynchronous
communications, and a S if it supports Synchronous communications. Both forms are
described below.

Some common acronyms are:

UART Universal Asynchronous Receiver/Transmitter

USART Universal Synchronous-Asynchronous Receiver/Transmitter

 SYNCHRONOUS SERIAL TRANSMISSION

Synchronous serial transmission requires that the sender and receiver share a clock
with one another, or that the sender provide a strobe or other timing signal so that the
receiver knows when to “read” the next bit of the data. In most forms of serial
Synchronous communication, if there is no data available at a given instant to transmit, a
fill character must be sent instead so that data is always being transmitted. Synchronous
communication is usually more efficient because only data bits are transmitted between
sender and receiver, and synchronous communication can be more costly if extra wiring
and circuits are required to share a clock signal between the sender and receiver.

A form of Synchronous transmission is used with printers and fixed disk devices in
that the data is sent on one set of wires while a clock or strobe is sent on a different wire.
Printers and fixed disk devices are not normally serial devices because most fixed disk
67
interface standards send an entire word of data for each clock or strobe signal by using a
separate wire for each bit of the word. In the PC industry, these are known as Parallel
devices.

The standard serial communications hardware in the PC does not support


Synchronous operations. This mode is described here for comparison purposes only

 ASYNCHRONOUS SERIAL TRANSMISSION

Asynchronous transmission allows data to be transmitted without the sender


having to send a clock signal to the receiver. Instead, the sender and receiver must agree
on timing parameters in advance and special bits are added to each word which are used to
synchronize the sending and receiving units.

When a word is given to the UART for Asynchronous transmissions, a bit called
the "Start Bit" is added to the beginning of each word that is to be transmitted. The Start
Bit is used to alert the receiver that a word of data is about to be sent, and to force the
clock in the receiver into synchronization with the clock in the transmitter. These two
clocks must be accurate enough to not have the frequency drift by more than 10% during
the transmission of the remaining bits in the word. (This requirement was set in the days
of mechanical teleprinters and is easily met by modern electronic equipment.)

After the Start Bit, the individual bits of the word of data are sent, with the Least
Significant Bit (LSB) being sent first. Each bit in the transmission is transmitted for
exactly the same amount of time as all of the other bits, and the receiver “looks” at the
wire at approximately halfway through the period assigned to each bit to determine if the
bit is a 1 or a 0. For example, if it takes two seconds to send each bit, the receiver will
examine the signal to determine if it is a 1 or a 0 after one second has passed, then it will
wait two seconds and then examine the value of the next bit, and so on.

The sender does not know when the receiver has “looked” at the value of the bit.
The sender only knows when the clock says to begin transmitting the next bit of the word.

68
When the entire data word has been sent, the transmitter may add a Parity Bit that
the transmitter generates. The Parity Bit may be used by the receiver to perform simple
error checking. Then at least one Stop Bit is sent by the transmitter.

When the receiver has received all of the bits in the data word, it may check for the
Parity Bits (both sender and receiver must agree on whether a Parity Bit is to be used), and
then the receiver looks for a Stop Bit. If the Stop Bit does not appear when it is supposed
to, the UART considers the entire word to be garbled and will report a Framing Error to
the host processor when the data word is read. The usual cause of a Framing Error is that
the sender and receiver clocks were not running at the same speed, or that the signal was
interrupted.

Regardless of whether the data was received correctly or not, the UART
automatically discards the Start, Parity and Stop bits. If the sender and receiver are
configured identically, these bits are not passed to the host.

If another word is ready for transmission, the Start Bit for the new word can be
sent as soon as the Stop Bit for the previous word has been sent.

Because asynchronous data is “self synchronizing”, if there is no data to transmit,


the transmission line can be idle.

9.2 NEED FOR SERIAL COMMUNICATION

Serial Cables can be longer than Parallel cables. The serial port transmits a '1' as -3
to -25 volts and a '0' as +3 to +25 volts where as a parallel port transmits a '0' as 0v and a
'1' as 5v. Therefore the serial port can have a maximum swing of 50V compared to the
parallel port which has a maximum swing of 5 Volts. Therefore cable loss is not going to
be as much of a problem for serial cables than they are for parallel.

You don't need as many wires than parallel transmission. If your device needs to
be mounted a far distance away from the computer then 3 core cable (Null Modem
Configuration) is going to be a lot cheaper that running 19 or 25 core cable. However you
must take into account the cost of the interfacing at each end.

69
Microcontroller's have also proven to be quite popular recently. Many of these
have in built SCI (Serial Communications Interfaces) which can be used to talk to the
outside world. Serial Communication reduces the pin count of these MPU's. Only two pins
are commonly used, Transmit Data (TXD) and Receive Data (RXD) compared with at
least 8 pins if you use an 8 bit Parallel method (You may also require a Strobe).

The serial communication is between the MCU and PC. In order to connect micro
controller to a pc a serial port is used. Serial communication is a very common protocol
for device communication that is standard on almost every PC Most computers include
two RS-232 based serial ports. Serial communication is also a common communication
protocol that is used by many devices for instrumentation acquisition in conjunction with a
remote sampling device. The concept of serial communication is simple. The serial port
sends and receives bytes of information one bit at a time. Although this is slower than
parallel communication, which allows the transmission of an entire byte at once, it is
simpler and can be used over longer distances. For example, the IEEE 488 specifications
for parallel communication state that the cabling between equipment can be no more than
20 meters total, with no more than 2 meters between any two devices. Serial, however, can
extend as much as 1200meters.Typically, serial is used to transmit ASCII data.
Communication is completed using 3 transmission lines:

 Ground,
 Transmit
 Receive.
Since serial is asynchronous, the port is able to transmit data on one line while
receiving data on another. Other lines are available for handshaking, but are not required.
The important serial characteristics are baud rate, data bits, parity, and stop bits. For two
ports to communicate, these parameters must match.
 Band rate: The band rate (bits per second) determines how much information is
transferred over a given time interval. A band rate can usually be selected between 100
and 76800 baud, e.g. a band rate of 9600 corresponds to 9600 bits per second.
 Data with: the data with can be either 8 bits or 7 bits depending upon the nature of
the data being transferred.

70
 Parity: The parity bit is used to check the correctness of the transmitted or
specified at all.
 Stop bit: The stop bit is used as the terminator bit and it is possible to specify
either one or two stop bits
Serial data is transmitted and received in frames where a frame consists of:

 1 start bit
 7 or 8 data bits
 Optional parity bit
 1 stop bit

In many application 10 bits are used to specify an RS232 frame, consisting of 1


start bit, 8 data bits, no parity bit and 1 stop bit. For example, character ‘A’ has the ASCII
bit ‘01000001’ and is transmitted as shown in Fig. 6.1 with 1 start bit, 8 data bits, no
parity, and 1 stop bit. The data is transmitted least significant bit first.

Figure. 8.2.1 Transmitting character ‘A’ (bit pattern 01000001)

When 10 bits are used to specify the frame length, the time taken to transmit or receive
each bit can be found from the band used.

71
9.3 RS232 CONNECTORS

As shown in Fig. 6.2, two types of connectors are used from RS232
communications. These are the 25-way D-type connector (known as DB25) and the 9-pin
D-type connector (also known as DB9). Table 6.2 lists the most commonly used signal
names for both DB9 and DB25 type connectors. The used signals are:

Figure. 8.3.1 RS232 Connection

72
Description Signal 9 pin

Carrier detect CD 1

Receive data RD 2

Transmit data TD 3

Data terminal ready DTR 4

Signal ground SG 5

Data set ready DSR 6

Request to send RTS 7

Clear to send CTS 8

Ring indicator RI 9

SG: Signal ground. This pin is used in all RS232 cables


RD: Received data. Data is received at this pin. This pin is used in all two-way
communications
TD: Transmit data. Data is sent out from this pin. This pin is used in all two-way

73
communications
RTS: Request to send. This signal is asserted when the device requests data to be sent
CTS: Clear to send. This signal is asserted when the device is ready to accept data
DTR Data set ready. This signal is asserted to indicate that the device is ready.
:
DSR: Data set ready. This signal indicates, by the device at the other end that it is
ready
CD: Carrier detects. This signal indicates that a carrier signal has been detected by a
modem connected to the line.

In some RS232 application it is sufficient to use only the SG, RD, and TD.
Also, in some application (e.g. when two similar devices are connected together) it is
necessary to twist pins RD and TD so that the transmit pin of one device is connect to the
receive pin of the other device and vice versa.

RS232 SIGNAL LEVELS


RS232 is bi-polar and a voltage of +3 to +15 indicates an ON state (or
SPACE), while a voltage of -3 to -15V indicate an OFF state (or MARK).

In practice, the ON and OFF state can be achieved with lower voltages.

Figure 8.3.2 Pin configuration of MAX232

74
Standard TTL logic devices, including the 89C52 microcontroller, operate with TTL logic
levels between the voltages of 0 and +5V. Voltage level converter IC’s are used to convert
between the TTL and RS232 voltage levels. One such popular IC is MAX232,
manufactured by MAXIM, and operators with +5 supply. This MAX232 is a 16-pin DIL
chip incorporating two receivers and two transmitters (see Fig. 6.3) and the device
requires four external capacitors for proper operation.

The 89C51 microcontroller can output TTL level RS232 signals from its
TXD (or pin p3.1) pin and it can receive TTL level RS232 signals from its RXD (or pin
P3.0) pin. This microcontroller can connect to the external RS232 compatible equipment
via a MAX232 type voltage converter IC.

75
9.4 LIMITATIONS OF RS-232

RS-232 has some serious shortcomings as an electrical interface.

Firstly, the interface presupposes a common ground between the DTE and DCE. This is a
reasonable assumption where a short cable connects a DTE and DCE in the same room,
but with longer lines and connections between devices that may be on different electrical
busses, this may not be true. We have seen some spectacular electrical events causes by
"uncommon grounds".

Secondly, a signal on a single line is impossible to screen effectively for


noise. By screening the entire cable one can reduce the influence of outside noise, but
internally generated noise remains a problem. As the baud rate and line length increase,
the effect of capacitance between the cables introduces serious crosstalk until a point is
reached where the data itself is unreadable.

Using low capacitance cable can reduce crosstalk. Also, as it is the higher
frequencies that are the problem, control of slew rate in the signal (i.e., making the signal
more rounded, rather than square) also decreases the crosstalk. The original specifications
for RS-232 had no specification for maximum slew rate.

76
Voltage levels with respect to ground represent the RS 232 signals. There is a
wire for each signal, together with the ground signal (reference for voltage levels). This
interface is useful for point-to-point communication at slow speeds. For example, port
COM1 in a PC can be used for a mouse, port COM2 for a modem, etc. This is an example
of point-to-point communication: one port, one device. Due to the way the signals are
connected, a common ground is required. This implies limited cable length - about 30 to
60 meters maximum. (Main problems are interference and resistance of the cable.)
Shortly, RS 232 was designed for communication of local devices, and supports one
transmitter and one receiver.

77
A PPLICATIONS :
1. AC Voltage input monitoring 
2. DC Voltage input Monitoring 
3. DC current input monitoring 
4. Temperature Monitoring 
5. It can be widely used in industries, Household buildings, petrol-Stations, Rail-
ways, Schools...etc.

F UTURE S COPE

1.Pressure sensor can be implemented

2.Water Level Indicators can be added

3.Fire alert system can be Implemente

78
CONCLUSION :
Hence we successfully implemented the working of GSM BASED
SCADA IMPLEMENTATION USING MICROCOTROLLER.

By implementing this project, the authority can remotely access


the machines through GSM via simple SMS. This usage of remote connectivity helps
controlling and acknowledgment of the machine status within in seconds of any fault.

This project deals with the GSM based monitoring of the systems
comprising of heavy duty electrical and electronics equipment. Depending on the status
and electrical parameters considering the duty timing considerations of the equipment, the
relays are controlled from GSM by the user.

REFERENCES:

 http://support.radioshack.com/support_tutorials/gps/gps_tmlin
e.htm
 http://www.cellular.co.za/gsmtechdata.htm
 "A Guide To The Global Positioning System (GPS) — GPS Timeline".
Radio Shack. Retrieved 2010-01-14.
  "GSM Technical Data". Cellular.co.za. Retrieved 2010-08-30.
 “Let us C”, YashwanthKanethkar.
  Giovino, Bill. "Microcontroller.com - Embedded Systems supersite"
 http://en.wikipedia.org/wiki/Embedded_system

CODE:

79
#include<avr/io.h>
#include<avr/interrupt.h>
#include "adc_routines.h"
#include "Gsm_Routines.h"
#define _ADC_APPLIC_H_
#define _ADC_APPLIC_H_

#define AREF (5.0/1024)


#define VOLT_OFF 0
#define CURR_OFF 0
unsigned int Adc_Read(unsigned char ch);
void adc_init(void );

int Voltage_Read(char ch );
int Temp_Read(char ch );
int Current_Read(char ch );

#endif

extern unsigned char lowbyte,highbyte;

unsigned int Adc_Read(unsigned char ch)


{
ch=ch&0b00000111; //channel selecting

ADMUX = ch;
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADC; // returning adc result

void adc_init(void )
{

//ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);

//ADMUX=(1<<ADLAR);

ADMUX=0x00;

ADCSRA=0x87;
SFIOR&=0Xef
}

EPROM PROGRAM:

80
#include <avr/io.h>
#include <avr/pgmspace.h>
#include"EEPROM_routines.h"
#include <avr/eeprom.h>
#ifndef _EEPROM_ROUTINES_H_
#define _EEPROM_ROUTINES_H_
void EEPROM_write(unsigned int addr,unsigned char data);

char EEPROM_read(unsigned int addr);

#endif

void EEPROM_write(unsigned int addr,unsigned char data)


{
//printf("write into eepron %d %x\n\r",addr,data);
// WAIT FOR COMPLETION OF PREVIOUS WRITE
while(EECR&0X02);
//SETUP ADDRESS AND DATA REGISTERS
EEAR=addr;
EEDR=data;
// WRITE LOGICAL ONE TO EEMWE

EECR|=0X04;

// START EEPROM WRITTING BY SETTING EEWE


EECR|=0X02;
}

char EEPROM_read(unsigned int addr)


{
// WAIT FOR COMPLETION OF PREVIOUS WRITE
while(EECR&0X02);
//SETUP ADDRESS REGISTERS
EEAR=addr;

// WRITE LOGICAL ONE TO EERE

// START EEPROM READING BY SETTING EERE


EECR|=0X01;
return EEDR;
}

UART INTRODUCTION

#include "UART_routines.h"
81
#include <avr/io.h>
#include <avr/pgmspace.h>

void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = (1 << URSEL) | 0x06;
UBRRL = 0x33; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0x98;
}

unsigned char receiveByte( void )


{
unsigned char data;

while(!(UCSRA & (1<<RXC)));

data = UDR;

return(data);
}

void transmitByte( unsigned char data )


{
while ( !(UCSRA & (1<<UDRE)) ;

UDR = data;
}

void transmitString_F(char* string)


{
while (pgm_read_byte(&(*string)))
transmitByte(pgm_read_byte(&(*string++)));
TX_NEWLINE;//transmitByte(0x0d);// carriage return
}
void transmitString( char* string)
{
while (*string)
transmitByte(*string++);

void transmitHex( unsigned char dataType, unsigned long data


)
{
unsigned char count, i, temp;
82
char dataString[] = "0x ";

if (dataType == CHAR) count = 2;


if (dataType == INT) count = 4;
if (dataType == LONG) count = 8;

for(i=count; i>0; i--)


{
temp = data % 16;
if((temp>=0) && (temp<10)) dataString [i+1] = temp + 0x30;
else dataString [i+1] = (temp - 10) + 0x41;

data = data/16;
}
dataString [i]='\0';
transmitString (dataString);
}

MAIN :

#include <avr/io.h>
#include <avr/pgmspace.h>
#include<util/delay.h>
#include <stdio.h>
#include "Gsm_Routines.h"
#include "adc_routines.h"
#include "UART_routines.h"
#include "EEPROM_routines.h"

char Mobile_No[]="9866483830";

static int uart_putchar(char c, FILE *stream);

static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar,


NULL,

_FDEV_SETUP_WRITE);

static int
uart_putchar(char c, FILE *stream)
{

if (c == '\n')
uart_putchar('\r', stream);
loop_until_bit_is_set(UCSRA, UDRE);
UDR = c;
return 0;
83
}

void port_init(void)
{

PORTB = 0x00;
DDRB = 0xFF;
PORTC = 0x00;
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0xFF;
}

void init_devices(void)
{

port_init();

uart0_init();
adc_init( );
//MCUCR = 0x00;
//GICR = 0x00;
//TIMSK = 0x00; //timer interrupt sources
//all peripherals are now initialized
}

int main(void)
{
init_devices();
int VOLT_RMS=0;
int temp=0;
int volt_flag=1;
int volt_flag2=1;
int volt_flag3=1;
int temp_flag=1;
int temp_flag2=1;

int i;
for(i=0;Mobile_No[i]!='\0';i++)
EEPROM_write(i,Mobile_No[i]);

stdout = &mystdout;
SendMessgToMobile("WELCOME TO INDUSTRIAL FAULT
MONITORING!\n");
PrepareMobile2ReciveMsg();

while(1)
{

84
if(RMesgFlag==1)
{
Read_Msg();
ExtractMessg();
}

temp= Temp_Read(0);
VOLT_RMS= Voltage_Read(1);
VOLT_RMS=VOLT_RMS;
if (temp<=40)
{
if(temp_flag)
{
temp_flag=0;
temp_flag2=1;
PORTB=0b00000001;
SendMessgToMobile("Normal temperature");
}
}

else if(temp>=42)
{
if(temp_flag2)
{
temp_flag=1;
temp_flag2=0;
PORTB=0b00000010;
SendMessgToMobile("Fault occur High temperature");
}
}

if(VOLT_RMS<148)
{
if(volt_flag)
{
volt_flag =0;
volt_flag2=1;
volt_flag3=1;
PORTD=0b00000100;
SendMessgToMobile("LOW VOLTAGE");
}
}

else if(VOLT_RMS>232)
{
if(volt_flag2)
{
volt_flag =1;
volt_flag2=0;

85
volt_flag3=1;
PORTD=0b00000100;
SendMessgToMobile("Status: HIGH VOLTAGE");
}
}

else if(VOLT_RMS>150&&VOLT_RMS<=230)
{

if(volt_flag3)
{
volt_flag =1;
volt_flag2=1;
volt_flag3=0;
PORTD=0b00001000;
SendMessgToMobile("RUNNING IN NORMAL VOLTAGE");
}
}
}
}

86

You might also like