2018年12月23日 星期日

NC Verilog與ModelSim的模擬結果不一致

(1). 上圖為ModelSim模擬的結果,下圖為NC Verilog模擬的結果,一模一樣的Verilog code卻產生不同的結果。


















(2). 主要是因為module的input輸入值,需要先宣告一個reg接受並且給予初始值。

module PureBus(
.....
input [2:0]Mode,
.....
);

reg [2:0]mode_set;

always@(posedge Clk or negedge Reset)
begin
if(!Reset)
begin
        ........
r_mode_set <= 0;
end
else
begin
                 .......
                 r_mode_set <= Mode;
        end
end
endmodule

修改完成,再用NC Verilog模擬,結果就與ModelSim模擬的結果一樣。有使用Active HDL測試,發現Active HDL與NC Verilog模擬的結果是一樣的,Active HDL與NC Verilog相對於ModelSim對於電路初始值得要求比較嚴謹。

2018年12月21日 星期五

NC-Verilog(3) - 模擬

(1). 選擇"Tools" > "Elaborator..."。

(2). 勾選"Other Options",輸入"-timescale 1ns/1ns",設定模擬 的(單位)/(精度),設定完成按"OK"。
**如果所有的Verilog程式碼開頭都有加入"-timescale 1ns/1ns",可以省去此項步驟。

(3). 點選"testbench",再點選"Elaborator"。

(4). 點選"worklib.testbench.module",再點選"Simulator"。

(5). 開啟"SimVision"視窗。

(6). 點選"testbench",再點選"Send"。

(7). 開啟"Waveform"視窗,點選"Run"視窗執行並顯示模擬結果。


NC-Verilog(2) - 執行NCLaunch與編譯

 (1). 開啟Linux作業系統中的"Terminal",輸入"nclaunch -new &",開啟NCLaunch。

(2). 點選"Multiple Step"。

(3). 點選"...",選擇上個章節Verilog的程式路徑,之後按"OK"。

(4). 新的專案要建立Library,點選"Yes"。

(5). 點選"OK"。

(6). 點選"OK"。

(7). 點選需要編譯的Verilog程式,再點選"Verilog compiler",開始編譯。

NC-Verilog(1) - 硬體描述語言撰寫

NC-Verilog下的三個工具:
ncvlog (Compiles the Verilog source files.)
ncelab (Elaborates the design and generates a simulation snapshot.)
ncsim (Simulates the snapshot.)

(1). 先產生Verilog程式,如下所示。

/////////////////////////////Schematic
module Test(a, b, c, d, En, Sel, f);
input  a, b, c, d, En, Sel;
output f;

wire   f;
wire   g, h, i, j;

