verilog实现串并及并串转换文档格式.docx
《verilog实现串并及并串转换文档格式.docx》由会员分享,可在线阅读,更多相关《verilog实现串并及并串转换文档格式.docx(12页珍藏版)》请在冰豆网上搜索。
Simulator
NC-Verilog5.4+Debussy5.4v9
6
Synthesizer:
QuartusII7.2
7
Description:
parallelinserialoutrtl
8
Release
Oct/24/20091.0
9
*/
10
11
modulep2s(
12
clk,
13
rst_n,
14
load,
15
pi,
16
so
17
);
18
19
inputclk;
20
inputrst_n;
21
inputload;
22
input[3:
0]pi;
23
outputso;
24
25
reg[3:
0]r;
26
27
always@(posedgeclkor
negedgerst_n)
28
if(~rst_n)
29
r<
=
4'
h0;
30
else
if(load)
31
=pi;
32
else
33
={r,1'
b0};
34
35
assignso=r[3];
36
37
endmodule
33行
r<
用Verilog實現shiftregister有很多種方式,但以33行這種方式最精簡,其他codingstyle可參考(筆記)如何將值delayn個clock?
(SOC)(Verilog)。
Testbench
p2s_tb.v/Verilog
p2s_tb.v
parallelinserialouttestbench
`timescale1ns/1ns
`include
"
p2s.v"
modulep2s_tb;
regclk;
regrst_n;
regload;
wireso;
initial
begin
load=
1'
b0;
pi=
#10;
load<
b1;
pi<
b1010;
#20;
end
initialclk=
always#10clk=
~clk;
rst_n=
#5;
38
39
40
41
42
$fsdbDumpfile("
p2s.fsdb"
43
$fsdbDumpvars(0,p2s_tb);
44
#150;
45
$finish;
46
47
48
p2sp2s_0(
49
.clk(clk),
50
.rst_n(rst_n),
51
.load(load),
52
.pi(pi),
53
.so(so)
54
55
56
模擬結果
串進並出(SerialInParallelOut)
serialdata依序送進shiftregister,當en為1時,一次將shiftregister內的資料送進parallelout。
s2p.v/Verilog
s2p.v
serialinparalleloutrtl
modules2p(
en,
si,
po
inputen;
inputsi;
output[3:
0]po;
8'
={r,si};
assignpo=(en)?
r:
4'
s2p_tb.v/Verilog
serialinparallelouttestbench
s2p.v"
modules2p_tb;
regen;
regsi;
wire[3:
en=
si=
//4'
b1010
s2p.fsdb"
$fsdbDumpvars(0,s2p_tb);
#200;
s2ps2p_0(
57
58
.en(en),
59
.si(si),
60
.po(po)
61
62
63
串進串出(SerialInSerialOut)
基本上串進串出沒有任何實用功能,只能當成delayn個clk用,與(筆記)如何將值delayn個clock?
(SOC)(Verilog)一樣,只是在此順便提及。
s2s.v/Verilog
serialinserialoutrtl
modules2s(
s2s_tb.v/Verilog
s2s_tb.v
serialinserialouttestbench
s2s.v"
modules2s_tb;
re