Вы находитесь на странице: 1из 38

ABOUT THE GROUP

i3indya Started by a group of entrepreneurs with a sole mission of


establishing a dedicated Research & Development (R&D) Cell and
bringing the findings to the benefit of budding Engineers.
In just 4 years of its existence, i3indya has a pan India acclaim for its
unmatched quality services.

i3indya R&D Domain


i3indya is currently working the following domains of Research &
Development::
1.
Cyber Cell (Headed by Mr OoPpSs & Group)
2.
Robotics Cell (Headed by i3indya RoboChamps)

I3Indya Domains
i3indya Group of Companies:
1.
2.
3.
4.
5.
6.

i3indya Technologies
i3indya Cyber Solutions
i3indya Automations
i3indya Web Solutions
i3indya E-shop
i3indya Publications

INSTITUTIONS COVERED BY I3INDYA


TECHNOLOGIES

GOVERNMENT CLIENTS

INTRODUCTION TO EMBEDDED
SYSTEMS
An embedded system is a special-purpose system in which the computer
is completely encapsulated by the device it controls. Unlike a generalpurpose computer, such as a personal computer, an embedded system
performs pre-defined tasks, usually with very specific requirements.
Since the system is dedicated to a specific task, design engineers can
optimize it, reducing the size and cost of the product. Embedded systems
are often mass-produced, so the cost savings may be multiplied by
millions of items.
Handheld computers or PDAs are generally considered embedded
devices because of the nature of their hardware design, even though they
are more expandable in software terms. This line of definition continues
to blur as devices expand.
Physically, embedded systems range from portable devices such
as digital watches and MP3 players, to large stationary installations like
traffic lights, factory controllers. 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.
Embedded
systems
contain
processing
cores
that
are
either microcontrollers or digital signal processors (DSP). The key
characteristic, however, is being dedicated to handle a particular task.
Since the embedded system is dedicated to specific tasks, design
engineers can optimize it to reduce the size and cost of the product and
increase the reliability and performance. Some embedded systems are
mass-produced, benefiting from economies of scale.
Robotics and automation are a part of embedded systems itself. Robot
development and automation needs study of embedded systems.

Examples of Embedded System are


I. automatic teller machines (ATMs)
II. avionics, such as inertial guidance systems, flight control
hardware/software and other integrated systems in aircraft and
missiles
III. cellular telephones and telephone switches
IV. computer equipment such as routers and printers
V. engine controllers and antilock brake controllers for
automobiles
VI. home automation products, like thermostats, air conditioners,
sprinklers, and security monitoring systems
VII. handheld calculators
VIII. household appliances, including microwave ovens, washing
machines, television sets
IX. medical equipment
X. handheld computers
XI. videogame consoles

FEATURES OF EMBEDDED SYSTEMS


1.

2.

3.

4.

Embedded systems are designed to do some specific task, rather than


be a general-purpose computer for multiple tasks. Some also
have real-time performance constraints that must be met, for reasons
such as safety and usability; others may have low or no performance
requirements, allowing the system hardware to be simplified to
reduce costs.
The program instructions written for embedded systems are referred
to as firmware, and are stored in read-only memory or Flash
memory chips. Many embedded systems consist of small,
computerized parts within a larger device that serves a more general
purpose. For example- a line follower autonomous robot which
follows a specific path and moves accordingly to the path.
The embedded systems are special purpose computer systems
designed to perform only the specific purposes. For Example- a
system designed to display numbers cannot be used to operate
motors.
Embedded systems range from no user interface at all dedicated
only to one task to complex graphical user interfaces that resemble
modern computer desktop operating systems. Simple embedded
devices use buttons, LEDs, graphic or character LCDs (for example
popular HD44780 LCD) with a simple menu system.

EMBEDDED SYSTEMS PROCESSORS


Embedded processors can be broken into two broad categories. Ordinary
microprocessors (P) use separate integrated circuits for memory and
peripherals. Microcontrollers (C) have many more peripherals on chip,
reducing power consumption, size and cost. In contrast to the personal
computer market, many different basic CPU architectures are used, since
software is custom-developed for an application and is not a commodity
product installed by the end user. RISC (Reduced Instruction Set
Computing) as well as non-RISC processors are found. Word lengths
vary from 4-bit to 64-bits and beyond, although the most typical remain
8/16-bit.

