Lecturers: Professor John Devlin Mr Robert Ross

Slides:



Advertisements
Similar presentations
Chapter 6 General Purpose Input/Output
Advertisements

EMS1EP Lecture 6 Digital Inputs
ECE 382 Lesson 14 Lesson Outline Polling Multiplexing Intro to Logic Analyzer Debouncing Software Delay Routines Admin Assignment 3b due BOC today Assignment.
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Chung-Ta King National Tsing Hua University
Lab7: Introduction to Arduino
Chung-Ta King National Tsing Hua University
Chung-Ta King National Tsing Hua University
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
68HC11 Polling and Interrupts
Debouncing Switches Mechanical switches are one of the most common interfaces to a uC. Switch inputs are asynchronous to the uC and are not electrically.
ECE Lecture 1 1 L15 – Digital I/O Department of Electrical and Computer Engineering The Ohio State University ECE 2560.
Digital I/O Connecting to the Outside World
Chapter 6 – MSP430 Micro-Architecture. BYU CS/ECEn 124Chapter 6 - MSP430 Micro-Architecture2 Concepts to Learn… Computer Architecture MSP430 Micro-Architecture.
ECE 447 Fall 2009 Lecture 6: TI MSP430 IO Interfacing.
The 8051 Microcontroller and Embedded Systems
Chung-Ta King National Tsing Hua University
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
A Simple Tour of the MSP430. Light LEDs in C LEDs can be connected in two standard ways. Active high circuit, the LED illuminates if the pin is driven.
3-1 Digital I/O A group of I/O pins is called a PORT  A port is where data enters/leaves the system. Digital I/O pins are usually grouped into 8,16 or.
MICROPROCESSOR INPUT/OUTPUT
I/O devices Peripheral devices (also called I/O devices) are pieces of equipment that exchange data with a CPU Examples: switches, LED, CRT, printers,
1 ARM University Program Copyright © ARM Ltd 2013 General Purpose I/O.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
COMP3221: Microprocessors and Embedded Systems Lecture 18: Computer Buses and Parallel Input/Output (II) Lecturer: Hui.
1 ARM University Program Copyright © ARM Ltd 2013 General Purpose I/O.
Khaled A. Al-Utaibi  The Push Button  Interfacing Push Buttons to Arduino  Programming Digital Inputs  Working with “Bouncy”
Lecture 11: TI MSP430 Timers Compare Modes
1 LHO 13 The 8051CF020 and the University Daughter Card.
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
1 ECE 372 – Microcontroller Design Parallel IO Ports - Inputs.
Lecture 16: Digital to Analog Converter - PWM Implementation
IO Subsystem IV Ports and peripherals. IO Subsystem (1) All devices connected to the system buses, other than memory and CPU – Input and output ports.
Input Interface – Microprocessor
ECE Lecture 1 1 L15 –I/O Part II Department of Electrical and Computer Engineering The Ohio State University ECE 2560.
CSCI1600: Embedded and Real Time Software Lecture 9: Input Output Concepts Steven Reiss, Fall 2015.
Week 7 Low-Power Modes MSP430 Teaching Materials Hacettepe University Copyright 2009 Texas Instruments All Rights Reserved.
CSCI1600: Embedded and Real Time Software Lecture 16: Advanced Programming with I/O Steven Reiss, Fall 2015.
INTERNET OF EVERYTHING SDU 2016 Week 4. Simple Digital and Analog Inputs  The Arduino’s ability to sense digital and analog inputs allows it to respond.
Lecture 3 CSE 341 – Microprocessors Lecture 3 Md. Omar Faruqe UB 1228
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
Microcontrollers JULES CALELLA. Microcontrollers vs Microprocessors  Microprocessors – do not contain RAM, ROM, I/O  Microcontrollers – The whole package.
ISA CLICK CONTROL #38 – FALL 2014 ERIC BRUNNGRABER DRAKE ISABIRYE.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
Microprocessors A practical approach..
ECE 382 Lesson 32 Lesson Outline Lab 6 Introduction Pulse Width Modulation Capture / Compare Example Lab 6 Tips Admin Lab#6 “prelab” due BOC lesson 33.
Application Case Study Christmas Lights Controller
40106B Schmitt Trigger (A way of switch De-Bouncing)
CS4101 嵌入式系統概論 General Purpose IO
Microcontrollers, Basics Tips and Tricks with PIC MCUs
Peripherals – Keypad The Keypad provides a simple means of numerical data or control input. The keys can be attributed whatever data or control values.
Lecture 8: TI MSP430 Interrupts, ISRs
Microcontroller basics
ECE 382 Lesson 14 Lesson Outline Polling Multiplexing
Lesson Outline Interrupts Admin Assignment #9 due next lesson
Chapter 6 General Purpose Input/Output
CS4101 Introduction to Embedded Systems Lab 1: General Purpose IO
Lesson Outline Peripherals Memory-Mapped IO Ports GPIO Multiplexing
CS4101 嵌入式系統概論 General Purpose IO
Blinking an LED Using MSP430ware to Control GPIO
How to avoid catching things on fire.
CSCI1600: Embedded and Real Time Software
CSCI1600: Embedded and Real Time Software
CSCI1600: Embedded and Real Time Software
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
UNIT 9 Relays.
CSCI1600: Embedded and Real Time Software
Interrupts.
A modular robot for use in the RoboSumo lab
Presentation transcript:

