this is a complete summer training report on embedded sys_AVR. It aslo includes a project and its coding and other topics which are learnt in training.
1. A
Practical Training Report On
Embedded System
Taken at
RaycoreIndia PVT. LTD., Greater NOIDA
Submitted in Partial Fulfilment of
Bachelor of Technology
ECE IV Year VII Semester
Galgotias College of Engineering and Technology
Session (2016-2017)
Submitted by:-
Saket Mishra
Roll No.-1309731082
Submitted To:-
Mr. Depaak Gangwar
Department of Electronics & Communication Engineering
Galgotias College of engineering and technology, Greater NOIDA
2. CONTENTS
Serial
No.
Topic
1. Company Review
2. Training certificate
3. Embedded System
4. Microcontroller (AVR)
5. Architecture of AVR (Atmega 16)
6. Embedded C
7. Interfacing of AVR
8. Modules
9. Project
10. Bibliography
3. 1. Company Overview
RaycoreIndia Research & automation PVT. LTD. is the start-up leader in electronics,
software, services and solutions that help people and businesses realize their full
potential. At RaycoreIndia, we’re motivated and inspired every day by how our
customers use our services to find creative solutions to business problems, develop
breakthrough ideas, and stay connected to what’s most important to them. AN ISO
9001: 2008 certified company
Training And Project development
Embedded | Robotics | Automation
Placement
Software development
Robotics Products
Research
4. 2. Certification
REFF NO: RAYGN/15/1090
Internship Offer Letter
Date: 01/07/2015
SAKET MISHRA
ROLL NO: 1309731082
COLLEGE: GCET / BRANCH: ECE
Dear,
I am pleased to confirm your acceptance of an internship position as software trainee
in EMBEDDED SYSTEM. Complete module of ONE year at Greater Noida Branch. Your first
day of the training will be 04/07/2015. Your duties and assignments for this position will
be those described to you in your orientation with Mr Pradeep.
Please report to the Human Resources Department at 10 a.m. on 04/07/2015 with
the appropriate documents and completed forms.
If you have any questions, please feel free to contact Mr Amit. We are very pleased that
you have decided to join RaycoreIndia Pvt. Ltd. We look forward to seeing you on
04/17/2015 and offer a very warm welcome.
Sincerely,
Thanking you
HR DEPARTMENT
Satish Bhuyan
Raycore India Research & Automation PVT. LTD.
WWW.RAYCOREINDIA.COM : MOB: +91 9643736342: PHONE: 0120 4126369
5. 3. Introduction of Embedded System
Embedded means something that is attached to another thing. An embedded system can be
thought of as a computer hardware system having software embedded in it. An embedded
system can be an independent system or it can be a part of a large system. An embedded
system is a microcontroller or microprocessor based system which is designed to perform a
specific task.
DEFINITION: Embedded System is a combination of Hardware and Software to meet
specific needs in a given time frame.
Embeddedsystemscontaintwomainelements:
Embedded system hardware: As with any electronic system, an embedded system
requires a hardware platform on which to run. The hardware will be based around a
microprocessor or microcontroller. The embedded system hardware will also contain
other elements including memory, input output (I/O) interfaces as well as the user
interface, and the display.
Embedded system software: The embedded system software is written to perform a
particular function. It is typically written in a high level format and then compiled
down to provide code that can be lodged within a non-volatile memory within the
hardware.
Examples of Embedded System:
Automated transaction machines (ATMS).
Integrated system in aircraft and missile.
Cellular telephones and telephonic switches.
Computer network equipment, including routers timeservers and firewalls
Computer printers, Copiers.
6. Basic Structure of an Embedded System
Block diagram of a typical embedded system is shown in fig.
CHARACTERISTICS
Embedded systems are application specific & single functioned; the programs are
executed repeatedly.
Efficiency is of paramount importance for embedded systems. They are optimized for
energy, code size, execution time, weight & dimensions, and cost.
Embedded systems are typically designed to meet real time constraints; a real time
system reacts to stimuli from the controlled object/ operator within the time interval
dictated by the environment. For real time systems, right answers arriving too late (or
even too early) are wrong.
Embedded systems often interact (sense, manipulate & communicate) with external
world through sensors and actuators and hence are typically reactive systems; a reactive
system is in continual interaction with the environment and executes at a pace
determined by that environment.
They generally have minimal or no user interface.
4. Microcontroller Embedded Systems
7. A microcontroller is a functional computer system-on-a-chip. It contains an integrated
processor, memory (a small amount of RAM, program memory, or both), several peripheral
devices, such as timers, analog to digital converters, and serial communication devices all
on one chip resulting in compact and low-power implementations. It is not expandable as
it has no external bus interface.
Microcontrollers provide pin access which allows programs to easily monitor sensors, set
actuators, and transfer data with other devices. Providing specialized instructions improves
performance for embedded systems applications; thus, microcontrollers can be considered
ASIPs to some degree.
AVR
History of AVR:
AVR was developed in the year 1996 by Atmel Corporation. The architecture of AVR was
developed by Alf-Egil Bogen and Vegard Wollan. AVR derives its name from its
developers and stands for Alf-Egil Bogen Vegard Wollan RISC microcontroller, also
known as Advanced Virtual RISC. The AT90S8515 was the first microcontroller which
was based on AVR architecture however the first microcontroller to hit the commercial
market was AT90S1200 in the year 1997.
AVR microcontrollers are available in three categories:
1. Tiny AVR – Less memory, small size, suitable only for simpler applications
8. 2. Mega AVR – These are the most popular ones having good amount of memory (upto
256 KB), higher number of inbuilt peripherals and suitable for moderate to complex
applications.
3. Xmega AVR – Used commercially for complex applications, which require large
program memory and high speed.
The following table compares the above mentioned AVR series of microcontrollers:
Series Name Pins Flash Memory Special Feature
Tiny AVR 6-32 0.5-8 KB Small in size
Mega AVR 28-100 4-256KB Extended peripherals
X mega AVR 44-100 16-384KB
DMA , Event System
included
What’s special about AVR?
They are fast: AVR microcontroller executes most of the instructions in single execution
cycle. AVRs are about 4 times faster than PICs, they consume less power and can be operated
in different power saving modes. Let’s do the comparison between the three most commonly
used families of microcontrollers.
AVR is an 8-bit microcontroller belonging to the family of Reduced Instruction Set Computer
(RISC). In RISC architecture the instruction set of the computer are not only fewer in number
but also simpler and faster in operation. The other type of categorization is CISC (Complex
Instruction Set Computers).
CHARACTERISTICS 8051 PIC AVR
SPEED Slow Moderate Fast
MEMORY Small Large Large
ARCHITECTURE CISC RISC RISC
ADC Not Present Inbuilt Inbuilt
TIMERS Inbuilt Inbuilt Inbuilt
PWM Channels Not Present Inbuilt Inbuilt
9. What is 8-bit? This means that the microcontroller is capable of transmitting and receiving 8-
bit data. The input/output registers available are of 8-bits. The AVR family controllers have
register based architecture which means that both the operands for an operation are stored in a
register and the result of the operation is also stored in a register. Following figure shows a
simple example performing OR operation between two input registers and storing the value in
Output Register.
The CPU takes values from two input registers INPUT-1 and INPUT-2, performs the logical
operation and stores the value into the OUTPUT register. All this happens in 1 execution cycle.
In our journey with the AVR we will be working on Atmega16 microcontroller, which is a 40-
pin IC and belongs to the mega AVR category of AVR family. Some of the features of
Atmega16 are:
o 16KB of Flash memory
o 1KB of SRAM
o 512 Bytes of EEPROM
o Available in 40-Pin DIP
o 8-Channel 10-bit ADC
o Two 8-bit Timers/Counters
o One 16-bit Timer/Counter
o 4 PWM Channels
10. o In System Programmer (ISP)
o Serial USART
o SPI Interface
o Digital to Analog Comparator.
5. Architecture of AVR
The AVR microcontrollers are based on the advanced RISC architecture and consist of 32 x 8-
bit general purpose working registers. Within one single clock cycle, AVR can take inputs from
two general purpose registers and put them to ALU for carrying out the requested operation,
and transfer back the result to an arbitrary register. The ALU can perform arithmetic as well as
logical operations over the inputs from the register or between the register and a constant.
Single register operations like taking a complement can also be executed in ALU. We can see
that AVR does not have any register like accumulator as in 8051 family of microcontrollers;
the operations can be performed between any of the registers and can be stored in either of
them.
AVR follows Harvard Architecture format in which the processor is equipped with separate
memories and buses for Program and the Data information. Here while an instruction is being
executed, the next instruction is pre-fetched from the program memory.
Since AVR can perform single cycle execution, it means that AVR can execute 1 million
instructions per second if cycle frequency is 1MHz. The higher is the operating frequency of
the controller, the higher will be its processing speed. We need to optimize the power
consumption with processing speed and hence need to select the operating frequency
11. accordingly.
There are two flavours for Atmega16 microcontroller:
1. Atmega16:- Operating frequency range is 0 – 16 MHz
2. Atmega16L:- Operating frequency range is 0 – 8 MHz
If we are using a crystal of 8 MHz = 8 x 106 Hertz = 8 Million cycles, then AVR can execute
8 million instructions.
Naming Convention
The AT refers to Atmel the manufacturer, Megameans that the microcontroller belong to Mega
AVR category, 16 signifies the memory of the controller, which is 16KB.
Architecture Diagram: Atmega16
Following points explain the building blocks of Atmega16 architecture:
I/O Ports: Atmega16 has four (PORTA, PORTB, PORTC and PORTD) 8-bit input-output
ports.
Internal Calibrated Oscillator: Atmega16 is equipped with an internal oscillator for driving
its clock. By default Atmega16 is set to operate at internal calibrated oscillator of 1 MHz The
maximum frequency of internal oscillator is 8Mhz. Alternatively, ATmega16 can be operated
using an external crystal oscillator with a maximum frequency of 16MHz.
12. ADC Interface: Atmega16 is equipped with an 8 channel ADC (Analog to Digital Converter)
with a resolution of 10-bits. ADC reads the analog input for e.g., a sensor input and converts it
into digital information which is understandable by the microcontroller.
Timers/Counters: Atmega16 consists of two 8-bit and one 16-bit timer/counter. Timers are
useful for generating precision actions for e.g., creating time delays between two operations.
Interrupts: Atmega16 consists of 21 interrupt sources out of which four are external. The
remaining are internal interrupts which support the peripherals like USART, ADC, Timers etc.
USART: Universal Synchronous and Asynchronous Receiver and Transmitter interface
is available for interfacing with external device capable of communicating serially (data
transmission bit by bit).
General Purpose Registers: Atmega16 is equipped with 32 general purpose registers which
are coupled directly with the Arithmetic Logical Unit (ALU) of CPU.
Memory: Atmega16 consist of three different memory sections:
Flash EEPROM: Flash EEPROM or simple flash memory is used to store the program
dumped or burnt by the user on to the microcontroller. It can be easily erased electrically
a single unit. Flash memory is non-volatile i.e., it retains the program even if the power
is cut-off. Atmega16 is available with 16KB of in system programmable Flash
EEPROM.
Byte Addressable EEPROM: This is also a non-volatile memory used to store data
like values of certain variables. Atmega16 has 512 bytes of EEPROM, this memory can
13. be useful for storing the lock code if we are designing an application like electronic
door lock.
SRAM: Static Random Access Memory, this is the volatile memory of microcontroller
i.e., data is lost as soon as power is turned off. Atmega16 is equipped with 1KB of
internal SRAM. A small portion of SRAM is set aside for general purpose registers
used by CPU and some for the peripheral subsystems of the microcontroller.
ISP: AVR family of controllers have In System Programmable Flash Memory which can be
programmed without removing the IC from the circuit, ISP allows to reprogram the controller
while it is in the application circuit.
SPI: Serial Peripheral Interface, SPI port is used for serial communication between two
devices on a common clock source. The data transmission rate of SPI is more than that of
USART.
TWI: Two Wire Interface (TWI) can be used to set up a network of devices, many devices
can be connected over TWI interface forming a network, the devices can simultaneously
transmit and receive and have their own unique address.
DAC: Atmega16 is also equipped with a Digital to Analog Converter (DAC) interface which
can be used for reverse action performed by ADC. DAC can be used when there is a need of
converting a digital signal to analog signal.
AVR Pin description:
Pin No. Pin name Description Alternate Function
1
(XCK/T0)
PB0
I/O PORTB, Pin 0
T0: Timer0 External Counter Input.
XCK : USART External Clock I/O
2 (T1) PB1 I/O PORTB, Pin 1 T1:Timer1 External Counter Input
3
(INT2/AIN0)
PB2
I/O PORTB, Pin 2
AIN0: Analog Comparator Positive I/P
INT2: External Interrupt 2 Input
4
(OC0/AIN1)
PB3
I/O PORTB, Pin 3
AIN1: Analog Comparator Negative I/P
OC0 : Timer0 Output Compare Match Output
5 (SS) PB4 I/O PORTB, Pin 4 In System Programmer (ISP)
Serial Peripheral Interface (SPI)6 (MOSI) PB5 I/O PORTB, Pin 5
16. 6. Embedded C (AVR Programming language)
Embedded c is a subset of c language which is compatible with certain
microcontrollers.
Some features are added using header files like <avr/io.h>, <util/delay.h>.
Scanf and printf are removed as the inputs are scanned from the sensors and outputs are
given to the ports.
Control structures remain the same like if-statement, for loop, do while etc.
STRUCTURE OF A C PROGRAM FOR AN EMBEDDED SYSTEM
//Headers
#include<avr/io.h>//header file for avr I/O
#include<util/delay.h>//header file for delay
//main program
{
int main ()
while (1)
{
Code….
}
return(0);
}
We have four Ports
PORT A
PORT B
PORT C
PORT D
All ports have Read-Modify-Write functionality (all pins are capable of performing dual
functions)
17. Points to be noted for Programming:
PORT : group of 8 pins, or set of pins used for exchanging data with external world
Width of almost all registers : 8 bits (some 16 bits)
In port related registers, every bit corresponds to one pin of the port.
Bit 0 corresponds to Pin 0 & Bit 0 corresponds to Pin 1... Etc.
Remember direct one to one correspondence between HEX and BINARY numbers.
0xFF = 1111 1111
0xAA = 1010 1010
0x11 = 0001 0001
Input/output Basics:
DDRx: Data Direction (input/output) pins
Configures data direction of the port - Input / Output
DDRx.n = 0 > makes corresponding port pin as input
DDRx.n = 1 > makes corresponding port pin as output
Examples :
1. To make all pins of port A as input pins :
DDRA = 0b00000000;
2. To make all pins of port A as output pins
DDRA = 0b11111111;
3. To make lower nibble of port B as output and higher nibble as input
DDRB = 0b00001111;
PIN Register
Used to read data from port pins, when port is configured as input.
First set DDRx to zero, then use PINx to read the value.
If PINx is read, when port is configured as output, it will give you data that has
been outputted on port.
1. Example :
DDRA = 0x00; //Set PA as input
x = PINA; //Read contents of PA
18. PORT Register
For data output, when port is configured as output:
Writing to PORTx.n will immediately (in same clock cycle) change state of the
port pins according to given value.
Do not forget to load DDRx with appropriate value for configuring port pins as
output.
Examples :
1. To output 0xFF data on PB
DDRB = 0b11111111; //set all pins of port b as outputs
PORTB = 0xFF; //write data on port
2. To output data in variable x on PA
DDRA = 0xFF; //make port a as output
PORTA = x; //output 8 bit variable on port
For configuring pin as tristate/pullup, when port is configured as input):
When port is configures as input (i.e. DDRx.n=1), then PORTx.n controls the
internal pull-up resistor.
PORTx.n = 1 : Enables pullup for nth bit
PORTx.n = 0 : Disables pullup for nth bit, thus making it tristate
Examples :
1. To make PA as input with pull-ups enabled and read data from PA
DDRA = 0x00; //make port a as input
2. PORTA = 0xFF; //enable all pull-ups
y = PINA; //read data from port a pins
3. To make PB as tri stated input
DDRB = 0x00; //make port b as input
4. PORTB = 0x00; //disable pull-ups and make it tri state
19. 7. Interfacing and sending code from PC to AVR
Steps for coding in AVR Studio:
AVR studio is an Integrated Development Environment (IDE) by ATMEL for developing
applications based on AVR microcontroller.
STEP 1:
Click on new project.
STEP 2:
20. 1. Click on AVR GCC
2. Write the project name
3. Select your project location.
4. Click on Next>>
STEP 3:
1. Click on AVR Simulator in left block and then select your controller (e.g.: ATmega16).
2. Click on finish button.
STEP 4:
1. Write the code in main body area.
21. 2. Save the project file.
STEP5:
Go to BUILD -> Compile.
This will compile your code and generate error if there will be any.
STEP 6:
22. Again go to BUILD and click on Build. This will generate hex file of the code. Use that Hex
file to burn your microcontroller.
USBASP USB Programmer:
The USBasp USB programmer is connected to PC from USB side and to the AVR through
wires from the pin side. The connection is used to send the HEX file from PC to AVR
microcontroller.
The converted HEX file of the code is sent from PC/ system to the microcontroller is done by
a software called, sinaprog.
STEP 1: Click the “Folder” icon in the Hex file section and browse for the Hex file of the
project, which you want to download to the microcontroller and Select the HEX file.
23. STEP 2: Click the “Program” button in the Flash section to start the download of code/program
(Hex file of project) to the Flash memory of the microcontroller.
24. STEP 3: If the code/program download succeeds, then “Programming Flash…OK” is displayed
in the Status section band if the download fails, then “Programming failed” is displayed in the
Status section.
8. Modules
1. I R sensors:
The principle of operation of an infrared sensor is based on infrared light that is
reflected when hitting an obstacle. An IR receiver (Photo Diode) captures the reflected
light and the voltage are measured based on the amount of light received. Infrared
sensors are used in a wide range of applications proximity detection, robotic
applications for distance and object detection, and colour detection and tracking. The
output of the IR sensor can be digital or analog.
25. If the output of the analog IR sensor is analog in nature and these analog signals cannot
be processed directly by the ATmega16 microcontroller. So, first this signal needs to
be converted to digital value to be processed by the microcontroller. The conversion
can be done with the help of ADC of the AVR ATmega16 microcontroller. After
converting the analog signal to digital, the microcontroller will display the digital value
in the 1×8 LED array.
Pin description:
Pin 1 is the output so we wire this to a visible LED and resistor
Pin 2 is ground
Pin 3 is VCC, connect to 5V
2. Relay:
Relays are very interesting and useful electronic component. They are a kind of switch,
like those we use every day in our home and offices to turn on and off electrical devices
like bulbs, TVs, fans etc. The function of relay is to control the switching of a relatively
heavier load which demands high voltages (like 240 V AC mains) or high current, from
a relatively low voltage control signal (like 5v or 12v).
When power flows through the first circuit (1), it activates the electromagnet (brown),
generating a magnetic field (blue) that attracts a contact (red) and activates the second
circuit (2). When the power is switched off, a spring pulls the contact back up to its
original position, switching the second circuit off again.
Relays have the exact working of a switch. A relay is said to switch one or more
poles. Each pole has contacts that can be thrown in mainly three ways. They are
Normally Open Contact (NO) – NO contact is also called a make contact. It closes
the circuit when the relay is activated. It disconnects the circuit when the relay is
inactive.
26. Normally Closed Contact (NC) – NC contact is also known as break contact. This is
opposite to the NO contact. When the relay is activated, the circuit disconnects. When
the relay is deactivated, the circuit connects.
Change-over (CO) / Double-throw (DT) Contacts – This type of contacts are used
to control two types of circuits. They are used to control a NO contact and also a NC
contact with a common terminal. According to their type they are called by the
names break before make and make before break contacts.
3. Transmitter and receiver :
An RF Transmitter and Receiver pair is used for wireless communication. The wireless
data transmission is done using 433 MHz Radio Frequency signals. The circuit is
divided into transmitter and receiver sections. The transmitter section consists of an RF
Transmitter, HT12E encoder IC and four push buttons. The receiver section consists of
RF Receiver, HT12D Decoder IC and four LEDs. An extra LED is connected to VT
(Valid Transmission) pin of the decoder IC. This is used to indicate a successful
transmission of data
The RF transmitter transmits this serial data using radio signals. At the receiver side,
the RF receiver receives the serial data.
27. RF Transmitter
Pin
No
Function Name
1 Ground (0V) Ground
2 Serial data input pin Data
3 Supply voltage; 5V Vcc
4 Antenna output pin ANT
RF Receiver
Pin
No
Function Name
1 Ground (0V) Ground
2 Serial data output pin Data
3 Linear output pin; not connected NC
4 Supply voltage; 5V Vcc
5 Supply voltage; 5V Vcc
6 Ground (0V) Ground
7 Ground (0V) Ground
8 Antenna input pin ANT
LCD Module:
LCD (Liquid Crystal Display) screen is an electronic display module and find a wide
range of applications. A 16x2 LCD display is very basic module and is very commonly
used in various devices and circuits. A 16x2 LCD means it can display 16 characters
per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel
matrix. This LCD has two registers, namely, Command and Data. The command
register stores the command instructions given to the LCD. A command is an
instruction given to LCD to do a predefined task like initializing it, clearing its screen,
setting the cursor position, controlling display etc. The data register stores the data to
28. be displayed on the LCD. The data is the ASCII value of the character to be displayed
on the LCD.
Bluetooth Module:
Bluetooth is a type of wireless communication protocol used to send and receive date
between two devices. It is free to use wireless communication protocol.
The Module has two modes of operation namely,
AT Command Mode:
It is a mode of the module where a set of commands (AT Commands) are used to
setup and configure the module. In this mode, the module can’t be detected by other
Bluetooth Devices. For this mode take Key pin to HIGH. All the Commands are sent
to the module serially as a string.
Connection Mode:
In this mode the device can directly communicate with other devices. We can search
this device on other devices and can connect via entering the passkey.
29. The connections between HC05 module & microcontroller or other device are simple
as below:
VCC ——> 5.0V
GND ——> GND
TXD ——> RXD
RXD ——> TXD
9. PROJECT
Title: Bluetooth Based Home Automation system using smart phone.
Tools used: AVR microcontroller, AVR studio 4.0, UASasp programmer, Bluetooth HC
-06, Relays, Motors/ Bulb , Android smart phone , Wires.
Theory: We design a relay and HC-06 Bluetooth based Android Mobile controlled wireless
Home Automation system with AVR ATmega16 microcontroller .We will also use
the Android Mobile as the input device to control the appliances wirelessly.
The communication between HC-06 Bluetooth Module and Android Mobile takes
place through wireless Bluetooth technology. And the communication between
HC-06 Bluetooth Module and ATmega16 microcontroller takes place through
UART serial communication protocol. The HC-06 Bluetooth Module and Android
Mobile are connected through Bluetooth. User enters the control signal from
Android Mobile through Bluetooth Terminal App and the Android Mobile
transmits the control signal to the HC-06 Bluetooth Module through its bluetooth.
The HC-06 Bluetooth Module receives the control signal and transmits it to the
ATmega16 microcontroller through UART.The ATmega16 microcontroller
receives the control signal and processes it and sends the required control signal to
the Relay Driver. Relay Driver will turn On or Off the home appliances according
the control signal received from the ATmega16 microcontroller. The ATmega16
microcontroller also sends the appliance status to the Android Mobile through
bluetooth.