SlideShare une entreprise Scribd logo
1  sur  48
Télécharger pour lire hors ligne
Introduction to
Microcontroller
Eng:Mohamed Loay Ali Eng:Khaled Khamis
1
Contents
• Types of Controllers.
• Types of Compilers.
• AVR DataSheet.
• AVR input/output Configuration.
• Writing First Code in AVR.
• Transfer First Program to AVR.
• Switch Debouncing (Case Study).
Eng:Mohamed Loay Ali Eng:Khaled Khamis
2
Types of Controllers
1)Microprocessor based Systems:
Industrial PC, u computer , mainframes
Eng:Mohamed Loay Ali Eng:Khaled Khamis
3
Types of Controllers
1)Microprocessor based Systems:
Industrial PC, u computer , mainframes
Microprocessor
(CPU).
Eng:Mohamed Loay Ali Eng:Khaled Khamis
4
Types of Controllers
1)Microprocessor based Systems:
Industrial PC, u computer , mainframes
Microprocessor Architecture:
Eng:Mohamed Loay Ali Eng:Khaled Khamis
5
Types of Controllers
1)Microprocessor based Systems:
Industrial PC, u computer , mainframes
 The MPU communicates with Memory and I/O using the
System Bus
 Address bus
 Unidirectional
 Memory and I/O Addresses
 Data bus
 Bidirectional
 Transfers Binary Data and Instructions
 Control lines
 Read and Write timing signals
Eng:Mohamed Loay Ali Eng:Khaled Khamis
6
Example Microprocessor System
Types of Controllers
1)Microprocessor based Systems:
Industrial PC, u computer , mainframes
Eng:Mohamed Loay Ali Eng:Khaled Khamis
7
Types of Controllers
2) MCU:
Eng:Mohamed Loay Ali Eng:Khaled Khamis
8
Types of Controllers
2) MCU:
 System hardware
 Discrete components
 Microprocessor, Memory, and I/O
 Components connected by buses
 Address, Data, and Control
 System software
 A group of programs that monitors the functions of the
entire system
Eng:Mohamed Loay Ali Eng:Khaled Khamis
9
Types of Controllers
2) MCU:
Example Microcontroller System
Eng:Mohamed Loay Ali Eng:Khaled Khamis
10
CISC
Complex Instruction Set Computer
 “High level" Instruction Set
 Executes several “low level operations”
 Ex: load, arithmetic operation, memory store
Features of CISC:
 Initially made to do very complex instructions.
 Instructions can operate directly on memory
 Small number of general purpose registers
 Instructions take multiple clocks to execute
 Few lines of code per operation
Types of Controllers
2) MCU(Instruction Set):
Eng:Mohamed Loay Ali Eng:Khaled Khamis
11
RISC
Reduced Instruction Set Computer
 RISC is a CPU design that recognizes only a limited number of
instructions
 Simple instructions
 Instructions are executed quickly
Features of RISC:
 Found to be more efficient in computing very complex instructions
by using many of very short and simple instructions.
 Executes a series of simple instruction instead of a complex
instruction
 Instructions are executed within one clock cycle.
 Incorporates a large number of general registers for arithmetic
operations to avoid storing variables on a stack in memory.
 Only the load and store instructions operate directly onto memory.
Types of Controllers
2) MCU (Instruction Set):
Eng:Mohamed Loay Ali Eng:Khaled Khamis
12
RISC Vs CISC
Types of Controllers
2) MCU (Instruction Set):
Eng:Mohamed Loay Ali Eng:Khaled Khamis
13
Register File: A (usually) relatively small memory embedded on
the CPU. It is used as a scratchpad for temporary storage of
values the CPU is working with you could call it the CPU’s short
term memory.
Data Memory: For longer term storage, generic CPUs usually
employ an external memory which is much larger than the
register file. Data that is stored there may be short-lived, but
may also be valid for as long as the CPU is running
Instruction Memory: Like the data memory, the instruction
memory is usually a relatively large external memory (at
least with general CPUs)
Types of Controllers
2) MCU(Memory Types):
Eng:Mohamed Loay Ali Eng:Khaled Khamis
14
Types of Controllers
2) MCU (Memory Types):
Eng:Mohamed Loay Ali Eng:Khaled Khamis
15
Volatile Memory RAM (Random access memory):
1)SRAM (Static RAM):
 SRAM consists of flip flops (Electronic component that can store data).
 Expensive.
 Exists in small sizes.
 DRAM consists of capacitors (Electronic component that can
store data by charging and discharging).
 Needs refresh circuit to keep the capacitors charged (when
holding ‘1’).
 Inexpensive.
 Exists in larger sizes.
