SlideShare a Scribd company logo
Lecture 6 – Introduction to the
ATmega328 and Ardunio
CSE P567
Outline
  Lecture 6
  ATmega architecture and instruction set
  I/O pins
  Arduino C++ language
  Lecture 7
  Controlling Time
  Interrupts and Timers
  Lecture 8
  Guest lecture – Radio communication
  Lecture 9
  Designing PID Controllers
AVR Architecture
AVR Architecture
  Clocks and Power
  Beyond scope of this
course
AVR Architecture
  CPU
  Details coming
AVR Architecture
  Harvard architecture
  Flash – program memory
  32K
  SRAM – data memory
  2K
  EEPROM
  For long-term data
  On I/O data bus
Memory
  Flash (32K) (15-bit addresses)
  Program memory – read only
  Non-volatile
  Allocate data to Flash using PROGMEM keyword
  see documentation
  SRAM (2K)
  Temporary values, stack, etc.
  Volatile
  Limited space!
  EEPROM (1K)
  Long-term data
  see documentation on EEPROM library
AVR CPU
  Instruction Fetch
and Decode
AVR CPU
  ALU Instructions
AVR CPU
  I/O and special
functions
AVR Register File
  32 8-bit GP registers
  Part of SRAM memory space
Special Addressing Registers
  X,Y and Z registers
  16-bit registers made using registers 26 – 31
  Support indirect addressing
AVR Memory
  Program memory – Flash
  Data memory - SRAM
Addressing Modes
  Direct register
addressing
Addressing Modes
  Direct I/O addressing
Addressing Modes
  Direct data memory addressing
Addressing Modes
  Direct data memory with displacement addressing
Addressing Modes
  Indirect data memory addressing
Addressing Modes
  Indirect data memory addressing with pre-decrement
Addressing Modes
  Indirect data memory addressing with post-increment
Addressing Modes
  Program memory addressing (constant data)
SRAM Read/Write Timing
Stack Pointer Register
  Special register in I/O space [3E, 3D]
  Enough bits to address data space
  Initialized to RAMEND (address of highest memory address)
  Instructions that use the stack pointer
Program Status Register (PSR)
  
  Status bits set by instructions/Checked by Branch/Skip
instructions
  I – Global interrupt enable
  T – Flag bit
  H – Half carry (BCD arithmetic)
  S – Sign
  V – Overflow
  N – Negative
  Z – Zero
  C – Carry
Simple 2-Stage Pipeline
  Branch/Skip??
Single-Cycle ALU Instructions
  Most instructions execute in one cycle
  Makes program timing calculations (relatively) easy
  No cache misses
  1 clock/instruction
Addressing Modes
  JMP, CALL – Direct Program Memory Addressing
Addressing Modes
  IJMP, ICALL – Indirect program memory addressing
Addressing Modes
  RJMP, RCALL – Relative program memory addressing
Arithmetic Instructions
Logical Instructions
Jump and Call Instructions
Skip and Branch Instructions
Skip and Branch (cont)
Move, Load
Store
Load/Store Program Memory
Move, I/O, Push/Pop
Shift and Bit Instructions
Bit Instructions (cont)
AVR Architecture
  Three timers
  Very flexible
  Choose clock rate
  Choose “roll-over” value
  Generate interrupts
  Generate PWM signals
  (represent 8-bit value with
using a clock signal)
  More in next lecture…
Arduino Timing Functions
  delay(ms)
  wait for ms milliseconds before continuing
  delayMicroseconds(us)
  wait for us microseconds before continuing
  unsigned long millis( )
  return number of milliseconds since program started
  unsigned long micros( )
  return number of microseconds since program started
  resolution of 4 microseconds
AVR Architecture
  Interface to pins
  Each pin directly
programmable
  Program direction
  Program value
  Program pull-ups
  Some pins are special
  Analog vs. Digital
  Clocks
  Reset
