EXERCISE 3: Calculations and Input Conditioning

Similar documents
EXERCISE 3: String Variables and ASCII Code

Lab 1: Full Adder 0.0

An Introduction to MPLAB Integrated Development Environment

Jianjian Song LogicWorks 4 Tutorials (5/15/03) Page 1 of 14

5. Tutorial. Starting FlashCut CNC

E-Blocks Easy Internet Bundle

Programming PIC Microcontrollers in PicBasic Pro Lesson 1 Cornerstone Electronics Technology and Robotics II

Two's Complement Adder/Subtractor Lab L03

Introduction to LogixPro - Lab

User's Guide DylosLogger Software Version 1.6

GarageBand 2.0 Getting Started

Xilinx ISE. <Release Version: 10.1i> Tutorial. Department of Electrical and Computer Engineering State University of New York New Paltz

The goal is to program the PLC and HMI to count with the following behaviors:

Flip Video Digital Camcorder Startup Guide and Making Movies Tutorial Trevor Oakley, Teen Services Librarian, Saratoga Springs Public Library

Decimal Number (base 10) Binary Number (base 2)

Internet Explorer 7. Getting Started The Internet Explorer Window. Tabs NEW! Working with the Tab Row. Microsoft QUICK Source

Getting Started on the Computer With Mouseaerobics! Windows XP

M8 basics. Setting Up Your M8 Android Box Remote Essentials Using Your M8 Android Box Setting up Wireless... 6

Task Card #2 SMART Board: Notebook

Pivot Tables & Pivot Charts

USER GUIDE Version 2.0

2 : BISTABLES. In this Chapter, you will find out about bistables which are the fundamental building blocks of electronic counting circuits.

Knowledgebase Article

Creating a Project with PSoC Designer

Auto Clicker Tutorial

20 Saving Device Data Backup

Installing a Browser Security Certificate for PowerChute Business Edition Agent

Creating trouble-free numbering in Microsoft Word

First Bytes Programming Lab 2

Windows XP Pro: Basics 1

BioWin Network Installation

Merging Labels, Letters, and Envelopes Word 2013

HOW TO BURN A CD/DVD IN WINDOWS XP. Data Projects

Make Voice Calls and Share Documents using Skype*

SnagIt Add-Ins User Guide

Appendix K Introduction to Microsoft Visual C++ 6.0

Digital Controller for Pedestrian Crossing and Traffic Lights

