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

More Related Content

PPTX
Advance Microcontroller AVR
PDF
AVR_Course_Day5 avr interfaces
PDF
AVR_Course_Day6 external hardware interrupts and analogue to digital converter
PPTX
Introduction to AVR Microcontroller
PPTX
Avr and arm
PPT
Developing an avr microcontroller system
PDF
AVR Microcontroller
PPTX
ATmega32-AVR microcontrollers-Part I
Advance Microcontroller AVR
AVR_Course_Day5 avr interfaces
AVR_Course_Day6 external hardware interrupts and analogue to digital converter
Introduction to AVR Microcontroller
Avr and arm
Developing an avr microcontroller system
AVR Microcontroller
ATmega32-AVR microcontrollers-Part I

What's hot (20)

PPTX
ATmega 16
PDF
Interfacing using ِAtmega16/32
PPTX
Tutorial on avr atmega8 microcontroller, architecture and its applications
PPTX
Micro-controller course lec 01
PPTX
Features of ATMEL microcontrollers
PDF
AVR introduction
PDF
Introduction to microcontrollers
PPT
Avr introduction
PPTX
embedded system and AVR
PPTX
Microcontroller presentation
PPTX
3.TechieNest microcontrollers
PDF
Introduction in microcontroller
PPTX
Intro to micro controller (Atmega16)
PPTX
AVR ATmega32
PDF
AVR Micro controller Interfacing
PPSX
ATmega32
PPT
Introduction to Atmel's 8-bit AVR Microcontrollers
ATmega 16
Interfacing using ِAtmega16/32
Tutorial on avr atmega8 microcontroller, architecture and its applications
Micro-controller course lec 01
Features of ATMEL microcontrollers
AVR introduction
Introduction to microcontrollers
Avr introduction
embedded system and AVR
Microcontroller presentation
3.TechieNest microcontrollers
Introduction in microcontroller
Intro to micro controller (Atmega16)
AVR ATmega32
AVR Micro controller Interfacing
ATmega32
Introduction to Atmel's 8-bit AVR Microcontrollers
Ad

Viewers also liked (20)

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

Similar to AVR_Course_Day4 introduction to microcontroller (20)

PPTX
Micro Controllers engineering - computer engineering
PPT
Ajal mod 1
PPTX
Microcontroller presentation
PPTX
Embedded system
PPTX
microcontroller-presentation-1-638 (30 files merged).pptx
PDF
Introduction to Avr Microcontrollers
PPTX
LECT 2.pptx
PPTX
Msp 430 architecture module 1
PDF
E-Note_19681_Content_Document_20240512114009AM.pdf
PDF
MTE104-L2: Overview of Microcontrollers
PPTX
ESD Presenation.pptx All about embeded system
PDF
3245731 tele-controlled-steper-motor-thesis
PDF
1.Introduction to AVR.pdf
PPTX
Embedded systems 101 final
PDF
Introduction to Arduino
DOCX
Avr report
PDF
MC_Module_1 (2).pdf MICROCONTROLLER VTU. MODULE 2
PPTX
Microcontroller
PPTX
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
PPTX
PLC ARCHITECTURE AND HARDWARE COMPONENTS
Micro Controllers engineering - computer engineering
Ajal mod 1
Microcontroller presentation
Embedded system
microcontroller-presentation-1-638 (30 files merged).pptx
Introduction to Avr Microcontrollers
LECT 2.pptx
Msp 430 architecture module 1
E-Note_19681_Content_Document_20240512114009AM.pdf
MTE104-L2: Overview of Microcontrollers
ESD Presenation.pptx All about embeded system
3245731 tele-controlled-steper-motor-thesis
1.Introduction to AVR.pdf
Embedded systems 101 final
Introduction to Arduino
Avr report
MC_Module_1 (2).pdf MICROCONTROLLER VTU. MODULE 2
Microcontroller
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
PLC ARCHITECTURE AND HARDWARE COMPONENTS

Recently uploaded (20)

PDF
IAE-V2500 Engine Airbus Family A319/320
PPT
Unit - I.lathemachnespct=ificationsand ppt
PDF
Recent Trends in Network Security - 2025
PDF
BBC NW_Tech Facilities_30 Odd Yrs Ago [J].pdf
PPTX
1. Effective HSEW Induction Training - EMCO 2024, O&M.pptx
PDF
ASPEN PLUS USER GUIDE - PROCESS SIMULATIONS
PPTX
INTERNET OF THINGS - EMBEDDED SYSTEMS AND INTERNET OF THINGS
PDF
Module 1 part 1.pdf engineering notes s7
PDF
Performance, energy consumption and costs: a comparative analysis of automati...
PDF
CBCN cam bien cong nghiep bach khoa da năng
PPTX
quantum theory on the next future in.pptx
PDF
LS-6-Digital-Literacy (1) K12 CURRICULUM .pdf
PPT
Basics Of Pump types, Details, and working principles.
PPTX
Design ,Art Across Digital Realities and eXtended Reality
PDF
BTCVPE506F_Module 1 History & Theories of Town Planning.pdf
PDF
PhD defense presentation in field of Computer Science
PPTX
Hardware, SLAM tracking,Privacy and AR Cloud Data.
PDF
1.-fincantieri-investor-presentation2.pdf
PDF
IAE-V2500 Engine for Airbus Family 319/320
PPTX
240409 Data Center Training Programs by Uptime Institute (Drafting).pptx
IAE-V2500 Engine Airbus Family A319/320
Unit - I.lathemachnespct=ificationsand ppt
Recent Trends in Network Security - 2025
BBC NW_Tech Facilities_30 Odd Yrs Ago [J].pdf
1. Effective HSEW Induction Training - EMCO 2024, O&M.pptx
ASPEN PLUS USER GUIDE - PROCESS SIMULATIONS
INTERNET OF THINGS - EMBEDDED SYSTEMS AND INTERNET OF THINGS
Module 1 part 1.pdf engineering notes s7
Performance, energy consumption and costs: a comparative analysis of automati...
CBCN cam bien cong nghiep bach khoa da năng
quantum theory on the next future in.pptx
LS-6-Digital-Literacy (1) K12 CURRICULUM .pdf
Basics Of Pump types, Details, and working principles.
Design ,Art Across Digital Realities and eXtended Reality
BTCVPE506F_Module 1 History & Theories of Town Planning.pdf
PhD defense presentation in field of Computer Science
Hardware, SLAM tracking,Privacy and AR Cloud Data.
1.-fincantieri-investor-presentation2.pdf
IAE-V2500 Engine for Airbus Family 319/320
240409 Data Center Training Programs by Uptime Institute (Drafting).pptx

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 - [email protected] - 5.5V,  0 - [email protected] - 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