I/O Ports
  3 8-bit Ports (B, C, D)
  Each port controlled by 3 8-bit registers
  Each bit controls one I/O pin
  DDRx – Direction register
  Defines whether a pin is an input (0) or and output (1)
  PINx – Pin input value
  Reading this “register” returns value of pin
  PORTx – Pin output value
  Writing this register sets value of pin
Pin Circuitry
Pin Input
off
DDRx = 0
PORTx
PINx
Synchronization Timing
  Note:Takes a clock cycle for data output to be reflected
on the input
Pin Output
on
DDRx = 1
PORTx
PINx
Pin Input – PORT controls pullup
off
DDRx = 0
PORTx
PINx
I/O Ports
  Pullups
  If a pin is an input (DDRxi = 0):
  PORTxi = 0 – pin is floating
  PORTxi = 1 – connects a pullup to the pin
  Keeps pin from floating if noone driving
  Allows wired-OR bus
  Individual bits can be set cleared using bit-ops
  A bit can be toggled by writing 1 to PINxi
  SBI instruction e.g.
I/O Protection
Arduino Digital and Analog I/O Pins
  Digital pins:
  Pins 0 – 7: PORT D [0:7]
  Pins 8 – 13: PORT B [0:5]
  Pins 14 – 19: PORT C [0:5] (Arduino analog pins 0 – 5)
  digital pins 0 and 1 are RX and TX for serial communication
  digital pin 13 connected to the base board LED
  Digital Pin I/O Functions
  pinMode(pin, mode)
  Sets pin to INPUT or OUTPUT mode
  Writes 1 bit in the DDRx register
  digitalWrite(pin, value)
  Sets pin value to LOW or HIGH (0 or 1)
  Writes 1 bit in the PORTx register
  int value = digitalRead(pin)
  Reads back pin value (0 or 1)
  Read 1 bit in the PINx register
Arduino Analog I/O
  Analog input pins: 0 – 5
  Analog output pins: 3, 5, 6, 9, 10, 11 (digital pins)
  Analog input functions
  int val = analogRead(pin)
  Converts 0 – 5v. voltage to a 10-bit number (0 – 1023)
  Don’t use pinMode
  analogReference(type)
  Used to change how voltage is converted (advanced)
  Analog output
  analogWrite(pin, value)
  value is 0 – 255
  Generates a PWM output on digital pin (3, 5, 6, 9, 10, 11)
  @490Hz frequency
AVR Architecture
  Analog inputs
  Convert voltage to a
10-bit digital value
  Can provide reference
voltages
PWM – Pulse Width Modulation
  Use one wire to represent a multi-bit value
  A clock with a variable duty cycle
  Duty cycle used to represent value
  We can turn it into a analog voltage using an integrating filter
Port Special Functions
  Lots of special uses for pins
  Clock connections
  Timer connections
  e.g. comparator output for PWM
  Interrupts
  Analog references
  Serial bus I/Os
  USART
  PCI
Reading and Writing Pins Directly
  Only one pin can be changed using the Arduino I/O
functions
  Setting multiple pins takes time and instructions
  To change multiple pins simultaneously, directly read/write
the pin registers
  DDR{A/B/C}
  PORT{A/B/C}
  PIN{A/B/C}
  e.g. to set all digital pins 0 – 7 to a value:
  PORTD = B01100101;
AVR Architecture
  Special I/O support
  Serial protocols
  Uses special pins
  Uses timers
  Beyond scope of this
course
Arduino C Programs
  Arduino calls these “sketches”
  Basically C with libraries
  Program structure
  Header: declarations, includes, etc.
  setup()
  loop()
  Setup is likeVerilog initial
  executes once when program starts
  loop() is likeVerilog always
  continuously re-executed when the end is reached
Blink Program
int ledPin = 13; // LED connected to digital pin 13
// The setup() method runs once, when the sketch starts
void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}
The Arduino C++ Main Program
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}
Arduino Serial I/O
  Communication with PC via USB serial line
  Use the Serial Monitor in the IDE
  Or set up a C or Java (or you-name-it) interface
  Example Serial library calls
  Serial.begin(baud-rate)
  9600 default
  Serial.println(string)
  int foo = Serial.read()
  Read one byte (input data is buffered)
  See documentation for more
