I signed up for HackerBoxes back in November of 2015, so I’ve been with them for their monthly electronics boxes almost from the beginning. Some of the boxed electronics kits have been better than others. Some have had fairly well-defined projects. Others, like #12, seemed to leave some folks scratching their heads on how to proceed. At least so it seemed on HackerBox’s official Instructable page.
The #12 HackerBox is all about digital logic, and included in the kit (among other components) are digital ICs as well as an Altera Max II EPM240T100C5N CPLD Development Board aka “CPLD C-M240”. Other than some links to Altera’s free version of the development software and a link to a PDF for the MAX II’s schematics and pins, there was not much given in the way of project instructions.
I’ve read about FPGAs and CPLDs, but getting to play with the CPLD Dev Board was a first for me, and in a way, I’m glad HackerBoxes forced me to dig into it on my own instead of giving me a set project to follow. So what follows is the crash course I took to start learning about the MAX II EPM240.
HackerBoxes suggested implementing digital circuits for the Max II using the Schematic Capture tool included with Quartus Prime Lite or to go the Verilog/VHDL route. I tried some different examples with both the Schematic Capture tool and Verilog, however, I left the VHDL alone…maybe some other time.
Before moving on to the examples, I should mention that the USB Blaster used to program the Dev Board seems a little finicky under Linux (at least with Ubuntu 16.0.4). Most of my issues appeared to be related to getting user permissions set up properly for the daemon that interfaces between the USB Blaster and the USB driver. Fortunately, the world is full of people smarter than I am, and I found some help for fixing the permissions issue at: http://www.fpga-dev.com/altera-usb-blaster-with-ubuntu/.
Create a New Project
Setting up a project in Quartus Prime Lite, is fairly straightforward. First, start a project by clicking “File”->”New”->”New Quartus Prime Project”.
Click through with “Next” until you reach the dialog page titled “Directory, Name, Top-Level Entity”. Here, give your project a directory to live in as well as a name. I’ll create a schematic for lighting up a LED on the Dev Board, so I’ll call my file “basic_led”. I’ve also gotten in the habit of creating all the output files in a subdirectory of the project directory named “output_files”.
Click through with “Next” again until you reach the dialog page titled “Famly, Device & Board Settings”. Select “Max II” under the “Family” dropdown, and then scroll through the boards under “Available Devices” until you can select the EPM240t100C5. Click through with “Next” and then click “Finish”.
Creating the Schematic
To start a schematic, click “File”->”New”->”Block Diagram/Schematic File”. This will open up the schematic editor in the middle of the Quartus Prime Lite screen. For the simple circuits I implemented, the process was the same for both the Schematic and the Verilog approach – design the circuit, and then assign the pins. In this example, I am simply going to light up one of the LEDs on the C-M240 Dev Board.
The Dev Board has 8 LEDs built-in to the board which are connected to PIN_51 through PIN_58. One side of each LED is already tied to 3.3V via a 1.5K resistor leaving just a connection to ground to complete the circuit. To get the components click the “Symbol Tool”, then navigate through the library folders to reach “primitives->other->gnd”. Select the “gnd” symbol and then left click in the editor screen to place a copy of the “gnd” symbol.
Select a symbol for the output buffer and output pin as well by clicking the “Symbol Tool” and navigating through the symbol library to select: “primitives->buffer->alt_outbuf” for the output buffer and “primitives->pin->output” for the output pin. Place a copy of these symbols in teh editor screen as well.
Now I can connect the pieces together to create the circuit needed to pull PIN_51 low so the LED at PIN_51 will light up. This is pretty intuitive, but you basically just click and drag the wires until the connect. You’re essentially creating a circuit that says you want a low output on one of the CPLD’s pins. We will define exactly which pin that is in just a minute. The end result should look like this:
Unused Pins and Compiling
I need to compile the schematic, but before I do that I am going to go back and set all unused pins to a state so that when I do load the program to the board, everything works as expected. To do this, I double click on the board name “MAX II: EPM240T100C5” on the left side of the screen.
This will bring up the “Device” screen. Click the “Device and Pin Options…” button, and then select “Unused Pins” under “Category”. Next to “Reserve all unused pins:”, select “As input tri-stated”. Click “OK” and then “OK” again to get back to the editor screen. Just to be clear, this is what I used to avoid everything on the C-M240 Dev Board from lighting up and the alarm buzzer wailing away non-stop.
Save your project. Now that the unused pins are set, I’ll compile the schematic using the “Start Compilation” button. You may get some warnings about using an unregistered version and missing pin assignments, but hopefully no errors.
Assigning Pins to Inputs/Outputs
Once the compilation is complete, I can assign the pins for the project, and then re-compile. Setting the pins is done by clicking the “Pin Planner” in the top toolbar.
Next, I can assign pins to the inputs/outputs in the schematic. For this project, I only have one output pin which is connected to the LED I want to turn on – PIN_51. With the “Pin Planner” dialog screen open, there is a table at the bottom of the screen. Clicking the dropdown labeled “Location” allows me to choose PIN 51. Clicking again anywhere in a blank area of the “Pin Planner” dialog screen will update the large chip schematic in the middle of the screen. At this point, I am done with the pin assignments, so I can just close the dialog and save the project. Last, I compile again using the “Start Compilation” tool.
Programming the Board
The last step is to program the board by clicking the “Programmer” tool. Double check to be sure that the USB-Blaster is selected next to “Hardware Setup”. Add the “basic_led.pof” file (in my case the file is in the “output_files” directory), and click the top check box under “Program/Configure”. Finally, click “Start” and the program should load resulting in the awe-inspiring illumination of the LED at PIN_51.
My plan is to add a few more examples using Schematics, and then add a few using Verilog. Please keep in mind that these examples are from a beginner’s perspective, and there’s bound to be some mistakes on my part, but hopefully, they’ll help out some other beginner just starting out with the C-M240 Development Board.