320 likes | 661 Views
The Towel Dispenser. Computer Organization CS 140. The Towel Dispenser - Overview.
E N D
The Towel Dispenser Computer Organization CS 140 CS140 -Towel Dispenser
The Towel Dispenser - Overview The purpose of this Project is to duplicate the functionality of a Towel Dispenser. Well, actually, it will have the intelligence of a Towel Dispenser but won’t actually contain any paper or a motor powerful enough to drive that paper – otherwise it should be all there. In order to accomplish this Project, there are two important pieces you need to understand: • The PIC hardware and the associated pieces in our Towel Dispenser. This includes how the PIC works (you’ve seen a lot of that already) and the components (switches, lights, motor, etc.) that make up our version of the Towel Dispenser. • The REAL towel Dispenser – how does it work? What operations does it perform as a result of its “ordinary” mode – someone asking for a towel, and its “extraordinary” mode – opening the case and messing with the switches. • Wiring our Towel Dispenser so that the components hook up to the PIC. That’s part of what you need to do for this project. CS140 -Towel Dispenser
The Towel Dispenser - Overview This Project Document is divided up as follows: • Tool Usage and what’s available • Overview of our PIC Towel Dispenser – photos, schematics, and component descriptions. • A brief overview of the PICC-LITE compiler and a very brief introduction mapping C code onto the PIC processor. • An overview of software engineering. The methodology you will use on this project. • What it is you are doing – the stages of your project. • A Check Off sheet of concrete accomplishments. CS140 -Towel Dispenser
Tools So, what tools do you have available for this project? • Your brain – always the most important. • A PC running Windows 2000. • A C compiler – you can write this program in a high level language. We’ll be using the PICC-Lite as defined at http://www.htsoft.com/products/PICClite.php - take a look at this!! • MPLAB IDE – One advantage of this 16F877A chip is that you can debug your code directly on the chip – though you may be familiar enough with the simulator that this isn’t an advantage! • The wonders of Software Engineering. This tool will allow you to plan and develop code that’s relatively complex. Your life will never be the same again. CS140 -Towel Dispenser
Top View 3-way switch #1 3-way switch #2 3-way switch #3 2-way switch #4 PushButtons #1, #2 Door Switch LED 7-Segment Display Motor Relay Capacitor Wires From PIC Power CS140 -Towel Dispenser
Top View Door Closed Switch #1 Switch #2 Switch #3 Switch #4 LED PB #1 PB #2 Term CB12 CB07 CB26 CB29 CB43 CB43 CB46 CB47 CB59 CB13 CB27 CB30 CB44 Relay Connection CB55 CB04 CB09 CB14 CB24 CB29 CB34 CB27 CB32 CB37 CS140 -Towel Dispenser
Front View Door Switch Normally Open 2-way switch #4 Push Button #1 – Normally Open 3-way switches #3 #2 #1 LED Not Used Terminal Posts Push Button #2 – Normally Open POWER ON Green Light says Power to the box is on. CS140 -Towel Dispenser
Back View Reset Not Used Programming Input 5V power connector CS140 -Towel Dispenser
16F877A The Towel Dispenser • 1 MCLR • 2 AN0 • 3 AN1 • 4 AN2 • 5 AN3 • 6 RA4 • 7 AN4 • RE0 • RE1 • RE2 • Vdd • Vss • CLKin • CLKout • RC0 • RC1 • RC2 • RC3 • RD0 • RD1 PGD 40 PGC 39 RB5 38 RB4 37 RB3 36 RB2 35 RB1 34 RB0 33 Vdd 32 Vss 31 RD7 30 RD6 29 RD5 28 RD4 27 RC7 26 RC6 25 RC5 24 RC4 23 RD3 22 RD2 21 CB05 CB04 CB09 CB10 CB11 CB12 CB13 Diagnostic Lights CB14 CB24 15-33pF CB25 CB26 To “CB” Connector Board CB27 CB29 CB30 CB31 CB32 CB37 CB34 CB36 Diagnostic Lights CB35 CS140 -Towel Dispenser
The Programmer Circuit: This is the electrical circuit that downloads the program into the processor chip. The Towel Dispenser • 1 MCLR • 2 AN0 • 3 AN1 • 4 AN2 • 5 AN3 • 6 RA4 • 7 AN4 • RE0 • RE1 • RE2 • Vdd • Vss • CLKin • CLKout • RC0 • RC1 • RC2 • RC3 • RD0 • RD1 PGD 40 PGC 39 RB5 38 RB4 37 RB3 36 RB2 35 RB1 34 RB0 33 Vdd 32 Vss 31 RD7 30 RD6 29 RD5 28 RD4 27 RC7 26 RC6 25 RC5 24 RC4 23 RD3 22 RD2 21 16F877A Programmer Box 1 MCLR (White) 2 +5V (Black) 3 Ground (Red) 4 Data (Green) 5 Clock (Yellow) +5V 10KW 470W Reset Switch 22uF CS140 -Towel Dispenser
-- 17 13 14 19 16 17 18 19 20 -- 4 8 7 6 5 4 3 2 1 The Programmer Circuit: This is the alternate LVP circuit The Towel Dispenser • 1 MCLR • 2 AN0 • 3 AN1 • 4 AN2 • 5 AN3 • 6 RA4 • 7 AN4 • RE0 • RE1 • RE2 • Vdd • Vss • CLKin • CLKout • RC0 • RC1 • RC2 • RC3 • RD0 • RD1 PGD 40 PGC 39 RB5 38 RB4 37 RB3 36 RB2 35 RB1 34 RB0 33 Vdd 32 Vss 31 RD7 30 RD6 29 RD5 28 RD4 27 RC7 26 RC6 25 RC5 24 RC4 23 RD3 22 RD2 21 This is the electrical circuit that downloads the program into the processor chip. +5V 10KW 470W Reset Switch 22uF 16F877A CS140 -Towel Dispenser
1 14 2 13 12 4 6 9 7 8 The Relay Circuit: The Towel Dispenser Components 2-Way Switch 7-Segment Display • Anode F • Anode G • NC • Cathode • NC • Anode E • Anode D • Anode C • Anode RHDP • NC • NC • Cathode • Anode B • Anode A +5V 1 50KW Internal connections 2 http://www.omron.com/ecb/products/pry/111/g5v_1.html 3 560W 50KW +5V In this nomenclature, when the switch is pushed “up”, then Pin 1 is connected internally to Pin 2. Truth Table for this switch: Switch Position: Pin 1 Pin 3 “Up” Low High “Down” High Low 33W 9 6 To Pic (CB55) This is a bonus item for your amusement. “Cathode” means ground. An anode is a high voltage that will turn this on. Relay 1000 uF 1 2 Motor 1 +5V 50KW 3-Way Switch 2 3 560W 4 The PIC doesn’t have enough power to drive the motor directly. So it uses the relay as a “switch”. The PIC can apply a small amount of power to the relay – this turns it on and allows the current to flow to the motor. The capacitor provides a current reservoir so the motor doesn’t drain the current from the rest of the circuit. NOTE: Don’t leave the motor on for long periods. 50KW Truth Table for this switch: Switch Position: Pin 1 Pin 4 “Top” High Low “Middle” Low Low “Bottom” Low High CS140 -Towel Dispenser
The Towel Dispenser +5V +5V 560Ohms 560Ohms To PC – CB51 To PC – CB50 50KW 50KW 1 1 1 +5V +5V +5V 50KW 50KW 50KW 2 2 2 3 3 3 560W 560W 560W 4 4 4 50KW 50KW 50KW +5V 33W To PC – CB55 Components and their Placement on the Connector Board 9 6 1000 uF Relay 1 2 Motor Motor and driver relay (Note on photo where this CB55 connection Is located. +5V To PC – CB59 CB44 +5V 1 50KW 150Ohms 2 3 560W CB43 50KW 2-Way Switch #4 1.0K To PC – CB46 LED Binding Posts Push Button #2 Push Button #1 +5V +5V CB30 CB27 CB13 150Ohms 560Ohms CB29 CB26 CB12 Power on Light To PC – CB07 3-Way Switch #3 3-Way Switch #2 3-Way Switch #1 Door Switch CS140 -Towel Dispenser
Compilers Compilers that are designed to produce code for particular devices (like the PIC) have extensions to the standard language. So the PICC-LITE that we are using has the normal C language support, and in addition has a few special instructions that talk to the hardware. When using the compiler with the IDE, the compile is called with command line options that pass into the code things like the kind of processor being used, the configuration bits to be used, etc. This is how the environment can be easily set up. Here are a few language extensions that you will find very useful: PORTC = 0x0F; // Put a 15 onto the 8 bits of the port RC0 = 1; // Set high bit 0 on Port C. There are a number of great examples available when you download the PICC-LITE compiler. I’m not going to give you a particular example – read their examples. CS140 -Towel Dispenser
Software Engineering Engineering is the art and science of building things. Over the years, Engineering has moved more from art to technique. People have learned what works and have developed practices to build things as efficiently as possible. A little known fact is that half of all cathedrals built in Europe in the Middle Ages fell down (mostly during construction.) Those cathedrals were state-of-the-art for their time; they stretched materials and craftsmanship to their limits. Over the years, we’ve learned a great deal about building things. For instance, the last time a major suspension bridge fell down was in the 1930’s. You occasionally hear about buildings falling down, but it’s usually attributed to shoddy construction - the builders didn’t follow the rules. In a similar fashion, Software Engineering is the craft of building large software programs. CS140 -Towel Dispenser
Software Engineering You are ready to hear about this topic, because Software Engineering is required whenever you have a project to build that you can’t keep in your head all at one time. When you start writing programs, they are usually exercises, used as examples of coding techniques. By the time you get to upper level courses, you are no longer learning programming for the sake of learning programming, but have a reason associated with that program - you’re trying to build something. And that something can get quite large. So it’s time to start using some of the techniques of Software Engineering in order to build your projects. CS140 -Towel Dispenser
Software Engineering Software Engineering covers a wide range of topics: • Figuring out what it is you want to build - the requirements of the project. • Going from the requirements to a functional design. • Taking that high level/functional design and turning it into smaller chunks or algorithms. • Coding the algorithms in a specific language. • Testing the code to ensure that it works as required. • Maintaining the code - fixing bugs and adding modifications as the requirements change. For our purposes, we’re going to look at Steps 1 and 5, though you’ll get plenty of opportunity to do the bug fixing mentioned in #6. CS140 -Towel Dispenser
Requirements Software Engineering Requirements are a statement of what a product should do – how it should behave. These requirements can be stated in many ways; often they are in free-form text – simple to understand but easy to misinterpret as well. Sometimes they are in a formal discrete-math sort of language – difficult to understand but precise in their meaning. Our towel dispenser lends itself well to a requirements statement as a type of truth table. There’s a sample below. Feel free to modify this to meet your needs. However note that any structure you use must be unambiguous and should be clear to everyone what is expected. CS140 -Towel Dispenser
Functional Design Software Engineering Again, the Functional Design can take many forms. The goal of overriding importance is to make it clear – what is it you’re trying to do. Once you have the requirements, you want some idea of how the code will behave – how do you produce the actions described in your requirements. This could be as simple as the design given below, but in fact will probably be a bit more comprehensive. Read Inputs Produce Outputs CS140 -Towel Dispenser
Low Level Design Software Engineering Now we’re going to learn a few rules. Then we’ll apply these rules in a very simple example. And then we’ll go wild and try the rules on a more complicated software example. The Rules: 1. Break down the project into smaller pieces. A. There should be no more than four or five pieces. B. If possible, make those pieces approximately equal in size. 2. If each of the pieces contains more than one action, go to Step 1. 3. Stop only when you have a series of pieces and sub-pieces that each contain only one action. CS140 -Towel Dispenser
Low Level Design Software Engineering An Example: Break down into single actions, the “Project” of eating lunch in the cafeteria. Level 1 - Eating Lunch: 1. Find a friend to eat lunch with. 2. Get your food. 3. Eat it. Level 2 - 2. Get your food: 2A. Pay the cashier. 2B. Salad bar 2C. Pasta Bar 2D. Hot food 2E. Dessert Each of the Level 1 items has a Level 2. Picking just one of these we get Breaking this down still further CS140 -Towel Dispenser
Low Level Design Software Engineering Level 3 - 2A. Pay The Cashier: 2A1. Find your card 2A2. Hand the card to the cashier 2A3. Get the card back from the cashier 2A4. Say “Thank You” 2A5. Put the card back in your pocket. Breaking this down still further CS140 -Towel Dispenser
Low Level Design Software Engineering Can you think and talk at the same time Yes No Level 4 - 2A1. Find your card: Stop Talking Think about where your card is. Reach into your pocket. This is a flowchart Is the card there? No Yes Extract Card From Pocket. A decision box A descriptive box CS140 -Towel Dispenser
Low Level Design Software Engineering Level 4 - 2A1. Find your card: 2A1a. Can you think and talk at the same time? If yes, go to 2A1c. 2A1b. Stop talking. 2A1c. Think about where your card is. 2A1d. Reach into your pocket. 2A1e. Is the card there? If no, go to 2A1a. 2A1f. Extract card from pocket. This is a list. This page and the previous one are identical. Either a flowchart or a list works for showing decision making. CS140 -Towel Dispenser
Low Level Design Software Engineering Here it is from another perspective!! CS140 -Towel Dispenser
Breaking Down A Project OK, so that was good practice. Let’s try the same thing but on a programming problem. You’ll find that problem at the end of this handout. Now it’s your turn to practice. Task N: Your job will be (eventually) to write a program to solve this problem. But we’re going to sub-divide the job into many smaller tasks. Task 1: Write a series of Level 1 steps that break down this problem. Remember, there should be no more than 4 or 5 steps in this level. Remember also you want to make each of the steps about equal in weight. This is equivalent to the example we did where we ended up with the following: Level 1 - Eating Lunch: 1. Find a friend to eat lunch with. 2. Get your food. 3. Eat it. Go no further – we’re going to talk this over as a group. CS140 -Towel Dispenser
Breaking Down A Task Now that we’ve talked over the Results of Task 1, we are ready to go on. Task 2: • Take the first of these high-level steps and subdivide IT into Level 2 Steps. (This can be either a list or a flowchart.) • Find a friend in the lab, and talk over your solutions to this Level 2 subdivision. Agree on the “best” way of doing this subdivision. • Go no further – we’re going to talk over this result as a group. CS140 -Towel Dispenser
Breaking Down A Task Now that we’ve talked over the Results of Task 2, we are ready to go on. Task 3: Are your Level 2 steps small enough? Can you take each of those steps and write code? If yes, great. But you might find that you need to do a low-level breakdown. • Take one of your Level 2 steps and break it down until it is of a size that can be coded – these are Level 3 steps. (This can be either a list or a flowchart.) • Find a friend in the lab, and talk over your solutions to this Level 3 subdivision. Agree on the “best” way of doing this subdivision. • Go no further – we’re going to talk over this result as a group. CS140 -Towel Dispenser
Breaking Down A Task Now that we’ve talked over the Results of Task 3, we are ready to go on. Task 4: You will do the rest of this on your own. Do NOT work with a partner on the remaining pieces. • Continue to break down your remaining Level 1 Steps, each into a series of Level 2 Steps. • Those Level 2 Steps that are still too big to code directly should be divided into Level 3 Steps. • You will end up with something like the chart below. • Hand in this final product. CS140 -Towel Dispenser
Low Level Design Software Engineering There are a number of ways of representing the complete breakdown of the problem LIST 1. Step 1 – Level 1 Description 2. Step 1A – Level 2 Description 3. Step 1B – Level 2 Description 4. Step 1C – Level 2 Description 5. if input is TRUE, then goto line 7 6. Step 1C1 – Level 3 Description 7. Step 1C2 – Level 3 Description 8. Step 1D – Level 2 Description 9. Step 2 – Level 1 Description 10. etc. Flow Chart Step 1 – Level 1 CS140 -Towel Dispenser
What You Should Do Week 1: • My advice on this project is to PLAN! • Write a Requirements Specification for the Towel Dispenser. This can be in the form of a Truth Table as described before – in fact I recommend that format. It’s a lot easier than writing English, and a lot less ambiguous. • Write a Design Specification. This will be a series of boxes, with arrows pointing from one to another. OR, it might be a list of actions with the particular order in which they will be executed. In any case, each of these boxes/lists can be broken down into further pieces in the next step. • Write pseudo-code. Break down the boxes further. Possible pseudo-statements might be “Get the inputs on Port D”, “Take action based on D-Inputs” • Write the code. • Write the test plan – this will look amazingly like the Requirements Spec you produced in Step 2. • Run the code and test it. • Be ready for me to test your result. Week 2: CS140 -Towel Dispenser
What You Should Have Accomplished By Check-Off Time Towel Dispenser Name ______________ • A Requirements Document: • Lists all the possible inputs, pre-conditions, and resulting actions. • It’s in approximately the format requested. A spreadsheet is the obvious best tool for this. • A Design Document: • Complete with flowcharts or lists. • Document is clear and I can understand it without having to ask questions – the document stands on its own. • A Pseudo-Code Document • It’s derived from the Design Document – not made up of something completely different. • Document is clear and I can understand it without having to ask questions – the document stands on its own. • A Test Plan • It’s complete and includes all possible inputs. • Document is clear and I can understand it without having to ask questions – the document stands on its own. • The Code Runs • I can specify that I want you to run any one of the tests on your Test Plan. When you do so, you get the result that is specified. • This result is what the real towel dispenser would do. CS140 -Towel Dispenser