Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| learn:fundamentals:digital-logic:verilog-hdl-the-first-example:start [2016/08/09 16:45] – created Martha | learn:fundamentals:digital-logic:verilog-hdl-the-first-example:start [2022/10/04 11:38] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 19: | Line 19: | ||
| </ | </ | ||
| + | Indexing a bus in Verilog is similar to indexing an array in the C language. For example, if we want to index the second bit of sw bus declared above, we will use sw[1]. | ||
| + | |||
| + | ===== Assign Statement ===== | ||
| + | The assign statement in the example above assigns the signal value on the net “sw” to the net “led”. In implementation, | ||
| + | |||
| + | An assign statement can also be used to assign one signal of a bus to one signal of another bus. For example, if we declared sw as an 8-bit wide bus and LED as an 8-bit wide bus, and we want to use second switch to control fourth LED, the code will be: | ||
| + | |||
| + | <code vhdl> | ||
| + | module led_sw( | ||
| + | output [7:0] led, | ||
| + | input [7:0] sw | ||
| + | ); | ||
| + | assign led[3] = sw[1]; | ||
| + | ... | ||
| + | endmodule | ||
| + | </ | ||
| + | |||
| + | ===== Constants ===== | ||
| + | You can also assign a constant number to a signal or a bus to tie them to either logic ' | ||
| + | |||
| + | **<Width in bits>'< | ||
| + | |||
| + | For example: | ||
| + | ^ Constant in Verilog | ||
| + | | 12' | ||
| + | | 20' | ||
| + | | 4' | ||
| + | |||
| + | |||
| + | To tie a signal or a bus to constant, we can use assign statement as well. For example, if we are going to tie an 8-bit bus “seg” to ground, we will write: | ||
| + | |||
| + | <code vhdl> | ||
| + | module top ( | ||
| + | ... | ||
| + | output [7:0] seg, | ||
| + | ... | ||
| + | ); | ||
| + | assign seg = 8'd0; | ||
| + | ... | ||
| + | endmodule | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | ==== Important Ideas ==== | ||
| + | * Module in Verilog HDL acts like the bounding box in circuit schematic. | ||
| + | * Bus is a group of signals (wires). | ||
| + | * Assign statement passes the value of a signal/bus to another signal/bus. | ||
| + | * Constant in Verilog HDL is presented in form of **<Width in bits>'< | ||
| + | |||
| + | {{tag> | ||