MICROPROCESSOR
A Microprocessor is an IC which has only the CPU inside it i.e. only
the processing powers such as Intels Pentium 1,2,3,4, core 2 duo, i3, i5
etc. Microprocessor find applications where tasks are unspecific like
developing software, games, websites, photo editing, creating documents
etc. In such cases the relationship between input and output is not
defined. They need high amount of resources like RAM, ROM, I/O ports
etc. So needs external RAM, ROM and Memory. The microprocessor
operates above 1GHz as they perform complex tasks.
The microprocessors are used in personal computers or other general
purpose applications such as for laptops and heavy applications where
complexity is more and memory requirements are high.
7

MICROCONTROLLER
A Microcontroller (sometimes abbreviated C, uC or MCU) is a small
computer on a single integrated circuit containing a processor core,
memory, and programmable input/output peripherals.
Microcontrollers are designed to perform specific tasks. Specific means
applications where the relationship of input and output is defined.
Depending on the input, some processing needs to be done and output is
delivered. For example, keyboards, mouse, washing machine, digicam,
pen drive, remote, microwave, cars, bikes, telephone, mobiles, watches,
etc.
Since the applications are very specific, they need small resources like
RAM, ROM, I/O ports etc. and hence can be embedded on a single chip.
The microcontrollers operate from a few MHz to 30 to 50 MHz.
The microcontroller is designed for embedded applications.
Microcontrollers are used in automatically controlled products and
devices, such as automobile engine control systems, implantable medical
devices, remote controls, office machines, appliances, power tools, toys
and other embedded systems.

So microcontrollers are more preferred over microprocessors for


embedded applications because of the simplicity in design and cheaper
availability. The system design using microcontroller cost much cheaper
than the microprocessors design because memory, RAM, and ROM is
built-in in a microcontroller as compared to microprocessor in which
external memory and RAM and ROM are to interfaced with it.

MICROCONTROLLER FAMILIES
8051- These microcontrollers are old but still trendy and most of the
companies fabricate these microcontrollers. The older types of 8051
have 12 clocks per instruction that make it sluggish whereas the recent
8051 have 6 clocks per instruction. The 8051 microcontroller does not
have an in built memory bus and A/D converters. In 1980, Intel
fabricated the single chip microcontroller 8051 with Harvard
architecture.
PIC- Programmable Interface Controller is usually referred as PIC.
They are slightly older than 8051 microcontrollers but excel because of
their small low pin count devices. They perform well and are affordable.
The Microchip technology fabricated the single chip microcontroller
PIC with Harvard architecture. The programming part is very tedious
and hence it is not recommended for beginners.
AVR (Advanced Version RISC) - In 1996, Atmel fabricated this single
chip microcontroller with a modified Harvard Architecture. This chip is
loaded with C- compiler, Free IDE and many more features. This
microcontroller is a bit difficult for the starters to handle.

AVR FAMILY
The AVR is
a modified
Harvard
architecture 8-bit RISC single
chip microcontroller which was developed by Atmel in 1996. The AVR
was one of the first microcontroller families to use on-chip flash
memory for program storage, as opposed to one-time programmable
ROM, EPROM, or EEPROM used by other microcontrollers at the time.