Example Program

More Related Content

What's hot

Assembler Programming
Assembler ProgrammingAssembler Programming
Assembler Programming
Omar Sanchez
 
microprocessor
 microprocessor microprocessor
microprocessor
ATTO RATHORE
 
digital logic circuits, digital component
digital logic circuits, digital componentdigital logic circuits, digital component
digital logic circuits, digital component
Rai University
 
Peripherals and interfacing
Peripherals  and interfacingPeripherals  and interfacing
Peripherals and interfacing
RAMPRAKASHT1
 
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Sivaranjan Goswami
 
Embedded System Programming on ARM Cortex M3 and M4 Course
Embedded System Programming on ARM Cortex M3 and M4 CourseEmbedded System Programming on ARM Cortex M3 and M4 Course
Embedded System Programming on ARM Cortex M3 and M4 Course
FastBit Embedded Brain Academy
 
Embedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programmingEmbedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programmingIkhwan_Fakrudin
 
Assembly programming
Assembly programmingAssembly programming
Assembly programming
Omar Sanchez
 
Chp7 pic 16 f84 interfacing - copy
Chp7 pic 16 f84 interfacing - copyChp7 pic 16 f84 interfacing - copy
Chp7 pic 16 f84 interfacing - copymkazree
 
Presentation
PresentationPresentation
Presentation
Abhijit Das
 
Microcontroller ppt
Microcontroller pptMicrocontroller ppt
Microcontroller ppt
prajjwalsharma37
 
8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C
Aman Sharma
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
Omar Sanchez
 
microprocessor
   microprocessor   microprocessor
microprocessor
ATTO RATHORE
 
Assembler4
Assembler4Assembler4
Assembler4
Omar Sanchez
 
Best-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbaiBest-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbai
Unmesh Baile
 
Embedded system (Chapter )
Embedded system (Chapter )Embedded system (Chapter )
Embedded system (Chapter )Ikhwan_Fakrudin
 

What's hot (19)

Assembler Programming
Assembler ProgrammingAssembler Programming
Assembler Programming
 
microprocessor
 microprocessor microprocessor
microprocessor
 
digital logic circuits, digital component
digital logic circuits, digital componentdigital logic circuits, digital component
digital logic circuits, digital component
 
Peripherals and interfacing
Peripherals  and interfacingPeripherals  and interfacing
Peripherals and interfacing
 
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
 
Embedded System Programming on ARM Cortex M3 and M4 Course
Embedded System Programming on ARM Cortex M3 and M4 CourseEmbedded System Programming on ARM Cortex M3 and M4 Course
Embedded System Programming on ARM Cortex M3 and M4 Course
 
Embedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programmingEmbedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programming
 
8086 assembly
8086 assembly8086 assembly
8086 assembly
 
Assembly programming
Assembly programmingAssembly programming
Assembly programming
 
Chp7 pic 16 f84 interfacing - copy
Chp7 pic 16 f84 interfacing - copyChp7 pic 16 f84 interfacing - copy
Chp7 pic 16 f84 interfacing - copy
 
Presentation
PresentationPresentation
Presentation
 
Microcontroller ppt
Microcontroller pptMicrocontroller ppt
Microcontroller ppt
 
Lecture8
Lecture8Lecture8
Lecture8
 
8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
microprocessor
   microprocessor   microprocessor
microprocessor
 
Assembler4
Assembler4Assembler4
Assembler4
 
Best-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbaiBest-embedded-corporate-training-in-mumbai
Best-embedded-corporate-training-in-mumbai
 
Embedded system (Chapter )
Embedded system (Chapter )Embedded system (Chapter )
Embedded system (Chapter )
 

Similar to Lecture6

AVR arduino dasar
AVR arduino dasarAVR arduino dasar
AVR arduino dasar
Oktaf Kharisma
 
