Assignment 02
Multiple Signals
Assignment
Implement these gates, using these signatures:
Or16(inp_a, inp_b, out) Not16(inp, out) And16(inp_a, inp_b, out) Or8Way(inp_a, inp_b, inp_c, inp_d, inp_e, inp_f, inp_g, inp_h, out) Mux(select, inp_a, inp_b, out) DMux(select, inp, out_a, out_b) Mux16(select, inp_a, inp_b, out) Mux4Way16(select, inp_a, inp_b, inp_c, inp_d, out) Mux8Way16(select, inp_a, inp_b, inp_c, inp_d, inp_e, inp_f, inp_g, inp_h, out) DMux4Way(select, inp, out_a, out_b, out_c, out_d) DMux8Way(select, inp, out_a, out_b, out_c, out_d, out_e, out_f, out_g, out_h)
Each file should include both the gate and a value called tests
containing 5 or more test cases.
Ensure your filename matches the the name of the gate. For example:
filename | name of gate |
---|---|
Or16.py | Or16 |
DMux8Way.py | DMux8Way |
Refer to the 2nd half of Chapter 1, beginning around page 20, for more detail on Mux, Demux, and multi-bit gates.
Testing
Inside each .py file
See Mux.py or Or8Way.py for examples.
Each gate will be tested by comparing the actual outputs (from the myHDL block) with the expected outputs (from the test) for the given inputs.
filename | gatename | 5 tests |
---|---|---|
Or16.py | Or16 | [[0, 0, 0], [1, 0, 1], [2, 3, 3], [65535, 0, 65535], [65535, 1, 65535]] |
Mux.py | Mux | [[0, 1, 1, 1], [0, 0, 0, 0], [0, 0, 1, 0], [1, 0, 0, 0], [1, 0, 1, 1]] |
etc. |
- Or16 has 3 parameters (
inp_a
,inp_b
,out
) so each of its tests has 3 values. Also, because Or16 takes 2 16-bit values, its inputs are inrange(0, 2**16)
(minimum value 0, maximum value 65535). - Mux has 4 parameters, so each of its 5 tests has 4 values. Since it's a 1-bit Mux, each of the values in its tests are 0 or 1.
Provide a variable called tests
, which is a list containing 5 or more test cases.
Each test case is a list, with the same number of parameters as the gate.
For example, Mux.py looks like this:
# Mux.py from myhdl import block, always_comb @block def Mux(select, inp_a, inp_b, out): @always_comb def f(): out.next = inp_b if select else inp_a return f tests = [ # sel a b out [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 0, 1], [1, 0, 0, 1], [1, 0, 1, 1], ]
Another example, Or8Way.py is also provided for reference.
Run the autograder tests locally
You can download all the tests from here in order to test before submitting to the autograder. Test files have the same name as the gate files, but start with "Test".
To run:
cd
into the directory containing your files and the test scripts- then use
python3 TestName.py
from the terminal
cd ~/folder-where-you-saved-your-files-and-the-tests/ python3 TestAnd16.py python3 TestDMux4Way.py python3 TestDMux8Way.py python3 TestDMux.py python3 TestMux16.py python3 TestMux4Way16.py python3 TestMux8Way16.py python3 TestMux.py python3 TestNot16.py python3 TestOr16.py python3 TestOr8Way.py # alternatively, you can add verbose logging to unittest like this: python3 -m unittest -v TestMux.py
Note
Working implementations for Or8Way.py
and Mux.py
are already provided, and Test.py
is used by all of the TestGate.py
files, so don't remove it.