1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-01-30 02:32:53 +08:00
oh/docs/verilog_faq.md

119 lines
1.9 KiB
Markdown
Raw Normal View History

2015-10-14 23:11:07 -04:00
----
2015-10-15 11:00:52 -04:00
## How to create a "Hello world" in verilog?
```verilog
module hello();
initial
begin
$display ("Hello World!");
end
endmodule
```
2015-10-14 23:11:07 -04:00
----
## How to write a verilog testbench?
2015-10-15 11:00:52 -04:00
EXAMPLE
2015-10-14 23:11:07 -04:00
----
## How to run a verilog simulation?
2015-10-15 11:00:52 -04:00
```
EXAMPLE
----
## How to write a state machine?
EXAMPLE
2015-10-14 23:11:07 -04:00
----
2016-01-13 15:30:15 -05:00
## How to create a synchronous reset flip-flop?
2015-10-14 23:11:07 -04:00
```
always @ (posedge clk)
if(reset)
q <= 1'b0;
else
2016-01-13 15:30:15 -05:00
q <= d;
2015-10-14 23:11:07 -04:00
```
2015-10-15 11:00:52 -04:00
EXAMPLE
2015-10-14 23:11:07 -04:00
----
2016-01-13 15:30:15 -05:00
## How to create an asynchronous reset flip-flop?
2015-10-14 23:11:07 -04:00
```
always @ (posedge clk or posedge reset)
if(reset)
q <= 1'b0;
else
2016-01-13 15:30:15 -05:00
q <= d;
2015-10-14 23:11:07 -04:00
```
----
## How to synchronize a reset across clock domains?
2016-01-13 15:30:15 -05:00
[EXAMPLE](http://github.com/parallella/oh/common/hdl/oh_dsync.v)
2015-10-14 23:11:07 -04:00
----
## How to print a number/string with no leading white space?
```
$display("%0s\n", mystring);
```
----
## How to check for 'X' in test environments?
```
if(fail===1'bX)
```
2016-01-13 15:30:15 -05:00
[REFERENCE](http://www.sutherland-hdl.com/papers/2013-DVCon_In-love-with-my-X_paper.pdf)
2015-10-15 11:00:52 -04:00
----------------------------------------
## How to access hierarchical signals?
2016-01-13 15:30:15 -05:00
Use "."
2015-10-15 11:00:52 -04:00
----------------------------------------
## How to dump a waveform?
```
initial
begin
$dumpfile("test.vcd"); //file name to dump into
$dumpvars(0, top); //dump top level module
#10000
$finish; //end simulation
end
```
To dump the waves in .lxt2 format for gtkwave, set the following at the command line.
```
setenv IVERILOG_DUMPER lxt2
----------------------------------------
## How to initialize a memory from a file?
----------------------------------------
## How to view a waveform?
```
sudo apt-get install gtkwave
gtkwave test.vcd
```
-----------------------------------------
## How to reduce typing in emacs?
2016-01-13 15:30:15 -05:00
Use Verilog mode
2015-10-15 11:00:52 -04:00
-----------------------------------------
## What are the most important emacs mode keywords?
* /*AUTOARG*/
* /*AUTOINST*/
* /*AUTOWIRE*/
* /*AUTOINPUT*/
* /*AUTOOUTPUT*/
* /*AUTOTEMPLATE*/
2016-01-13 15:30:15 -05:00
2015-10-14 23:11:07 -04:00