Microprocessor and Interfacing 261214. Example: Writing a Game Need to Check Keyboard Input.

Slides:



Advertisements
Similar presentations
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
Advertisements

I/O Unit.
Loops, and sub-routines Interrupts Can be very useful in control applications particularly when the microprocessor must perform two tasks apparently.
 CPU: Central Processing Unit  I/O: Input /Output  Bus: Address bus & Data bus  Memory: RAM & ROM  Timer  Interrupt  Serial Port  Parallel Port.
Arduino Microcontrollers SREEJAA SUNDARARAJU AND R. SCOTT CARSON BME 462.
Events and Interrupts. Overview  What is an Event?  Examples of Events  Polling  Interrupts  Sample Timer Interrupt example.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
6-1 I/O Methods I/O – Transfer of data between memory of the system and the I/O device Most devices operate asynchronously from the CPU Most methods involve.
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
Read Chapter 3 (David E. Simon, An Embedded Software Primer)
AVR Programming CS-212 Dick Steflik. ATmega328P I/O for our labs To get data into and out of our Arduino its a little trickier than using printf and.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
Timers and Interrupts Shivendu Bhushan Sonu Agarwal.
INPUT/OUTPUT ARCHITECTURE By Truc Truong. Input Devices Keyboard Keyboard Mouse Mouse Scanner Scanner CD-Rom CD-Rom Game Controller Game Controller.
chipKit Sense Switch & Control LED
CS 0004 –Lecture 1 Wednesday, Jan 5 th, 2011 Roxana Gheorghiu.
V 0.91 Polled IO versus Interrupt Driven IO Polled Input/Output (IO) – processor continually checks IO device to see if it is ready for data transfer –Inefficient,
Introduction to Embedded Systems Buffering and DMA (Direct Memory Access) Lecture 11.
Input/ Output By Mohit Sehgal. What is Input/Output of a Computer? Connection with Machine Every machine has I/O (Like a function) In computing, input/output,
ELEC4601 Microprocessor systems Lab 3 Tutorial
Introduction to PIC-C. Required Software PIC-C Compiler Firmware Downloader Driver for the USB->Serial Adapter.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
(More) Interfacing concepts. Introduction Overview of I/O operations Programmed I/O – Standard I/O – Memory Mapped I/O Device synchronization Readings:
Chapter 8 I/O. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-2 I/O: Connecting to Outside World So far,
Introduction to Sensor Technology Week Five Adam Taylor
Interrupt.
Interrupts By Ryan Morris. Overview ● I/O Paradigm ● Synchronization ● Polling ● Control and Status Registers ● Interrupt Driven I/O ● Importance of Interrupts.
I/O Interfacing A lot of handshaking is required between the CPU and most I/O devices. All I/O devices operate asynchronously with respect to the CPU.
Interrupts Useful in dealing with: The interface: Random processes;
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs.
Introduction to PIC-C. Installing PIC-C Goto Username/pass = guest/cpecmu Download and install:  IDEUTIL  PCWHD.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
1 © Unitec New Zealand Interrupt Lecture 6 Date: - 20 Sept, 2011 Embedded Hardware ETEC 6416.
1 Interrupts, Resets Today: First Hour: Interrupts –Section 5.2 of Huang’s Textbook –In-class Activity #1 Second Hour: More Interrupts Section 5.2 of Huang’s.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Interrupts Microprocessor and Interfacing
CSCI1600: Embedded and Real Time Software Lecture 16: Advanced Programming with I/O Steven Reiss, Fall 2015.
TIMERS AND INTERRUPTS AVI SINGH KEVIN JOSE PIYUSH AWASTHI.
KEYBOARD INTERFACING Keyboards are organized in a matrix of rows and columns The CPU accesses both rows and columns through ports. ƒTherefore, with two.
Purpose of Operating System Monil Adhikari. Agenda Introduction Responsibilities of Operating System User Interfaces Command Line Interface Graphical.
RFID Access Control System Lucius Knight. General System Design  Microcontroller  PSoC CY8C29466  24MHz Bus Frequency  Memory Available  32kB FLASH.
Alpha/Numeric Keypad Functions using AVR Preliminary Design Review Luke R. Morgan ECE /17/2008.
© 2004, D. J. Foreman 1 Device Mgmt. © 2004, D. J. Foreman 2 Device Management Organization  Multiple layers ■ Application ■ Operating System ■ Driver.
I/O Organization Competency – C6. Important facts to remember when I/O devices are to be connected to CPU There is a vast variety of I/O devices. Some.
بسم الله الرحمن الرحيم MEMORY AND I/O.
LED CUBE Preliminary System Software Design Fernando J. Garcia May
I/O Software CS 537 – Introduction to Operating Systems.
Embedded Systems February 10, Serial Interface - SPI  Serial Peripheral Interface  Synchronous communications  Clock supplied by the Master.
Interrupts Microprocessor and Interfacing
LED CUBE Preliminary System Software Design Fernando J. Garcia May
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
MICROCONTROLLER INTERFACING WITH STEPPER MOTOR MADE BY: Pruthvirajsinh Jadeja ( ) COLLEGE:DIET BRANCH:EC.
Chapter 7 Input/Output and Storage Systems. 2 Chapter 7 Objectives Understand how I/O systems work, including I/O methods and architectures. Become familiar.
1. PIC ADC  PIC18F877 has 8 analog input channels i.e. port A pins(RA0 to RA5) and port E pins(RE1 and RE2). These pins are used as Analog input pins.
Case Study #1 Microcontroller System. What is a microcontroller? A microcontroller can be considered a self-contained system with a processor, memory.
Microprocessor Systems Design I
The deadline establish a priority among interrupt requests.
Arduino Part 1 Topics: Microcontrollers Programming Basics
Chapter 8 I/O.
CSCI 315 Operating Systems Design
Operating Systems Chapter 5: Input/Output Management
Interrupt Programming
Chapter 8 I/O.
BRX Technical Training
COMPUTER PERIPHERALS AND INTERFACES
TCSP: Software Development Status
Chapter 8 I/O.
Presentation transcript:

