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.
You'll be using the walkthrough to construct your circuit.
Besides the PIC circuit on your breadboard, bring the required parts to Labs 6-10 and the practicum:
multimeter that can measure microamps of current
spare wires (jumper wires are handy for making quick/temporary connections or attaching to meter leads, but they are not to be used for basic wiring or you will not receive prelab credit)
tools (wire cutter and/or stripper, needlenose pliers, IC puller)
Here is the schematic and the PIC pinout for your reference:
From B.A. Jones, R. Reese, and JW Bruce, Microcontrollers: From Assembly Language to C Using the PIC24 Family, 2nd ed. Cengage Learning, 2015.
Here are some additional pictures from Spring 2024. This circuit wasn't built exactly like the walkthrough, but it's close enough:
Pins 15-28
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 (0.1 uF) between LM2937 pin 1 and ground
51 ohm (220-910 ohm) resistor from PIC pin 26 (RB15) to 3.3 V
LED from PIC pin 26 (RB15) to ground (shorter leg of LED)
For prelab (in-person students), you need to have your PIC circuit wired on the board before you enter lab. Consult the walkthrough for detailed directions on how to do this.
If you're an in-person student, write your name on the front of the breadboard baseplate in metallic permanent marker. If your breadboard doesn't have a baseplate, write your name on the back of it in regular permanent marker. This can also be done in lab after you get checked off (the TAs have markers). If you're a distance student, you do not have to write your name on your breadboard.
After you are checked off, give your PIC to a TA so they can program it with the serial bootloader firmware.
Board wired neatly. All components/connections present including power/ground straps. Wires are flat to board and not long enough to slip a finger underneath. Resistor, capacitor, pushbutton, and LED leads have been trimmed. (20/20)
Board not neatly wired and/or untrimmed components. All components present, incorrect connection(s) 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/no breadboard. (0/20)
Attempt to deceive TA by plugging parts and wires in haphazardly, displaying another student's board, etc. (0 for entire lab).
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. When the power switch is on, both LEDs 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.
Get a programmed PIC from the TA.
For Distance Students : Program your chip
With the switch off, and the USB cable disconnected, plug your PIC back into the board.
Connect the USB cable and switch on your board. The heartbeat LED should flicker rapidly for a couple of seconds.
Press the reset button on your board. The heartbeat LED should once again flicker.
Open BullyCPP.
Select the COM port. 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 the MCLR box is checked, the padlock is unlocked, and "Program config bits" is unchecked.
Start MPLAB. Open the project C:/ece3724/pic24_code_examples/chap08/ledflash.x (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).
Build the project (Production > Build Main Project orF11). In the Output window, copy (Ctrl-C) the hex file name and path that appears below BUILD SUCCESSFUL:
Just the highlighted portion, not the "Loading code from" or the "..."
Paste it into the "Target hex file" blank in BullyCPP:
Click on the ‘Program!’ button in BullyCPP in order to download the program into your PIC.
You should see a progress bar and then your LED should start flashing.
If you get an error, the most likely causes are:
Board is not switched on
Board is wired wrong (capacitors being incorrect can cause intermittent failures where Bully works in one lab and then not in the next)
Chose wrong COM port
Didn't paste .hex file name right
If you modify the program you are trying to upload to your board, you need to rebuild it in MPLAB. However, you do not need to repaste the .hex file name into Bully, as that does not change.
Your LED is flashing
Take a picture of your board. The LED(s) does not have to be on. Your name should be visible in the picture. If you are a distance student, or your name is on the bottom of the breadboard, have your student ID showing in the photo instead. Take a nice clear picture so you can use it for reference later if something gets disconnected.
Open the project C:/ece3724/pic24_code_examples/chap8/echo.x. Build it and upload it to your board.
This project tests your UART connection. It reads a character from the serial port, increments it, and echoes it back, so ‘1’ is echoed as ‘2’, ‘a’ as ‘b’, etc. (The reason it increments is that otherwise you couldn't be sure that the characters were being sent to the PIC).
Test it out by clicking in the BullyCPP window and typing. If you type "123ABC", you should see "234BCD".
Create a new C Source File. Name it echo_inc.c. Include it, and exclude echo.c:
Copy the contents of echo.c into echo_inc.c. Remove the header and replace it with:
/***********************
* Name
* ECE3724 - Section __
* Lab #6 - echo_inc.c
* Date
************************/
Modify echo_inc.c to increment the first character by 0, the second by 1, the third by 2, and etc. Hint: this probably requires you to make a new variable, and add two more lines of code.
Upload it to your board to test it out. Type in some gibberish. Hold down "1" for a minute or so. You should see some nonsense like this:
When you're done playing around, call the TA over to get checked off.
Your program increments incrementally.
Click "Clear Scrollback". Reprogram your board, or reset the PIC. Type in ECE3724 (with capital letters), and take a screenshot of what shows up in Bully.
Change the header of your code - give it the correct filename and description.
Note: You cannot do this task with a meter that does not measure microamps. Don't even bother until you can borrow one from someone else. You can also try using the meter function of the VirtualBench, however, be sure to have the TA check your circuit before powering it on as these are $2000 scopes.
Open the chap8/reset.x project in MPLAB, build it, and upload it to 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/upload the program again.
Turn power switch off. Unplug your USB cable, and remove the wire connecting PIC pin13) to the Vcc 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 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. In-person students - 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 28-35 mA). You may have to restart BullyCPP. Record the current measurement for Normal operation mode. Then record the current measurement in the following modes by selecting the appropriate menu option in BullyCPP: Idle, Sleep, Doze (/2), Doze (/4), Doze (/128). All should be different. For sleep mode, you need to set your meter to measure microamps of current to get an accurate reading.
3a. (Distance students 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.
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.
Capture a screenshot of your modified menu choices in BullyCPP.
Distance students only: Picture showing current measurement.
Distance students only: Screenshot of cases 5-8 in your C code
Your report must have a title page.
Briefly describe the overall lab. Mention the full name of the device you used once - after that you are permitted to refer to it as "the PIC" or "my PIC".
Note the following spelling/capitalization so that you don't look ignorant and lose points needlessly: BullyCPP, C, LED, ledflash.X, PIC.
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
Use the following equation to predict the current for Doze (/4). See Adequate Calculations section below:
Doze current (/N mode) = idle current + ((normal current – idle current) / N)
Include a Current Measurement Table like the following:
Use proper units on the table: mA or uA as appropriate. If you have an answer of 0 mA, 0.1 mA, or 1 mA for sleep current, this is wrong. Use a better meter that can measure microamps.
(Distance students only) Include the photo of current measurement you took. Include the screenshot of your menu options. (/Distance students only)
Calculate your percent error as:
%error = ((expected – measured) / expected) x 100%
If you want to use absolute value for error calculations, that also is perfectly fine. See below for an example of adequate calculations.
Submit your echo_inc.c file. Be sure it is tidy and has a header on it.
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 grade:
garbled / confusing text ("this Program impregements the Var by one more each")
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.")
using vague or incorrect terminology ("dsPIC3" "C++")
excessive text (Each subtask requires approximately 1-3 sentences, not paragraphs or pages)
blatantly erroneous text ("This table shows voltages")
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...")
untidy code
poor screenshots (didn't crop enough, too small, etc)
table is unruly or handwritten
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 task is worth 10 points. The second task is worth 20 points. The third task is worth 30 points. The following non-exhaustive list of errors will result in losing credit from a task:
missing photo/screenshot/table/text
photo/table/screenshot of the wrong thing
(Task 1) photo does not include name/ID
(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
(Tasks 2 & 3) screenshot shows incorrect results
(Tasks 2 & 3) awful screenshot (didn't crop, tiny, blurry, etc)
(Task 2) code wouldn't run / code would produce incorrect results
(Tasks 2) no header on code / left default header on code
(Task 3) handwritten/missing/erroneous/inadequate calculations (see below)
(Task 3) no units in table
(Task 3) implausible/incorrect/incomplete results in current measurements (0 or 1 mA for sleep mode, identical readings)
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.
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.
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.
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.
Use a DMM to measure the voltage coming from your USB cable; it should be 5 V.
Use a DMM to measure the voltage on your Vcc 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.
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.