BRIEF HISTORY
The AVR architecture was conceived by two students at the Norwegian
Institute of Technology (NTH) Alf-Egil Bogen Blog and Vegard
Wollan.
The original AVR MCU was developed at a local ASIC house
in Trondheim, Norway called Nordic VLSI at the time, now Nordic
Semiconductor, where Bogen and Wollan were working as students. It
was known as a RISC (Micro RISC) and was available as silicon
IP/building block from Nordic VLSI. When the technology was sold to
Atmel from Nordic VLSI, the internal architecture was further
developed by Bogen and Wollan at Atmel Norway, a subsidiary of
Atmel. The designers worked closely with compiler writers at IAR
Systems to ensure that the instruction set provided for more
efficient compilation of high-level languages. Atmel says that the name
AVR is not an acronym and does not stand for anything in particular.
The creators of the AVR give no definitive answer as to what the term
"AVR" stands for. However, it is commonly accepted that AVR stands
for Alf (Egil Bogen) and Vegard (Wollan)'s RISC processor.
Note that the use of "AVR" here generally refers to the 8-bit RISC line
of Atmel AVR Microcontrollers.
Among the first of the AVR line was the AT90S8515, which in a 40-pin
DIP package has the same pinout as an 8051 microcontroller, including
the external multiplexed address and data bus. The polarity of
the RESET line was opposite (8051's having an active-high RESET,
10

while the AVR has an active-low RESET), but other than that, the
pinout was identical.

BASIC FAMILIES
AVRs are generally classified into six broad groups:
tinyAVR the ATtiny series
0.516 kB program memory
632-pin package
Limited peripheral set
megaAVR the ATmega series
4512 kB program memory
28100-pin package
Extended
instruction set (multiply instructions and
instructions for handling larger program memories)
Extensive peripheral set
XMEGA the ATxmega series
16384 kB program memory
4464100-pin package (A4, A3, A1)
Extended performance features, such as DMA, "Event
System", and cryptography support.
Extensive peripheral set with ADCs
Application-specific AVR
megaAVRs with special features not found on the other
members of the AVR family, such as LCD
controller, USB controller, advanced PWM, CAN, etc.
FPSLIC (AVR with FPGA)
FPGA 5K to 40K gates
SRAM for the AVR program code, unlike all other AVRs
AVR core can run at up to 50 MHz.
32-bit AVRs
In 2006 Atmel released microcontrollers based on the new,
32bit, AVR32 architecture. They include SIMD and DSP instructions,
along with other audio and video processing features. This 32-bit family
11

of devices is intended to compete with the ARM based processors. The


instruction set is similar to other RISC cores, but it is not compatible
with the original AVR or any of the various ARM cores.

Programming interfaces
There are many means to load program code into an AVR chip. The
methods to program AVR chips varies from AVR family to family.

ISP

6- and 10-pin ISP header diagrams


The in-system programming (ISP) programming method is functionally
performed through SPI, plus some twiddling of the Reset line. As long
as the SPI pins of the AVR are not connected to anything disruptive, the
AVR chip can stay soldered on a PCB while reprogramming. All that is
needed is a 6-pin connector and programming adapter. This is the most
common way to develop with an AVR.
The Atmel AVR ISP mkII device connects to a computer's USB port and
performs in-system programming using Atmel's software.

AVRDUDE
(AVR Downloader/UploaDEr) runs on Linux, FreeBSD, Windows,
and Mac OS X, and supports a variety of in-system programming
hardware, including Atmel AVR ISP mkII, Atmel JTAG ICE, older
12

Atmel serial-port based programmers, and various third-party and "do-ityourself" programmers.

PDI
The Program and Debug Interface (PDI) is an Atmel proprietary
interface for external programming and on-chip debugging of XMEGA
devices. The PDI supports high-speed programming of all non-volatile
memory (NVM) spaces; flash, EEPROM, fuses, lock-bits and the User
Signature Row. This is done by accessing the XMEGA NVM controller
through the PDI interface, and executing NVM controller commands.
The PDI is a 2-pin interface using the Reset pin for clock input
(PDI_CLK) and a dedicated data pin (PDI_DATA) for input and output.

High voltage serial


High-voltage serial programming (HVSP) is mostly the backup mode on
smaller AVRs. An 8-pin AVR package does not leave many unique
signal combinations to place the AVR into a programming mode. A 12
volt signal, however, is something the AVR should only see during
programming and never during normal operation.

High voltage parallel


High voltage parallel programming (HVPP) is considered the "final
resort" and may be the only way to fix AVR chips with bad fuse
settings.

Bootloader
Most AVR models can reserve a bootloader region, 256 B to 4 KB,
where re-programming code can reside. At reset, the bootloader runs
first, and does some user-programmed determination whether to re13

program, or jump to the main application. The code can re-program


