This is part four in a series of beginner tutorials for the C-M240 Development Board that was included with HackerBoxes #12. For a complete beginner like myself, figuring out how to use the Verilog code with the block schematics in Quartus Prime Lite was a bit of a pain, but once I figured out the correct procedure, it was really pretty easy. Also, as a side benefit, I can now save my commonly used Verilog code blocks in a directory which I can then include as symbols with new projects, thus saving me the time of recreating them again.
My original problem was that I wanted to include a clock signal which I had created using Verilog into my block schematic. Here is the process that worked for me:
Create the Verilog Code for a Clock
Create the Verilog code for the clock first so we can use it in a block schematic. Create a “New Project” as described in Tutorial Part 1. Give the project a name like “myClk”. By default, this becomes the name of the top-level entity. Be sure that the top-level entity and the name you use for your module match or it won’t compile.
Once the project is done setting up, select “File->New->Verilog HDL File”. In the text editor, add the following code for the clock and save the file as “myClk.v” :
// Verlilog code block for a clock
// Be sure your top level entity and module name match!
module myClk(input clk, output reg clkOutput);
reg [22:0] counter;
always @(posedge clk)
if(counter==5000000) counter <= 0; else counter <= counter+1;
always @(posedge clk)
clkOutput <= ~clkOutput;
This should create a clock with a frequency of 5 Hz and a 50% duty cycle. For more information on how to setup a frequency, check out the tutorial on blinking a led with Verilog. Be sure to set your unused pins to a state such “as input tri-stated”. Save and compile the project.
Create a Directory for Your Custom Symbols
Assuming there are no errors, go ahead and create a directory where you can start saving your custom symbols. You will be able to access these for your other projects when you need them. I’ll call my directory “jaspers_custom”.
Create the Custom Symbol and Save
In your open project, click the tab for “myClk.v” so that it is selected (you should be able to edit the code in the window). Click “File->Create/Update->Create Symbol Files for Current File”. The symbol will compile in a few seconds.
Now, go to your project directory and locate the *.bsf and *.v files and copy and paste them into you custom symbols folder you created earlier. In my case, the “myClk.bsf” and “myClk.v” files are in my “/output_files” directory, and I copy and paste them into the “jaspers_custom” directory.
The custom symbol is created, so go ahead and close up your current project, and we’ll create a new project to test the custom symbol out.
Create a New Project to Test the Custom Symbol
Create a new project with a new name, and click “Next” until you reach the “Add Files” dialog. This is where we’ll add the directory for our custom symbols. Click the “User Libraries…” button down at the bottom of the dialog screen.
After clicking “User Libraries…”, another dialog screen will open. Under “Global libraries (all projects)” click the “…” button to browse to your directory for your custom symbols. Click “Add”, and then “Ok”. Finish completing the project as you normally would.
Create a New Block Schematic
Once the new project setup is complete, we need to create a new schematic. Click “File->New->New Block Diagram/Schematic File”. Clicking on the “Symbols Tool” will open a dialog that should now show two directories from which to choose tools – one for the Quartus symbols, and another directory which should be your custom symbols directory created earlier. Inside your directory, you should see the custom symbol you created. My custom symbol is simply labeled “myClk”. Go ahead and select it, and place an instance of the symbol on your schematic.
Now generate pins for the ports on your imported Verilog symbol. Right click on the symbol in the block diagram, and select “Generate Pins for Symbol Ports”. You will now have an input pin for the global clock and an output pin added to your schematic. Save and compile.
Before you assign pins, be sure to set your unused pins to something like “as input tri-stated”. Use the “Pin Planner” tool to assign PIN_12 (global clock) for the input labeled “clk” and Pin_58 for the output labeled “clkOutput”.
Pin_58 is connected to an onboard LED which should flash at the clock frequency we defined in the imported custom Verilog symbol – 5 Hz. Save, compile, and use the “Programmer” tool to load the program into the EPM240T100C5N chip.
Your LED should now be flashing at 5 Hz. Not all that exciting, but the custom clock symbol could be used in other projects, and you won’t have to keep creating it every time.