Lecture6.pptx
Lecture6.pptxLecture6.pptx
Lecture6.pptx
KamalZeghdar
 
Embedded systems optimization memory requirments.pptx
Embedded systems optimization memory requirments.pptxEmbedded systems optimization memory requirments.pptx
Embedded systems optimization memory requirments.pptx
satheeshKumar750
 
Microcontroller
MicrocontrollerMicrocontroller
MicrocontrollerSpitiq
 
Avr report
Avr reportAvr report
Avr report
NITISH KUMAR
 
MICROCONTROLLER.pptx
MICROCONTROLLER.pptxMICROCONTROLLER.pptx
MICROCONTROLLER.pptx
fiqrie mohd
 
Arduino Foundations
Arduino FoundationsArduino Foundations
Arduino Foundations
John Breslin
 
teststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptxteststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptx
ethannguyen1618
 
Arduino cic3
Arduino cic3Arduino cic3
Arduino cic3
Jeni Shah
 
amba.ppt
amba.pptamba.ppt
amba.ppt
DivyaDewkathe
 
amba.ppt
amba.pptamba.ppt
amba.ppt
VediAshutosh
 
amba (1).ppt
amba (1).pptamba (1).ppt
amba (1).ppt
ssallu0727
 
Microcontroller 8051 By Mitesh kumar
Microcontroller 8051 By Mitesh kumarMicrocontroller 8051 By Mitesh kumar
Microcontroller 8051 By Mitesh kumar
Mitesh Kumar
 
microcontroller basics
microcontroller basicsmicrocontroller basics
microcontroller basics
sagar Ramdev
 
Arduino intro.pptx
Arduino intro.pptxArduino intro.pptx
Arduino intro.pptx
SanthanaMari11
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051Rashmi
 
Embedded system course projects - Arduino Course
Embedded system course projects - Arduino CourseEmbedded system course projects - Arduino Course
Embedded system course projects - Arduino Course
Elaf A.Saeed
 
Arduino Programming
Arduino ProgrammingArduino Programming
Arduino Programming
Dr Karthikeyan Periasamy
 

Similar to Lecture6 (20)

AVR arduino dasar
AVR arduino dasarAVR arduino dasar
AVR arduino dasar
 
Lecture6.pptx
Lecture6.pptxLecture6.pptx
Lecture6.pptx
 
Embedded systems optimization memory requirments.pptx
Embedded systems optimization memory requirments.pptxEmbedded systems optimization memory requirments.pptx
Embedded systems optimization memory requirments.pptx
 
Microcontroller
MicrocontrollerMicrocontroller
Microcontroller
 
Avr report
Avr reportAvr report
Avr report
 
MICROCONTROLLER.pptx
MICROCONTROLLER.pptxMICROCONTROLLER.pptx
MICROCONTROLLER.pptx
 
Arduino Programming Basic
Arduino Programming BasicArduino Programming Basic
Arduino Programming Basic
 
Arduino Foundations
Arduino FoundationsArduino Foundations
Arduino Foundations
 
teststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptxteststststststLecture_3_2022_Arduino.pptx
teststststststLecture_3_2022_Arduino.pptx
 
Arduino cic3
Arduino cic3Arduino cic3
Arduino cic3
 
amba.ppt
amba.pptamba.ppt
amba.ppt
 
amba.ppt
amba.pptamba.ppt
amba.ppt
 
amba (1).ppt
amba (1).pptamba (1).ppt
amba (1).ppt
 
Microcontroller 8051 By Mitesh kumar
Microcontroller 8051 By Mitesh kumarMicrocontroller 8051 By Mitesh kumar
Microcontroller 8051 By Mitesh kumar
 
Arduino
ArduinoArduino
Arduino
 
microcontroller basics
microcontroller basicsmicrocontroller basics
microcontroller basics
 