through any interface available, it could read an encrypted binary
through an Ethernet adapter like PXE. Atmel has application notes and
code pertaining to many bus interfaces.

ROM
The AT90SC series of AVRs are available with a factory mask-ROM
rather than flash for program memory. Because of the large up-front cost
and minimum order quantity, a mask-ROM is only cost-effective for
high production runs.

aWire
aWire is a new one-wire debug interface available on the new UC3L
AVR32 devices.

14

ATMEGA 16 MICROCONTROLLER
ATmega16 is an 8-bit high performance microcontroller of Atmels
Mega AVR family with low power consumption. Atmega16 is based on
enhanced RISC (Reduced Instruction Set Computing, Know more
about RISC and CISC Architecture) architecture with 131 powerful
instructions. Most of the instructions execute in one machine cycle.
Atmega16 can work on a maximum frequency of 16MHz.
ATmega16 has 16 KB programmable flash memory, static RAM of 1
KB and EEPROM of 512 Bytes. The endurance cycle of flash memory
and EEPROM is 10,000 and 100,000, respectively.
ATmega16 is a 40 pin microcontroller. There are 32 I/O (input/output)
lines which are divided into four 8-bit ports designated as PORTA,
PORTB, PORTC and PORTD.
ATmega16 has various in-built peripherals like USART, ADC, Analog
Comparator, SPI, JTAG etc. Each I/O pin has an alternative task related
to in-built peripherals.

FEATURES
High-performance, Low-power AVR 8-bit Microcontroller
Advanced RISC Architecture
- 131 Powerful Instructions - Most Single Clock Cycle Execution
- 32 x 8 General Purpose Working Registers
- Up to 6 MIPS Throughput at 16MHz
- Fully Static Operation
- On-chip 2-cycle Multiplier
Nonvolatile Program and Data Memories
- 16k Bytes of In-System Self-Programmable Flash
- Optional Boot Code Section with Independent Lock Bits
- 512K Bytes EEPROM
15

- Programming Lock for Software Security


JTAG (IEEE std. 1149.1 Compliant) Interface
- Boundary-scan Capabilities According to the JTAG Standard
- Extensive On-chip Debug Support
- Programming of Flash, EEPROM, Fuses, and Lock Bits through the
JAGS Interface
Peripheral Features
- On-chip Analog Comparator
- Programmable Watchdog Timer with Separate On-chip Oscillator
- Master/Slave SPI Serial Interface
- Two 8-bit Timer/Counters with Separate Prescalar, Compare
- One 16-bit Timer/Counter with Separate Prescaler, Compare and
Capture mode
- Real Time Counter with Separate Oscillator
- Four PWM Channels
- 8-channel, 10-bit ADC
- Byte-oriented Two-wire Serial Interface
- Programmable Serial USART
Special Microcontroller Features
- Power-on Reset and Programmable Brown-out Detection
- Internal Calibrated RC Oscillator
- External and Internal Interrupt Sources
- Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Powerdown, Standby, and Extended Standby
I/O and Packages
- 32 Programmable I/O Lines
- 40-pin PDIP, 44-lead TQFP, and 44-pad MLF
Operating Voltages
- 4.5-5.5V for ATmega16
Speed Grades
- 0-16 MHz for ATmega16
Power Consumption at 4 Mhz, 3V, 35 C
- Active: 1.1mA
- Idle Mode: 0.35mA
- Power-down Mode: < 1A
16

PIN DIAGRAM

17

PIN DESCRIPTION
Pin No.

Pin name

Description

Alternate Function

(XCK/T0) PB0

I/O PORTB, Pin 0

T0: Timer0 External Counter Input.


XCK : USART External Clock I/O

(T1) PB1

I/O PORTB, Pin 1

T1:Timer1 External Counter Input

(INT2/AIN0) PB2

I/O PORTB, Pin 2

AIN0: Analog Comparator Positive I/P


INT2: External Interrupt 2 Input

(OC0/AIN1) PB3

I/O PORTB, Pin 3

AIN1: Analog Comparator Negative I/P


OC0 : Timer0 Output Compare Match Output

(SS) PB4

I/O PORTB, Pin 4

