Lab 7: LED/Switch I/O

In this lab you have to implement a LED/button/switch I/O problem using a finite state machine (FSM). You will also capture the falling and rising edges of a pushbutton press using an oscilloscope.

Prelab (20)

Wiring and testing new components (10)

If your heartbeat LED and the wire connecting pin 13 and the 3.3 V rail are still disconnected from Lab 6 Task 3, reconnect them.

You will need to add the following parts from your kit to your breadboard:

Below is a part of a pin diagram of the PIC. The pins we are interested in for this lab are RB12, RB13, and RB14. These are pins 23-25.

RB14 = Pin 25

RB13 = Pin 24

RB12 = Pin 23

From Microchip DS70000657J 

Connect the parts as follows:

Here is one way to do this:

Overview of entire board. The green LED (and 51 ohm resistor) on the left lets me know the position of my on-off switch. This is optional. 

I used a blue LED and a 680 ohm resistor.

You do not have to connect your components exactly like this, but:

Open the MPLAB project C:\ece3724\pic24_code_examples\chap8\ledsw1.X. Take a look at ledsw1.c. You will be modifying this program to solve your problem.

States from ledsw1.c with descriptions corrected/clarified

Build ledsw1 and copy the hexfile info into BullyCPP. Upload it to your board and test that your new LED, switch and pushbutton work properly.

State Machine Diagram (10)

Based on the last digit of your student ID number, you will be implementing one of the following LED/Switch I/O problems. Be sure to do the right problem or you will receive a 0 for the lab:

Last Digit 1 or 6:

Last Digit 2 or 7:

Last Digit 3 or 8:

Last Digit 4 or 9:

Last Digit 5 or 0:

Draw a state diagram for your problem. This is a Moore machine where outputs are only dependent on the current state.

Below is an example of a state diagram for ledsw1. Your state diagram will be larger, with perhaps a dozen states:

Your state diagram should be of equal or greater quality to get prelab credit. You may draw with a computer. You may not use MS Paint or the equivalent.

TA Checkoff

Components are not wired, components are untrimmed, wires are sticking out from the board. One or more components do not work properly when running ledsw1. (0)

Your state diagram looks like you made it in the elevator on the way to the lab. (0)

0.0

Distance Students Only: Take a picture of your new components and your initial state chart (similar to the photos above). Submit them with your report.

Task 1 - LED/Switch/Button State Machine (45)

Note: To blink means to flash on and off. Gradually dimming over the course of several minutes and then slowly reilluminating is not blinking. To blink rapidly means that the flashing of the LED should be visibly faster than when blinking at the normal rate. To press a button means to push the button down and hold it down.

Good.

Bad.

3.  Change the state strings

4. Now you have to change your switch statement. 

2 toggles = 1 blink

Build your program and upload it to your board. Test it: Go through every state and make sure the name of the state is correct and that the output (LED) is doing what it says on the screen. Make sure your program does what the description of the problem says it is supposed to do. Take a screenshot of BullyCPP showing most/all of your states.

A good screenshot of ledsw1 in action.

TA Checkoff

Your program performs correctly.

Task 2 - Pushbutton Fall and Rise Times (15 points)

VirtualBench Setup (Starkville students)

Where to set Volts/Div for channel 1.

Measuring Fall and Rise Times with VirtualBench (Starkville students)

Data below the waveform.

5. Based on Δ Y and the top (100%) and bottom (0%) of your waveform, calculate where 10% and 90% are and move the horizontal cursors to those levels. For example, if the bottom of your waveform is 0 V and the top is 3.3 V, set one cursor to 330 mV and the other to 2.97 V (or as close as you can get them).

6. Move the vertical cursors to the intersection of the horizontal cursors and your waveform. Δ X will be your rise or fall time.

7. You can take a screenshot by clicking the camera icon in the top left corner. Your screenshots should look something like this (but without the current elf):

Falling edge of pushbutton switch.

The following video shows Mrs. Jane Moorhead demonstrating the VirtualBench software to measure the falling edge of a pushbutton switch:

Connection for the first two measurements

2.  Configure the scope for single-shot rising edge capture, and capture the rising edge of a button press. (Hold the button down and then let it up.) Measure the rise time from VDD to GND. Take a screenshot.

Remove the scope probe and the wire it is attached to. Place a 51 ohm resistor between the (non-grounded side of the) button and 3.3 V (similar to how the reset button is connected). Connect the scope probe to the resistor as shown below:

3. Repeat the measurement of the rising edge of a button press. The external pullup decreases the total resistance to VDD and should result in a shorter (faster) rise time. The total resistance to VDD is decreased because the external pullup is in parallel with the internal weak pullup, and the external resistor has lower resistance than the weak pullup. Take a screenshot.

TA Checkoff

You have taken all three measurements and have obtained valid results and decent screenshots.

Report

Grading

If you do not successfully complete a task and your report fails to mention or glosses over this fact, you will receive a zero for the report portion of your grade as well as for the task. If you attempt to deceive the grader, e.g. by including screenshots not generated by the code you submitted, your instructor will be notified and you will be recommended for an Honor Code violation.

The report is worth 20 points for neatly and coherently presenting your information to a reader. The following non-exhaustive list of errors will result in losing credit from the report portion of the lab grade:

The tasks are worth 60 points. If your report indicates that you did not successfully complete or do not understand a task, you will lose credit, even if you performed it during the lab. The same is true for tasks performed during the prelab. There are two tasks. The first task is worth 45 points and the second task is worth 15 points. The following non-exhaustive list of errors will result in losing credit from a task:

Lab reports that flagrantly violate submission policy (wrong lab, no screenshots, no title page, no text besides headings/labels, mostly blank, code pasted into pdf, paragraphs of lab text pasted in, extremely sloppy/unprofessional, missing code etc.) will not be accepted. The student will receive a zero for the lab and may resubmit with late penalty.