random number generation section 3.10 section 4.12
DESCRIPTION
Observations from Last Thursday’s Lab (1) The verilog code should be saved in a *.v file, e.g. – fig3p37.v is the file name – to execute the simulation, you need to type verilog +gui fig3p37.v &TRANSCRIPT
![Page 1: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/1.jpg)
Random Number Generation
Section 3.10Section 4.12
![Page 2: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/2.jpg)
Outline• Observations from the last week’s lab• Anatomy of a Verilog Program• More about Verilog
– Including a file– Test a Module with a Random Sequence
• Example: NAND Implementation of a NOT Gate
• The NAND Implementation of a NOR Gate– Implementation Using 74LS00
![Page 3: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/3.jpg)
Observations from Last Thursday’s Lab (1)
• The verilog code should be saved in a *.v file, e.g. – fig3p37.v is the file name– to execute the simulation, you need to
type verilog +gui fig3p37.v &
![Page 4: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/4.jpg)
Observations from Last Thursday’s Lab (2)
Correction: Remove semicolon from the end of timescale line.
![Page 5: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/5.jpg)
Observations from Last Thursday’s Lab (3)
Correction: Use a backward quote (`), not a single quote (‘)
![Page 6: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/6.jpg)
Observations from Last Thursday’s Lab (4)
Definition of the module
fig3p37 is the module name.I1 is the instance of the module.
Comment: You need both modules!
![Page 7: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/7.jpg)
Observations from Last Thursday’s Lab (5)
System! Source file "fig3p37.v" cannot be opened for reading [Verilog-SFCOR]
Solution:[r2d2@localhost verilogSandBox]$ chmod 755 fig3p37.v
![Page 8: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/8.jpg)
Question
// comments out a line
![Page 9: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/9.jpg)
Question: How do I get the play button back?
If you comment out $stop and stop the simulation by using Initial #200 $finish, you will not get the play button.
What do you do then?
![Page 10: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/10.jpg)
Solution: Simulation ->Reinvoke Simulator
![Page 11: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/11.jpg)
Solution: Simulation ->Reinvoke Simulator
Select Yes
![Page 12: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/12.jpg)
You Get the Play Button Back!
Play button
![Page 13: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/13.jpg)
Review of What We have Learned
• A minimalist’s view of a verilog Module
• A minimalist’s view of a module test bench
![Page 14: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/14.jpg)
Anatomy of a Verilog Module
module fig3p37 (A,B,C,D,E);output D,E;input A,B,C;wire w1;
and G1(w1,A,B);not G2(E,C);or G3(D,w1,E);
endmodule
![Page 15: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/15.jpg)
module....endmodule
module fig3p37 (A,B,C,D,E);output D,E;input A,B,C;wire w1;
and G1(w1,A,B);not G2(E,C);or G3(D,w1,E);
endmodule
Always start the verilog programwith the keyword pairmodule…endmodule
The keyword module must always be terminated by the keywordendmodule.
![Page 16: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/16.jpg)
output/input
module fig3p37 (A,B,C,D,E);output D,E;input A,B,C;wire w1;
and G1(w1,A,B);not G2(E,C);or G3(D,w1,E);
endmodule
1. output/input2. wire
![Page 17: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/17.jpg)
Program Body
module fig3p37 (A,B,C,D,E);output D,E;input A,B,C;wire w1;
and G1(w1,A,B);not G2(E,C);or G3(D,w1,E);
endmodule
Program body
![Page 18: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/18.jpg)
Anatomy of a Test BenchTest Bench
1. `timescale2. module module_tb (, , ,)…endmodule 3. ouput,reg4. Invoke the module5. Define the input vector
![Page 19: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/19.jpg)
Use `include to reference a file
Troubleshooting Exercise:verilog +gui fig3p37.v &
![Page 20: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/20.jpg)
Introduce a Random Test Vector• flip_me function
Q: What is the function of this module?
![Page 21: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/21.jpg)
flip_me_tb.v• Test Bench Definition: Feed a random
sequence of binary numbers to flip_me.v
A=random inputB=flipped version of A
![Page 22: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/22.jpg)
Test Bench for flip_me.vReference: Mano page 170-174.
![Page 23: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/23.jpg)
`timescaleComment out time scaleEach time interval is one second.
![Page 24: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/24.jpg)
include flip_me.v
![Page 25: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/25.jpg)
Define outputs,regWe will read random numbers from a file.The random numbers are stored in t_A.vectornum is the index of the t_A.At the falling edge of the t_clock, a randomnumbers stored in t_A is transferred to A.
![Page 26: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/26.jpg)
flip_me.v is called.
![Page 27: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/27.jpg)
1000 time intervals will be simulated.
![Page 28: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/28.jpg)
Clock Generation
t_clock is initially 0.t_clock is flipped every 5 time intervals.The period of t_clock is 10 time intervals.
![Page 29: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/29.jpg)
Read numbers from an input file
Random number is stored in t_A.
![Page 30: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/30.jpg)
Update at NegEdge of t_clock
At negative edge of t_clock,transfer the random number fromt_A to A.
![Page 31: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/31.jpg)
Monitor Numbers
Monitor numbers
![Page 32: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/32.jpg)
Waveforms
![Page 33: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/33.jpg)
Run Verilog Using Command-line
$monitor only displays the results when A changes.Actual sequence: 101011001011…
![Page 34: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/34.jpg)
Implement NOR with NANDs
C
D
E
F
A, B as inputs C,D, E as wiresF as output
G1
G2
G3 G4
![Page 35: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/35.jpg)
nor_with_nand.v
![Page 36: Random Number Generation Section 3.10 Section 4.12](https://reader035.vdocument.in/reader035/viewer/2022062413/5a4d1b307f8b9ab05999afba/html5/thumbnails/36.jpg)
nor_with_nand_tb.v
Use flip_me_tb.v as a guide. Complete the code for nor_with_nand_tb.v