Arduino intro.pptx
Arduino intro.pptxArduino intro.pptx
Arduino intro.pptx
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
Embedded system course projects - Arduino Course
Embedded system course projects - Arduino CourseEmbedded system course projects - Arduino Course
Embedded system course projects - Arduino Course
 
Arduino Programming
Arduino ProgrammingArduino Programming
Arduino Programming
 

More from Mahmut Yildiz

Arm code arduino
Arm code arduinoArm code arduino
Arm code arduino
Mahmut Yildiz
 
Drv8833 motor driver datasheet
Drv8833 motor driver datasheetDrv8833 motor driver datasheet
Drv8833 motor driver datasheet
Mahmut Yildiz
 
Tcs230
Tcs230Tcs230
Lecture7
Lecture7Lecture7
Lecture7
Mahmut Yildiz
 
Microsd card spec
Microsd card specMicrosd card spec
Microsd card spec
Mahmut Yildiz
 
Micro sd specification
Micro sd specificationMicro sd specification
Micro sd specification
Mahmut Yildiz
 
Comunication project
Comunication projectComunication project
Comunication project
Mahmut Yildiz
 
Audioprocessing
AudioprocessingAudioprocessing
Audioprocessing
Mahmut Yildiz
 
Us6330335
Us6330335Us6330335
Us6330335
Mahmut Yildiz
 
96683234 project-report-steganography
96683234 project-report-steganography96683234 project-report-steganography
96683234 project-report-steganography
Mahmut Yildiz
 
Amplitude modulation
Amplitude modulationAmplitude modulation
Amplitude modulation
Mahmut Yildiz
 
Introduction to modulation and demodulation
Introduction to modulation and demodulationIntroduction to modulation and demodulation
Introduction to modulation and demodulation
Mahmut Yildiz
 
Matlabders
MatlabdersMatlabders
Matlabders
Mahmut Yildiz
 
Matlab.pdf
Matlab.pdfMatlab.pdf
Matlab.pdf
Mahmut Yildiz
 
Matlab grafik
Matlab grafikMatlab grafik
Matlab grafik
Mahmut Yildiz
 
Basic Info for Matlab
 Basic Info for Matlab Basic Info for Matlab
Basic Info for Matlab
Mahmut Yildiz
 

More from Mahmut Yildiz (16)

Arm code arduino
Arm code arduinoArm code arduino
Arm code arduino
 
Drv8833 motor driver datasheet
Drv8833 motor driver datasheetDrv8833 motor driver datasheet
Drv8833 motor driver datasheet
 
Tcs230
Tcs230Tcs230
Tcs230
 
Lecture7
Lecture7Lecture7
Lecture7
 
Microsd card spec
Microsd card specMicrosd card spec
Microsd card spec
 
Micro sd specification
Micro sd specificationMicro sd specification
Micro sd specification
 
Comunication project
Comunication projectComunication project
Comunication project
 
Audioprocessing
AudioprocessingAudioprocessing
Audioprocessing
 
Us6330335
Us6330335Us6330335
Us6330335
 
96683234 project-report-steganography
96683234 project-report-steganography96683234 project-report-steganography
96683234 project-report-steganography
 
Amplitude modulation
Amplitude modulationAmplitude modulation
Amplitude modulation
 
Introduction to modulation and demodulation
Introduction to modulation and demodulationIntroduction to modulation and demodulation
Introduction to modulation and demodulation
 
Matlabders
MatlabdersMatlabders
Matlabders
 
Matlab.pdf
Matlab.pdfMatlab.pdf
Matlab.pdf
 
Matlab grafik
Matlab grafikMatlab grafik
Matlab grafik
 
Basic Info for Matlab
 Basic Info for Matlab Basic Info for Matlab
Basic Info for Matlab
 

Recently uploaded

MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
Kamal Acharya
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
dxobcob
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 

Recently uploaded (20)

MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 

