The global coronavirus pandemic is/was more than anyone could have anticipated, and has presented novel challenges to collegiate education across the country and the planet. In the context of this Digital System Design, course the foremost of these challenges is access to hardware, necessary for the execution of many labs but wholly inaccessible to both teachers and students barred from accessing campus in a national quarantine. In a situation such as this, we rely on innovation to find new solutions to these problems. As such, I've used the resources I have available to replace the PMOD ADC & Potentiometer necessary to move the paddle in Lab 6 - Pong Game. With the contribution I detail here, DSD students next semester who may still be learning remotely can complete Lab 6 without specialized hardware.
The first version of this project aimed to emulate the functionality of the PMOD analog-to-digital converter with an external microprocessor, such as the Arduino or Raspberry Pi I have lying around. Such an implementation would have required the following materials:
After a few iterations of trying to emulate a digital signal with user input from the RPi/Arduino, I faced two immutable facts:
Therefore, the third design iteration aimed to eliminate all unnecessary hardware and write VHDL code on the FPGA itself to control the paddle's motion on the VGA screen. Since its motion is only on one axis, there is only a need for two inputs to control left/right motion - therefore, the BTNL & BTNR buttons should provide all the user input necessary.
Lab 6 is supposed to be a game of pong; the user tries to bounce a ball around by controlling the position of a one-dimensional paddle with an analog signal, generated by a potentiometer. This analog signal is sampled by the PMOD ADC device, and an SPI-adjacent digital signal is presented to the JA port on the board. This signal is directly sampled by the adc_if.vhd source, using headers defined in the pong.xdc constraint file to interface directly with the hardware. The architecture of this 'adc_if' entity is fairly concise, and is shown to the left (top). The component has six ports; four inputs from the JA, including two data ports (SDATA1,SDATA2), a clock signal SCK and a chip select signal CS, and two outputs data_1 & data_2, each containing the digital data from their respective inputs. The architecture only defines two processes; adpr uses the CS signal and SCK clock to collect 11 bits of data on a falling clock edge, then shifts the data to the output ports on the rising edge.
This signal is then piped to the main behavioral file, pong.vhd in a component definition. I've included the relevant snippets to the left - note the six ports on the component definition, of which we only truly care about data_1 and data_2 with regard to the paddle movement. Farther down the file, the entity is mapped more definitevly, where we discover that the data_1 signal is discarded altogether and the data_2 signal is redirected to another standard logic vector, 'adout'. This signal is only used once in the entire program, shown to the left as the final line where it is used to set the state of an 11-bit 'batpos' signal. This seemed to be the easiest point in the program to manipulate the signal and reroute control of the bat motion.
Now that a bottleneck in the code had been identified, it's time to implement a new process to control the position of the bat, controlled single-handed by the 'batpos' vector. The first order of business is adding new headers to the constraint file, allowing us to measure input from the BTNL and BTNR buttons - these headers are shown to the right (top). The remainder of our edits will take place in the pong.vhd source, where BTNL and BTNR must both be added as input STD_LOGIC signals to the entity.
In order to manipulate the batpos signal, we will create a new process, 'movepaddle', within the architecture of our 'pong' entity. This function must accomplish two objectives:
Two separate additions are shown to the right below the constraint file addition; we have an integer signal, 'prescalar' added to the signal declaration section, and a complete batmove process shown below this. The movebat process takes five inputs on its sensitivity list; the system clock (clk_in), our new prescalar integer (prescalar), the hardware interface for the left and right buttons (BTNL & BTNR), and the 11-bit variable determining the position of the bat (batpos). The process has three nested IF blocks; the first listens for a rising clock edge - nothing happens for the remainder of the clock cycle. The next IF block tests the prescaler value and is responsible for slowing our process down; the process increments the counter if it is not equal to our set scalar (250K in my code); otherwise, the prescalar is reset and the final IF block is executed. Here, an IF/ELSIF pair tests both BTNL & BTNR, and uses the conversion functions from the IEEE library to convert the 11-bit 'batpos' into a value, de/increment the value accordingly, and recast it as a standard vector before reassigning it to the batpos signal.
Overall, this design experiment was incredibly successful. Whereas I was initially unable to test Lab 6 due to the absence of the necessary hardware, I've now been able to mess with the code and test the program.
There are three labs in this course that require specialized PMOD hardware - Lab 6 was selected due to the relative simplicity of its circuitry (Lab 4 requires a 16bit DAC keypad, and Lab 5 requires a chip with a 3.5mm output [although the A7 board has a 3.5mm port; maybe it could be used instead]). This design decision was made when a physical emulation circuit was still under consideration, but still stands to reason with the entirely-VHDL design.
I am proud of my code, but there are still areas to improve on; I leave these notes for future students who may want to advance this project:
As the Covid19 crisis doesn't seem to be anywhere near its end, students in the next academic year may not have access to all the same hardware we would traditionally have at Stevens. Hopefully, this project provides a tool these students can use to optimize their learning in quarantine.
Project files can be found in my Lab 6 GitHub - I've gone ahead and pushed the updates from this project to the repository.