Project Using Microcontroller-Atmega16: Pushparaj Mani Pathak
Project Using Microcontroller-Atmega16: Pushparaj Mani Pathak
ATMEGA16
PUSHPARAJ MANI PATHAK
MECHANICAL & INDUSTRIAL ENGINEEING, IIT ROORKEE
1
Microcontroller
• Microcontroller is a compact integrated circuit designed to
govern a specific operation to control various electronic devices.
2
Classification of Microcontroller
4
ATmega16
• ATmega16 is a low power CMOS 8-bit microcontroller based on
AVR enhanced RISC architecture.
• CMOS (Complementary Metal Oxide Semiconductor) provides
high noise immunity and low static power consumption.
• 8 Bit means – 00000000 capable of doing number up to 255 (0-
255).
• RISC (Reduced Instruction Set Computer) architecture utilizes a
small and highly optimized set of instruction.
5
• Input/Output:
1. Four Ports : PORTA , PORT B , PORT C , PORT D of total 32 I/O
Pins.
2. ADC Pins : A0 to A7
3. USART : PD0 (RXD) PD1(TXD)
4. PWM : Four PWM Channels
• Power: Chip operates in between 2.5V to 5.5V
6
Features of ATmega16
• 16 Kbytes of in-system programmable flash memory.
• Read-While -Write capability.
• 512 bytes EEPROM, 1 Kbytes SRAM.
• 32 general purpose input/output pins, 32 general purpose working
registers.
• Write/Erase cycle: 10,000 Flash/1000,000 EEPROM.
• Data Retention: 20 years at 85° 𝐶 or 100 years at 25° 𝐶.
• Up to 16 MIPS throughput at 16 MHz.
7
Peripheral Features
• Two 8-bit Timer/Counters, One 16-Bit Timer/Counter.
• Four PWM Channels.
• 8-Channel, 10-Bit ADC.
• Programmable Watchdog Timer.
• Six Sleep Modes (Idle, ADC Noise Reduction, Power Save,
Power down, Standby, Extended Standby).
• Operating Voltage: 2.7V-5.5V for ATmega16L and 4.5V-5.5V
for ATmega16.
• Power Consumption @1MHz, 3V & 25° 𝐶 for ATmega16:
Active-1.1 mA, Idle Mode- 0.35 mA, Power-down mode <1 μA.
8
(XCK)/T0 PB0 PA0 (ADC0)
(T1) PB1 PA1 (ADC1)
(INT2/AIN0) PB2 PA2 (ADC2)
PORTB (OC0/AIN1) PB3 PA3 (ADC3) PORTA
(SS) PB4 PA4 (ADC4)
(PIN # 1-8) (MOSI) PB5 PA5 (ADC5) (PIN # 33-40)
ATmega16
(MISO) PB6 PA6 (ADC6)
(SCK) PB7 PA7 (ADC7)
RESET AREF
VCC GND
GND AVCC
XTAL2 PC0 (TOSC2)
XTAL1 PC1 (TOSC1)
(RDX) PD0 PC2 (TDI)
(TXD) PD1 PC3 (TDO) PORTC
PORTD (INT0) PD2 PC4 (TMS)
(INT1) PD3 PA5 (TCK) (PIN # 22-29)
(PIN # 14-21) (OS1B) PD4 PC6 (SDA)
(OS1A) PD5 PC7 (SLC)
(ICP) PD6 PD7 (OC2) PORTD
9
ATmega16 Pin Description
• ATmega16 have total of 40 pins from which 32 are I/O pins.
10
• PORT B (PB0-PB7) , PORT C (PC0-PC7) & PORT D (PD0-PD7): 8-bit
bi-directional I/O port with internal pull-up resistors selected for
each bit.
• RESET: Reset input a low level on this pin for longer than the
minimum pulse length will generate a reset.
• AVCC: It acts supply voltage pin for PORT A and the A/D
converter.
• AREF: AREF is the analog reference pin for the A/D converter.
• XTAL 2: Output to inverting oscillator amplifier.
11
PDIP Vs TQFP
Plastic dual-in-line Package Thin Quad Flat Package
abbreviated as PDIP is a chip- abbreviated as TQFP is a chip-
package with rectangular package with quad housing
housing and two parallel rows with “gull wing” leads
of electrical connecting pins. extending from each of four
sides.
12
Pin Diagram of PDIP Pin Diagram of TQFP
13
Basic Requirements and Concepts to Implement Program
• Software Required to load program in to ATmega16 is Atmel
Studio for any window other than 7 and AVR Studio for window7.
• Cross Compiler: Convert program code to executable form so
that our microcontroller can understand our code.
DDRX (X =B,C OR D)
1. DDR : Data Direction Register
2. Bits stored in this register represents the nature of the
respective line (either it is input line or output line).
14
3. If stored value is 0, it means that respective line is acting as input
line (for connecting input devices like sensors).
4. Similarly if value is 1, it means that respective line is acting as
output line (for connecting output devices).
5. Ex: Ob-Binary, Ox-Hexadecimal, Pin A3 to Pin A0 can
Number like 15-Decimal only be used for output
DDR A = O b 0 0 0 0 1 1 1 1
Port A Pin A7 to Pin A4 can
only be used for input
15
PORTX (X=B,C or D)
1. Use in output lines to define voltage level in respective line.
2. If value stored=1 (output voltage is 5 volts).
3. If value stored=0 (output voltage is 0 volts).
PINX (X=B,C or D)
1. Use in input lines and these are read only registers, means
values are set by input device automatically.
2. If value stored=1 (input voltage is 5 volts).
3. If value stored=0 (input voltage is 0 volts).
16
DDRA = Ob00001111
PORTA = Ob00001010
These pins are high. Means PA1 & PA3 pins are at high voltage
whereas pin PA0 & PA2 are at low voltage. PORT represents that we
are dealing with output.
18
PORTB=0b00011000; // Glow LED connected to PB3 & PB4
_delay_ms(1000); // Delay of 1 sec
PORTB=0b00000110; // Glow LED connected to PB1 & PB2
_delay_ms(1000); // Delay of 1 sec
PORTB=0b00011110; // Glow LED connected to PB1 to PB4
_delay_ms(1000); // Delay of 1 sec
PORTB=0b00000000; // Do not glow any LED
_delay_ms(1000);
}
}
19
Program of Line Follower Robot
// Sensor 1 & sensor 2 are connected to PC0 & PC1 respectively.
// Motor 1 connected to PB1 & PB2 ; motor 2 connected to PB3 & PB4.
#include <avr/io.h>
int main(void)
{
DDRC=0b0000000; //Optional
DDRB=0b00011110; //Define PB1,PB2,PB3,PB4 as output lines
int sensor=0; //Variable to store status of sensors
while(1) {
20
sensor= PINC & 0b0000011; //Statement to store value from pin
register to variable
if(sensor==0b0000011) //Conditional statements
{PORTB=0b00001010;}
else if (sensor==0b0000001)
{PORTB=0b00000010;}
else if(sensor==0b0000010)
{PORTB=0b00001000;}
else //Condition when both sensors are off
{PORTB=0b00000000;} } }
21
Line Follower Robot
• The Line follower robot is a mobile machine that can detect and
follow the line drawn on the floor.
• The path is predefined and can be like a black line or it can be
invisible like a magnetic field.
• Therefore, this kind of Robot should sense the line with its
Infrared Ray (IR) sensors that is installed under the robot.
• Line follower robot is widely used in ware houses, industries,
and stores etc., where it follows a dedicated path.
22
List of Equipment's Required
• Atmega16 Development Board.
• Two Motor, two Wheels and Caster Wheel
• Chassis & Fitting Packet, Screwdriver & 40 Pin Wires
• 2 IR Sensor, 1 USB Programmer and Battery Snipper.
IR Sensor
Atmega16 Motor and Wheel Pin wires and Chassis USB Programmer
23
Connection Guide
• The step-by-step connection guide for Line Follower Robot with
ATmega16 using Analog IR Sensor is as follows:
26
IR Sensor
• Line Follower Robot is able to track a line with the help of an
IR sensor.
• This sensor has a IR Transmitter and IR receiver. The IR
transmitter (IR LED) transmits the light and the Receiver
(Photodiode) waits for the transmitted light to return back.
• An IR light will return back only if it is reflect by a surface.
Whereas, all surfaces do not reflect an IR light, only white the
colour surface can completely reflect them and black colour
surface will completely observe them.
27
IR RX Reflected IR RX
Light
Light
Absorbed
IR Light IR Light
IR TX IR TX
White Surface Black Surface
28
Both Sensors on White Surface
• These two IR sensors will be placed one on either side of the
line. If none of the sensors are detecting a black line
then microcontroller instructs both the motors to move
forward as shown below.
Left
Sensor
Black Line
Right
Sensor
Forward Motion
29
Left Sensor on Black Line and Right Sensor on White Surface
• If left sensor comes on black line then the microcontroller
instructs the robot to turn left by rotating the right wheel alone.
Left
Sensor
Black Line
Right
Sensor
Turning Left
30
Left Sensor on White surface and Right Sensor on Black Line
• If right sensor comes on black line then the microcontroller
instructs the robot to turn right by rotating the left wheel alone.
Turning Right Left
Sensor
Black Line
Right
Sensor
31
Both Sensors on Black Line
• If both sensors comes on black line, robot stops.
Left
Sensor
Right
Sensor
32
33
Thank You
34