Microcontrollers and Interfacing

Similar documents
Portland State University MICROCONTROLLERS

Arduino Microcontroller Processing for Everyone!: Third Edition / Steven F. Barrett

Lab 2: Blinkie Lab. Objectives. Materials. Theory

CSCI1600 Lab 4: Sound

EE283 Electrical Measurement Laboratory Laboratory Exercise #7: Digital Counter

Embedded Systems and Software

Elements of Electronics and Circuit Analysis

Breadboard Traffic Light System

EE-110 Introduction to Engineering & Laboratory Experience Saeid Rahimi, Ph.D. Lab Timer: Blinking LED Lights and Pulse Generator

Embedded Systems. Oscillator and I/O Hardware. Eng. Anis Nazer First Semester

Design and Technology

HAW-Arduino. Sensors and Arduino F. Schubert HAW - Arduino 1

Lazy Clock Electronics and Software

νµθωερτψυιοπασδφγηϕκλζξχϖβνµθωερτ ψυιοπασδφγηϕκλζξχϖβνµθωερτψυιοπα σδφγηϕκλζξχϖβνµθωερτψυιοπασδφγηϕκ χϖβνµθωερτψυιοπασδφγηϕκλζξχϖβνµθ

FABO ACADEMY X ELECTRONIC DESIGN

HIGH LOW Astable multivibrators HIGH LOW 1:1

Lesson 3: Arduino. Goals

+5V, Low-Power µp Supervisory Circuits with Adjustable Reset/Watchdog

OBJECTIVE The purpose of this exercise is to design and build a pulse generator.

Using the Z8 Encore! XP Timer

Electronics Design Laboratory Lecture #9. ECEN 2270 Electronics Design Laboratory

Introduction to IC-555. Compiled By: Chanakya Bhatt EE, IT-NU

+15 V 10k. !15 V Op amp as a simple comparator.

Sequential Logic Circuits

CprE 288 Introduction to Embedded Systems (Output Compare and PWM) Instructors: Dr. Phillip Jones

Single Device Combines Pushbutton On/Off Control, Ideal Diode PowerPath and Accurate System Monitoring

Attribution Thank you to Arduino and SparkFun for open source access to reference materials.

MICROCONTROLLER TUTORIAL II TIMERS

J. La Favre Using Arduino with Raspberry Pi February 7, 2018

ECE 511: FINAL PROJECT REPORT GROUP 7 MSP430 TANK

Lecture 4: Basic Electronics. Lecture 4 Brief Introduction to Electronics and the Arduino

Preface. If you have any problems for learning, please contact us at We will do our best to help you solve the problem.

VLA Hybrid Gate Driver Application Information. DC-DC Converter V D 15V. V iso = 2500V RMS

Electronics Design Laboratory Lecture #10. ECEN 2270 Electronics Design Laboratory

AVL-10000T AUDIO VIDEO LINK TRANSMITTER TECHNICAL MANUAL

Exercise 5: PWM and Control Theory

Atmel U6032B. Automotive Toggle Switch IC DATASHEET. Features. Description

Objectives: Learn what an Arduino is and what it can do Learn what an LED is and how to use it Be able to wire and program an LED to blink

Setup Period. General Description

For this exercise, you will need a partner, an Arduino kit (in the plastic tub), and a laptop with the Arduino programming environment.

Module: Arduino as Signal Generator

DS1869 3V Dallastat TM Electronic Digital Rheostat

EE-110 Introduction to Engineering & Laboratory Experience Saeid Rahimi, Ph.D. Labs Introduction to Arduino

EE 307 Project #1 Whac-A-Mole

Workshops Elisava Introduction to programming and electronics (Scratch & Arduino)

Coding with Arduino to operate the prosthetic arm

PLAN DE FORMACIÓN EN LENGUAS EXTRANJERAS IN-57 Technology for ESO: Contents and Strategies

Measuring Distance Using Sound

EE445L Fall 2014 Quiz 2A Page 1 of 5

INA169 Breakout Board Hookup Guide

Project Final Report: Directional Remote Control

TDA 4700 TDA Control IC for Single-Ended and Push-Pull Switched-Mode Power Supplies (SMPS)