2)DRAM (Dynamic RAM):
Types of Controllers
2) MCU (Memory Types):
Eng:Mohamed Loay Ali Eng:Khaled Khamis
16
Non Volatile memories ROM (Read only memory):
PROM (Programmable ROM )
1- One time programmable (OTP).
2- Used to protect the data that can’t be erased and rewritten.
EPROM (Erasable PROM)
1. Multi-time programmable.
2. Can be erased using UV (Ultraviolet) rays from the sun.
3. Needs long time to be erased (about 20 minutes).
Types of Controllers
2) MCU (Memory Types):
Eng:Mohamed Loay Ali Eng:Khaled Khamis
17
EEPROM (Electrically EPROM)
1. Multi-time programmable.
2. Can be erased using Electricity (from PC).
3. Needs short time to be erased (few milliseconds).
Flash EEPROM
1. Multi-time programmable.
2. Can be erased using Electricity (from PC).
3. Needs very short time to be erased (few microseconds).
Types of Controllers
2) MCU (Memory Types):
Eng:Mohamed Loay Ali Eng:Khaled Khamis
18
Types of Controllers
2) MCU (Memories Located in MCUS):
Eng:Mohamed Loay Ali Eng:Khaled Khamis
19
Types of Controllers
2) MCU (Registers in MCUS):
The memory in which the microcontroller stored data
during the execution of the program.
Classified into two types:
1. General purpose registers.
 There are 30 General purpose registers in microcontrollers rages from R1 to
R31.
 Any variables are declared in the program are stored in this registers, like the
variables of mathematical operations.
2. Special function registers.
• Special function registers are registers defined by the manufacturer of the
microcontroller itself to give an access to the features of microcontroller like
Timer, SPI, UART, ADC, IO ports and external interrupt modules.
• Ex:
DDRA: determine the state of this port I/p or O/p
PORTA: determine if the port generate logic 1 or 0.
Eng:Mohamed Loay Ali Eng:Khaled Khamis
20
Types of Controllers
2) MCU (Comparison between Different types of MCUs):
Eng:Mohamed Loay Ali Eng:Khaled Khamis
21
Types of Controllers
3)DSP (Digital Signal Processor):
Advantages of DSP
 Conventional DSP devices are well-suited to a wide range of
applications requiring mathematical processing power.
 This arises from the high-speed DSP cores of the devices and a number
of architectural features.
 DSPs typically support a single-cycle multiply-accumulate function,
crucial to efficient DSP algorithm implementations.
Disadvantages of DSP:
 Not Suitable for application requiring Computaional processing power and
interrupts.
 Doesn’t include automotive communication module (CAN,LIN).
 Very Expensive Compared with MCU.
Eng:Mohamed Loay Ali Eng:Khaled Khamis
22
Types of Controllers
3)DSC (Digital Signal Controller):
DSC series of devices specifically addresses two main application requirement
areas.
First, computational requirements associated with complex control algorithms are
met by a high-speed core, capable of executing up to 40 million
multiply-accumulate operations per second.
Second, control system interface requirements are met by a rich integrated
peripheral set, including PWM capability, analog-to-digital conversion, bit I/O,
and multiple serial interfaces.
Examples:
1) The 56F800 DSC series (Free Scale).
2)The Lm4f123 DSC (Texas Instruments)
Eng:Mohamed Loay Ali Eng:Khaled Khamis
23
Types of Compilers
1) Atemel Studio (GCC Compiler):
The GNU Compiler Collection (GCC) is a compiler system produced by
the GNU Project supporting various programming languages.
GCC is a key component of the GNU toolchain.
The Free Software Foundation (FSF) distributes GCC under the GNU General
Public License (GNU GPL)
GCC target processor families as of version 4.3 include:
Alpha,ARM,AVR,Blackfin,H8/300,HC12,IA-32 (x86),IA-64,MIPS,Motorola
68000,PA-RISC,PDP-11,PowerPC,R8C / M16C / M32C,SPARC,SPU,SuperH
System/390 / zSeriesVAX,x86-64
Eng:Mohamed Loay Ali Eng:Khaled Khamis
24
Types of Compilers
2)CodeVision:
Is the only integrated development environment on the market that features
an automatic program generator for AVR Family.
It targets only the AVR Processor.
Eng:Mohamed Loay Ali Eng:Khaled Khamis
25
ATmega8 - RISC Architecture
● 131 Instructions – Most Single-clock Cycle Execution
● 32 x 8 General Purpose Working Registers
● 64 x 8 Special Function Registers (I/O Registers)
● Up to 16 MIPS Throughput at 20 MHz
● On-chip 2-cycle Multiplier
Nonvolatile Program and Data Memories
● 4/8/16/32K Bytes of In-System Self-Programmable Flash
10,000 Write/Erase Cycles
● Optional Boot Code Section with Independent Lock Bits
● 256/512/1 Bytes EEPROM (100,000 Write/Erase Cycles)
● 1K Byte Internal SRAM
● Programming Lock for Software Security
AVR Datasheet
Eng:Mohamed Loay Ali Eng:Khaled Khamis
26
Peripheral Features
● Two 8-bit Timer/Counters
● One 16-bit Timer/Counter with Capture Mode
● Real Time Counter with Separate Oscillator
● 6 PWM Channels
● 8-channel ADC with 10 resp 8 Bit resolution (TQFP: 8 channels)
● Two-wire Serial Interface (TWI)
● Programmable Serial USART
● Master/Slave SPI Serial Interface
● Programmable Watchdog Timer with On-chip Oscillator
● On-chip Analog Comparator
AVR Datasheet
Eng:Mohamed Loay Ali Eng:Khaled Khamis
27
Special Microcontroller Features
● Programmable Brown-out Detection
● Internal Calibrated RC Oscillator
● External and Internal Interrupt Sources
● 6 Sleep Modes
I/O and Packages
● 23 Programmable I/O Lines
● 28-lead PDIP, 32-lead TQFP, and 32-pad MLF
AVR Datasheet
Eng:Mohamed Loay Ali Eng:Khaled Khamis
28
Operating Voltages
1.8v to 5.5v
Speed Grades
 0 - 4MHz@1.8 - 5.5V,
 0 - 10MHz@2.7 - 5.5.V,
 0 - 20MHz @ 4.5 - 5.5V
