Lab 4 Latest
Lab 4 Latest
Lab 4 Latest
452
1. Pre-lab
In
the
pre-lab
you
will
do
some
filter
generation
using
fdatool
and
get
to
see
some
of
the
effects
of
quantization
on
the
transfer
function.
In
addition
you
will
learn
a
bit
of
new
Verilog
syntax.
Notice:
You
may
do
the
two
last
problems
with
your
lab
partner.
EECS 452 assign coef[0] = 11; assign coef[1] = 28; assign coef[2] = 15;
Where coef[x] is the xth coefficient of the FIR filter. Q5. Attach the code you used to generate the coefficients in the format shown above. You do not need to attach the actual coefficients to your pre-lab report but you will need them for the in- lab part. Q6. What is the largest (in terms of absolute value) integer value you have as a coefficient? The smallest? What is the largest Q value you could have used to represent these coefficients (assuming you continued to use 16-bits)?
More
Verilog
Consider
the
following
Verilog
code.
Assume
that
the
module
bh
takes
a
4-bit
input
and
generates
the
corresponding
hex
digit.
module lab4( input [17:0]SW, input [3:0] KEY, output [7:0] HEX0, output [7:0] HEX1, output [7:0] HEX2, output [7:0] HEX3 ); reg reg reg reg [3:0] [3:0] [3:0] [3:0] a; b; c; d;
always@(negedge KEY[0]) begin a<=SW[3:0]; b<=a; c<=b; d<=c; end bh bh bh bh one two three four (a,HEX0); (b,HEX1); (c,HEX2); (d,HEX3);
endmodule Q7. Consider the above code. a. Describe how you would expect the code to behave. Be detailed. 1/25/2012 9:09 PM V1.5 Page 2 of 10
EECS 452
Lab 4: DSP on the DE2-70 FPGA board b. How would it be different if the <= in the always block was changed to a =?
reg [3:0] delay [4:1]; integer i; always@(negedge KEY[0]) begin delay[1]<=SW[3:0]; for(i=2;i<4;i=i+1) begin delay[i] <= delay[i-1]; end end endmodule
You
can
do
by
doing
something
like
bob=delay[4]
and
then
referencing
bob[2]
The
two
basic
options
are
to
flatten
the
array
of
busses
into
a
big
bus
or
to
use
SystemVerilog.
SystemVerilog
is
to
Verilog
as
C++
is
to
C.
It
is
a
much
more
complex
but
darn
useful
expansion
of
the
language.
2 1
Page 3 of 10
EECS 452
This does exactly the same thing as the code referenced in Q7. Q8. Consider these two ways of implementing the same functionality. a. What are the advantages of the second scheme (with the for loop and array of busses) over the first? b. When would you really want to use the for loop? c. What might be an issue/worry with using the for loop solution?
PMod
converters
Thus
far
we
have
been
using
audio
inputs
and
outputs
to
do
digital
conversion.
This
has
some
clear
downsides
as
we
are
stuck
with
filters
that
are
typically
associated
with
audio
(generally
things
less
than
7Hz
and
greater
than
20
kHz
get
filtered
out).
Now
we
are
going
to
learn
to
use
two
boards:
PmodDA2
and
PmodAD1.
Documentation
is
available
at
http://digilentinc.com/Data/Products/PMOD-AD1/Pmod%20AD1_rm.pdf
http://www.digilentinc.com/Data/Products/PMOD-DA2/PMod%20DA2_rm.pdf
Q9. For the PmodDA2: a. For each male pin, describe what each pin does. Provide more than just a signal name: describe what role the pin plays. b. As part a of this question, but for the female pins. Q10. Find the datasheet for the ADC. What is the fastest sclk could be according to the specification? (Hint: you should search for the datasheet for the ADC chip instead of the reference manual for the Pmod provided above.) Q11. Do these two Pmod devices use SPI? Q12. Write a Verilog module which implements a 3-tap direct form FIR filter. It should use 16-bit Q15 for its input, coefficients and output. Let the coefficient b[0]=0.333, b[1]=-0.25, and b[2]=0.125. Name the input x, the output y and the clock clk. Do not use a for loop or an array of busses. This problem will be graded fairly generously given that you arent expected to test your solution. Just think about how it should be written and you dont have to worry about rounding. You may do this problem with your lab partner.
Page 4 of 10
EECS 452
2. In-lab
In
labs
1
and
2
we
did
filtering
and
a
bit
of
other
signal
processing
using
a
processor.
In
this
lab
we
will
use
do
similar
tasks
on
an
FPGA.
You
should
come
out
of
this
lab
getting
a
sense
for
what
works
well
on
an
FPGA
and
what
its
limitations
are.
The
DE2-70
board
has
a
number
of
I/O
devices
including
switches,
buttons,
LEDs,
an
LCD,
and
GPIO.
It
also
has
an
audio
CODEC
chip.
Well
use
that
chip
to
input
and
output
waveforms
so
we
can
see
if
our
filters
are
working.
This
in-lab
consists
of
a
number
of
components:
Testing
the
ADC
and
DAC,
writing
a
simple
3-tap
low-pass
filter
from
scratch,
using
a
larger
direct-form
FIR
filter,
converting
that
filter
into
transposed
form
and
finally
some
more
advanced
DDS
work.
Page 5 of 10
EECS 452
Q4. Our ADC inverts the input so in order to avoid a 180 degree phase shift between the input and output, we have to negate the input values before feeding to the output. Given that, what else do you think the lines below are doing? always@(negedge AUD_DACLRCK) DataOut<= (DataIn == 16'h8000) ? 16'h7fff:-DataIn; Change the code above to the code below and look at a 50Hz sine wave with Vpp = 1 V. always@(negedge AUD_DACLRCK) DataOut<={-DataIn[15:13],13'd0}; Q5. What happens? Explain what that code is doing and why the output changes as it does.
Page 6 of 10
EECS 452
Look over the code and diagrams and figure out where to connect the ADC Pmod. Once again power off the FPGA board before you connect anything. Have your GSI confirm that youve connected the Pmod correctly. Now, revert your changes you made for G1 (it may be easiest to just re-download the code). The code should be set up to send the data received by the ADC to the DAC. Input a reasonable signal (in particular being sure to keep the signal sent to the ADC in the 0-3.3V range by setting the offset to be 1.65 Vdc). Q8. What is the approximate delay from the ADC to the DAC output? Q9. Change the input signal to 20 KHz, measure gain and phase and compare to your results in Q1(d).
EECS 452
Q13. What type of filter (lowpass, bandpass, highpass) do we have? What are the cutoffs? Next we will look at the worst-case combinational logic delay. Its a bit tricky to get to. Click on the Start TimeQuest Timing Analyzer icon on the top of the screen. It may take a few seconds to run. Then click on the TimeQuest Timing Analyzer icon that is right next to the previous icon. The TimeQuest tool will pop up. Find the tasks window (left middle). Scroll down in that window until you find the Report Path option.
In the window that pops up, click on Report Path and after a few moments you will see the worst case path. The time units are nanoseconds.
Q14. What is the worst case delay for this design? Where does it start and where does it end? Next, well gather a few more data points about resource utilization and delay scaling with filter size. Replace the coef.v file with the coefficients you generated in pre-lab Q5 and make any other necessary changes. Build your project (which may take a while). You can work on the next question in the meantime. G3. Demonstrate your filter to your GSI. Q15. Look at the code and explain why sum is computed using a blocking assignment while delay is computed using a non-blocking assignment. Q16. For your answer to G3, what did the utilization of resources look like? Did it scale in a reasonable way given the order of the filter? How about the worst-case path? Build and implement the filter shown below. Notice the maximum gain expected and test to see what actually happens for that frequency.
Page 8 of 10
EECS 452
Now, consider the code below (found in FIR.v). What does it do? Think carefully about what Q value is associated with sum and what Q value is associated with y. Modify the code so that when SW[0] is on, y is just equal to sum[30:15] and when SW[0] is off y is assigned as below and rebuild your filter. assign y = (sum[31:30]==2'b10) ? 16'h8000: (sum[31:30]==2'b01) ? 16'h7fff: sum[30:15]; G4. Demonstrate your code. Explain to your GSI what is going on and how your code demonstrates the purpose of the code segment above. Now rewrite the FIR filter in transposed form and use the same coefficients as in G3. G5. Demonstrate and show your code for your transposed form FIR filter. Q17. Answer the following questions. a. What is the worst-case path for your design? How does it compare to the direct form? Does that seem reasonable? Try to explain the results as best you can. b. What about the utilization of resources? Any change with respect to the direct form? Does this seem reasonable? Try to explain the results as best you can. 1/25/2012 9:09 PM V1.5 Page 9 of 10
EECS 452
The FIR filter is currently running at 48 kHz. Modify the code so that its running at 100 kHz. Q18. What is the new cut-off frequency? G6. Demonstrate your modified filter to your GSI and explain how you would calculate the new cut- off frequency based on the original filter coefficients.
3. Post-lab
Q19. The
signal
processing
we
can
do
with
the
audio
inputs
and
outputs
on
the
DE2-70
and
the
C5515
USB
stick
are
fairly
limited
due
to
filters
built
into
those
devices.
Why
do
you
suppose
those
filters
are
there?
Q20. Consider
the
worst-case
delay
you
found
for
the
largest
filter
you
built.
a. What
speed
(in
Hz)
could
it
in
theory
run
at?
Assume
you
need
to
add
5ns
(total)
to
deal
with
clock
skew,
latch
delay
and
setup
time.
b. Give
a
rough
idea
how
that
compares
to
the
C5515
doing
a
similar
sized
filter.
Page 10 of 10