讀書筆記(Verilog HDL那些事兒_建模篇0)
說明:寫程式碼總感覺不是很好,向前輩學習,提升自己。
感悟:文章作者可以將一個大工程劃分為多個子模組,主要分功能模組和控制模組,一個功能一個模組的思路剛開始覺得很繁瑣,但是到後來卻發 現他利於移植,更重要的是將功能劃分開,方便閱讀和維護。
進度:第三章(159頁)
整理來自:時間的詩
1、模組:功能模組、控制模組、組合模組
2、準則:一個模組一個功能
3、訊號:
組合模組:clk, rst_n, RX_Pin_In, TX_Pin_Out // 埠訊號
控制模組:clk, rst_n, Start_Sig, Done_Sig, TX_En_Sig, TX_Done_Sig,
功能模組:clk, rst_n, Start_Sig, Done_Sig
模組內部:
TX_Data, // 資料訊號
isS, isO, //中間訊號
assign S_Start_Sig = isS; //埠訊號
assign O_Start_Sig = isO;
“仿順序操作”的建模都有標誌性的“ 模組構造”,
就是所有模組都擁有“ Start_Sig”和“ Done_Sig”。
“ Start_Sig”如同 C 語言中的呼叫指令,
“ Done_Sig”如同 C 語言的返回指令。
這兩個訊號的存在就是為了控制模組的呼叫。
計數器:isCount, // 標誌暫存器使能著該定時器
Count1, // 計數到1ms
Count_MS, // 技術多少個1ms
rTimes, // 計數次數
4、模組命名方式及模組訊號註釋:
sos_module
sos_control_module
s_module
o_module
sos_control_module U3 ( .CLK( CLK ), .RSTn( RSTn ), .Start_Sig( Start_Sig ), // input - from top .S_Done_Sig( S_Done_Sig ), // input - from U1 .O_Done_Sig( O_Done_Sig ), // input - from U2 .S_Start_Sig( S_Start_Sig ), // output - to U1 .O_Start_Sig( O_Start_Sig ), // output - to U2 .Done_Sig( Done_Sig ) // output - to top );
5、常用定時器 計數器模板
/****************************************/
parameter T1MS = 16'd49_999; //開發板使用的晶振為50MHz,50M*0.001-1=49_999
/***************************************/
reg [15:0]Count1;
always @ ( posedge CLK or negedge RSTn )
if( !RSTn )
Count1 <= 16'd0;
else if( Count1 == T1MS )
Count1 <= 16'd0;
else if( isCount )
Count1 <= Count1 + 1'b1;
else if( !isCount )
Count1 <= 16'd0;
/****************************************/
reg [9:0]Count_MS;
always @ ( posedge CLK or negedge RSTn )
if( !RSTn )
Count_MS <= 10'd0;
else if( Count_MS == rTimes )
Count_MS <= 10'd0;
else if( Count1 == T1MS )
Count_MS <= Count_MS + 1'b1;
/******************************************/
6、仿順序操作狀態機:
always @ ( posedge CLK or negedge RSTn )
if( !RSTn ) begin
i <= 4'd0;
isO <= 1'b0;
isS <= 1'b0;
isDone <= 1'b0;
end
else if( Start_Sig )
case( i )
4'd0:
if( S_Done_Sig ) begin isS <= 1'b0; i <= i + 1'b1; end
else isS <= 1'b1;
4'd1:
if( O_Done_Sig ) begin isO <= 1'b0; i <= i + 1'b1; end
else isO <= 1'b1;
4'd2:
if( S_Done_Sig ) begin isS <= 1'b0; i <= i + 1'b1; end
else isS <= 1'b1;
4'd3:
begin isDone <= 1'b1; i <= 4'd4; end
4'd4:
begin isDone <= 1'b0; i <= 4'd0; end
default:
begin isDone <= 1'b0; i <= 4'd0; end
endcase
/*****************************************/