名稱:時(shí)分?jǐn)?shù)據(jù)交換系統(tǒng)Verilog代碼vivado仿真
軟件:vivado
語(yǔ)言:Verilog
代碼功能:
請(qǐng)?jiān)O(shè)計(jì)一個(gè)串行輸入、串行輸出的時(shí)分?jǐn)?shù)據(jù)交換系統(tǒng)。該時(shí)分?jǐn)?shù)據(jù)輸入如下圖所示:
針對(duì)上述輸入信號(hào),現(xiàn)要求給出如下的輸出(可以有不超過(guò)8個(gè)時(shí)鐘延時(shí)):
請(qǐng)給出詳細(xì)的設(shè)計(jì)思路、實(shí)現(xiàn)步驟、電路原理圖,并在給出時(shí)序圖的基礎(chǔ)上說(shuō)明“將第1路數(shù)據(jù)交換至第4路數(shù)據(jù)輸出時(shí)”的工作原理。
其中:
時(shí)鐘端?Clk:?電路的工作時(shí)鐘
串行輸入Din:?串行輸入數(shù)據(jù),圖中序號(hào)表示對(duì)應(yīng)的信道號(hào)
輸入使能端En:?高有效,表示當(dāng)前對(duì)應(yīng)的信道需要進(jìn)行交換
串行輸出Dout:?指示交換之后的數(shù)據(jù)輸出
輸出有效Eo:?高有效,指示當(dāng)前輸出的Dout數(shù)據(jù)為有效交換數(shù)據(jù)
信道指示Ind[1:0]:?指示當(dāng)前輸出Dout數(shù)據(jù)對(duì)應(yīng)的信道號(hào)
FPGA代碼Verilog/VHDL代碼資源下載:www.hdlcode.com
演示視頻:
設(shè)計(jì)文檔:
1. 工程文件
2. 程序文件
3. 程序編譯
4. Testbench
5. 仿真圖
部分代碼展示:
reg?[3:0]?cnt=0; reg?[3:0]?in_cnt=0; reg?[3:0]?out_cnt1=0; reg?[3:0]?data_in=0; reg?[3:0]?cnt1=0; reg?[3:0]?cnt2=0; parameter?state1?=?4'b0001;//狀態(tài)機(jī) parameter?state2?=?4'b0010; parameter?state3?=?4'b0011; parameter?state4?=?4'b0100; reg?[3:0]?state?=?4'b0001;//輸入狀態(tài) always?@(posedge?CLK?) begin ?case(state) ????????state1:? if(EN) begin state?<=?state2; data_in?<=?{data_in[2:0],DIN}; cnt2?<=?cnt2?+1'd1; end state2:? if(EN) begin state?<=?state3; data_in?<=?{data_in[2:0],DIN}; cnt2?<=?cnt2?+1'd1; end state3:? if(EN) begin state?<=?state4; data_in?<=?{data_in[2:0],DIN}; cnt2?<=?cnt2?+1'd1; end state4:? if(EN) begin state?<=?state1; data_in?<=?{data_in[2:0],DIN}; in_cnt?<=?in_cnt?+?1'd1; cnt2?<=?cnt2?+1'd1; end endcase end reg?[3:0]?data,data1; always@(posedge?CLK) begin if(state?==?state1)//數(shù)據(jù)緩存 begin data?<=?data_in; end end reg?[3:0]?state_out?=?4'b0001;//輸出狀態(tài) always?@(posedge?CLK?) begin if(cnt2?>=?5) begin ?case(state_out) state1: if(out_cnt1?<?in_cnt) begin cnt1?<=?4'd1; state_out?<=?state2; EO?<=?1'd1; Ind?<=?Ind?-?1; end else begin EO?<=?1'd0; end state2: begin cnt1?<=?4'd2; state_out?<=?state3; Ind?<=?Ind?-?1; end state3: begin cnt1?<=?4'd3; state_out?<=?state4; Ind?<=?Ind?-?1; end state4: begin cnt1?<=?4'd0; out_cnt1?<=?out_cnt1?+?1'd1; state_out?<=?state1; Ind?<=?Ind?-?1; end ?endcase end else begin Ind?<=?2'b00; end end always@(posedge?CLK) begin case(cnt1) 4'd0:DOUT?<=?data[0]; 4'd1:DOUT?<=?data[1]; 4'd2:DOUT?<=?data[2]; 4'd3:DOUT?<=?data[3]; endcase end endmodule
點(diǎn)擊鏈接獲取代碼文件:http://www.hdlcode.com/index.php?m=home&c=View&a=index&aid=479