Wentworth Institute of Technology

Department of Electrical Engineering and Technology

Elec 667 Advanced Programmable Logic

Binary Count with 7-segment display


Objective: Students implement the seven segment display feature provided in the binary count template.


Reference Text: DE2 User Manual


Materials: DE2 Evaluation Board



  1. Begin a new project naming it Lab4 with its own folder under the Altera folder on the C drive.
  2. The SOPC should be set up as seen below with a 20 Kbyte on-chip memory, 16-bit wide output data bus for two 7-segment displays, and the 8 bit led output bus.


Figure 1 Our hardware SOPC design.


  1. Generate the SOPC design, add it to the project with I/O pins and bus connections as needed.Note that the clock input is a bus of 1: PLD_CLOCKINPUT[1] and the output pins are named the same as mentioned in the comments section of the Binary_count C program.


Figure 2 Basic design


  1. Compile the design for the first time.
  2. Next open up the DE2 User Manual and start adding the pin outs to the outputs.The section of the manual for the green LEDs is reproduced in Figure 3 for your convenience.


Figure 3 Pin outs for the LEDs green.


  1. Try using the Pin Planner for the pin assignments.Double left click on the location cell to open up the selections options then just type the alphanumeric value and the software will fill in the PIN designation automatically.
  2. In order to get the least significant bit to the right on the board, copy the pins according to each bit assignment as seen in Figure 3. In other words, led_pio[0] is Pin_AE22


Figure 4 Pin outs for the 7-segment displays from the User Manual.


  1. The seven segment display assignments are different from what is shown in the User Manual.The bus has to be 16 bits wide.Bits 0-6 of seven_seg_pio are for HEX0, the right most display for the least significant decimal numbers.An eighth bit, seven-seg_pio[7] for the decimal point is unassigned. The second display aligns HEX1 bits 0-6 with seven_seg_pio[8-14] with the eight bit seven_seg_pio[15] unassigned.


Figure 5 Using the Pin Planner to make pin assignments


  1. Because we made the clock input a bus of width 1, we can assign pins using the Groups section.Close out of the Pin Planner reveals all the pins assignment on the *.bdf.Compile the project a 2nd time saving the changes (the pin outs) before downloading the design to the DE2 Board.

Figure 6 Assignments posted on the design.They may appear in a different order from Fig. 5.


  1. After downloading the design to the DE2 board open up Eclipse using the button in the SOPC builder.For those students using the OPEN Web licenseóthis instruction should occur in the reverse order.


Figure 7 Change the workspace if needed to the folder you created for this project.


  1. Start a new application.


Figure 8 Begin a new application and BSP from Template.


  1. Find the correct *.sopcinfo file by changing folders if necessary, add a version designation to the name of the project and select the Count Binary template.


Figure 9 Setting up the software parameters.

Figure 10 Verifying that the C program is present.


  1. Once we get the process down pat, we can start writing our own C programs.
  2. We now have to insure that the program will fit into the memory space we made available during the hardware portion of the design.Begin by selecting the Board Support Package for Count_binary_v1 in the Project Explorer panel then right click to select Properties.


Figure 11 Several items to check and uncheck.


  1. Once the Properties box opens select Nios II BSP Properties from the navigation list under the Settings Tab.†† Check off Reduced device drivers and Small C library and uncheck Support C++. Click on the Apply button so these choices are propagated in the BSP then click on the BSP Editor Button to verify that the choices propagated.


Figure 12 Two items are selected under the Setting Tab.


  1. This verifies that the enable_reduced_device_drivers and enable_small_C_library were selected.You can additionally check under the Common>>hal folder that the options are enabled.


Figure 13 Enabled.


Figure 14 Enabled.


  1. Finally, make sure under the Drivers Tab that the small JTAG UART drivers is not Enabled; this turns off your outputs and is different from the small drivers selected previously.


Figure 15 Uncheck the enable_small_driver box.


  1. Next click the Generate button in the lower right and close the window.
  2. If you didnít click on the Apply button previously, double-check that the C++ box is not selected.If it is, go thru these steps again selecting and deselecting the options.
  3. Now select the Count_binary_v1 folder itself, right click and click on Build Project.


Figure 16 After finishing the BSP, you build the project.


  1. This will take a bit of time for Eclipse to write all the files used by the project.In the Console window is the report information.Sometimes it contains good news and other times it tells you what is wrong with the project; so read carefully what it is telling you.


Figure 17 This was a successful build!


  1. Anyone completing this Lab without the DE2 Board such as students in their dorm rooms should be able to get to this point without wasting time in their Lab period.
  2. Next, we use the same click path only this time we select Run As>> Nios II Hardware.


Figure 18 Just about to test the software on the hardware.

  1. The opening screen may or may not convey disappointing news usually about the System ID.


Figure 19 This is a successful read of the microprocessor loaded onto the DE2 Board.


  1. Before clicking on Run, check that the Target Connection Tab to see if the USB is connected properly.


Figure 20 Connection information and more.


  1. On this tab, you can always refresh if the USB hasnít released yet if you didnít close out of the programmer when you downloaded the hardware design to the board.You can also check here for troubles related to System ID.
  2. This program is ready to go so click on Run.


Figure 21 Console window show the program starting address.If you accidentally checked off enable_small_driver mentioned in Figure 15, this is all you will see.I stared at a blank screen for several days before solving his problem.


  1. I had a number of errors that I had to clear in the troubleshooting phase of my design:
    1. I had named the output port different from what the software required so the program was running but it was calling on ports using alias that didnít exist in the hardware.
    2. The second error was that I didnít set the JTAG UART port IRQ to 16 so the system was hung up in the interrupt section of the code.
  2. Both of these errors I had to go back to Quartus II and make the changes in the SOPC, regenerate, compile and download the hardware then delete and recreate the software each time.
  3. While writing this lab I learned that either of the Nios II/e or the Nios II/s cores will work with the software and fit into the 20 Kilobyte on-chip memory.
  4. To run the count slower change the value of the usleep function in the count_binary.c main(void) from 100000 to a larger number.


Figure 22 Adding a zero to the delay.


  1. The two seven-segment displays were totally messed up until it was discovered that an eight bit needed to be allowed for each display and left unassigned.This information took about two weeks to discover.
  2. I learned that I could make changes to the hardware, such as the pin outs in Quartus but not the SOPC, compile the changes, download the changes to the DE2 Board and then go back to Eclipse and by selecting Run As>>Nios II Hardware, observe the changes.This was a reasonably quick process.
  3. For your lab report,
    1. turn in your analysis of your attempt to make this program run
    2. appropriate screen shots and
    3. demonstrate the operation of this lab to your instructor.††