How To Program A Microcontroller Board (Eb064) With A Psp Microcontroller (B064-74) With An Ios 2.5V (Power) And A Ppt (Power Control) (Power Supply) (

Introduction to Visio 2003 By Kristin Davis Information Technology Lab School of Information The University of Texas at Austin Summer 2005

How to test and debug an ASP.NET application

CrossLoop Help. What would you like to do? Joining A Session

Creating tables of contents and figures in Word 2013

PPM Users Manual Signature Software

Step Sheet: Creating a Data Table and Charts

FlowKit in-circuit debug system

Introduction to Microsoft Word 2003

Debouncing Switches. Mechanical switches are one of the most common interfaces to a uc.

INTRODUCTION TO COMPUTER CONCEPTS CSIT 100 LAB: MICROSOFT POWERPOINT

WHAT S NEW IN WORD 2010 & HOW TO CUSTOMIZE IT

Making Basic Measurements. Publication Number August Training Kit for the Agilent Technologies Series Logic Analysis System

CM HOST CM CardTransporter Fuel Communication and Management Software Software version up to 3.1

Facilities and Safety How-To Guide: Accessing and Using Your UCF Webmail Account

Using Rational Rose to Create Object-Oriented Diagrams

Microsoft Outlook Introduction

Introduction to MS WINDOWS XP

Jump-Start Tutorial For ProcessModel

E-Blocks Easy RFID Bundle

ezsystem elab16m Project 1F: Alarm System (Full Project description)

Start A New Project with Keil Microcontroller Development Kit Version 5 and Freescale FRDM-KL25Z

1. SAFETY INFORMATION

PowerWorld Simulator

Using WINK to create custom animated tutorials

FREE FALL. Introduction. Reference Young and Freedman, University Physics, 12 th Edition: Chapter 2, section 2.5

Computer Basics: Tackling the mouse, keyboard, and using Windows

Content Author's Reference and Cookbook

USB Flash Drive. The New Age of Data Storage Future. 1990s

Windows Movie Maker 2012

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

Counters and Decoders

Let s put together a Manual Processor

BID2WIN Workshop. Advanced Report Writing

Getting Started with Citrix Remote Connectivity Service

mdm-mp3 minidirector with MP3 Player

Importing Contacts to Outlook

Microcontroller Systems. ELET 3232 Topic 8: Slot Machine Example

Creating a Distribution List from an Excel Spreadsheet

Windows XP Managing Your Files

QUICK START GUIDE. SG2 Client - Programming Software SG2 Series Programmable Logic Relay

Using SFTP to Transfer TEXAS GRANT Year End Reports

Fault Analysis I PowerWorld Corporation

Introduction. POP and IMAP Servers. MAC1028 June 2007

Creating a Poster in PowerPoint A. Set Up Your Poster

1. Click the File tab 2. Click "Options" 3. Click "Save" 4. In the line labeled "Default file location", browse to the desired folder 5.

The RIDZ 8x2 Audio Switcher

Table Of Contents. iii

Google Sites. How to create a site using Google Sites

Right-click the Start button and select Properties. Click the Customize button and choose from the options displayed:

Working with the Multi Cam Mode in EDIUS

Section 5: Installing the Print Driver

Creating a Gradebook in Excel

Creating a table of contents quickly in Word

How To Print To Scale With Easy Blue Print

Introduction To Microsoft Office PowerPoint Bob Booth July 2008 AP-PPT5

Automatic Scheduling Using AutoTrack Command Line Options

Statgraphics Getting started

Using an Automatic Back Up for Outlook 2003 and Outlook 2007 Personal Folders

Excel macros made easy

Appendix A How to create a data-sharing lab

This Skill Builder demonstrates how to define and place sketched symbols in drawings.

Operating Systems. and Windows

Transcription:

EXERCISE 3: Calculations and Input Conditioning EXERCISE OBJECTIVE When you have completed this exercise, you will be able to describe switch bounce, explain switch debouncing, and use Flowcode to program your FACET board to perform binary addition. EXERCISE DISCUSSION Switch Bounce Switches contain two metal contacts, made of brass. When switched off, these contacts are held apart, separated by an insulator - air. To switch on, these contacts are slapped together by some lever mechanism, aided by a strong spring. Now, metals are springy. When the contacts hit each other, they bounce apart, hit each other again and may continue to do this a number of times before coming to rest in contact with each other. All of this happens very quickly. We normally do not notice it, and it causes no problem. When the switch is part of a switch unit, this bouncing causes a series of changes in output, as shown in the diagram. We can show these changes on a voltage/time graph: 150 FACET by Lab-Volt

Loops, Messages, and Calculations Switch debouncing Switch bounce is a problem when the switch is part of a counting system. Each time the switch is pressed, instead of the count increasing by one, it can increase by two, three or four, or more! The solution is to debounce the switch. This does not stop the mechanical bounces of the switch, but cuts out the repeated electrical pulses that the bounce otherwise causes. We add a debouncing circuit to the output of the switch unit. There are a number of techniques that can be used in the debouncing circuit. We will use a time delay. This relies on making the first of the electrical pulses trigger a long pulse that lasts longer than the train of pulses caused by the bouncing. To do this, add a time delay circuit between the switch unit and the counting system. The effect of this is illustrated in the following graphs. The counting system receives just a single pulse each time the switch is pressed. Switch bounce is very fast - a simple way of avoiding switch bounce problems is to simply make your program wait for a millisecond after a switch input is detected. EXERCISE QUESTIONS One way to eliminate the errors in counting that can be caused by switch bouncing is to add a a. loop. b. string. c. time delay circuit FACET by Lab-Volt 151

EXERCISE PROCEDURE Set up the equipment The following is the equipment you will need for this exercise: Multiprogrammer Hardware: Setting: PICmicro Device Toggle Switch (Fast/Slow) Toggle Switch (RC/XTAL) XTAL PORTA PORTB PORTC PORTD PORTE 16F877A N/A XTAL 19,660,800 Hz N/A Switch Block Switch Block LED Block N/A A binary adder In this section you can see how the PICmicro brain works by making a system that can add two numbers. The simplest way to input a binary number is to use a set of switches attached to the input port. We want to input two binary numbers, so we will need two sets of switches, and two input ports. We want to see the result of the calculation. For now, we will use a LED array, connected to the output port, to show the result. We need a PICmicro chip with three ports! 152 FACET by Lab-Volt

Loops, Messages, and Calculations Set up the flowchart 1. Launch Flowcode. Start a new flowchart. 2. Select 16F877A from the Choose a Target Dialog box scroll down menu, then click OK to close the Dialog box. 3. Click and drag a loop icon between the Begin and End boxes. 4. Click and drag an input icon and drop it in between the ends of the loop. 5. Click and drag a second input icon and drop it in between the ends of the loop. 6. Click and drag an output icon and drop it just below the input boxes. 7. Click and drag a Calculation icon, and place it in between the second input icon and the output icon. 8. Your flowchart should look like the one shown. FACET by Lab-Volt 153

Create the variables 1. Click on Edit, on the menu bar, and then on 'Variables...'. This opens up the Variable Manager dialogue box. 2. We are going to create three variables, called 'input1', 'input2' and 'sum'. 3. The first two will store the numbers that we feed in from the switches. The variable SUM will store the result of adding together the two numbers stored in INPUT1 and INPUT2. 4. Click on the Add New Variable button in the dialogue box. You now see another dialogue box. 5. Type in the word 'input1', and then click on OK. Leave 'Variable type:' as Byte. This dialogue box closes and the name of the new variable appears in the Variable Manager dialogue box. 6. Create the other two variables, 'input2' and 'sum', in the same way. 7. Click on the Close button to shut down the Variable Manager. 154 FACET by Lab-Volt

Loops, Messages, and Calculations Set up the inputs 1. Right click on the top input icon, and select Properties from the menu. The following dialogue box appears. 2. Double click on the word 'Input' in the Display name window to highlight it. Type "Input the first number" to replace it. This will appear alongside the input icon on the flowchart. In a complex flowchart, adding labels like this helps users to understand what is happening. 3. Click on the 'Variables...' button. This will open the Variable Manager. It lists the three variables that you just created. 4. Click on the word 'input1'. Next click on the 'Use Variable' button. FACET by Lab-Volt 155

5. Back to the Input Properties box again. It is set to Port A at the moment. Click on the down arrow at the end of the Port window, and select PORT B. Click on OK to close the Input Properties box. 6. Double-click on the second input icon. (This is a quick way to open the Properties box, instead of right clicking on the icon and selecting from the menu.) Set up this input to: display the label 'Input the second number' use the variable input2 and use PORT C 7. Close the Input Properties box. Set up the calculation Double click on the Calculation icon to open the Properties dialogue box. 1. Change the 'Display name:' text box to "Add the two numbers together". 2. Tell the Calculations icon what it is supposed to calculate by adding the following to the 'Calculations:' box: 156 FACET by Lab-Volt

Loops, Messages, and Calculations sum = input1 + input2 You can either type this in directly, or use the 'Browse for variable...' button to select each variable in turn, and then add the '=' and '+' signs in the right place! 3. Then click on the 'OK' button, to close the dialogue box. Set up the output 1. Double click on the output icon, to open the Output Properties dialogue box. 2. Click on the 'Variables...' button. 3. Click on the word 'sum' and then on the 'Use Variable' button. 4. You are now back on the Output Properties box. Change the port used to PORT D. 5. Click on 'OK' to close the Output Properties box. 6. The flowchart should now look like the one shown. FACET by Lab-Volt 157

Adding the LED array 1. Click once on the LED icon. Place the LED array where you want it on the work area by moving the cursor over the title bar of the LED's box and then clicking and dragging the box into position. 2. Click once on the button. Then click once on the 'Components Connections...' option on the menu to open the 'Specify Component Pin Connections' dialogue box. 3. Click on the down arrow at the end of the Port window, and click once on the PORT D option to connect the LED's to the pins on Port D. Click on the 'Done' button to finish the process. Adding the switches You will use two sets of switches, one for each binary number. The output port has only eight bits, and so the biggest number that it can output is 1111 1111. This is equal to 255 in decimal. We are going to limit ourselves to inputting only seven bit numbers. This means that the biggest number we can input is 111 1111, which equals 127 in decimal. If we used bigger numbers, then we would overflow the capacity of the output. 1. Click once on the switch icon, and drag it into a suitable spot on the work area. 2. Click once on the button, and select the 'Properties' option. Using the arrow in the 'Number of Switches' box, select 7 switches. In the same way, select 'Toggle' in the 'Switch Type' box. Then click on the 'OK' button. 3. Click once again on the button, and select the 'Component Connections' option. Connect the switches to Port B, using the down arrow at the end of the Port box. 4. Now set up the second set of switches by following the same process. This time, connect the switches to Port C. Slow simulation Flowcode allows you to run through the flowchart one step (icon) at a time. You can watch the effect of each step on the variables and on the output. 1. There are three ways to run the program step-by-step: a. on the menu click on the RUN... STEP INTO b. press the F8 function key on the keyboard c. click on the 'Step Into' icon on the simulation bar. Do one of these! 2. Several things happen. a. A red rectangle appears around the BEGIN icon, showing that this is the current step. b. Two more boxes appear - Variables and Call Stack. 158 FACET by Lab-Volt

Loops, Messages, and Calculations c. The Variables box lists the three variables that you defined for this program, and shows their current values - all zero at the moment. Ignore the Call Stack box for the moment. 3. Now set up two numbers on the switch components. Move the cursor over the switch box connected to Port B. Click on switches B0, B1, and B3, to close these switches. The switch box now looks like the one shown. You have set up the binary number 000 1011 (which is the number eleven in decimal). B6 gives the most significant bit of the number, and B0 the least significant bit. Set up the number 000 1111 (fifteen) on the switch box connected to Port C. 4. Now step on to the next icon in the program by, for example, pressing F8 once more. 5. The red rectangle moves on to the next icon, the Loop icon, but little else happens. 6. Press F8 once again. The red rectangle moves on to the first INPUT icon. 7. Press F8 again and the Variable box shows that the INPUT1 variable now contains 11. This is the result of the INPUT instruction just carried out. 8. Press F8 again and the Variable box shows that INPUT2 now contains 15. 9. Press F8 again and the calculation is carried out. The SUM variable stores the result. 10. Press F8 again. The value stored in SUM is transferred to the LED array. FACET by Lab-Volt 159

Reading from Most significant bit (D7) to Least significant bit (D0), the LED array shows the number 0001 1010. In decimal, this is the number 26. No surprises there then! 11.Repeat step 3 using different numbers, and step through the program to check what the sum of the numbers is. The program is finished, and working. As usual, you need to let Flowcode translate it into machine code, and burn it into a PICmicro chip. 12. Set up the Clock for XTAL in Flowcode and on the FACET Board using the Toggle switch. 13. Save the program as Ex 3: Calculations and Input Conditioning with your initials in your folder and run the program on the FACET Board. Note that the Switches on the FACET Board are momentary switches rather than toggle switches. You must, therefore, hold down the switches you want the program to add. 160 FACET by Lab-Volt

Loops, Messages, and Calculations EXERCISE QUESTIONS 1. In this exercise you input two binary numbers by using a. two sets of switches and one input port. b. one set of switches and two input ports. c. two sets of switches and two input ports. 2. The results were shown using a(n) a. LCD array b. LED array c. Key pad EXERCISE CONCLUSION When switch contacts hit each other, they bounce apart. They may repeat this process a number of times before coming to rest. Switch bounce creates a problem when the switch is part of a counting system. A debounce circuit cuts out the repeated electrical pulses caused by bouncing. A debounce circuit is created by programming a time delay between a switch unit and a counting system. REVIEW QUESTIONS 1. When a switch is turned on, two metal contacts a. always make contact immediately and remain that way until the switch is turned off. b. always separate from each other and remain that way until the switch is turned off. c. often make and break contact before they come to rest with an insulator between them. d. often make and break contact several times before coming to rest in contact with each other. 2. Using a time delay to debounce a switch a. does not stop the mechanical bounces of the switch. b. stops the mechanical bounces of the switch. c. cuts out the repeated electrical pulses caused by bouncing. d. Both a and c are correct. 3. The following sequence represents an attempt to debounce a switch: a. Time delay - Switch unit - Counting system b. Switch unit - Time delay - Counting system c. Switch unit - Counting system - Time delay d. Counting system - Time delay - Switch unit 4. When a switch is part of a switch unit, bouncing causes: a. a series of changes in output. b. a series of changes in input. c. a series of changes in both output and input. d. a short in the circuit. FACET by Lab-Volt 161

5. The decimal number 10 is represented by in the binary system. a. 10 b. 101 c. 1001 d. 1010 CMS AVAILABLE FAULTS AVAILABLE 162 FACET by Lab-Volt