Lab 6: PIC24 System Startup
This lab has you wire the dsPIC33EP128GP502 on a breadboard. You will test to see that you are powering the PIC properly. Next you will program the PIC with the serial bootloader firmware. You will download a C program to your PIC with BullyCPP and modify the program. Finally, you will measure the operating current of the PIC.
Basics
If you have not already done so, download the ZIP archive of the PIC24 library collection and extract it to C:\ece3724\pic24_code_examples.
For prelab (in-person students), you need to have your PIC system wired on the board before you enter lab. Besides your parts kit, you need:
A breadboard with four rows, power/ground posts, and power/ground rails
Correct.
Very incorrect.
Wire. You can use a roll of #22 gauge solid wire and lovingly cut, measure, strip, and insert each individual connection, or you can use precut lengths like these:
A multimeter. Any inexpensive meter capable of measuring voltage, current, and resistance will do. The Virtual Bench oscilloscopes in the lab also have this capability, however:
You don't want to have to get out your laptop, boot up the software, and connect to the bench scope just to check a resistor.
You may be using the scope to take another measurement simultaneously.
A scope may not be available: somebody else may be using it, or you may want/need to do part of the lab at home.
So, bring a multimeter to labs 6-10.
Wire cutter/wire stripper. You may not have the exact precut length of wire you need in your kit. Wires and component leads need to be trimmed down so they are not protruding precariously from your board or you will lose credit.
The following are recommended:
Jumper wires. Note: These are handy for making quick/temporary connections or attaching to meter leads, but they are not to be used for basic wiring. If you use them in the construction of your circuit for Lab 6, you will not get prelab credit.
This is why.
Small pair of needle-nose pliers.
IC puller for getting your PIC in and out of the board without damaging it.
Prelab (20)
IF YOUR PIC IS ON YOUR BOARD, DO NOT APPLY POWER TO THE BOARD - EITHER BY PLUGGING IN THE WALL TRANSFORMER OR CONNECTING THE USB CABLE TO YOUR COMPUTER - UNTIL A TA HAS CHECKED YOUR CIRCUIT (IN-PERSON STUDENTS) OR UNTIL YOU HAVE COMPLETED TASK 1 (DISTANCE STUDENTS).
Follow the associated prototyping walkthrough document and build your board. Note: this document is from 2015 and contains errors. Use the below schematic and photographs as a guide.
From Microchip DS70000657J
Connect Pin 3 (3rd from right) of the FTDI serial connector to your power on/off switch as shown below (long red wire on left). This will allow you to use the USB cable to power your PIC instead of having to plug in the wall transformer. DO NOT USE BOTH SOURCES OF POWER AT THE SAME TIME.
Optional placement guide wire has been moved to right of PIC.
Pins 15-28
You do not need your power connector soldered to the wires that connect it to the board before lab. You can do this after you get checked off.
Stick the longer tines of the right-angle connector into the breadboard.
Connections to check:
PIC pins 13 (VDD) and 28 (AVDD) to 3.3 V power rail
PIC pins 8 (Vss), 19 (Vss), and 27 (AVss) to ground rail
10 uF C3 between PIC pin 20 and ground
FTDI connector pin 6 (far left) to PIC pin 1 (MCLR)
FTDI connector pin 5 (2nd from left) to PIC pin 22 (RB11)
FTDI connector pin 4 (3rd from left) to PIC pin 21 (RB10)
FTDI connector pin 3 (4th from left) to power on/off switch
FTDI connector pin 1 (far right) to ground
C1 (can) is connected between power and ground rails by LM2937 voltage regulator. Negative (gray stripe) connects to ground.
C5 1 uF (or 0.1 uF) between PIC pins 27 and 28 (AVss and AVDD)
C2 1 uF (or 0.1 uF) between PIC pins 8 and 13 (Vss and VDD)
C2 1 uF (or 0.1 uF) between PIC pin 19 (Vss) and 3.3 V
2.2 k R3 between PIC pin 1 (MCLR) and 3.3 V
Pushbutton switch between PIC pin 1 (MCLR) and ground
Fuse (looks like capacitor but has crooked legs) between on/off switch and LM2937 voltage regulator pin 1
LM2937 pin 2 to ground
LM2937 pin 3 to 3.3 V
(optional) C4 1 uF (or 0.1 uF) between LM2937 pin 1 and ground
51 ohm (or 910 ohm) resistor from PIC pin 26 (RB15) to 3.3 V
LED from PIC pin 26 (RB15) to ground (shorter leg of LED)
Write your NetID on the front of the breadboard baseplate in metallic permanent marker. This can also be done after you get checked off (the TAs have markers).
Prelab Checkoff
Board wired neatly. All components/connections present including power/ground straps. Wires are flat to board and snug. Resistor, capacitor, pushbutton, and LED leads have been trimmed. (20/20)
Board not neatly wired and/or untrimmed components. All components present, incorrect connection spotted by TA. (10/20)
Board uses jumper wires for connections. Board missing multiple connections. Board missing components. Multiple untrimmed components and sloppy wiring. Student does not have parts kit. Undersized breadboard. (0/20)
Attempt to deceive TA by plugging parts and wires in haphazardly, displaying another students board, etc. (0 for entire lab).
Task 1 - Testing Power (10)
First, remove your PIC from the board.
Starkville students: Give your PIC to a TA so they can program it with the serial bootloader firmware. If you haven't soldered your power connector yet, now is the time to do so.
Distance students: Program your PIC with the serial bootloader firmware. Directions are here.
Make sure that you have removed your PIC from the board. Verify that your multimeter is configured to measure DC voltage (not current – you will blow the meter’s fuse!). Plug the USB cable into your computer. Your power LED should turn on solidly. With the COM (black) lead of your meter connected to the ground rail of the breadboard, use the red lead to measure the voltage at the following points.
Pin 3 (third from right) of FTDI connector should be ~5 V.
Power rails should be ~3.3 V. Test in several locations.
Ground rails in other locations should all be ~0 V.
Pin 1 of LM2937 should be ~5 V.
Pin 3 of LM2937 should be ~3.3 V.
Where pins 1, 13, 21, 22, and 28 of your PIC used to be should be ~3.3 V.
Where pin 20 of your PIC used to be should be 0 V. (1.8 V once PIC is reattached)
Where pins 8, 19, and 27 of your PIC used to be should be 0 V.
TA Checkoff
Your power rails have 3.3 V and your power LED comes on.
Reporting
Plug your PIC back into the board. Take a picture of your board with your NetID visible. Take a nice clear picture so you can use it for reference later if something gets disconnected.
Task 2 - Downloading a Program using BullyCPP (10)
Ensure that you have your USB-to-Serial cable plugged into the board and into your PC. When you press the reset button on your board, the LED should flicker rapidly for a couple of seconds. The same thing should happen when you start BullyCPP or when you program the PIC with the MCLR box checked. (If the MCLR box is not checked you can program the PIC by hitting the reset button and then quickly clicking Program while the LED is still flickering.)
Start up Bully CPP on your PC. Select the COM port for USB-To-Serial cable. If you do not know the COM port number, then use the ‘Device Manager’ under Control Panel | System | Hardware | Device Manager to see a list of serial ports. Click on a serial port, and will see a description of the PORT – the USB-to-Serial manufacturer should be labeled as ‘FTDI’ with location ‘on USB Serial Converter’. Select the 230400 baud rate in Bully CPP. Make sure MCLR box is checked.
Start MPLAB. Open the project chap8/echo.x in the example code provided with this lab (note: you must start MPLAB first, then open the project file – do not open the project file by double-clicking on it since it does not have a workspace file with it). This project reads a character from the serial port, increments it, and echoes it back (so ‘1’ is echoed as ‘2’, ‘a’ as ‘b’, etc.).
Build the echo.x project (Production > Build Project orF11). Copy complete hex file name and path that appears below BUILD SUCCESSFUL:
Just this part, not the "Loading code from" or the three periods.
5. Click on the ‘Program!’ button in BullyCPP in order to download the program into your PIC. (Note if you have already built a project, you can click Open and find the hex file in the /dist/default/production/ directory of the project.)
6. Test the echo.c program functionality by clicking in the BullyCPP window and typing. You should see the characters you type echoed back, incremented by 1. (So if you type "1", you should see "2".)
7. Modify the echo.c program to increment the character by 2 instead of by 1. (So if you type "1", you see "3".) Type ECE3724 and capture a screenshot of BullyCPP showing the results, e.g. G......
TA Checkoff
Your modified echo.c program increments the characters by 2.
Task 3 – Current Measurement (40)
Chapter 7 lecture notes (p35-36) cover the difference between idle, doze, and sleep modes.
Open the chap8/reset.x project in MPLAB, build it, and download it into your board. Try all the menu options. Some of them require you to push the reset button on your board to continue. The program keeps count of the number of times the PIC has been reset. (Note that to go from one doze mode to another you must reset the PIC first.)
Modify the reset.c program to add a menu choice for Doze (/4) mode. Make it case 6 (so the former case 6 bumps down to 7 and the former case 7 bumps down to 8). To figure out how to do this, look at the dsPIC33E/PIC24E Family Reference Manual, Section 7 (the Oscillator). Find the definition of the DOZE bits in the CLKDIV register. Use the one that gives a FCY/4 value. Build / download the program again and capture a screenshot of your modified menu choices in Bully CPP.
Turn power switch off. Unplug your power source (USB or backup wall transformer), and remove the wire connecting VDD (pin 13) to the 3.3V power rail. Unplug the heartbeat LED on RB15 (pin 26) so that this does not contribute to the current draw. Be sure that DC current measurement is enabled on your multimeter. Connect the meter in series with the PIC VDD to monitor current as shown in the figure below:
Note: You must actually connect this - you cannot hold the meter probes in your hand.
3. Before turning power back on, let a TA check your connection. Plug board back in, turn power on, and verify that you are getting a valid current measurement (it should be somewhere in the range of 30-40 mA). You may have to restart BullyCPP. Record the current measurement for the following modes: Normal operation, Idle, Sleep, Doze (/2), Doze (/4), Doze (/128). For sleep mode, you need to set your meter to measure microamps of current to get an accurate reading.
3a. (Distance students and those completing task without TA present only) Take a picture showing Doze (/4) current measurement. The picture should clearly show your multimeter reading as well as the location in the circuit where you are measuring. The value on your meter should match the value you submit in your table.
TA Checkoff
Your reset.c menu has an option for Doze (/4) mode, located between Doze (/128) and Doze (/2). You are correctly measuring the current in Doze (/4) mode.
Report (20)
Your report must have a title page.
Label the first section Task 1.
Write a few sentences describing what you did for Task 1.
Include the picture of your circuit. If something was wrong with your wiring, and you had to make changes to complete the lab, take a new picture.
Label the second section Task 2.
Write a few sentences describing what you did for Task 2.
Include the screenshot from BullyCPP showing your program performing properly.
Label the third section Task 3.
Write a few sentences describing what you did for Task 3. These sentences should be interspersed with the following:
Include your screenshot of the new menu options you added to reset.c (10)
Use the following equation to predict the current for Doze (/4). (10)
Doze current (/N mode) = idle current + ((normal current – idle current) / N)
Include a Current Measurement Table like the following: (10)
(Distance students only) Include the photo of current measurement you took. (/Distance students only)
Compute your percent error (10) as:
%error = ((expected – measured) / expected) x 100%
Submit your echo.c file.
Submit your reset.c file.
Both files must be properly commented. This is a very simple job, since you only should have written about five lines of code total. Just make sure the comments on the part of the programs that you wrote are accurate and look like the comments on the surrounding parts of the program.
Tidy the files - again simple. Your part of the program should be indented the same way as the surrounding parts of the program.
Remove the boilerplate headers from the top of each file and replace with a header of your own including name, course number, lab number, lab section number, and file name.
Grading
The report is worth 20 points for neatly and coherently presenting your information to a reader.
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 three tasks. The first two tasks are worth 10 points each. The third task is worth 40 points and has 4 subtasks, each worth 10 points (menu options, current prediction, current measurement table, error computation).
The following non-exhaustive list of errors will result in losing full credit for a task/subtask:
missing photo/screenshot/table/text
photo/table/screenshot of the wrong thing
(Task 1) photo does not include NetID
(Task 1) photo is bad (out of focus, not zoomed sensibly, doesn't show connections on board clearly)
(Task 1) photo shows bad/sloppy wiring technique (jumper wires, untrimmed components, spaghetti) or incorrect connections
copy/pasting part of the lab writeup rather than using your own words
text is "lab jargon" unintelligible to an outside reader ("I put my PIC on the board" "Here is a screenshot of echo.c for task 2")
text is phrased as instructions to a second party ("Take current measurements.")
text is a literal recap of the activities you performed rather than communicating your results ("After the TA checked my circuit, I replaced the PIC on the board. Then I took some current measurements. At first I was having trouble, but then I realized I was measuring voltage. Once I fixed that, I had to modify my program...")
blatantly erroneous text ("This table shows voltages")
(Tasks 2 & 3) screenshot shows incorrect results
(Tasks 2 & 3) awful screenshot (didn't crop, tiny, blurry, etc)
(Tasks 2 & 3) code wouldn't run / code would produce incorrect results
(Tasks 2 & 3) missing comments / comments falsely indicate what code does
(Tasks 2 & 3) no header on code / left default header on code
(Task 3) handwritten/missing/erroneous/inadequate calculations (see below)
(Task 3) implausible/incorrect/incomplete results in current measurements
The following non-exhaustive list of errors will result in losing partial credit for a task/subtask:
garbled / confusing text
using vague or incorrect terminology
excessive text (Each subtask requires approximately 1-3 sentences, not paragraphs or pages)
(Tasks 2 & 3) untidy code
(Tasks 2 & 3) poor screenshot (didn't crop enough, too small, etc)
(Task 3) table is unruly
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.
Adequate Calculations
I used Ohm's law to find the current in the circuit. [explanation of what you're calculating]
V = IR [the formula]
120 = I (60) [numbers plugged into the formula]
I = 2 A [answer with units]
You do not need to show intermediate algebraic or mathematical steps. Do not write "[explanation of what you're calculating]" etc. next to your calculations.
Notes
For downloading programs to your PIC, read the documentation on the Bully Bootloader.
Refer to the PIC24 library collection documentation as necessary.
If you are getting too high a current for 'sleep' mode (greater than a milliamp) then make sure that your heartbeat LED is out of the circuit and is not drawing current. For all current measurements, the heatbeat LED should be removed from the board.
If Bully CPP returns the following error "The application failed to initialize properly (0xc0000135)" in a pop-up window, this may indicate that your .NET runtime is missing or not installed. You need to install at least up to .NET runtime 2.0, go to Microsoft Downloads and search for ".NET framework".
If the 'USB serial ports' with manufacturer name as FTDI is not listed in the device manager under ports, you probably do not have the drivers for the cable. Get the drivers from FTDI by clicking on the "setup executable" link.
FTDI USB to Serial Cable drivers: CDMxxxxx_Setup.zip
To download, scroll down to "VCP Drivers". Find "Windows (Desktop)" and "Available as a setup executable". Download from this link. (Currently here, but it could move).
Download this anywhere, extract the CDMxxxxx_Setup.exe file, and doubleclick to install it.
In the Bully CPP window, always select the port from dropped down list. Do not type/edit to change the COM port.
Troubleshooting
Check Bully CPP.
Verify that the COM port you've selected is correct.
Verify that the "Program config bits" checkbox is not checked and that the "MCLR before programming" checkbox is checked.
Verify that the lock symbol next to the MCLR button is unlocked.
Check your wiring.
Make sure the round "can" capacitor, which has a large stripe with minus signs next to one pin, is connected to ground.
Make sure the little plus sign on the capacitor placed between pins 19 and 20 is above the wire which connects to pin 20.
Make sure your PIC is fully inserted into the breadboard -- it's easy to not seat it fully.
Make sure you connected a wire between the MCLR pin (pin 1) and the FTDI USB-to-serial cable.
Check power and ground.
Verify that the power connector is soldered well and that the wires leading from this connector to your breadboard are securely fastened. Wiggle these; if the heartbeat LED flickers, something is poorly connected.
Use a DMM to measure the voltage coming from your power supply; it should be 5 V.
Use a DMM to measure the voltage on all your rails -- it should be 3.3 V.
Use a DMM to measure the voltage on pins 13 and 28 -- it should be 3.3 V.
Use a DMM to measure the voltage on pin 20 -- it should be 1.8 V.
Check your reset.
Use a DMM to measure the voltage on pin 1 -- it should be 3.3 V.
Press the reset pushbutton and hold it. Use a DMM to measure the voltage on pin 1 -- it should be 0 V. Release the reset button; the voltage should return to 3.3 V.
Press and hold the reset button on the bootloader. Use a DMM to measure the voltage on pin 1 -- it should be 0 V. Release the reset button; the voltage should return to 3.3 V.
Check your PIC.
Before programming your PIC, the heartbeat LED should flash rapidly as soon as you turn power on. If not, something is wrong with your PIC or your board.
Remove your PIC from your board, and a working PIC from another board.
If your board now works, the problem is your PIC. Ask a TA to re-flash it and try again.
If the other person's board still works, the problem is your wiring. Check it carefully.