(MOSI) PB5

I/O PORTB, Pin 5


In System Programmer (ISP)
Serial Peripheral Interface (SPI)

(MISO) PB6

I/O PORTB, Pin 6

(SCK) PB7

I/O PORTB, Pin 7

RESET

Reset Pin, Active Low Reset

10

Vcc

Vcc = +5V

11

GND

GROUND

12

XTAL2

Output to Inverting Oscillator Amplifier

13

XTAL1

Input to Inverting Oscillator Amplifier

14

(RXD) PD0

I/O PORTD, Pin 0

15

(TXD) PD1

I/O PORTD, Pin 1

16

(INT0) PD2

I/O PORTD, Pin 2

External Interrupt INT0

17

(INT1) PD3

I/O PORTD, Pin 3

External Interrupt INT1

18

(OC1B) PD4

I/O PORTD, Pin 4

19

(OC1A) PD5

I/O PORTD, Pin 5

20

(ICP) PD6

I/O PORTD, Pin 6

Timer/Counter1 Input Capture Pin

21

PD7 (OC2)

I/O PORTD, Pin 7

Timer/Counter2 Output Compare Match Output

22

PC0 (SCL)

I/O PORTC, Pin 0

23

PC1 (SDA)

I/O PORTC, Pin 1

24

PC2 (TCK)

I/O PORTC, Pin 2

USART Serial Communication Interface

PWM Channel Outputs

TWI Interface

JTAG Interface

18

25

PC3 (TMS)

I/O PORTC, Pin 3

26

PC4 (TDO)

I/O PORTC, Pin 4

27

PC5 (TDI)

I/O PORTC, Pin 5

28

PC6 (TOSC1)

I/O PORTC, Pin 6

Timer Oscillator Pin 1

29

PC7 (TOSC2)

I/O PORTC, Pin 7

Timer Oscillator Pin 2

30

AVcc

Voltage Supply = Vcc for ADC

31

GND

GROUND

32

AREF

Analog Reference Pin for ADC

33

PA7 (ADC7)

I/O PORTA, Pin 7

ADC Channel 7

34

PA6 (ADC6)

I/O PORTA, Pin 6

ADC Channel 6

35

PA5 (ADC5)

I/O PORTA, Pin 5

ADC Channel 5

36

PA4 (ADC4)

I/O PORTA, Pin 4

ADC Channel 4

37

PA3 (ADC3)

I/O PORTA, Pin 3

ADC Channel 3

38

PA2 (ADC2)

I/O PORTA, Pin 2

ADC Channel 2

39

PA1 (ADC1)

I/O PORTA, Pin 1

ADC Channel 1

40

PA0 (ADC0)

I/O PORTA, Pin 0

ADC Channel 0

19

DTMF BASED POSITION CALCULATOR


GENERAL DESCRIPTION
It is a two wheeled robot which calculates the displacement and
direction of its current position with respect to its initial position. It also
calculates the total distance travelled while reaching the current position.
The movement of the robot is controlled by DTMF signalling through a
mobile phone. The robot calculates the distance, displacement and
direction and displays it on the LCD. It uses stepper motors for
definitive and controlled movements.

COMPONENTS USED
1. LCD
2. STEPPER MOTORS-TWO
3. DTMF DECODER
4. ULN2803

20

LCD
LCD (Liquid Crystal Display) is a display device used to display an
output of from the microcontroller. The microcontroller is much faster
than the LCD, so the LCD has a feature to inform us of this busy status.
For the LCD to accept information, we must turn its enable pin on and
off while the information is present for the LCD to accept.

PIN CONFIGURATION:

Memory Mapping in 16*2 LCD:


The memory of a LCD is divided into three regions. They are:
(a)DDRAM (Display data random access memory)
(b)CGRAM (Character generation random access memory)
(c)CGROM (Character generation read only memory)
21

DDRAM: (Display data RAM)


