Troubleshooting
Installations
If building the projects in MPLAB fails with an "XC-16 toolchain missing" error, close MPLAB, install the C compiler (xc16-vx.xx-full-install-windows64.exe) and try again.
If you did install the C compiler but MPLAB was running, close and reopen MPLAB and try again.
Cyclone IV support (or Cyclone V) must be enabled for Quartus to run the project from Lab 1. If Quartus complains about "device support," uninstall, re-install and make sure these boxes are checked
Don't put spaces in filenames. Keep path lengths reasonably short. Failure to adhere to these guidelines can cause mysterious bugs later.
Put pic24_code_examples and nsc_altera in C:\ece3724, not OneDrive or My Documents folder. Even though you can look inside the archives in File Explorer, you need to extract them from the zip file.
Browser/anti-virus may block downloads (particularly with BullyCPP which is an .exe file). If clicking on a link opens a new tab and then immediately closes it, right-click and "Save Link As..." Then go to your downloads window (Ctrl-J in Firefox and Chrome) and keep the file, ignoring the warnings about malicious downloads.
If VirtualBench does not show up automatically when the scope is plugged in, try installing the drivers: VirtualBench USB Scope: ni-virtualbench_xx.x_online_repack.exe
If ModelSim won't run after the Quartus project is compiled, go to Tools->Options->EDA Tool Options. For "Directory Containing Tool Executable", ModelSim (3rd from bottom) and ModelSim-Altera (bottom) should contain C:\intelFPGA_lite\17.1\modelsim_ase\win32aloem
If the simulation fails to launch after correctly configuring the path to Modelsim (see text in yellow), there may be a permissions problem.
Double-click on modelsim.exe in C:\intelFPGA_lite\17.1\modelsim_ase\. If Windows asked you if it's OK to run this file, you have a permissions problem.
If this is the problem, exit Quartus, then run it as Administrator. Compile your design as usual and it should now work.
Quartus/ModelSim
If your project compiles in Quartus, opens ModelSim, but then has an error like this:
Check that nsc.bdf is set as the top level entity in the Quartus project Hierarchy.
Wrong
What you should see
You can change it by going back to Files in the dropdown and right-clicking nsc.bdf, then selecting "Set as Top-Level Entity".
If your simulation looks funny (wrong number, addresses aren't 16-24, jumps from line to line erratically, bunch of Z's, etc):
Check myrom.v first.
Are your addresses (line numbers) 5 bits?
Are your instructions 7 bits? You can add an underscore between the opcode and the operand to read the instruction better.
The first two bits of the instruction is the opcode. 00 = JMP, 01 = JC, 10 = OUT. Check with your comments to make sure you're doing what you want.
Check the second five bits (operand) to make sure the address/numbers are correct.
Check that you start at line 0, jump immediately to line 16, execute your program and then jump back to line 16. The default case should never execute, so it can go back to line 0 or 16. However the default case shouldn't be used to provide the initial jump to line 16. You need to have specifically added a line to the program to do this.
Next, check your schematic (nsc.bdf). Did you widen all your buses? Pay particular attention to single control lines e.g. mem[#]. If they're supposed to represent bits from the opcode, do they?
Finally, check your other Verilog files. Besides myrom.v, you should have edited:
mycounter.v
myreg.v
nsc.vt
If the labels on your schematic are enormous and difficult to read, try changing the scale of your display. Hit the Windows key, then type in "Scaling". Select "Change the size of text, apps, and other items."
MPLAB
A common error is to be viewing/modifying a source code file from one project while actually debugging another project. When you are done working on a project, close it.
I am editing mptst_word but assembling mptst_byte. It's not going well.
If your project won't build in MPLAB (possibly with a "simulator not found" or "makefile not found" error, and you're sure it's not due to syntax errors, try the following solutions in order:
Recreate the project (see below for instructions). If this doesn't work...
Redownload/extract archive containing code for the lab. The download may have been incomplete, or something could have happened to the files on your disk. If this is also unsuccessful...
Uninstall/reinstall XC16 Compiler and MPLAB
To create a project:
Open an old project that, if possible, is similar to the task you want to complete.
Open the source file from that project.
Right-click on the project name in the Projects window and select Copy (or Project -> Copy in MPLAB 6.20+) then enter your new project name.
Save As the source file with a new filename.
In the Projects window, under Source Files, remove the new file from the old project.
In the Projects window, under Source Files, choose Add existing item to add your new file to the new project.
Close the old project and the old file.
If you suddenly receive an "Error 255 compilation error," exit and restart MPLAB. If you continue to receive this error, close MPLAB again, hit Ctrl-Alt-Delete, and select Task Manager. Close any MPLAB tasks or processes, and restart MPLAB.
Assembly Language
In the ebook and lecture slides, variable names are prefaced with underscores. In the lab we do not do this for reasons of compatibility with existing code.
You can't move a literal (number) right into data memory (variable). You have to move it into a register and then move it from the register to the variable. If you want to put it into a 16-bit variable (u16_something), you can use register W0-W7. If it's an 8-bit number, it has to go into WREG.
If you have confusion on the usage of WREG and W0, refer to the Chapter 3 lecture notes. In short, if you're using byte-sized quantities and a data memory location in the same instruction it's WREG, otherwise it's W0.
Note that the bitwise inclusive or operation, |, is performed as IOR, not OR
A prefix of 0 indicates an octal number. If part of your student ID number that you need to use in a program starts with a 0, omit it or you'll experience odd results or compilation errors. For example, for decimal #0123, just use #123 instead. For hex #0x0123 use #0x123.
Do not use the variable names a or b - they are reserved names for the 40 bit accumulators used by DSP instructions. Using them will give errors during assembly.
Other Issues
Lab 9
Some computers seem to read CTRL+V as two distinct keypresses. If pasting strings does not give you an UART overflow, try installing an older version of BullyCPP.
Common C Compilation Problems
The linker is reporting an undefined reference to a function. You have either misspelled the function name, or did not include the C/Header files that contained the function (e.g. common/pic24_timer.c, include/pic24_timer.h if the undefined function is a timer function).
Common Hardware Problems
Your processor is reseting and reporting a WDT timeout with an error message mentioning an I2C function. This means that your I2C device is not responding, perhaps you have used the wrong I2C address to talk to it or your I2C bus is miswired (do you have your external pullup resistors on the I2C bus??).
Your processor is reseting and reporting an unhandled interrupt. Look at the priority level that is printed for the unhandled interrupt - if it is 7 or lower, then you have enabled an interrupt, and do not have an ISR declared for the interrupt. If it is higher than 7, then it is a trap error and the printed priority level identifies the particular trap (see the textbook). This could be for a variety of reasons - you will get an address trap error (priority 0x0D = 13) if you leave the while(1){} loop out of your code and you fall through main and main does not have a return (if you return from main, a software reset is generated).
Otherwise, read and follow the hardware debugging checklist.