ECE3073 2014 Lab 3
ECE3073 2014 Lab 3
1. Objectives
The first two laboratory exercises were based on machine code and assembler. Now you are moving on
to using C code. In this exercise you will investigate simple C code programming of the Nios processor
to write polling loops. This will require you to specify a more complex Nios processor system with
multiple input and output ports. You will then investigate the latency in responding to a service request
both theoretically using the instruction timings you found last week and practically using an
oscilloscope. For many real-time applications the speed with which a microprocessor system responds
to outside events is very important. This lab will give you an idea of the factors limiting response time
and how to measure it. In this exercise you will:
Equipment
DE2 FPGA Development Board
A USB memory device provided by you to store your design files
A 2 or 4 channel 1GS/s digital oscilloscope
Breakout pins to allow connection of CRO probes to DE2 board
2. Preliminary work
You must complete this preliminary work before attending the lab session.
Read through the whole of this document so that you understand all of the things you will be required
to do.
In this lab exercise you will add an always block to your top level Verilog file that generates a periodic
waveform and connect this to the PIO_in1 input. This can be achieved by using a simple 20-bit counter
triggered on the positive edge of CLOCK_50. The rising edge of the most significant bit can be used as
a request for service.
What is the frequency of this rising edge? Your answer ..
And what period does this correspond to (in milliseconds).
This is what your C code should do:
1) initialize registers with pointers to I/O ports, and any variables required
2) perform an infinite loop :
a) if there is a rising edge on the output of the most significant bit
of the counter:
write a 1 to GPIO_1[12], and then
increment an 8-bit binary number displayed on the 8 red LEDs
2
(LEDR[7:0]) and
write a 0 just before returning to the polling loop.
b) when Key1 is pressed then toggle the state of green LED (LEDG[1]). Note that it
is not guaranteed that reading an output port will return the last value you wrote
there (depends on the port architecture).
As part of your preliminary work write C code to implement the polling loop (further details are
provided later in this document). Of course you do not know port addresses yet so you can leave them
blank in you preliminary code.
/* Declare volatile pointers to I/O registers. This will ensure that the
resulting code will bypass the cache*/
volatile int * InPort_Key1 = (int *) 0x00003010;
// check port address
volatile int * OutPort_GREENLED = (int *) 0x00003020; // check port address
while(1)
{
SW_value=*(InPort_Key1);
// read Key1
*(OutPort_GREENLED) = SW_value; // transfer the value to green LED 1
4
}
You can use the Microsoft C development environment to write your C program but it will be
compiled in the Altera Monitor environment so dont compile it in the Microsoft C environment.
b) Using your oscilloscope measure the latency (Hint: use of single shot may help). Note that at low
digital oscilloscope timebase speeds very narrow pulses will disappear completely. Therefore, if you
cannot see a short pulse on the oscilloscope you should try increasing the timebase speed.
..
What do you think could account for any discrepancy between calculated and experimental values?
..
When you have complete the lab or when time is running out then start the assessment quiz
for this laboratory exercise. The demonstrator will enter the password and record your mark
(out of 5, one for each check box).
Ensure that your mark for this exercise is entered before you leave the lab.
Appendix A
Layout of DE2 board JP2 socket.
RAR
28/01/2014