Display data RAM is the memory area used for displaying character.
This is memory area associated with the display area on the LCD. A
max. of 80 characters can be stored in this memory out of which only 32
characters are visible at a time on LCD screen. These 32 characters are
displayed as 16 characters in one row and rest in other row. To display
any character on the LCD, we pass the display location (DDRAM
address) to the Hitachis microcontroller and then the character to be
displayed. DDRAM memory address starts from 0x80 to 0xA7 in the
first row and 0xC0 to 0xE7in the second row.

CGROM (Character generation ROM)


This is memory where all the predefined patterns are stored. The
patterns are drawn in this area at the time of LCD manufacturing. The
patterns are stored such that their memory address is equivalent to the
ASCII code for that pattern.

CGRAM (Character Generator RAM)


This area of the LCD memory is used when the user wants to create its
own character like a bell shape, a heart shape or something else. As we
can see in the memory diagram, we have blank locations from 0 to 7 (a
total of 8 locations). These locations are used for accessing the user
defined characters created in CGRAM memory area.

22

STEPPER MOTOR

A stepper motor is a widely used device that translates electrical pulses


into mechanical movements. Stepper motor is mainly used when we
require an accurate movement or step by step movement. In application
such as disk drives, dot matrix printer, and robotics, the stepper motor is
used for position control.
Stepper motors commonly have permanent magnet rotor (also called
shaft) surrounded by stator.
The most common stepper motors have four stator windings that are
paired with a center-tapped common .this type of stepper motor is
commonly referred to as a four-phase or unipolar stepper motor. The
center tap allows a change of the stator. Notice that the stepper motor
shaft moves in a fixed repeatable increment, which allows one to move it
to a precise position. This repeatable fixed movement is possible as a
result of basic magnetic theory where poles of the same polarity repel
and opposite poles attract. The direction of the rotation is dictated by the
stator poles.

23

STEP ANGLE
How much movement is associated with a single step depends on the
internal construction of the motor, in particular the number of teeth on
the stator step. Various motors have different step angles.
STEPS per second and RPM relation
The relation between rpm(revolutions per minute) or steps per
revolution, and steps per second is as follows:
Steps per second = RPM * steps per revolution/ 60
UNI-POLAR VS BI-POLAR stepper motor interface:
There are three common types of stepper motors:
Universal
Unipolar and
Bipolar.
They can be identified by the no. of connections to the motor. A
universal stepper motor has eight, while the unipolar has 5 or 6 and
bipolar has four. The universal motor can be configured for all three
modes, while the unipolar can be either unipolar or bipolar. Obviously
the bipolar cannot be configured for universal or the unipolar.

ULN2803
This IC is basically for interfacing the stepper motor to the microcontroller. This IC also prevent the micro-controller from the eddy
current generated by the stepper motor. Thus it is also called buffer IC.
Basically its a 18pin IC. The first eight pins are for inputs,pin 9 is for
GND, pin 10 is for Vcc(common positive), and pin 11 to 18 are for
outputs. The input pins are directly connected with the micro-controller
to take the corresponding code which is given in the program. The ouput
of the ULN2803 IC is just reverse of the input code given to the
24

ULN2803 by the micro-controller through the program. The basic pin


diagram of ULN2803 IC is given below-

Circuit diagram: in this we connect one stepper motor with microcontroller.


The hex code table of a single stepper motor is shown below to show
that how is the coding of the stepper motor is done for different
directions. The corresponding program is also given below:

Direction : forward
PIN 1
PIN2
1
0

PIN3
0

PIN4
0
25

HEX CODE
01

0
0
0

1
0
0

0
1
0

0
0
1

02
04
08

PIN4
1
0
0
0

HEX CODE
08
04
02
01

Program for forward direction:


