ECE 4760: Laboratory 1
You will produce a music synthesizer, played using a keypad, and with a programmable playback function. But first you need to set up a board, arrange jumpers, learn how to connect peripheral devices and use the compiler. I strongly suggest that you use some of the time during the first lab exercise to build your own PIC32 board, which you can then keep, but if you wish you can borrow one. Once you do that, the MicrostickII will be the programmer for the new board.
The Big Board which you will build features a port expander, DAC, TFT header-socket, programming header-plug, and power supply.
See the construction/testing page for specific code examples of each device on the big board.
The connections from the PIC32 to the various peripherials is determined by the construction of the board. The list is repeated here.
PIC32 i/o pins used on big board, sorted by port number. Any pin can be
recovered for general use by unplugging the device that uses the pin.
SPI chip select ports have jumpers to unplug.
RA0 on-board LED. Active high.
RA1 Uart2 RX signal, if serial is turned on in protothreads 1_2_2
RA2 port expander intZ
RA3 port expander intY
PortExpander SPI MISO
RB0 TFT D/C
RB1 TFT-LCD SPI chip select (can be disconnected/changed)
RB2 TFT reset
RB4 DAC SPI chip select (can be disconnected/changed)
RB5 DAC/PortExpander SPI MOSI
RB6 !!! Does not exist on this package!!! (silk screen should read Vbus)
RB9 Port Expander SPI chip select (can be disconnected/changed)
RB10 Uart2 TX signal, if serial is turned on in protothreads 1_2_2
RB11 TFT SPI MOSI
RB12 !!! Does not exist on this package!!! (silk screen should read Vusb3.3)
RB14 TFT SPI Sclock
RB15 DAC/PortExpander SPI Sclock
But note the few silk-screen errors on the board.
Big Board silk screen errors.
--Edge connector pin marked RB6 -- RB6 Does not exist on this package! Silk screen should read Vbus.
--Edge connector pin marked RB12 -- RB12 Does not exist on this package! Silk screen should read Vusb3.3.
--LED D1 outline -- Silk screen should have flat side should be oriented toward PIC32.
Software you will use is freely downloadable and consists of:
- MPLABX version 3.05
(near bottom of page choose Downloads Archive)
- XC32 compiler version 1.40 (near bottom of page choose Downloads Archive)
- plib (near bottom of page choose Downloads -> scroll to bottom) (local copy)
- Getting started with PIC32
- MPLABX IDE users guide
- 32_bit peripherials library -- PLIB examples (ZIPPED) -- (full Legacy PLIB 115 MB)
- 32 bit language tools and libraries including C libraries, DSP, and debugging tools
- XC32 Compiler Users Guide
- PIC32MX2xx datasheet -- Errata
- MicrostickII pinout
- PIC32MX250 configuration options
- JTAG enable overrides pins 13, 14, and 15
- Primary oscillator enable overrides pins 9 and 10
- Secondary oscillator enalbe overrudes pins 11 and 12
- PIC32 reference manual (local copy)
(this is HUGE -- better to go to PIC32 page, then Documentation>Reference Manual and choose the section)
- Specific pages from the PIC32 datasheet
- PIC32MX250F128B PDIP pinout by pin
- PIC32MX250F128B ::: Signal Names=>Pins ::: 1, 2, 3, 4, 5, 6, 7 PDIP highlighted in green (for PPS see next tables)
- PIC32MX250F128B Peripheral Pin Select (PPS) input table
example: UART receive pin ::: specify PPS group, signal, logical pin name
PPSInput(2, U2RX, RPB11); //Assign U2RX to pin RPB11 -- Physical pin 22 on 28 PDIP
- PIC32MX250F128B Peripheral Pin Select (PPS) output table
example: UART transmit pin ::: specify PPS group, logical pin name, signal
PPSOutput(4, RPB10, U2TX); //Assign U2TX to pin RPB10 -- Physical pin 21 on 28 PDIP
Microstick2 as a programmer
The connections to the microcontroller socket on the Microstick2 act like the standard programming signals from the PICKIT3, the programmer which was used to develop the boards you will build. On both the big and small board, J1 marks pin1 of the 6-pin ICSP header.
connector on board
|prog data (PGD)
|prog clock (PGC)
A wiring example is shown below. Note that pin 1, MCLR, is only available on the Microstick2 DIP socket as shown.
When you click on the images below, you will get enlargments with the pin numbers indicated.
- The current version of Protothreads is 1_3_2.
All example programs using this threader may be found on the Development board page.
Program example 3, DDS_Accum_Expander_BRL4.c, on the Development board page is the basis for this lab.
- For most of the semester you will be using the TFT LCD for output and debugging.
You will need to use some of the graphics library calls described in the test code in this lab.
Test code: TFT_test_BRL4.c -- displays color patches, system time, moves a ball, generates a slow ramp on the DAC, and blinks the LED.
- You may want to refer the the ProtoThreads page for the general threading setup.
But note that the UART functions mentioned on that page should be disabled for this lab.
In config_1_3_2.h you need to undefine (comment out) the use_uart_serial define statement.
- Timing of all functions in this lab, and every exercise in this course will be handled by interrupt-driven counters, (including the builtin functions in ProtoThreads) and not by software wait-loops. This will be enforced because wait-loops are hard to debug and tend to limit multitasking. You may not use any form of a delay(mSec) function.
- The oscilloscope is essential for debugging this lab (and every lab).
The oscilloscope is the only way of deciding if -- It doesn't work! -- results from hardware or software.
You can connect the oscilloscope to the computer with a USB cable (type-B connector) attached to the back of the oscilloscope (not the type-A connector on the front).
To use the Tektronix software on the PC:
- Search for
OpenChoice Desktop in the start menu, and start the program.
- When the main panel appears, choose
- In the select dialog box, choose the
USB device, and click
- Back in the main panel, click
- Copy or save the image or data to your lab report.
See the Suggested Background problems for the specifications on frequency, harmonic distortion, and envelope shaping. Generally speaking you want to make pleasant sounding synthesis. You may want to look at the sound synthesis page, but you should use linear envelopes (example 1), rather than exponential (example 2). I suggest starting with a linear attack of about 1000 samples, a sustain of about 1000 samples and a decay of 10000 samples. You are going to use either additive (Fourier) or FM synthesis to build interesting sounds. Near the bottom of the older AVR DSP page is a list of additive synthesis parameters for different sounds. The newer sound synthesis page has parameters for FM synthesis.
A table of note frequencies is below. If you prefer, you may use a higher or lower octave.
But if you go to a lower octave, the little speakers may not have much response below 200 Hz:
C4 262 Hz (middle C)
I suggest that you organize the program as follows:
- Protothreads maintains the ISR-driven, millisecond-scale timing as part of the supplied system.
Use this for all low-precision timing (can have several milliseconds jitter).
- Synthesis ISR uses a timer interrupt to ensure an exact 44KHz synthesis sample rate.
- DDS of sine waves.
- Additive or FM synthesis
- DAC output
- Sample count for precise timing of notes.
- Main sets up peripherials and protothreads then just schedules tasks, round-robin.
- User Input Thread
- Scans and debounces the keypad and any other buttons you may use.
- Parses the command (if any)
and updates state variables (play-mode, note list, etc)
- Waits for 30 mSec using
PT_YIELD_TIME_msec(30), then repeats.
- Play Thread
- Sets up the DDS parameters for the note to be played.
- Maintains playback timing using the sample count from the timer ISR.
- Waits for 10 mSec using
PT_YIELD_TIME_msec(10), then repeats.
You may find some of previous year's lectures useful. Particularly lectures 2, 3, 4.
Week one required checkpoint
By the end of lab session in week one of the lab you must either have
built and tested your own board or tested a prebuilt board.
- Before you test, be sure to attach the chip-select jumpers for the TFT and DAC.
Testing includes TFT, DAC, LED, and i/o expander with Keypad.
You can omit the serial test for this lab.
On the Development Board page, search for Current Protothreads version is 1_3_2 and download the ZIP file.
- Finishing a checkpoint does NOT mean you can leave lab early!
Week two required checkpoint
By the end of lab session in week two of the lab you must have:
- Frequency test mode working for all 8 frequencies and have accurate sinewave tones.
- Play mode working so that you can play a tune manually, but only as a sinewave without envelope control.
- Finishing a checkpoint does NOT mean you can leave lab early!
Week three Assignment
Timing of all functions in this lab, and every exercise in this course will be handled by interrupt-driven counters, not by software wait-loops.
ProtoThreads maintains a ISR driven timer for you! This will be enforced because wait-loops are hard to debug and tend to limit multitasking.
Write a Protohreads C program which will:
- The program starts In play mode. The program will play the notes C4 through C5 using the keypad keys 1 to 8.
The notes will play with an envelope and spectrum that you choose, but cannot be a boring pure sine wave, or a harsh square wave.
Perhaps use FM synthesis to make a sound which is string-like or drum-like.
- The program will produce a rest (no sound) when you press keypad key 0.
This is mostly usful in record mode (see below).
- In play mode the program will play the recorded (see below) note sequence at a fixed rate, perhaps one or two notes/second when the # key is pressed.
The notes will play with an envelope and spectrum that you choose, but cannot be just a pure sine wave.
- The program should have three modes:
- Upon power-up the system should go to play mode and play a note for every keypad press.
- Pressing and holding a separate button (not the keypad) puts the system into frequency test mode for frequency calibration.
In this mode each button, 1 to 8, produces a pure sine wave for as long as it is pushed, at full intensity, with no envelope.
- Pressing and holding another button (not the keypad) puts the system into record mode so that each keypad press is recorded for later playback. Recording continues until the record mode button is released. This mode requires keypad debouncing. The duration of each keypad key press does not affect the recording.
- The program should support one timbre (envelope and spectral content) that you can hard-code.
- There should be no clicks, pops, or other audio artifacts of synthesis.
When you demonstrate the program to
a staff member, you should demonstrate all three modes, the accuracy of the note frequencies using the scope, and record and play back a sequence of notes. One possibility for demo is below, but you can play any tune you like.
Notes: E E E | F F | G F E | D E F | G C F | E D | C C
Play the hollow notes twice as long as the filled notes.
Your written lab report should include the sections mentioned in the policy page, and :
- Measurements of frequency accuracy, with oscilloscope traces.
- A scope display of a typical note playing.
- A heavily commented listing of your code.
Copyright Cornell University
June 19, 2019