Lecture6

  • 1. Lecture 6 – Introduction to the ATmega328 and Ardunio CSE P567
  • 2. Outline   Lecture 6   ATmega architecture and instruction set   I/O pins   Arduino C++ language   Lecture 7   Controlling Time   Interrupts and Timers   Lecture 8   Guest lecture – Radio communication   Lecture 9   Designing PID Controllers
  • 4. AVR Architecture   Clocks and Power   Beyond scope of this course
  • 6. AVR Architecture   Harvard architecture   Flash – program memory   32K   SRAM – data memory   2K   EEPROM   For long-term data   On I/O data bus
  • 7. Memory   Flash (32K) (15-bit addresses)   Program memory – read only   Non-volatile   Allocate data to Flash using PROGMEM keyword   see documentation   SRAM (2K)   Temporary values, stack, etc.   Volatile   Limited space!   EEPROM (1K)   Long-term data   see documentation on EEPROM library
  • 8. AVR CPU   Instruction Fetch and Decode
  • 9. AVR CPU   ALU Instructions
  • 10. AVR CPU   I/O and special functions
  • 11. AVR Register File   32 8-bit GP registers   Part of SRAM memory space
  • 12. Special Addressing Registers   X,Y and Z registers   16-bit registers made using registers 26 – 31   Support indirect addressing
  • 13. AVR Memory   Program memory – Flash   Data memory - SRAM
  • 14. Addressing Modes   Direct register addressing
  • 16. Addressing Modes   Direct data memory addressing
  • 17. Addressing Modes   Direct data memory with displacement addressing
  • 18. Addressing Modes   Indirect data memory addressing
  • 19. Addressing Modes   Indirect data memory addressing with pre-decrement
  • 20. Addressing Modes   Indirect data memory addressing with post-increment
  • 21. Addressing Modes   Program memory addressing (constant data)
  • 23. Stack Pointer Register   Special register in I/O space [3E, 3D]   Enough bits to address data space   Initialized to RAMEND (address of highest memory address)   Instructions that use the stack pointer
  • 24. Program Status Register (PSR)     Status bits set by instructions/Checked by Branch/Skip instructions   I – Global interrupt enable   T – Flag bit   H – Half carry (BCD arithmetic)   S – Sign   V – Overflow   N – Negative   Z – Zero   C – Carry
  • 26. Single-Cycle ALU Instructions   Most instructions execute in one cycle   Makes program timing calculations (relatively) easy   No cache misses   1 clock/instruction
  • 27. Addressing Modes   JMP, CALL – Direct Program Memory Addressing
  • 28. Addressing Modes   IJMP, ICALL – Indirect program memory addressing
  • 29. Addressing Modes   RJMP, RCALL – Relative program memory addressing
  • 32. Jump and Call Instructions
  • 33. Skip and Branch Instructions
  • 34. Skip and Branch (cont)
  • 36. Store
  • 39. Shift and Bit Instructions
  • 41. AVR Architecture   Three timers   Very flexible   Choose clock rate   Choose “roll-over” value   Generate interrupts   Generate PWM signals   (represent 8-bit value with using a clock signal)   More in next lecture…
  • 42. Arduino Timing Functions   delay(ms)   wait for ms milliseconds before continuing   delayMicroseconds(us)   wait for us microseconds before continuing   unsigned long millis( )   return number of milliseconds since program started   unsigned long micros( )   return number of microseconds since program started   resolution of 4 microseconds
  • 43. AVR Architecture   Interface to pins   Each pin directly programmable   Program direction   Program value   Program pull-ups   Some pins are special   Analog vs. Digital   Clocks   Reset
  • 44. I/O Ports   3 8-bit Ports (B, C, D)   Each port controlled by 3 8-bit registers   Each bit controls one I/O pin   DDRx – Direction register   Defines whether a pin is an input (0) or and output (1)   PINx – Pin input value   Reading this “register” returns value of pin   PORTx – Pin output value   Writing this register sets value of pin
  • 46. Pin Input off DDRx = 0 PORTx PINx
  • 47. Synchronization Timing   Note:Takes a clock cycle for data output to be reflected on the input
  • 48. Pin Output on DDRx = 1 PORTx PINx
  • 49. Pin Input – PORT controls pullup off DDRx = 0 PORTx PINx
  • 50. I/O Ports   Pullups   If a pin is an input (DDRxi = 0):   PORTxi = 0 – pin is floating   PORTxi = 1 – connects a pullup to the pin   Keeps pin from floating if noone driving   Allows wired-OR bus   Individual bits can be set cleared using bit-ops   A bit can be toggled by writing 1 to PINxi   SBI instruction e.g.
  • 52.
  • 53. Arduino Digital and Analog I/O Pins   Digital pins:   Pins 0 – 7: PORT D [0:7]   Pins 8 – 13: PORT B [0:5]   Pins 14 – 19: PORT C [0:5] (Arduino analog pins 0 – 5)   digital pins 0 and 1 are RX and TX for serial communication   digital pin 13 connected to the base board LED   Digital Pin I/O Functions   pinMode(pin, mode)   Sets pin to INPUT or OUTPUT mode   Writes 1 bit in the DDRx register   digitalWrite(pin, value)   Sets pin value to LOW or HIGH (0 or 1)   Writes 1 bit in the PORTx register   int value = digitalRead(pin)   Reads back pin value (0 or 1)   Read 1 bit in the PINx register
  • 54. Arduino Analog I/O   Analog input pins: 0 – 5   Analog output pins: 3, 5, 6, 9, 10, 11 (digital pins)   Analog input functions   int val = analogRead(pin)   Converts 0 – 5v. voltage to a 10-bit number (0 – 1023)   Don’t use pinMode   analogReference(type)   Used to change how voltage is converted (advanced)   Analog output   analogWrite(pin, value)   value is 0 – 255   Generates a PWM output on digital pin (3, 5, 6, 9, 10, 11)   @490Hz frequency
  • 55. AVR Architecture   Analog inputs   Convert voltage to a 10-bit digital value   Can provide reference voltages
  • 56. PWM – Pulse Width Modulation   Use one wire to represent a multi-bit value   A clock with a variable duty cycle   Duty cycle used to represent value   We can turn it into a analog voltage using an integrating filter
  • 57. Port Special Functions   Lots of special uses for pins   Clock connections   Timer connections   e.g. comparator output for PWM   Interrupts   Analog references   Serial bus I/Os   USART   PCI
  • 58. Reading and Writing Pins Directly   Only one pin can be changed using the Arduino I/O functions   Setting multiple pins takes time and instructions   To change multiple pins simultaneously, directly read/write the pin registers   DDR{A/B/C}   PORT{A/B/C}   PIN{A/B/C}   e.g. to set all digital pins 0 – 7 to a value:   PORTD = B01100101;
  • 59. AVR Architecture   Special I/O support   Serial protocols   Uses special pins   Uses timers   Beyond scope of this course
  • 60. Arduino C Programs   Arduino calls these “sketches”   Basically C with libraries   Program structure   Header: declarations, includes, etc.   setup()   loop()   Setup is likeVerilog initial   executes once when program starts   loop() is likeVerilog always   continuously re-executed when the end is reached
  • 61. Blink Program int ledPin = 13; // LED connected to digital pin 13 // The setup() method runs once, when the sketch starts void setup() { // initialize the digital pin as an output: pinMode(ledPin, OUTPUT); } // the loop() method runs over and over again, // as long as the Arduino has power void loop() { digitalWrite(ledPin, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(ledPin, LOW); // set the LED off delay(1000); // wait for a second }
  • 62. The Arduino C++ Main Program int main(void) { init(); setup(); for (;;) loop(); return 0; }
  • 63. Arduino Serial I/O   Communication with PC via USB serial line   Use the Serial Monitor in the IDE   Or set up a C or Java (or you-name-it) interface   Example Serial library calls   Serial.begin(baud-rate)   9600 default   Serial.println(string)   int foo = Serial.read()   Read one byte (input data is buffered)   See documentation for more