Int main()
{
DDRB=0xff;
While(1)
{
PORTB=0x01; _delay_ms(5);
PORTB=0x02; _delay_ms(5);
PORTB=0x04; _delay_ms(5);
PORTB=0x08; _delay_ms(5);
Direction : backward
PIN 1
PIN2
PIN3
0
0
0
0
0
1
0
1
0
1
0
0
Program for backward direction:
Int main()
{
DDRB=0xff;
While(1)
{
PORTB=0x08; _delay_ms(5);
PORTB=0x04; _delay_ms(5);
PORTB=0x02; _delay_ms(5);
PORTB=0x01; _delay_ms(5);

26

DTMF
DTMF stands for Dual Tone Multiple Frequency. It is a system which
consists of two frequencies superimposed. Individual frequencies are
chosen such that it is easy to design filters and easy to transmit the tones
through a telephone line having bandwidth of approximately 3.5 kHz.

Hz
697
770
852
941

1209
1
4
7
*

1336
2
5
8
0

1477
3
6
9
#

1633
A
B
C
D

GENERATING DTMF
DTMF signals can be generated through dedicated ICs or by using RC
networks connected to a microprocessor. MT8880 is an example of a
dedicated IC. Most often, DTMF encoder software in P.C. or inbuilt
dialling pulse of landline/mobile can be used for encoding purpose of
generating DTMF signals.

DECODING DTMF
For detecting purpose, a dedicated IC MT8870 is used. It uses two 6 th
order band-pass filters using switched capacitor filters which suppress
harmonics and hence good sine waves can be produced from distorted
input.

27

DIGITAL OUTPUTS TABLE


KEY
1
2
3
4
5
6
7
8
9
0
*
#
A
B
C
D

F1(Hz)
1209
1336
1477
1209
1336
1477
1209
1336
1477
1336
1209
1477
1633
1633
1633
1633

F2(Hz)
697
697
697
770
770
770
852
852
852
941
941
941
697
770
852
941

Q1
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1

Q2
0
0
0
1
1
1
1
0
0
0
0
1
0
1
1
1

INTERFACING

28

Q3
0
1
1
0
0
1
1
0
0
1
1
0
1
0
1
1

Q4
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
1

PROGRAM CODE
#include<avr/io.h>
#include<util/delay.h>
#include<math.h>
#define F_CPU 1000000
#define RS 0
#define RW 1
#define EN 2
#define LCD PORTB
#define LEFT PORTD
#define RIGHT PORTC
#define r 3
#define R 5
#define NOC 90
//lcd functions
void lcd_init()
{
lcd_cmd(0x02);
lcd_cmd(0x28);
lcd_cmd(0x06);
lcd_cmd(0x0C);
}
void lcd_cmd(unsigned int X)
{
LCD=X&(0xF0);
LCD=LCD&(~(1<<RS));
LCD=LCD&(~(1<<RW));
LCD=LCD|(1<<EN);
_delay_ms(1);
LCD=LCD&(~(1<<EN));
29

X=(X<<4);
LCD=X&(0xF0);
LCD=LCD&(~(1<<RS));
LCD=LCD&(~(1<<RW));
LCD=LCD|(1<<EN);
_delay_ms(1);
LCD=LCD&(~(1<<EN));
}
void lcd_data(unsigned int Y)
{
LCD=Y&(0xF0);
LCD=LCD|(1<<RS);
LCD=LCD&(~(1<<RW));
LCD=LCD|(1<<EN);
_delay_ms(1);
LCD=LCD&(~(1<<EN));
Y=(Y<<4);
LCD=Y&(0xF0);
LCD=LCD|(1<<RS);
LCD=LCD&(~(1<<RW));
LCD=LCD|(1<<EN);
_delay_ms(1);
LCD=LCD&(~(1<<EN));
}
void lcd_number(unsigned int pos,unsigned int num)
{
unsigned int a;
lcd_cmd(pos);
lcd_cmd(0x04);
while(num!=0)
{
30

a=num%10;
lcd_data(a+48);
num=num/10;
}
lcd_cmd(0x06);
}
void lcd_string(unsigned int pos,unsigned char *p)
{
for(int i=0;p[i]!='\0';i++)
{
lcd_data(p[i]);
}
}
//display on lcd
void display(unsigned int distance,unsigned int D,int phi)
{
lcd_cmd(0x01);
lcd_string(0x80,"DISTANCE");
lcd_number(0x8f,distance);
lcd_string(0xC0,"DISPLACEMENT");
lcd_number(0xCf,D);
_delay_ms(1000);
lcd_cmd(0x01);
lcd_string(0x80,"ANGLE");
lcd_number(0x8f,(unsigned int)phi);
if(phi<0)
{
lcd_string(0xc0,"CLOCKWISE");
}
else
{
lcd_string(0xc0,"ANTICLOCKWISE");
31

}
_delay_ms(1000);
}
//calculate functions
unsigned int calc_d(unsigned int NOC2)
{
unsigned int d;
d=(NOC2*2*3.14*r)/NOC;
return d;
}
int calc_theta(unsigned int NOC3,unsigned int input)
{
int theta;
if(input==4)
{
theta=(NOC3*2*3.14*r)/(R*NOC);
}
else if(input==6)
{
theta=(-1)*((NOC3*2*3.14*r)/(R*NOC));
}
else
{
theta=0;
}
return theta;
}
int calc_phi(int phi,int theta)
{
32

phi=phi+theta;
return phi;
}
int calc_x(int x,unsigned int d,int phi)
{
x=x+d*cos(phi);
return x;
}
int calc_y(int y,unsigned int d,int phi)
{
y=y+d*sin(phi);
return y;
}
unsigned int calc_distance(unsigned int distance,unsigned int d)
{
distance=distance+d;
return distance;
}
unsigned int calc_D(int x,int y)
{
unsigned int D;
D=sqrt(pow(x,2)+pow(y,2));
return D;
}
33

//user input function


unsigned int get_and_convert_input()
{
unsigned int input=8;
if(PINA==0b00100000)
{
input=2;
}
else if(PINA==0b01000000)
{
input=4;
}
else if(PINA==0b01100000)
{
input=6;
}
else if(PINA==0b10000000)
{
input=8;
}
return input;
}
//stepper motor funtions
void forward_cycle()
{
LEFT=0b10000000;
RIGHT=0b10000000;
_delay_ms(15);
LEFT=0b01000000;
RIGHT=0b01000000;
_delay_ms(15);
LEFT=0b00100000;
RIGHT=0b00100000;
_delay_ms(15);
34

LEFT=0b00010000;
RIGHT=0b00010000;
_delay_ms(15);
}
void anticlockwise_cycle()
{
LEFT=0b00010000;
RIGHT=0b10000000;
_delay_ms(15);
LEFT=0b00100000;
RIGHT=0b01000000;
_delay_ms(15);
LEFT=0b01000000;
RIGHT=0b00100000;
_delay_ms(15);
LEFT=0b10000000;
RIGHT=0b00010000;
_delay_ms(15);
}
void clockwise_cycle()
{
LEFT=0b10000000;
RIGHT=0b00010000;
_delay_ms(15);
LEFT=0b01000000;
RIGHT=0b00100000;
_delay_ms(15);
LEFT=0b00100000;
RIGHT=0b01000000;
_delay_ms(15);
LEFT=0b00010000;
RIGHT=0b10000000;
_delay_ms(15);
35

}
void main()
{
DDRA=0x00;
DDRB=0xff;
DDRC=0xff;
DDRD=0xff;
lcd_init();
unsigned int input,NOC2,NOC3,d,D,distance;
int x,y,theta,phi;
input=8;
NOC2=0;
NOC3=0;
x=0;
y=0;
theta=0;
phi=0;
d=0;
D=0;
distance=0;
while(1)
{
while(1)
{
if(input==8)
{
display(distance,D,phi);
}
else if(input==2)
{
forward_cycle();
NOC2++;
36

}
else if(input==4)
{
anticlockwise_cycle();
NOC3++;
}
else if(input==6)
{
clockwise_cycle();
NOC3++;
}

if(input!=get_and_convert_input())
{
theta=calc_theta(NOC3,input);
phi=calc_phi(phi,theta);
d=calc_d(NOC2);
x=calc_x(x,d,phi);
y=calc_y(y,d,phi);
distance=calc_distance(distance,d);
D=calc_D(x,y);
input=get_and_convert_input();
NOC2=0;
NOC3=0;
break;
}
}
}
}

37

BIBLIOGRAPHY

www.wikipedia.com
www.i3indya.com
www.atmel.com
Embedded systems and robotics basic module by
i3indya technologies
Embedded systems and robotics advanced module by
i3indya technologies
www.avrfreaks.com

38

Вам также может понравиться