Introduction: VHDL Photosensitive Synth Machine
This project and its tutorial were completed as part of our CPE 133 final project at Cal Poly San Luis Obispo. Our goal was to create a complete logical game in VHDL using a Nexys 3 FPGA board and an off-board component. Instead of a more conventional game, we designed a photosensitive keyboard to synthesize a range of tones for users to play. Having an actual "keyboard" made from photoresistors is what made our project a unique and exciting learning experience. The "game" we made lets users play around with something fun without any winning or end game conditions.
· An FPGA board (we used a Nexys 3), and all its accouterments
· 16 photoresistors (for 16 the different notes)
· 16 high value resistors (to prevent noise in the circuit)
· a compatible speaker
· 38 wires
· 2 breadboards, or one large enough to fit the circuit components
· Xilinx software
Step 1: Create Black Box Diagram
To clarify and visualize the principal functions of our keyboard representation, we created a black box diagram. The various components of the black box diagram include: a soundboard block, a note decoder block, a clock divider block, a sound wave generator block, and a note multiplexer block.
The note decoder block receives the raw signal from the keys and feeds it the key data to the 16 sound wave generator modules.
Each sound wave generator contains a clock divider which is constructed with a specific, static frequency for its respective note. All generators output either a low signal or a square wave which feed into a 16-bit wide bus.
Finally, the waveform bus goes to a note multiplexer which time multiplexes the signals. The multiplexer selects each signal for 50000 cycles, then switches to the next live signal. The multiplexed output is sent to the speaker pin, which in turn produces a sound with the same frequency as the input square wave.
Step 2: Design Note Decoder Module
The Note Decoder is the first digital logic in our circuit. It uses 16 D-latches within a behavioral architecture to store the input key data more reliably. It also switches the 16 key signals from active-low inputs (photoresistors block current, creating 0's) to active-high outputs. The current note decoder module we are using switches every 2000 cycles, but this value is not too sensitive to change between 100.
Step 3: Design Clock Divider Module
The purpose of the clock divider module is to produce different output frequencies by switching at various clock cycle intervals. Using VHDL, we designed this module consisting of a clock signal, a ten bit wide bus representing the various pitches of frequencies ranging from 262 Hz to 1022 Hz, and a single bit square wave output.The range of the frequencies is determined by the number of bits in the pitch input (10 bits = 1022 max).
Step 4: Design Sound Wave Generator Module
To create a sound process, we designed a sound wave generator in VHDL and instantiated it 16 times in our circuit. The generator inputs are the clock, a ten bit wide bus representing the specific pitch an enable bit, and a sound output.
The generator contains a clock divider that outputs to the generator's sound output. The pitch of the clock divider is the pitch of the generator. The generator's sound process outputs a square wave frequency signal if enabled, otherwise it outputs 0.
Step 5: Design Note Multiplexer Module
A multiplexer is used to select one of the sixteen sound signals generated from the previous VHDL modules, allowing the key specified by the user to be played. It receives the clock and 16 bits of square wave signals and outputs a single dynamic square wave.
Our multiplexer switches at 50000 cycles and skips any notes that aren't playing.
Step 6: Design Soundboard and Switchboard Module
Finally, we got to plug everything in together to see it work. In addition to the soundboard module, there is a switchboard module that relies on the switches on the Nexys 3 board for debugging purposes, however apart from differences in size and inputs, the circuits function the same way.
Step 7: Hardware Implementation
Our project only had two pieces of hardware to implement off board: the speaker and the keyboard.
Thanks to the known laws of physics, it turns out that any speaker with a square wave input will produce a tone with consistent with the tone it would produce if it received a sinusoidal wave. Obviously, with the use of a digital to analog converter, the sound would be cleaner and louder, but our method was much more simple. As you can see from the photos, we simply plugged speakers into the signal and ground pins and they made sounds.
The keyboard took significantly more time to implement but was relatively simple:
We split an analog power pin between 16 photoresistors. The photoresistors act as opens when they receive light (not played) and shorts when light is blocked (played). These electrical properties led our circuit to have active-low enables. The other end of the photoresistor connects to a wire and a high-value (10K) resistor in parallel. The wire goes to one of 16 signal pins in the Nexys board and the resistor goes to ground. This completes a grounded input circuit that can send 16 bits of data to the Nexys board.
Step 8: Establish Relationship Between Software and Hardware
Create a ucf file that maps your circuit inputs to your keyboard's inputs. Synthesize the design and upload the .bit file to your Nexys board. Putting your finger over the photoresistors should produce a sound from the speaker, though its recommended to do only three or so at a time or the sound will get rather warped (Read: "ALIENS!!!!"). If the ambient light in the room is too diffused, you may need a more direct light source to create contrast between the photoresistor inputs.
Step 9: Play the Keyboard and Have Fun!
To play the keyboard, simply wave your finger above the photoresistors. For a more defined sound of a specific note, place one finger directly on the photoresistor surface. It spans about 2 octaves, the notes are written in the VHDL processes, starting with middle C and ending with the D two octaves up. You can produce various tunes, from "Mary Had a Little Lamb" to "Twinkle Twinkle Little Star," for example. Be creative and have fun playing the VHDL photosensitive synth machine!