Power Consumption at 4 Mhz, 3V, 25°C
● Active: 0.2 mA
● Idle Mode: 0.1uA
● Power-down Mode: 0.1 μA
AVR Datasheet
Eng:Mohamed Loay Ali Eng:Khaled Khamis
29
AVR Pin Configuration (Atmega328)
AVR Datasheet
Eng:Mohamed Loay Ali Eng:Khaled Khamis
30
Pin and Port Overview:
GND: Ground (0V)
VCC: Digital Supply Voltage (2,7 – 5,5V)
AVCC: Analog Supply Voltage
connect to low-pass filtered VCC
AREF: Analog Reference Voltage, usually AVCC
/ Reset: Low level on this pin will generate a reset
Port B, Port C, Port D:
General Purpose 8 Bit bidirectional I/O - Ports,
optional internal pullup-resistors when configured as input
output source capability: 20mA
Special Functions of the Ports available as configured using the SFRs:
Port D: Uart, external Interrupts, Analog Comparator
Port B: External Oscillator/Crystal, SPI
Port C: A/D converters, TWI
AVR Datasheet
Eng:Mohamed Loay Ali Eng:Khaled Khamis
31
AVR Block Diagram (Atmega328)
AVR Datasheet
Eng:Mohamed Loay Ali Eng:Khaled Khamis
32
AVR Datasheet
AVR Circuit (Atmega328)
Eng:Mohamed Loay Ali Eng:Khaled Khamis
33
AVR Datasheet
AVR Circuit Components (Atmega328)
1) Atemga328.
2) Crystal Oscillator 16 MHz
3) 2 Capacitor 22 pf.
4) 10 Kilo ohm Resistor.
5) Press Switch.
6) Power Supply 5V
Eng:Mohamed Loay Ali Eng:Khaled Khamis
34
AVR Datasheet
AVR Clock Systems
Eng:Mohamed Loay Ali Eng:Khaled Khamis
35
● Clock Muliplexer selects the clock
source according to FUSE settings
● Clock Control Unit distributes clocks
clocks can be halted to reduce power
consumption
● CPU Clock: CPU, ALU, GPRs
● I/O Clock: Ports, Timers, SPI, UART
● ADC Clock: seperate cock for ADC
noise reduction in sleep mode
● Asynchronous Timer Clock:
external 32kHz Crystal for realtime clock,
keeps timer module running during sleep mode
AVR Datasheet
AVR Clock Systems(options)
Eng:Mohamed Loay Ali Eng:Khaled Khamis
36
● The four CKSEL Bits of the FUSE – Byte select the main Clock Source
● The startup time to stabilize power supply and oscillator can be changed
with the SUT fuses
● The device is shipped with internal RC oscillator at 8.0MHz and with the fuse
CKDIV8 programmed, resulting in 1.0MHz system clock.
AVR Datasheet
AVR Clock Systems(Fuse Bits)
Eng:Mohamed Loay Ali Eng:Khaled Khamis
37
AVR Datasheet
AVR Clock Systems(Using External Crystal)
Eng:Mohamed Loay Ali Eng:Khaled Khamis
38
AVR Input/ Output Configuration
The following registers are related to the various port
operations that we can perform with the GPIO
pins.
1) DDRx – Data Direction Register
2) PORTx – Pin Output Register
3) PINx – Pin Input Register
where x = GPIO port name (A, B, C or D)
Eng:Mohamed Loay Ali Eng:Khaled Khamis
39
AVR Input/ Output Configuration
Eng:Mohamed Loay Ali Eng:Khaled Khamis
40
AVR Input/ Output Configuration
Eng:Mohamed Loay Ali Eng:Khaled Khamis
41
AVR Input/ Output Configuration
DDRX Registers:
DDRx initializes the port shown in the following figure
DDRC = 0b10110001;
DDRC = 0xB1; //suitable to define all pins of the port
DDRC = (1<<0)|(1<<4)|(1<<5)|(1<<7);
DDRC|= (1<<PINC0)| (1<<PINC4) |(1<<PINC5) |(1<<PINC7);//using bitwise
suitable to define one pin
Eng:Mohamed Loay Ali Eng:Khaled Khamis
42
AVR Input/ Output Configuration
PORTx Register:
 The PORTx register determines whether the output should be HIGH or
LOW of the pins.
 DDRx initializes the port shown in the following figure.
Examples of setting the output
PORTD = 0b01001001;
PORTD = 0x49; //suitable to define all pins of the port.
PORTD = (1 << 0)|(1 << 3)|(1 << 6);
PORTD|=(1<<PIND0) | (1<<PIND3) |(1<<PIND6);// using bitwise suitable to
define one pin.
Eng:Mohamed Loay Ali Eng:Khaled Khamis
43
AVR Input/ Output Configuration
PINx Register:
 The PINx register gets the reading from the input pins of the MCU.
 The register goes as follows:
Examples of setting the input
DDRC = 0b10110001;
PINC = 0b01001011;
Eng:Mohamed Loay Ali Eng:Khaled Khamis
44
Writing First Code in AVR
See the Appendix For information about Atmel Studio
Also, See the following Example (Led Blinking, Adding Button).
Eng:Mohamed Loay Ali Eng:Khaled Khamis
45
Transfer First Program to AVR
The following programs are used to download the program (Hex file):
1. Khazama
2. Extreme Burner
3. AVR Burn – O - Mat
Transfer the Program to AVR:
Eng:Mohamed Loay Ali Eng:Khaled Khamis
46
Switch Debouncing
The Problem:
Eng:Mohamed Loay Ali Eng:Khaled Khamis
47
Switch Debouncing
The Solution by Hardware:
Eng:Mohamed Loay Ali Eng:Khaled Khamis
48

Contenu connexe

Tendances

Features of ATMEL microcontrollers
Features of ATMEL microcontrollersFeatures of ATMEL microcontrollers
Features of ATMEL microcontrollers
Suraj Shandilya
 
Introduction to microcontrollers
Introduction to microcontrollersIntroduction to microcontrollers
Introduction to microcontrollers
Corrado Santoro
 

Tendances (20)

ATmega 16
ATmega 16ATmega 16
ATmega 16
 
Interfacing using ِAtmega16/32
Interfacing using ِAtmega16/32 Interfacing using ِAtmega16/32
Interfacing using ِAtmega16/32
 
Tutorial on avr atmega8 microcontroller, architecture and its applications
Tutorial on avr atmega8 microcontroller, architecture and its applicationsTutorial on avr atmega8 microcontroller, architecture and its applications
Tutorial on avr atmega8 microcontroller, architecture and its applications
 
Micro-controller course lec 01
Micro-controller course lec 01Micro-controller course lec 01
Micro-controller course lec 01
 
Features of ATMEL microcontrollers
Features of ATMEL microcontrollersFeatures of ATMEL microcontrollers
Features of ATMEL microcontrollers
 
AVR introduction
AVR introduction AVR introduction
AVR introduction
 
Introduction to microcontrollers
Introduction to microcontrollersIntroduction to microcontrollers
Introduction to microcontrollers
 
Avr introduction
Avr introductionAvr introduction
Avr introduction
 
embedded system and AVR
embedded system and AVRembedded system and AVR
embedded system and AVR
 
PIC_ARM_AVR
PIC_ARM_AVRPIC_ARM_AVR
PIC_ARM_AVR
 
Microcontroller presentation
Microcontroller presentationMicrocontroller presentation
Microcontroller presentation
 
3.TechieNest microcontrollers
3.TechieNest  microcontrollers3.TechieNest  microcontrollers
3.TechieNest microcontrollers
 
Dio
DioDio
Dio
 
Introduction in microcontroller
Introduction in microcontrollerIntroduction in microcontroller
Introduction in microcontroller
 
Intro to micro controller (Atmega16)
Intro to micro controller (Atmega16)Intro to micro controller (Atmega16)
Intro to micro controller (Atmega16)
 
AVR ATmega32
AVR ATmega32AVR ATmega32
AVR ATmega32
 
AVR Micro controller Interfacing
AVR Micro controller Interfacing AVR Micro controller Interfacing
AVR Micro controller Interfacing
 
ATmega32
ATmega32 ATmega32
ATmega32
 
Introduction to Atmel's 8-bit AVR Microcontrollers
Introduction to Atmel's 8-bit AVR Microcontrollers Introduction to Atmel's 8-bit AVR Microcontrollers
Introduction to Atmel's 8-bit AVR Microcontrollers
 
Timers
TimersTimers
Timers
 

En vedette

Introduction to arduino
Introduction to arduinoIntroduction to arduino
Introduction to arduino
Ahmed Sakr
 
APRS - the amateur radio tracking system
APRS - the amateur radio tracking system APRS - the amateur radio tracking system
APRS - the amateur radio tracking system
FSCONS
 

En vedette (20)

AVR_Course_Day1 basic electronics
AVR_Course_Day1 basic electronicsAVR_Course_Day1 basic electronics
AVR_Course_Day1 basic electronics
 
AVR_Course_Day7 timers counters and interrupt programming
AVR_Course_Day7 timers counters and  interrupt programmingAVR_Course_Day7 timers counters and  interrupt programming
AVR_Course_Day7 timers counters and interrupt programming
 
AVR_Course_Day2 what is pcb
AVR_Course_Day2 what is pcbAVR_Course_Day2 what is pcb
AVR_Course_Day2 what is pcb
 
AVR_Course_Day8 motor drive and pwm techniques
AVR_Course_Day8 motor drive and pwm techniquesAVR_Course_Day8 motor drive and pwm techniques
AVR_Course_Day8 motor drive and pwm techniques
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
 
Introduction to arduino
Introduction to arduinoIntroduction to arduino
Introduction to arduino
 
AVR_Course_Day3 c programming
AVR_Course_Day3 c programmingAVR_Course_Day3 c programming
AVR_Course_Day3 c programming
 
Architecture of 8051
Architecture of 8051Architecture of 8051
Architecture of 8051
 
INTRODUCTION TO MICROCONTROLLER
INTRODUCTION TO MICROCONTROLLERINTRODUCTION TO MICROCONTROLLER
INTRODUCTION TO MICROCONTROLLER
 
