From babe8c3702bee5203a0cc062724706c2efbf57ac Mon Sep 17 00:00:00 2001 From: lshprung Date: Wed, 7 Oct 2020 11:35:55 -0700 Subject: Post-class 10/07 --- 7.md | 4 ++ 8.1.png | Bin 0 -> 11573 bytes 8.2.png | Bin 0 -> 8541 bytes 8.3.png | Bin 0 -> 8235 bytes 8.4.png | Bin 0 -> 19961 bytes 8.5.png | Bin 0 -> 17095 bytes 8.6.png | Bin 0 -> 3843 bytes 8.md | 206 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 210 insertions(+) create mode 100644 8.1.png create mode 100644 8.2.png create mode 100644 8.3.png create mode 100644 8.4.png create mode 100644 8.5.png create mode 100644 8.6.png create mode 100644 8.md diff --git a/7.md b/7.md index b577373..3e14a6e 100644 --- a/7.md +++ b/7.md @@ -79,3 +79,7 @@ - Green crosses touch, black crosses do not ![diagram](7.6.png) + +--- + +[Verilog basics ->](8.md) diff --git a/8.1.png b/8.1.png new file mode 100644 index 0000000..2e422fb Binary files /dev/null and b/8.1.png differ diff --git a/8.2.png b/8.2.png new file mode 100644 index 0000000..5690b81 Binary files /dev/null and b/8.2.png differ diff --git a/8.3.png b/8.3.png new file mode 100644 index 0000000..1f11778 Binary files /dev/null and b/8.3.png differ diff --git a/8.4.png b/8.4.png new file mode 100644 index 0000000..38f05f8 Binary files /dev/null and b/8.4.png differ diff --git a/8.5.png b/8.5.png new file mode 100644 index 0000000..a847432 Binary files /dev/null and b/8.5.png differ diff --git a/8.6.png b/8.6.png new file mode 100644 index 0000000..8a222c4 Binary files /dev/null and b/8.6.png differ diff --git a/8.md b/8.md new file mode 100644 index 0000000..6f67b68 --- /dev/null +++ b/8.md @@ -0,0 +1,206 @@ +[\<- Shannon's Expansion and FPGAs](7.md) + +--- + +# Verilog basics + +## Introductory Verilog concepts + +### Verilog + +- A language to specify hardware + - Hardware Description Language (HDL) +- Has many features of other programming languages but it does \*not\* execute sequentially like most languages do +- Can specify structure or behavior + - Structure is like an actual circuit; netlist + - Behavior would be like logic equations or truth table + - Can be synthesized into a specific structure + +### Verilog module + +- HW is always described inside a module + - Like a schematic +- Always at least one output, and then however many inputs the circuit consumes + - Referred to as ports + - Taken together this is called the interface +- Variable names are used to make connections, either from ports to internal circuitry or between circuit elements inside the module + +--- + +## Describing structure of 2:1 mux + +- Example: Inputs x1,x2, and s, and output f + - This is the interface +- Need to describe what's happening inside + - Need to describe how gates are connected + - Use Verilog primitives to describe structure + +![diagram](8.1.png) + +### Interfaces for primitves + +- AND (2-input example): + +``` +module and(y,x1,x2); + input x1,x2; + output y; +``` + +- OR (4-input example): + +``` +module or (y,x1,x2,x3,x4); + input x1,x2,x3,x4; + output y; +``` + +- NOT (always just one input): + +``` +module not (y,x); + input x; + output y; +``` + +### Structural example + +- A gate-level implementation of a 2:1 mux +- Ports connected by name association + - E.g., "k" connects the output of the NOT gate to one of the inputs to the first AND gate + +``` +module example1(x1, x2, s, f); + input x1, x2, s; + output f; + wire k, g, h; + + not(k, s); + and(g, k, x1); + and(h, s, x1); + or(f, g, h); + +endmodule +``` + +![diagram](8.2.png) + +- Note that the declaration of the wires in the above code is optional, but makes for good habit + - If not explicitly declared, `k`, `g`, and `h` would be implicitly considered wires by Verilog + +--- + +## Behavioral description of 2:1 mux + +### Behavioral code + +- Uses syntax like our boolean algebra equations + - `&` instead of `*` + - `|` instead of `+` + - `~` instead of `!` +- Keyword of `assign` means the equation is always evaluated, just like logic gates work + +``` +module example3(x1, x2, s, f); + input x1, x2, s; + output f; + + assign f = (~s & x1) | (s & x2); + +endmodule +``` + +![diagram](8.3.png) + +--- + +## Behavioral description of a more complex module + +- Describe this circuit, with outputs f, g, h + +![diagram](8.4.png) + +- Assign statements don't have to be in the order listed + - Specifying the behavior of a wire +- Also don't have to specify intermediate nodes + +``` +module example4(x1, x2, x3, x4, f, g, h); + input x1, x2, x3, x4; + output f, g, h; + + assign g = (x1 & x3) | (x2 & x4); + assign h = (x1 | ~x3) & (~x2 | x4); + assign f = g | h; + +endmodule +``` + +--- + +## Hierarchy in Verilog + +### Hierarchical design + +- Block diagram of two modules working together + - Outputs of adder module connected to inputs of display module + +![diagram](8.5.png) + +### Code for the adder + +- What is the truth table for a circuit that treats two inputs as numbers and adds them together? + +![diagram](8.6.png) + +``` +//An adder module +module adder(a, b, s1, s0); + input a, b; + output s1, s0; + + assign s1 = a & b; + assign s0 = a ^ b; + +endmodule +``` + +- Note that `^` is XOR in Verilog + +### Code for the display driver + +- Useful to work out the truth table in order to figure out the equations + +``` +//A module for driving a 7-segment display +module display(s1, s0, a, b, c, d, e, f, g); + input s1, s0; + output a, b, c, d, e, f, g; + + assign a = ~s0; + assign b = 1; + assign c = ~s1; + assign d = ~s0; + assign e = ~s0; + assign f = ~s1 & ~s0 + assign g = s1 & ~s0 + +endmodule +``` + +### Instantiating and connecting + +- Note the "wire" declarations for the internal (to this module) connections between adder and display + - Variables not part of interface definition + +``` +module adder_display (x, y, a, b, c, d, e, f, g); + input x, y; + output a, b, c, d, e, f, g; + wire w1, w0; + + adder U1(x, y, w1, w0); + display U2(w1, w0, a, b, c, d, e, f, g); + +endmodule +``` -- cgit