128 KB (128K 1 = 128K

User Interface Engineering FS 2013

Servo Sweep. Learn to make a regular Servo move in a sweeping motion.

Written by Hans Summers Wednesday, 15 November :53 - Last Updated Wednesday, 15 November :07

University of California at Berkeley Donald A. Glaser Physics 111A Instrumentation Laboratory

Application Circuits 3. 3V R2. C4 100n G PI O. 0 G PI O S e t u p d a ta G PI O. 5 G PI O M o t i o n I n t G PI O. 4 G PI O.

PART TEMP RANGE PIN-PACKAGE

Houngninou 2. Abstract

GF of 9 THE GADGET FREAK FILES CASE #165. Analog Clock Measures Time in Meters

10-Bit µp-compatible D/A converter

Breadboard Arduino Compatible Assembly Guide

SRVODRV REV7 INSTALLATION NOTES

digitalread() EE 285 Arduino 1

EE445L Fall 2014 Quiz 2B Page 1 of 5

B.E. SEMESTER III (ELECTRICAL) SUBJECT CODE: X30902 Subject Name: Analog & Digital Electronics

Community College of Allegheny County Unit 4 Page #1. Timers and PWM Motor Control

Micrel, Inc Fortune Drive San Jose, CA USA tel + 1 (408) fax + 1 (408)

Montgomery Village Arduino Meetup Dec 10, 2016

Arduino Digital Out_QUICK RECAP

EE445L Fall 2011 Quiz 2A Page 1 of 6

High Current MOSFET Toggle Switch with Debounced Push Button

Current-Mode PWM Multiple Output Flyback Converter

APDS-9960 RGB and Gesture Sensor Hookup Guide

Introduction. Circuit diagram

Arduino Lesson 1. Blink. Created by Simon Monk

The Skiidometer. Hardware Description By: Adam Lee ; Etec474; Prof. Morton; WWU

Supervisory Circuits with Watchdog and Manual Reset in 5-Lead SC70 and SOT-23 ADM823/ADM824/ADM825

LM555 and LM556 Timer Circuits

Heliotrack Programmable Wind Alarm Switch V1.0 Developed in partnership with Inspeed.com, LLC

ELM409 Versatile Debounce Circuit

Hello, and welcome to this presentation of the STM32G0 digital-to-analog converter. This block is used to convert digital signals to analog voltages

Extremely Accurate Power Surveillance, Software Monitoring and Sleep Mode Detection. Pin Assignment. Fig. 1

PIC Functionality. General I/O Dedicated Interrupt Change State Interrupt Input Capture Output Compare PWM ADC RS232

DS1802 Dual Audio Taper Potentiometer With Pushbutton Control

Figure 1. C805193x/92x Capacitive Touch Sense Development Platform

MAKEVMA502 BASIC DIY KIT WITH ATMEGA2560 FOR ARDUINO USER MANUAL

High Voltage Generation for Xenon Tube Applications

EE445L Fall 2014 Quiz 2A Page 1 of 5

MICROCONTROLLERS BASIC INPUTS and OUTPUTS (I/O)

Arduino An Introduction

2.017 DESIGN OF ELECTROMECHANICAL ROBOTIC SYSTEMS Fall 2009 Lab 4: Motor Control. October 5, 2009 Dr. Harrison H. Chin

URM37 V3.2 Ultrasonic Sensor (SKU:SEN0001)

Electronic Instrumentation

LM4: The timer unit of the MC9S12DP256B/C

ANALOG TO DIGITAL CONVERTER

AN4507 Application note

Arduino STEAM Academy Arduino STEM Academy Art without Engineering is dreaming. Engineering without Art is calculating. - Steven K.

Process Components. Process component

Transcription:

Microcontrollers and Interfacing Week 07 digital input, debouncing, interrupts and concurrency College of Information Science and Engineering Ritsumeikan University 1

this week digital input push-button switches pull-up resistors debouncing in hardware in software 2

digital input configuring ditial pin as input: void pinmode(n, INPUT) pin becomes high impedance (high resistance) microcontroller does not generate a voltage on the pin microcontroller senses the voltage applied to the pin reading the voltage on the pin: int digitalread(n) returns HIGH or LOW transition from LOW to HIGH is somewhere between GND (0 V) and V cc (5 V) how do we find the exact voltages involved? 3

digital input from this we can calculate the maximum voltage that is guarnateed to be LOW the mimimum voltage that is guarnateed to be HIGH note: from the leakage current we can also calculate the effective input resistance of a digital I/O pin 4

push-button switches normally open push-button converts physical movement into a resistance change two contacts when button not pressed, contacts are open (not connected, infinite resistance) switch open when button pressed, contacts are closed (connected, zero resistance) switch closed challenge: design a circuit that produces 5 V when a switch is open (not pressed), or 0 V when a switch is closed (pressed) 5

push-button switches Arduino Arduino 5V 5V 56k 5V 56k 0V Dx 0.1 ma Dx switch open switch closed GND GND 6

digital input circuit two switches and seven-segment display can be connected at the same time set mode of digital pins 11 and 12 to INPUT pull-up resistors keep them HIGH pressing a switch pulls them LOW use digitalread() to read the value (HIGH or LOW) Arduino 5V D2 D3 510 510 10 9 A B 56k 56k D12 D4 D5 D6 510 510 510 7 5 4 C D E 7-segment display D11 D7 510 2 F D8 510 1 G GND 8 D9 510 6 3 DP GND GND GND 7

digital input breadboard layout 8

switch bounce 9

debouncing when our circuit (sketch) is fast enough each transisition of the signal can be seen as a separate button press one physical press is counted many times debouncing attempts to elimintate the false presses each physical press is counted only once by software 10

hardware debouncing need a circuit that will react quickly to the initial press recover slowly from closed (LOW) to open (HIGH) delay recovery until all bouncing has ceased press settled release INPUT bouncing HIGH OUTPUT HIGH/LOW threshold HIGH LOW gradual recovery 11

capacitors time delays (or filtering high-frequency noise) often done with a capacitor stores charge voltage proportional to stored charge rate of charging (current) inversely proportional to voltage V C 5V GND R time constant τ = R C time taken to reach 63% charge I C C R C... τ 0.7 τ 1.0 τ 4.0 τ 5.0 condition reached 50% of final voltage 63% of final voltage 98% of final voltage fully charged 12

capacitor markings 2200 µf polarised 100 nf (10 10 4 pf) + marking value 101 100 pf 100 pf 222 2200 pf 2.2 nf 103 10000 pf 10 nf 104 100000 pf 100 nf 13

software debouncing eliminate the need for physical capacitor simple approach: add fixed delay must design for worst possible switch behaviour delay is long enough (many tens of milliseconds) to be noticeable better approach: simulate the capacitor software timer represents the charge on the capacitor when switch state is open and input is LOW counter is reset to zero (simulated capacitor is discharged) switch state changes to closed when switch state is closed and input is HIGH counter increments each cycle (simulated capacitor charging) when counter reaches a threshold, switch state changes to open 14

pullup resistors pull-up resistors used very often can be provided externally, but every switch input requires one, so microcontroller can provide internal pull-up resistors for pin configured as INPUT: digitalwrite(pin, HIGH); enables the internal pull-up resistor digitalwrite(pin, LOW); disables the pull-up resistor or write a bit to the appropriate PORT register (or use pin mode INPUT_PULLUP to do everything at once) internal pull-up resistors are 20k Ω 0.25 ma flows out of the pin when it is pulled LOW 15

concurrency sketch does only one thing read switch inputs, adjust counter, display digit most of the time the switch is not pressed most of the time, the sketch is doing nothing (very busily) difficult to integrate other repetitive tasks better design: perform repetitive tasks in loop() respond to events (e.g., switch presses) by interrupting normal tasks interruption is transparent to normal tasks 16

interrupts normal program flow and logic does not interact with input pins external event (e.g., input pin state change) occurs here loop() {............ } implicit, immediate (asynchronous) call to interrupt service routine return from ISR resumes program intsvcroutine() {... } some services already provided by regular interrupts e.g., millis() which returns number of milliseconds elapsed since boot counter incremented by a simple ISR every 1 ms can also be triggered by input changes on pins 2 and 3 17

interrupts two input pin interrupts interrupt 0 associated with pin 2 interrupt 1 associated with pin 3 interrupt handler installed in setup() using attachinterrupt() void setup() { pinmode(2, INPUT); attachinterrupt(0, myisr, CHANGE); } void myisr() { //... deal with state change on pin 2... } attachinterrupt() has three arguments: the interrupt number (0 for pin 2, 1 for pin 3) the handler function (interrupt service routine) the state that triggers an interrupt: HIGH, LOW, RISING, FALLING, CHANGE 18

HIGH interrupt triggers HIGH HIGH LOW LOW FALLING CHANGE RISING trigger name LOW HIGH RISING FALLING CHANGE interrupts triggered... continuously while input is LOW continuously while input is HIGH whenever input transitions from LOW to HIGH whenever input transitions from HIGH to LOW whenever input changes state (rising or falling) 19

interrupt handlers (service routines) interrupts are disabled while a handler is running handler must finished quickly handler cannot use delay(), millis(), serial I/O, etc. all of these rely on interrupts of their own to work properly handler should not (normally) re-enable interrupts risk of the handler being called repeatedly from within itself if you need millisecond time in your ISR, update a global variable in loop() with the current millis() non-linear, unpredictable control flow confuses the compiler global variables modified from inside an ISR must be declared volatile warns the compiler that their value might change asynchronously, at any time e.g: volatile unsigned long eventcounter = 0; void myisr() { eventcounter += 1; } 20

next week IMPORTANT next week s class will be in room CC601 quick review (25 minutes) small test; please revise all slides and workshop/reference materials, including: how the resistor colour code works how to apply Ohm s law current-limiting resitors common electrical terms: anode, cathode, etc. diodes and forward voltage drop digital and analog input and output duty cycle and pulse-width modulation time delay, cycle time, and frequency etc. 21

exercises create digital inputs pushbuttons control a counter with them displayed on the seven-segment display debounce the buttons in hardware attach a parallel capacitor debounce the buttons in software using a delay by simulating a capacitor 22