Introduction to Microcontroller
Introduction to MicrocontrollerIntroduction to Microcontroller
Introduction to Microcontroller
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Electronics ppt
Electronics ppt Electronics ppt
Electronics ppt
 
Arduino Lecture 1 - Introducing the Arduino
Arduino Lecture 1 - Introducing the ArduinoArduino Lecture 1 - Introducing the Arduino
Arduino Lecture 1 - Introducing the Arduino
 
8051
80518051
8051
 
IoT開發平台NodeMCU
IoT開發平台NodeMCUIoT開發平台NodeMCU
IoT開發平台NodeMCU
 
Arduino Microcontroller
Arduino MicrocontrollerArduino Microcontroller
Arduino Microcontroller
 
Arduino Autonomous Robot
Arduino Autonomous Robot Arduino Autonomous Robot
Arduino Autonomous Robot
 
APRS - the amateur radio tracking system
APRS - the amateur radio tracking system APRS - the amateur radio tracking system
APRS - the amateur radio tracking system
 
SMT machine Training Manual for FUJI CP6 Series Level 3
SMT machine Training Manual for FUJI  CP6 Series Level 3SMT machine Training Manual for FUJI  CP6 Series Level 3
SMT machine Training Manual for FUJI CP6 Series Level 3
 
Complete Overview of MESH for Amateur Radio (Updated Nov. 2014)
Complete Overview of MESH for Amateur Radio (Updated Nov. 2014)Complete Overview of MESH for Amateur Radio (Updated Nov. 2014)
Complete Overview of MESH for Amateur Radio (Updated Nov. 2014)
 

Similaire à AVR_Course_Day4 introduction to microcontroller

8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontroller
snehapvs
 
3245731 tele-controlled-steper-motor-thesis
3245731 tele-controlled-steper-motor-thesis3245731 tele-controlled-steper-motor-thesis
3245731 tele-controlled-steper-motor-thesis
Thanh Nguyen
 

Similaire à AVR_Course_Day4 introduction to microcontroller (20)

8051 microcontroller
8051 microcontroller8051 microcontroller
8051 microcontroller
 
Arm Processors Architectures
Arm Processors ArchitecturesArm Processors Architectures
Arm Processors Architectures
 
Microcontroller overview 1
Microcontroller overview 1Microcontroller overview 1
Microcontroller overview 1
 
Embedded systems 101 final
Embedded systems 101 finalEmbedded systems 101 final
Embedded systems 101 final
 
Necessity of 32-Bit Controllers
Necessity of 32-Bit ControllersNecessity of 32-Bit Controllers
Necessity of 32-Bit Controllers
 
Embedded systems class notes
Embedded systems  class notes Embedded systems  class notes
Embedded systems class notes
 
Embedded system
Embedded systemEmbedded system
Embedded system
 
Embeddedsystem
EmbeddedsystemEmbeddedsystem
Embeddedsystem
 
unit 1ARM INTRODUCTION.pptx
unit 1ARM INTRODUCTION.pptxunit 1ARM INTRODUCTION.pptx
unit 1ARM INTRODUCTION.pptx
 
MODULE 1 MES.pptx
MODULE 1 MES.pptxMODULE 1 MES.pptx
MODULE 1 MES.pptx
 
Msp 430 architecture module 1
Msp 430 architecture module 1Msp 430 architecture module 1
Msp 430 architecture module 1
 
3245731 tele-controlled-steper-motor-thesis
3245731 tele-controlled-steper-motor-thesis3245731 tele-controlled-steper-motor-thesis
3245731 tele-controlled-steper-motor-thesis
 
MergeResult_2023_04_02_05_26_56.pptx
MergeResult_2023_04_02_05_26_56.pptxMergeResult_2023_04_02_05_26_56.pptx
MergeResult_2023_04_02_05_26_56.pptx
 
Ijetr042175
Ijetr042175Ijetr042175
Ijetr042175
 
Introduction to Microcontroller
Introduction to MicrocontrollerIntroduction to Microcontroller
Introduction to Microcontroller
 
EE6602 Embedded System
EE6602 Embedded SystemEE6602 Embedded System
EE6602 Embedded System
 
Arm usr m,anl
Arm usr m,anlArm usr m,anl
Arm usr m,anl
 
1.Introduction to AVR.pdf
1.Introduction to AVR.pdf1.Introduction to AVR.pdf
1.Introduction to AVR.pdf
 
Microcontroller from basic_to_advanced
Microcontroller from basic_to_advancedMicrocontroller from basic_to_advanced
Microcontroller from basic_to_advanced
 
Lecture 5-Embedde.pdf
Lecture 5-Embedde.pdfLecture 5-Embedde.pdf
Lecture 5-Embedde.pdf
 

Dernier

FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 

Dernier (20)

FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 

