Digital input and output

Similar documents
Analog input and output

Due date: Sunday, December 5 (midnight) Reading: HH section (pgs ), mbed tour

SWITCH: Microcontroller Touch-switch Design & Test (Part 2)

EET 1131 Lab #10 Latches and Flip-Flops

You will be first asked to demonstrate regular operation with default values. You will be asked to reprogram your time values and continue operation

imso-104 Manual Revised August 5, 2011

Module 4: Traffic Signal Design Lesson 1: Traffic Signal (Arduino) Control System Laboratory Exercise Grade 6-8

Design and implementation (in VHDL) of a VGA Display and Light Sensor to run on the Nexys4DDR board Report and Signoff due Week 6 (October 4)

The Micropython Microcontroller

Analyzing and Saving a Signal

CPE 200L LABORATORY 3: SEQUENTIAL LOGIC CIRCUITS UNIVERSITY OF NEVADA, LAS VEGAS GOALS: BACKGROUND: SR FLIP-FLOP/LATCH

Basic LabVIEW Programming Amit J Nimunkar, Sara Karle, Michele Lorenz, Emily Maslonkowski

DRAFT Microprocessors B Lab 3 Spring PIC24 Inter-Integrated Circuit (I 2 C)

APPLICATION NOTE # Monitoring DTMF Digits Transmitted by a Phone

Laboratory Exercise 4

Part No. ENC-LAB01 Users Manual Introduction EncoderLAB

Laboratory 1 - Introduction to Digital Electronics and Lab Equipment (Logic Analyzers, Digital Oscilloscope, and FPGA-based Labkit)

ENGR 1000, Introduction to Engineering Design

PRODUCT MANUAL. Product Description. Waterproof 4 Channel DMX to RGB-W LED Controller

MULTIPLE TPS REHOST FROM GENRAD 2235 TO S9100

Table of Contents Introduction

Lab #6: Combinational Circuits Design

(Skip to step 11 if you are already familiar with connecting to the Tribot)

Sample. Data Acquisition and Signal Conditioning. Course Manual. Course Software Version 2011 February 2012 Edition Part Number P-01

Special Applications Modules

OWL micro+ WIRELESS ELECTRICITY MONITOR

Light Emitting Diodes and Digital Circuits I

NEW MEXICO STATE UNIVERSITY Electrical and Computer Engineering Department. EE162 Digital Circuit Design Fall Lab 5: Latches & Flip-Flops

ELECTRICAL ENGINEERING DEPARTMENT California Polytechnic State University

Physics 123 Hints and Tips

Light Emitting Diodes and Digital Circuits I

Review C program: foo.c Compiler Assembly program: foo.s Assembler Object(mach lang module): foo.o. Lecture #14

CS61C : Machine Structures

Lab #10 Hexadecimal-to-Seven-Segment Decoder, 4-bit Adder-Subtractor and Shift Register. Fall 2017

Introduction. The Clock Hardware. A Unique LED Clock Article by Craig A. Lindley

FLIP-FLOPS AND RELATED DEVICES

MICROMASTER Encoder Module

Assignment 3: 68HC11 Beep Lab

Copyright 2011 by Enoch Hwang, Ph.D. and Global Specialties. All rights reserved. Printed in Taiwan.

DSP Laboratory: Analog to Digital and Digital to Analog Conversion *

LabView Exercises: Part II

SC26 Magnetic Field Cancelling System

EE 367 Lab Part 1: Sequential Logic

Lab #10: Building Output Ports with the 6811

Computer Systems Architecture

Go BEARS~ What are Machine Structures? Lecture #15 Intro to Synchronous Digital Systems, State Elements I C

The Haply Development Kit

LS1lightstrip User s Manual. Introduction Care and feeding Specifications. soundmachines user manual 1 LS1lightstrip

Noise Detector ND-1 Operating Manual

Digital Signal Processing Laboratory 7: IIR Notch Filters Using the TMS320C6711

FRQM-2 Frequency Counter & RF Multimeter

Data Acquisition Using LabVIEW

User Guide & Reference Manual

National Instruments SCB-68 Breakout Box

imso-104 Manual Revised July 19, 2012

Light Emitting Diodes and Digital Circuits I

Obtain Power Measurements of a DOCSIS Downstream Signal Using a Spectrum Analyzer

"shell" digital storage oscilloscope (Beta)

Digital Fundamentals. Lab 5 Latches & Flip-Flops CETT Name: Date:

Laboratory 10. Required Components: Objectives. Introduction. Digital Circuits - Logic and Latching (modified from lab text by Alciatore)

Analog Output for the TSI DUSTTRAK Aerosol Monitor Model 8520

SignalTap Plus System Analyzer

Oscilloscopes, logic analyzers ScopeLogicDAQ

Physics 323. Experiment # 10 - Digital Circuits

Integrated Circuit for Musical Instrument Tuners

uresearch GRAVITECH.US GRAVITECH GROUP Copyright 2007 MicroResearch GRAVITECH GROUP

Chapter 4: One-Shots, Counters, and Clocks

Application Note 11 - Totalization

Plessey PS EPIC 6:2 Multiplex box Instruction Manual.

CSCB58 - Lab 4. Prelab /3 Part I (in-lab) /1 Part II (in-lab) /1 Part III (in-lab) /2 TOTAL /8

A 400MHz Direct Digital Synthesizer with the AD9912

SignalTap: An In-System Logic Analyzer

Analog Discovery Scope and Waveform Generator Edited 11/15/2016 by Eric Scotti & DGH

Lab 2: A/D, D/A, and Sampling Theorem

CONTROL PANEL ENGLISH INSTRUCTIONS MOTORLINE MC 2 / SEAV LRS 2150 SET

LAX_x Logic Analyzer

SEQUENTIAL SHIFT LIGHT

User Manual for ICP DAS WISE Monitoring IoT Kit -Microsoft Azure IoT Starter Kit-

DIGITAL ELECTRONICS: LOGIC AND CLOCKS

Encoders and Decoders: Details and Design Issues

SignalTap Analysis in the Quartus II Software Version 2.0

The Serial Port is Dead! Long Live the Serial Port! USB Serial Port Breadboard Experiments with the FTDI FT232R

Triple RTD. On-board Digital Signal Processor. Linearization RTDs 20 Hz averaged outputs 16-bit precision comparator function.

Working with a Tektronix TDS 3012B Oscilloscope EE 310: ELECTRONIC CIRCUIT DESIGN I

IT T35 Digital system desigm y - ii /s - iii

Lab 1 Introduction to the Software Development Environment and Signal Sampling

Experiment # 4 Counters and Logic Analyzer

EET 1131 Lab #12 - Page 1 Revised 8/10/2018

EECS 140 Laboratory Exercise 7 PLD Programming

NanoGiant Oscilloscope/Function-Generator Program. Getting Started

Composing with Courage

NORTHWESTERN UNIVERSITY TECHNOLOGICAL INSTITUTE

LFSR Test Pattern Crosstalk in Nanometer Technologies. Laboratory for Information Technology University of Hannover, Germany

Programmable Logic Design Techniques II

CT-DMX-300 LED Controller

ENERGY STAR Program Requirements Product Specification for Televisions. Draft Test Method

Horita PTG. Portable SMPTE Time Code Generator With 2-Line LCD Display. Operating Instructions For Software Version V2.0. Doc. No Rev.

Using the XSV Board Xchecker Interface

WaveMaker III Gartech Enterprises Inc. 12/17/2012

ORM0022 EHPC210 Universal Controller Operation Manual Revision 1. EHPC210 Universal Controller. Operation Manual

Transcription:

Digital input and output DRAFT VERSION - This is part of a course slide set, currently under development at: http://mbed.org/cookbook/course-notes We welcome your feedback in the comments section of the course notes cookbook page. Tell us if these slides are useful, if you would use them to help run lessons, workshops or training, and how you d improve them. Written by R. Toulson (Anglia Ruskin University) and T. Wilmshurst (University of Derby), (c) ARM 2011 An accompanying textbook is also being considered if there is interest 1

Digital input and output Introduction to digital terminology Digital outputs on the mbed Using LEDs on the mbed pins Connecting switches to the mbed Implementing a digital switch input on the mbed 2

Introduction to digital terminology The mbed uses a power rail of 3.3 Volts - 0 Volts indicates off and 3.3 Volts indicates on. A number of terms are used interchangeably to describe on and off in digital systems: 0V 3.3V Open Off Low Clear Closed On High Set logic 0 logic 1 False True Note: terms logic 0 and logic 1 may be simply referred to as 0 and 1 3

Digital outputs on the mbed On the mbed, the four on-board LEDs are digital outputs which have been specially configured to operate with no extra wires or connections needed. The mbed also has 26 digital IO pins (pins 5-30) which can be configured as inputs or outputs. 4