Microprocessor and Interfacing

Example: Writing a Game Need to Check Keyboard Input

Method 1: Using a Loop Program keeps checking for keyboard input While (1) [ If Key = Right Then moveRight ElseIf Key = Left Then moveLeft End If ]

Mothod II: Use KeyPress Event Runs only when there is a keyboard interrupt KeyPressEvent(Key) If Key = Left Then MoveLeft ElseIf Key = Right Then MoveRight End If End Subroutine

Method I : Software Polling Method II : Event or Interrupt Driven

I/O Handling Techniques Software Polling Interrupts Direct Memory Access (DMA)

Benefits of Using Interrupts Consumes much less CPU Especially when interrupt generated by hardware Cleaner & Simpler Code Allows Basic Parallel Processing

Exercise: Program a PIC Microcontroller Blink an LED every 0.5 sec Also receives serial data from the computer While (1) { output_toggle(LED); delay_ms(500); data = getchar(); } What’s wrong with this program?

A better program, but not best While (1) { output_toggle(LED); delay_ms(500); if (kbhit()) { data = getchar(); }

How do we fix the problem? Available Commands Getchar() – wait and return serial data Output_toggle(LED) Time() – returns current time (in ms) Kbhit() – returns true if serial data is available

Solution Software Polling Int currentTime; Char data; startTime = time(); While (1) { if (time() – startTime > 500) { output_toggle(LED); startTime = time(); } if (kbhit()) { data = getchar(); }

Same Program with Timer Interrupt timerISR() { output_toggle(LED); } Main() { setupTimer(); while (1) { data = getchar(); }

Interrupt Handling

Multi-Interrupt Handling

Important Note: Must minimize the time an ISR takes to execute Interrupts should perform as little work as possible. Should not call I/O functions Keyboard input – getchar(), scanf() I2C commands Read sensor Should not call delay functions Delay_ms(), Dealy_us()

Useful technique: Asynchronous Execution timerISR() { output_high(LED); delay_ms(1000); output_low(LED); } Main() { setupTimer(); while (1) { // do main work } Example of a BAD interrupt code design: ISR includes a long delay

After using Asynchronous Execution: Execution Moved to main() int1 doBlink = 0; timerISR() { doBlink = 1; } Main() { setupTimer(); while (1) { // do main work if (doBlink == 1){ output_high(LED); delay_ms(1000); output_low(LED); doBlink = 0; }

Exercise: Use Asynchronous Execution to fix this program IO_ISR() { ss = readSensor(1); printf(“%ld\r\n”, ss); } Main() { setup_IO_Interrupt(); while (1) { // do main work } IO interrupts happen when the user presses a button connected to a micro-controller