HW2 - ndm736/ME433_2023 GitHub Wiki

Probably missing some details, especially if you did not take ME333

There are three parts to this assignment. First, build and test the 3.3V regulator circuit. Second, build the minimum necessary connections for the PIC32MX170F256B with serial bootloader. Third, write a short program to test the PIC circuit. Each section has deliverables in bold: these are the things that you need to turn in, sometimes with demo videos to record. Make a folder in your ME433 repo called HW2 and place all of the deliverables in it. On Canvas, submit a link to your HW2 folder, and any demo videos (don't put the videos in your repo, just code and images).

Build and test the 3.3V regulator

Old video on making 3.3V

We are using the AP7381 3.3V regulator to take 5V from a USB cable and power our board with a regulated 3.3V, up to 150mA.

Using the Adafruit Friend CP2102N (or equivalent), check that you have 5V between the 5V and GND pins. Use 5V as the input to the regulator, with a 1uF capacitor from 5V to GND and a 2uF capacitor (or two 1uF capacitors in parallel) from 3.3V to GND, and see if you get 3.3V out. Add a red LED in series with a 330 ohm resistor to the 3.3V output voltage, and check the voltage again (the LED should be on!). We'll use 3.3V and ground a lot, so make the rails on your breadboard 3.3V and ground according to the color code on the breadboard.

You can use a multimeter, oscilloscope, or nScope to verify the voltages. Note that an oscilloscope or nScope need to have common ground with the circuit to get correct readings, so be sure to attach the ground from your circuit to the oscilloscope or nScope ground. If you are using a scope, take the capacitors out temporarily and look at the AC noise on the output. Can you see the regulator turning on and off?

Build the PIC32 circuit

Old video on the minimum required PIC32 circuit (note we're not using the external oscillator or programmer this year)

As you should always do, first draw a circuit diagram of the voltage regulator and PIC32MX170F256B. This is a big circuit. This image is a useful cheat sheet.

  • Connect all VDD pins to 3.3V, all VSS pins to GND. Each VDD pin gets a 0.1uF or 1uF capacitor to GND (either value works). The capacitor is supposed to be as close to the pins as possible, to suppress noise that might make the PIC turn off if the power line fluctuates.
  • Connect the VCAP pin to a 10uF capacitor to GND (these are ceramic 10uF so they are not polarized, but note that many capacitors >1uF are made of tantalum, a conflict material, and are polarized)
  • Connect MCLR to a 10k pull-up resistor and a pushbutton to GND, this is the Reset button. These are the minimum connections necessary to make the PIC work, but with no inputs or outputs it is hard to tell, so we'll add two LEDs and a User button.
  • Connect pin B4 to a green LED to a 330 ohm resistor to GND.
  • Connect pin B5 to a yellow LED to a 330 ohm resistor to GND.
  • Connect pin A4 to a 10k pull-up resistor and a pushbutton to GND.
  • Connect pin A2 to the Friend TX pin
  • Connect pin B3 to the Friend RX pin

Build the circuit as neatly as you can, we will use it all quarter. Power your board and make sure the 3.3V is still the correct value (no shorts). Take a photo of your circuit diagram and a photo of your circuit.

Program the PIC32

At some location on your computer, copy nu32utility.c from the bootloader folder. Use gcc to compile nu32utility.c to a program called nu32ultility.

Start a new project in the MPLABX IDE. By default the project is saved to a folder called MPLABXProjects, you should redirect it to the HW2 folder in your repo. Copy the code template files template.c, nu32dip.h, nu32dip.c, and NU32DIPbootloaded.ld into the folder. In MPLABX, add the two c files to Source Files, the h file to Header Files, and the ld file to Linker Files.

Find the name of your Adafruit UART Friend board (using Device Manager in Windows, ls /dev/tty.* in OSX and linux).

Edit the Properties of the project by right clicking on the project name. Under the Building section, check the "Execute this line after build" button, and add the command to call the nu32utility program, something like (path to nu32utility) (COM name) ${ImagePath}

Compile and program the PIC by pressing the Build Main Program button (looks like a hammer). This will compile the code and run the utility to program the board, if it is in bootloader mode. To put the board in bootloader mode, press and hold the RESET button, press and hold the USER button, let go of the RESET button, then let go of the USER button. The green LED blinks in bootloader mode.

When the PIC programs successfully, the template code does the following:

  • initializes A4 as input, and B4 and B5 as output
  • in the infinite loop, wait until a newline is received from the computer, print it back, and if the USER button is not pressed, blink the LEDs 5 times over 2.5 seconds

On Windows, use putty, and on OSX and linux, use screen to communicate with the PIC.

Edit the code to receive two numbers from the user over the serial port, the number of times to blink and how long each blink period should be.

Upload your code to your repo, and take a video of your blinking LED, also showing the voltage on a multimeter, oscilloscope or an nScope trace that proves your LEDs blink for a time that matches the serial input.

Remember that the TRISx SFR controls whether a pin is an input (1) or an output (0). The PORTx SFR is read to determine if an input pin is on (1) or off (0). The LATx SFR sets whether an output pin is high (1) or low (0). The function _CP0_SET_COUNT(value) sets the value of the core timer, and _CP0_GET_COUNT() returns the value of the timer, which ticks at half the system clock (we are using 48MHz for sys clock). Typically a delay function sets the core timer to 0, then in a while loop gets the value of the core timer and compares it to the number of ticks necessary to wait the correct amount of time. Note that the MPLAB X IDE has autocompletion, so as you type something like "TRISBbits." the available bits appear! You can also right-click on a SFR or function and go to the definition, and the IDE will open up the file where it is defined. Very useful!