Digital outputs on the mbed The available library functions are shown in the table below. DigitalOut Functions DigitalOut write read operator= operator int() A digital output, used for setting the state of a pin Usage Create a DigitalOut connected to the specified pin Set the output, specified as 0 or 1 (int) Return the output setting, represented as 0 or 1 (int) A shorthand for write A shorthand for read 5

Digital outputs on the mbed The digital IO pins are configured by defining them at the start of the program code. Each digital IO is given a name and associated pin, for example: DigitalOut myname1(p5); DigitalOut myname2(p6); DigitalOut myname3(p7); etc The DigitalOut interface can be used to set the state of the output pin, and also read back the current output state. Set the DigitalOut to 0 to turn it off, or 1 to turn it on. 6

Using LEDs on the mbed pins Connect the mbed to a breadboard and attach a red LED to pin 5 and a green LED to pin 6. Remember to attach the positive side of the led (the side with the longer leg) to the mbed. The negative side should be connected to ground. The mbed has a common ground on pin 1. 7

Using LEDs on the mbed pins Exercise 1: Create a new program for the external LED project. Modify the default main.cpp code to become the following: #include "mbed.h" DigitalOut redled(p5); DigitalOut greenled(p6); int main() { while(1) { redled = 1; greenled = 0; wait(0.2); redled = 0; greenled = 1; wait(0.2); } } Compile, download and run the code on the mbed. 8

Using LEDs on the mbed pins Look at the example program and identify the key C programming elements as follows: The mbed.h library file is linked to by the `#include statement. DigitalOut objects are defined with a name and a chosen mbed pin. The main program function exists inside `int main() {... program... }. An infinite loop is implemented by the while(1) statement, so that the program continuously loops forever, allowing the led to flash continuously. Digital outputs are controlled simply by setting the relevant objects equal to 0 or 1. The mbed wait() function is used for timing control. 9

Digital inputs on the mbed Digital inputs values can be read. As with digital outputs, the same 26 pins (pins 5-30) can be configured as digital inputs, as follows: DigitalIn myname1(p5); DigitalIn myname2(p6); DigitalIn myname3(p7); The DigitalIn Interface determines the current logical state of the chosen input pin, e.g. logic '0' or logic '1'. Zero volts on a digital input pin returns a logical 0, whereas 3.3 Volts returns a logic 1. 10

Digital inputs on the mbed The available library functions are shown in the Table below. DigitalIn Functions DigitalIn read mode operator int() A digital input, used for reading the state of a pin Usage Create a DigitalIn connected to the specified pin Read the input, represented as 0 or 1 (int) Set the input pin mode A shorthand for read 11

Connecting switches to the mbed A simple mechanical switch to set a digital input pin either high ( 1 ) or low ( 0 ) by connecting it to switch between the 3.3V and GND rails. To the setup included in the previous example, add a mechanical switch output to pin 7. Connect the switch inputs to 0V (GND, pin1) and 3.3V (Vout, Pin 40). 12

Implementing a digital switch Exercise 2: Create a new program for the LED switch project. Modify the default main.cpp code as shown. When two forward slash symbols (//) are used, the compiler ignores any proceeding text, so we can use this to write useful comments. input on the mbed #include "mbed.h" DigitalOut redled(p5); DigitalOut greenled(p6); DigitalIn switchinput(p7); int main() { while(1) { } } if (switchinput==1) { greenled = 0; //green led is off redled = 1; // flash red led wait(0.2); redled = 0; wait(0.2); } else if (switchinput==0) { redled = 0; //red led is off greenled = 1; // flash green led wait(0.2); greenled = 0; wait(0.2); } 13

Implementing a digital switch input on the mbed Compile, download and run the code on the mbed. Look at the code, the if (switchinput==1) statement allows the code to operate in two different ways, dependent on the value of the digital input (i.e. the mechanical switch position). If the switch gives a value of 1, the green LED is set to zero (off) and the red LED is programmed to flash. If the digital input is low (0), we see the roles of the LEDs reversed. 14

Digital switch exercises Exercise 3: Create a 1000 Hz digital square wave output which can be analysed on an oscilloscope. Exercise 4: Using a digital input switch, create a square wave output that doubles in frequency when a digital input switch is switched on. Exercise 5: Create a system which counts the number of times a digital switch is pressed or changed, and lights an LED when 10 instances have been counted. 15

Summary Introduction to digital terminology Digital outputs on the mbed Using LEDs on the mbed pins Connecting switches to the mbed Implementing a digital switch input on the mbed 16