Lecturers: Professor John Devlin Mr Robert Ross Lecture 13: GPIO Inputs Lecturers: Professor John Devlin Mr Robert Ross

Overview Introduction to GPIO Interfacing inputs as GPIO Input ringing

Further Reading “A guide to Debouncing” http://www.ganssle.com/debouncing.pdf MSP430x2xx Family User’s Guide

Introduction to GPIO GPIO stands for General Purpose Input/Output, and relates to the pins which can be configured as digital input or output pins TI refer to GPIO as Digital I/O (Chapter 6 of the MSP430x2xx Family Users Guide) The MSP430-2013 has 2 GPIO ports (P1 and P2) P1 has 8 GPIO Pins P2 has 2 GPIO Pins

Introduction to GPIO All the pins can be individually configured as either Inputs or Outputs All the pins can be configured as triggers for interrupts All P1 pins share one interrupt vector (Flag: P1IFG), both P2 pins share a second interrupt vector (Flag: P2IFG) Each pin can be individually configured with internal pull-up or pull-down resistors Separate input and output registers (PxIN and PxOUT)

Configuring GPIO This lecture focuses on using GPIO pins for input, next lecture will discuss using GPIO pins for output Prior to use, pins must be configured as input or output – this is referred to as giving the pins a direction

Setting Direction To set direction: Examples: Write into PxDIR register the direction of all the pins x will be 1 for Port1, and 2 for Port2 (ie. P1DIR and P2DIR) ‘0’ = Input ‘1’ = Output Examples: BIS.b #001h, &P1DIR ; Sets Pin 0 of P1 as an output BIC.b #002h, &P2DIR ; Sets Pin 1 of P2 as an input BIS.b #00101101b, &P1DIR ; Sets Pins 0, 2, 3 and 5 of P1 as outputs BIC.b #11010010b, &P1DIR ; Sets Pins 1, 4, 6 and 7 of P1 as inputs MOV.b #10000100b, &P1DIR; Sets Pins 7 and 2 as outputs, the rest as inputs

Pull-up / pull-down resistors Pull-up or pull-down resistors can be activated by setting bits in the PxREN registers, provided that the pin is con.gured as an input. The MCU behaves randomly if you forget this step because the inputs floats!!!!!;

Input reading polling/interrupts A program can respond to inputs in two ways. For a simple analogy, suppose I am waiting for my daughter to come home while writing this book. She has forgotten her key so I need to unlock the door for her. • I could go regularly to the door and look out to see whether she has returned, after each paragraph for instance. This is polling. • I could carry on writing continuously until I receive an interrupt from the doorbell. I then fininish the sentence to leave the work in a well-defined state and go to the door.