AVR_Course_Day4 introduction to microcontroller

  • 2. Contents • Types of Controllers. • Types of Compilers. • AVR DataSheet. • AVR input/output Configuration. • Writing First Code in AVR. • Transfer First Program to AVR. • Switch Debouncing (Case Study). Eng:Mohamed Loay Ali Eng:Khaled Khamis 2
  • 3. Types of Controllers 1)Microprocessor based Systems: Industrial PC, u computer , mainframes Eng:Mohamed Loay Ali Eng:Khaled Khamis 3
  • 4. Types of Controllers 1)Microprocessor based Systems: Industrial PC, u computer , mainframes Microprocessor (CPU). Eng:Mohamed Loay Ali Eng:Khaled Khamis 4
  • 5. Types of Controllers 1)Microprocessor based Systems: Industrial PC, u computer , mainframes Microprocessor Architecture: Eng:Mohamed Loay Ali Eng:Khaled Khamis 5
  • 6. Types of Controllers 1)Microprocessor based Systems: Industrial PC, u computer , mainframes  The MPU communicates with Memory and I/O using the System Bus  Address bus  Unidirectional  Memory and I/O Addresses  Data bus  Bidirectional  Transfers Binary Data and Instructions  Control lines  Read and Write timing signals Eng:Mohamed Loay Ali Eng:Khaled Khamis 6
  • 7. Example Microprocessor System Types of Controllers 1)Microprocessor based Systems: Industrial PC, u computer , mainframes Eng:Mohamed Loay Ali Eng:Khaled Khamis 7
  • 8. Types of Controllers 2) MCU: Eng:Mohamed Loay Ali Eng:Khaled Khamis 8
  • 9. Types of Controllers 2) MCU:  System hardware  Discrete components  Microprocessor, Memory, and I/O  Components connected by buses  Address, Data, and Control  System software  A group of programs that monitors the functions of the entire system Eng:Mohamed Loay Ali Eng:Khaled Khamis 9
  • 10. Types of Controllers 2) MCU: Example Microcontroller System Eng:Mohamed Loay Ali Eng:Khaled Khamis 10
  • 11. CISC Complex Instruction Set Computer  “High level" Instruction Set  Executes several “low level operations”  Ex: load, arithmetic operation, memory store Features of CISC:  Initially made to do very complex instructions.  Instructions can operate directly on memory  Small number of general purpose registers  Instructions take multiple clocks to execute  Few lines of code per operation Types of Controllers 2) MCU(Instruction Set): Eng:Mohamed Loay Ali Eng:Khaled Khamis 11
  • 12. RISC Reduced Instruction Set Computer  RISC is a CPU design that recognizes only a limited number of instructions  Simple instructions  Instructions are executed quickly Features of RISC:  Found to be more efficient in computing very complex instructions by using many of very short and simple instructions.  Executes a series of simple instruction instead of a complex instruction  Instructions are executed within one clock cycle.  Incorporates a large number of general registers for arithmetic operations to avoid storing variables on a stack in memory.  Only the load and store instructions operate directly onto memory. Types of Controllers 2) MCU (Instruction Set): Eng:Mohamed Loay Ali Eng:Khaled Khamis 12
  • 13. RISC Vs CISC Types of Controllers 2) MCU (Instruction Set): Eng:Mohamed Loay Ali Eng:Khaled Khamis 13
  • 14. Register File: A (usually) relatively small memory embedded on the CPU. It is used as a scratchpad for temporary storage of values the CPU is working with you could call it the CPU’s short term memory. Data Memory: For longer term storage, generic CPUs usually employ an external memory which is much larger than the register file. Data that is stored there may be short-lived, but may also be valid for as long as the CPU is running Instruction Memory: Like the data memory, the instruction memory is usually a relatively large external memory (at least with general CPUs) Types of Controllers 2) MCU(Memory Types): Eng:Mohamed Loay Ali Eng:Khaled Khamis 14
  • 15. Types of Controllers 2) MCU (Memory Types): Eng:Mohamed Loay Ali Eng:Khaled Khamis 15
  • 16. Volatile Memory RAM (Random access memory): 1)SRAM (Static RAM):  SRAM consists of flip flops (Electronic component that can store data).  Expensive.  Exists in small sizes.  DRAM consists of capacitors (Electronic component that can store data by charging and discharging).  Needs refresh circuit to keep the capacitors charged (when holding ‘1’).  Inexpensive.  Exists in larger sizes. 2)DRAM (Dynamic RAM): Types of Controllers 2) MCU (Memory Types): Eng:Mohamed Loay Ali Eng:Khaled Khamis 16
  • 17. Non Volatile memories ROM (Read only memory): PROM (Programmable ROM ) 1- One time programmable (OTP). 2- Used to protect the data that can’t be erased and rewritten. EPROM (Erasable PROM) 1. Multi-time programmable. 2. Can be erased using UV (Ultraviolet) rays from the sun. 3. Needs long time to be erased (about 20 minutes). Types of Controllers 2) MCU (Memory Types): Eng:Mohamed Loay Ali Eng:Khaled Khamis 17
  • 18. EEPROM (Electrically EPROM) 1. Multi-time programmable. 2. Can be erased using Electricity (from PC). 3. Needs short time to be erased (few milliseconds). Flash EEPROM 1. Multi-time programmable. 2. Can be erased using Electricity (from PC). 3. Needs very short time to be erased (few microseconds). Types of Controllers 2) MCU (Memory Types): Eng:Mohamed Loay Ali Eng:Khaled Khamis 18
  • 19. Types of Controllers 2) MCU (Memories Located in MCUS): Eng:Mohamed Loay Ali Eng:Khaled Khamis 19
  • 20. Types of Controllers 2) MCU (Registers in MCUS): The memory in which the microcontroller stored data during the execution of the program. Classified into two types: 1. General purpose registers.  There are 30 General purpose registers in microcontrollers rages from R1 to R31.  Any variables are declared in the program are stored in this registers, like the variables of mathematical operations. 2. Special function registers. • Special function registers are registers defined by the manufacturer of the microcontroller itself to give an access to the features of microcontroller like Timer, SPI, UART, ADC, IO ports and external interrupt modules. • Ex: DDRA: determine the state of this port I/p or O/p PORTA: determine if the port generate logic 1 or 0. Eng:Mohamed Loay Ali Eng:Khaled Khamis 20
  • 21. Types of Controllers 2) MCU (Comparison between Different types of MCUs): Eng:Mohamed Loay Ali Eng:Khaled Khamis 21
  • 22. Types of Controllers 3)DSP (Digital Signal Processor): Advantages of DSP  Conventional DSP devices are well-suited to a wide range of applications requiring mathematical processing power.  This arises from the high-speed DSP cores of the devices and a number of architectural features.  DSPs typically support a single-cycle multiply-accumulate function, crucial to efficient DSP algorithm implementations. Disadvantages of DSP:  Not Suitable for application requiring Computaional processing power and interrupts.  Doesn’t include automotive communication module (CAN,LIN).  Very Expensive Compared with MCU. Eng:Mohamed Loay Ali Eng:Khaled Khamis 22
  • 23. Types of Controllers 3)DSC (Digital Signal Controller): DSC series of devices specifically addresses two main application requirement areas. First, computational requirements associated with complex control algorithms are met by a high-speed core, capable of executing up to 40 million multiply-accumulate operations per second. Second, control system interface requirements are met by a rich integrated peripheral set, including PWM capability, analog-to-digital conversion, bit I/O, and multiple serial interfaces. Examples: 1) The 56F800 DSC series (Free Scale). 2)The Lm4f123 DSC (Texas Instruments) Eng:Mohamed Loay Ali Eng:Khaled Khamis 23
  • 24. Types of Compilers 1) Atemel Studio (GCC Compiler): The GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain. The Free Software Foundation (FSF) distributes GCC under the GNU General Public License (GNU GPL) GCC target processor families as of version 4.3 include: Alpha,ARM,AVR,Blackfin,H8/300,HC12,IA-32 (x86),IA-64,MIPS,Motorola 68000,PA-RISC,PDP-11,PowerPC,R8C / M16C / M32C,SPARC,SPU,SuperH System/390 / zSeriesVAX,x86-64 Eng:Mohamed Loay Ali Eng:Khaled Khamis 24
  • 25. Types of Compilers 2)CodeVision: Is the only integrated development environment on the market that features an automatic program generator for AVR Family. It targets only the AVR Processor. Eng:Mohamed Loay Ali Eng:Khaled Khamis 25
  • 26. ATmega8 - RISC Architecture ● 131 Instructions – Most Single-clock Cycle Execution ● 32 x 8 General Purpose Working Registers ● 64 x 8 Special Function Registers (I/O Registers) ● Up to 16 MIPS Throughput at 20 MHz ● On-chip 2-cycle Multiplier Nonvolatile Program and Data Memories ● 4/8/16/32K Bytes of In-System Self-Programmable Flash 10,000 Write/Erase Cycles ● Optional Boot Code Section with Independent Lock Bits ● 256/512/1 Bytes EEPROM (100,000 Write/Erase Cycles) ● 1K Byte Internal SRAM ● Programming Lock for Software Security AVR Datasheet Eng:Mohamed Loay Ali Eng:Khaled Khamis 26
  • 27. Peripheral Features ● Two 8-bit Timer/Counters ● One 16-bit Timer/Counter with Capture Mode ● Real Time Counter with Separate Oscillator ● 6 PWM Channels ● 8-channel ADC with 10 resp 8 Bit resolution (TQFP: 8 channels) ● Two-wire Serial Interface (TWI) ● Programmable Serial USART ● Master/Slave SPI Serial Interface ● Programmable Watchdog Timer with On-chip Oscillator ● On-chip Analog Comparator AVR Datasheet Eng:Mohamed Loay Ali Eng:Khaled Khamis 27
  • 28. Special Microcontroller Features ● Programmable Brown-out Detection ● Internal Calibrated RC Oscillator ● External and Internal Interrupt Sources ● 6 Sleep Modes I/O and Packages ● 23 Programmable I/O Lines ● 28-lead PDIP, 32-lead TQFP, and 32-pad MLF AVR Datasheet Eng:Mohamed Loay Ali Eng:Khaled Khamis 28
  • 29. Operating Voltages 1.8v to 5.5v Speed Grades  0 - 4MHz@1.8 - 5.5V,  0 - 10MHz@2.7 - 5.5.V,  0 - 20MHz @ 4.5 - 5.5V Power Consumption at 4 Mhz, 3V, 25°C ● Active: 0.2 mA ● Idle Mode: 0.1uA ● Power-down Mode: 0.1 μA AVR Datasheet Eng:Mohamed Loay Ali Eng:Khaled Khamis 29
  • 30. AVR Pin Configuration (Atmega328) AVR Datasheet Eng:Mohamed Loay Ali Eng:Khaled Khamis 30
  • 31. Pin and Port Overview: GND: Ground (0V) VCC: Digital Supply Voltage (2,7 – 5,5V) AVCC: Analog Supply Voltage connect to low-pass filtered VCC AREF: Analog Reference Voltage, usually AVCC / Reset: Low level on this pin will generate a reset Port B, Port C, Port D: General Purpose 8 Bit bidirectional I/O - Ports, optional internal pullup-resistors when configured as input output source capability: 20mA Special Functions of the Ports available as configured using the SFRs: Port D: Uart, external Interrupts, Analog Comparator Port B: External Oscillator/Crystal, SPI Port C: A/D converters, TWI AVR Datasheet Eng:Mohamed Loay Ali Eng:Khaled Khamis 31
  • 32. AVR Block Diagram (Atmega328) AVR Datasheet Eng:Mohamed Loay Ali Eng:Khaled Khamis 32
  • 33. AVR Datasheet AVR Circuit (Atmega328) Eng:Mohamed Loay Ali Eng:Khaled Khamis 33
  • 34. AVR Datasheet AVR Circuit Components (Atmega328) 1) Atemga328. 2) Crystal Oscillator 16 MHz 3) 2 Capacitor 22 pf. 4) 10 Kilo ohm Resistor. 5) Press Switch. 6) Power Supply 5V Eng:Mohamed Loay Ali Eng:Khaled Khamis 34
  • 35. AVR Datasheet AVR Clock Systems Eng:Mohamed Loay Ali Eng:Khaled Khamis 35
  • 36. ● Clock Muliplexer selects the clock source according to FUSE settings ● Clock Control Unit distributes clocks clocks can be halted to reduce power consumption ● CPU Clock: CPU, ALU, GPRs ● I/O Clock: Ports, Timers, SPI, UART ● ADC Clock: seperate cock for ADC noise reduction in sleep mode ● Asynchronous Timer Clock: external 32kHz Crystal for realtime clock, keeps timer module running during sleep mode AVR Datasheet AVR Clock Systems(options) Eng:Mohamed Loay Ali Eng:Khaled Khamis 36
  • 37. ● The four CKSEL Bits of the FUSE – Byte select the main Clock Source ● The startup time to stabilize power supply and oscillator can be changed with the SUT fuses ● The device is shipped with internal RC oscillator at 8.0MHz and with the fuse CKDIV8 programmed, resulting in 1.0MHz system clock. AVR Datasheet AVR Clock Systems(Fuse Bits) Eng:Mohamed Loay Ali Eng:Khaled Khamis 37
  • 38. AVR Datasheet AVR Clock Systems(Using External Crystal) Eng:Mohamed Loay Ali Eng:Khaled Khamis 38
  • 39. AVR Input/ Output Configuration The following registers are related to the various port operations that we can perform with the GPIO pins. 1) DDRx – Data Direction Register 2) PORTx – Pin Output Register 3) PINx – Pin Input Register where x = GPIO port name (A, B, C or D) Eng:Mohamed Loay Ali Eng:Khaled Khamis 39
  • 40. AVR Input/ Output Configuration Eng:Mohamed Loay Ali Eng:Khaled Khamis 40
  • 41. AVR Input/ Output Configuration Eng:Mohamed Loay Ali Eng:Khaled Khamis 41
  • 42. AVR Input/ Output Configuration DDRX Registers: DDRx initializes the port shown in the following figure DDRC = 0b10110001; DDRC = 0xB1; //suitable to define all pins of the port DDRC = (1<<0)|(1<<4)|(1<<5)|(1<<7); DDRC|= (1<<PINC0)| (1<<PINC4) |(1<<PINC5) |(1<<PINC7);//using bitwise suitable to define one pin Eng:Mohamed Loay Ali Eng:Khaled Khamis 42
  • 43. AVR Input/ Output Configuration PORTx Register:  The PORTx register determines whether the output should be HIGH or LOW of the pins.  DDRx initializes the port shown in the following figure. Examples of setting the output PORTD = 0b01001001; PORTD = 0x49; //suitable to define all pins of the port. PORTD = (1 << 0)|(1 << 3)|(1 << 6); PORTD|=(1<<PIND0) | (1<<PIND3) |(1<<PIND6);// using bitwise suitable to define one pin. Eng:Mohamed Loay Ali Eng:Khaled Khamis 43
  • 44. AVR Input/ Output Configuration PINx Register:  The PINx register gets the reading from the input pins of the MCU.  The register goes as follows: Examples of setting the input DDRC = 0b10110001; PINC = 0b01001011; Eng:Mohamed Loay Ali Eng:Khaled Khamis 44
  • 45. Writing First Code in AVR See the Appendix For information about Atmel Studio Also, See the following Example (Led Blinking, Adding Button). Eng:Mohamed Loay Ali Eng:Khaled Khamis 45
  • 46. Transfer First Program to AVR The following programs are used to download the program (Hex file): 1. Khazama 2. Extreme Burner 3. AVR Burn – O - Mat Transfer the Program to AVR: Eng:Mohamed Loay Ali Eng:Khaled Khamis 46
  • 47. Switch Debouncing The Problem: Eng:Mohamed Loay Ali Eng:Khaled Khamis 47
  • 48. Switch Debouncing The Solution by Hardware: Eng:Mohamed Loay Ali Eng:Khaled Khamis 48