assign g = a | b;
assign i = g & En;
assign h = c | d;
assign j = h & En;
assign f = (Sel==1'b0) ? i : j;

endmodule

/////////////////////////////Testbench
module testbench;

reg a, b, c, d, En, Sel;

wire f;

Test UUT(
  .a(a),
  .b(b),
  .c(c),
  .d(d),
  .En(En),
  .Sel(Sel),
  .f(f) );

initial

begin
 a   = 1'b0; // Time = 0
 b   = 1'b1;
 c   = 1'b0;
 d   = 1'b1;
 En  = 1'b0;
 Sel = 1'b0;

 #20;    // Time = 20
 a  = 1'b1;
 #10;    // Time = 30
 b  = 1'b0;
 c  = 1'b1;
 #10;    // Time = 40
 a  = 1'b0;
 #10;    // Time = 50
 En = 1'b1;
 #10;    // Time = 60
 c  = 1'b0;
 #10;    // Time = 70
 a  = 1'b1;
 d  = 1'b0;
 #20;    // Time = 90
 c  = 1'b1;
 #20;    // Time = 110
 a  = 1'b0;
 #10;    // Time = 120
 a  = 1'b1;
 #10;    // Time = 130
 c  = 1'b0;
 Sel= 1'b1;
 #10;    // Time = 140
 a  = 1'b0;
 #30;    // Time = 170
 a  = 1'b1;
 #10;    // Time = 180
 c  = 1'b1;
 #20;    // Time = 200
 a  = 1'b0;
end

endmodule

(2). 在Linux作業系統中建立一個目錄,並將Schematic與Testbench,複製至目錄中。




2018年11月30日 星期五

Allegro電路板設計 - Layout時更新元件庫

(1). 先檢查Database,選擇"Tools" > "Database Check..."。

(2). 勾選"Update all DRC(including Batch)"與"Check shape outlines",按"Check",之後會產生一個報表,請檢查是否有錯誤。

(3). 更新元件庫,點選"Place" > "Update Symbols..."。

(4). 在Select definitions for update:中勾選元件庫路徑,再勾選"Update symbol padstacks",按"Refresh",更新元件庫。

2018年11月26日 星期一

Allegro電路板設計 - Via、Pad加入與刪除淚滴(Teardrop)

增加Teardrop主要是避免信號線的線寬突然變小而造成Crosstalk現象。

(1). 點選"Route" > "Gloss" > "Parameters..."。

(2). 點選"Fillet and tapered trace"左邊按鍵。

(3). 確認"Circular pads''、"Pins''、"Vias''、"T connections''有勾選,之後按"OK"。

(4). 在"Fillet and tapered trace"對應的"Run"勾選,之後按"Gloss"。

(5). 結果顯示如下圖所示。

(6). 刪除Teardrop,選擇"Route" > "Gloss" > "Delete Fillet"。

(7). 使用"滑鼠左鍵"按住,並框選PCB。

(8). "滑鼠左鍵"放開後,即可刪除Teardrop。

2018年11月13日 星期二

鍵盤事件

(1). 點選"控制項"。

(2). 在屬性視窗中點選"事件按鈕(閃電圖示)"。
(3). 選擇"KeyDown"、"KeyPress"或"KeyUP"事件"快按兩下"。
a. KeyDown事件: 鍵盤任意鍵按住不放時觸發。
b. KeyPress事件: 鍵盤字元鍵被按時觸發。
c. KeyUP事件: 鍵盤任意鍵按下放開時觸發。

(4). 輸入程式。
KeyDown範例:

if(e.KeyCode == Keys.Enter)
{
     ...............
}


KeyPress範例:

if(e.KeyCode == (char)Keys.A)
{
     ...............
}


KeyUP範例:

if(e.KeyCode == Keys.Enter)
{
     ...............
}

(5). 在Form1.cs下點選視窗外框,將"KeyPreview"改成"True"。

注意:

KeyEventArgs類別的屬性:
Alt 取得值,指出是否按下 ALT 鍵。
Control 取得值,指出是否按下 CTRL 鍵。
Handled 取得或設定值,指出是否處理事件。
KeyCode 取得 KeyDown 或 KeyUp 事件的鍵盤程式碼。
KeyData 取得 KeyDown 或 KeyUp 事件的按鍵資料。
KeyValue 取得 KeyDown 或 KeyUp 事件的鍵盤值。
Modifiers 取得 KeyDown 或 KeyUp 事件的輔助鍵旗標。 這些旗標是表示按下 CTRL、SHIFT 和 ALT 哪些按鍵組合。
Shift 取得值,指出是否按下 SHIFT 鍵。
SuppressKeyPress 取得或設定值,指出按鍵事件是否應該傳遞至基礎控制項。

Keys Enum(鍵盤列舉)
列舉常數值 KeyCode
Keys.D0~Keys.D9 48~57
Keys.A~Keys.Z 65~90
Keys.F1~Keys.F12 112~121
Keys.Left~Keys.Right 37、39
Keys.Up~Keys.Down 38、40
Keys.Enter~Keys.Space 13、32
Keys.ShiftKey 16
Keys.ControlKey 17
Keys.Escape 27