Wentworth Institute of Technology
Department of Electrical Engineering
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
- Begin a
new project naming it Lab4 with its own folder under the Altera folder on
the C drive.
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
Figure 1 Our hardware SOPC design.
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 and the output pins are named the
same as mentioned in the comments section of the Binary_count C program.
Figure 2 Basic design
the design for the first time.
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.
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.
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 is Pin_AE22
Figure 4 Pin outs for the 7-segment displays from the User
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 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
Figure 5 Using the Pin Planner to make pin assignments
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
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.
- Start a
Figure 8 Begin a new application and BSP from Template.
the correct *.sopcinfo file by changing folders if necessary, add a
version designation to the name of the project and select the Count Binary
Figure 9 Setting up the software parameters.
Figure 10 Verifying that the C program is present.
- Once we
get the process down pat, we can start writing our own C programs.
- 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.
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.
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.
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
Figure 15 Uncheck the enable_small_driver box.
- †Next click the Generate button in the
lower right and close the window.†
- 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.
select the Count_binary_v1 folder itself, right click and click on Build
Figure 16 After finishing the BSP, you build the project.
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!
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
we use the same click path only this time we select Run As>> Nios II
Figure 18 Just about to test the software on the hardware.
opening screen may or may not convey disappointing news usually about the
Figure 19 This is a successful read of the microprocessor
loaded onto the DE2 Board.
clicking on Run, check that the Target Connection Tab to see if the USB is
Figure 20 Connection information and more.
- 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.
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.
- I had a
number of errors that I had to clear in the troubleshooting phase of my
- 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.
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.
- 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.
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
- 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.
- 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.
- 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.†
your lab report,
in your analysis of your attempt to make this program run
screen shots and
the operation of this lab to your instructor.††