Академический Документы
Профессиональный Документы
Культура Документы
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
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.
2.
3.
4.
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.
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
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
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.
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
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
PIN DIAGRAM
17
PIN DESCRIPTION
Pin No.
Pin name
Description
Alternate Function
(XCK/T0) PB0
(T1) PB1
(INT2/AIN0) PB2
(OC0/AIN1) PB3
(SS) PB4
(MOSI) PB5
(MISO) PB6
(SCK) PB7
RESET
10
Vcc
Vcc = +5V
11
GND
GROUND
12
XTAL2
13
XTAL1
14
(RXD) PD0
15
(TXD) PD1
16
(INT0) PD2
17
(INT1) PD3
18
(OC1B) PD4
19
(OC1A) PD5
20
(ICP) PD6
21
PD7 (OC2)
22
PC0 (SCL)
23
PC1 (SDA)
24
PC2 (TCK)
TWI Interface
JTAG Interface
18
25
PC3 (TMS)
26
PC4 (TDO)
27
PC5 (TDI)
28
PC6 (TOSC1)
29
PC7 (TOSC2)
30
AVcc
31
GND
GROUND
32
AREF
33
PA7 (ADC7)
ADC Channel 7
34
PA6 (ADC6)
ADC Channel 6
35
PA5 (ADC5)
ADC Channel 5
36
PA4 (ADC4)
ADC Channel 4
37
PA3 (ADC3)
ADC Channel 3
38
PA2 (ADC2)
ADC Channel 2
39
PA1 (ADC1)
ADC Channel 1
40
PA0 (ADC0)
ADC Channel 0
19
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:
22
STEPPER MOTOR
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
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
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
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
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