Listing 4. 5: Program butled1 Listing 4.5: Program butled1.c in C to light LED1 when button B1 is pressed. This version has a single loop containing a decision statement. // butled1.c - press button to light LED // Single loop with "if" // Olimex 1121 STK board , LED1 active low on P2.3, // button B1 active low on P2.1 // J H Davies , 2006 -06 -01; IAR Kickstart version 3.41A // ---------------------------------------------------------------------- #include <msp430x11x1.h> // Specific device // Pins for LED and button on port 2 #define LED1 BIT3 #define B1 BIT1 void main (void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P2OUT |= LED1; // Preload LED1 off (active low!) P2DIR = LED1; // Set pin with LED1 to output for (;;) { // Loop forever if ((P2IN & B1) == 0) { // Is button down? (active low) P2OUT &= ˜LED1; // Yes: Turn LED1 on (active low!) } else { P2OUT |= LED1; // No: Turn LED1 off (active low!) }

Internal Pull Up/Down Resistor To enable internal resistor Write to PxREN register ‘0’ = Disabled ‘1’ = Enabled Examples: BIS.b #00101101b, &P1REN ; Enables internal resistor on pins 0, 2, 3 and 5 of P1 BIC.b #11010010b, &P1REN ; Disables internal resistor on pins 1, 4, 6 and 7 of P1

Input function select I/O pins are often multiplexed with special function peripherals (eg. ADC, DAC, PWM generator) The user needs to specify if the pins are simply digital I/O or if the special function is required: Write to PxSEL registers ‘0’ = Digital I/O ‘1’ = Special Function

Unused PINs Unused pins should not be left floating – this can waste power and cause strange behaviour TI recommends two different things can be done with unused pins: Configure as Digital I/O, Output and don’t connect to anything Configure as Digital I/O, Input, and enable the internal pull-up/down resistor

Σύνδεση με πληκτρολόγιο 3x4

Σύνδεση με πληκτρολόγιο 3x4

Σύνδεση με πληκτρολόγιο 3x4

Reading Input Pins The current state of input pins (0 or 1) can be read from the PxIN Registers This is a read-only register, TI notes that attempting to write to this register will result in increased power consumption for no useful result Remember ‘BIT’ Command is used to perform ‘AND’ updating the flags without writing to the dst register Examples: Check if Pin 0 on P1 is ‘1’: BIT #00000001b, &P1IN JNZ pin_1_high ; Jump if P1.0 was 1 Check if Pin 4 on P1 is ‘0’: BIT #00010000b, &P1IN JZ pin_4_low ; Jump if P1.4 was 0

Register Table

Connecting inputs (Hardware) Switches - most common digital input to a microcontroller Switches should be connected to a pull-up resistor (so the input doesn’t float) The MSP430 has internal pull-up resistors which can be used instead MCU 10k Vcc Vcc MSP 430

Switch Problems - Ringing Switches are mechanical devices – a piece of metal is used to close a circuit Unfortunately switches rarely close a circuit cleanly - the metal bounces, causing “ringing” Can anyone see a problem with this?

Solutions to ringing Hardware: Add additional hardware to ensure that the microprocessor only receives clean edges Software: Develop an algorithm which detects transitions but discards ringing

Debouncing - Hardware A capacitor can be used to remove bouncing Output is now more ramp-like (RC e-t/RC Charge/Discharge curves) Digital devices prefer sharp transitions – not a slow curve MCU 10k Vcc 10nF

Debouncing - Hardware A Schmitt trigger can be used to convert the curve to have sharper edges A Schmitt trigger will output a high when input is over a high threshold and a low when under a low threshold – in between they keep the same value Schmitt triggers therefore exhibit hysteresis 10k Vcc 10nF MCU

Debouncing - Software Software needs to detect discrete switch presses, without detecting bounces When switch is pressed, it should discriminate between a bounce and a valid button press.

Debouncing - Software Algorithm: When switched pressed start counting once per millisecond If switch value = 0, reset counter When counter = 20 (or so) the switch has been debounced

Do we always need to debounce? Not necessarily What does the system need to know – the time when a switch is first pressed, or the number of times a switch is pressed Switches that might not need debouncing: Game show buzzer Ejector seat TV remote control (sends same code until switch is not pressed)

Summary GPIO Pins are General Purpose Input and Output pins Before they are used they should be configured: Direction (Input or Output) (PxDIR) GPIO or Special Function (PxSEL) Resistor enable (PxREN) If pins are used to drive interrupts, several more registers need to be setup Switches need to be debounced if the number of switch presses is important