天天看點

011 Verilog原語

原語

是構成設計的最基本單元,通過真值表描述其功能,包括基本邏輯門在内有26個預定義功能模型

n輸入邏輯門

011 Verilog原語
原語 描述 使用
and 與門 and(yout, xin1, xin2, xin3)
nand 與非 nand(yout, xin1, xin2, xin3)
or 或門 or(yout, xin1, xin2, xin3)
nor 或非 nor(yout, xin1, xin2, xin3)
xor 異或 xor(yout, xin1, xin2, xin3)
xnor 同或 nxor(yout, xin1, xin2, xin3)

n輸出組合門

011 Verilog原語
011 Verilog原語
011 Verilog原語
011 Verilog原語

UDP(User Defined Primitive,使用者自定義原語)

符号彙總

符号 意義
0,1,x 邏輯0,1,x為未知值,UDP中沒有z
? 無關邏輯,可以是0,1,x
b 邏輯0或1
- 不變化
(xy) 從x變為y,如(01)為上升沿
* 輸入信号的任何變化
r 上升沿
f 下降沿
p 含x的上升沿,等同于(01)、(0x)、(x1)
n 含x的下降沿,等同于(10)、(x0)、(1x)

與門

primitive and(y, x1, x2);
	output y;
	input x1, x2;

	table
	// x1 x2 : y
	0 0 : 0;
	0 1 : 0;
	1 0 : 0;
	1 1 : 1;
	endtable
endprimitive
           

2輸入多路複用器

輸入可以是0,1,x,是以考慮所有情況的2輸入多路複用器如下:

primitive mux_two(out, select, a, b);
	output out;
	input select, a, b;
	// y = select ? a : b;

	table
	// select	a	b	:	out
	   0		0	0	:	0;
	   0		0	1	:	0;
	   0		0	x	:	0;
	   0		1	0	:	1;
	   0		1	1	:	1;
	   0		1	x	:	1;

	   1		0	0	:	0;
	   1		1	0	:	0;
	   1		x	0	:	0;
	   1		0	1	:	1;
	   1		1	1	:	1;
	   1		x	1	:	1;

	   x		0	0	:	0;
	   x		1	1	:	1;
	endtable
endprimitive
           

使用助記符?簡化,?=0,1,x

primitive mux_two(out, select, a, b);
	output out;
	input select, a, b;
	// y = select ? a : b;

	table
	// select	a	b	:	out
	   0		0	?	:	0;
	   0		1	?	:	1;

	   1		?	0	:	0;
	   1		?	1	:	1;

	   ?		0	0	:	0;
	   ?		1	1	:	1;
	endtable
endprimitive
           

透明鎖存器(電平敏感)

其實就是帶使能的鎖存器

primitive latch_with_enable(q_out, enable, data);
	output q_out;
	input enable, data;
	reg q_out;
	// q_out = enable ? data : q_out;
	// - 表示保持

	table
	// 時序邏輯table格式
	// input1	input2	state 	: 	output/next_state
	// enable	data	state	:	q_out/next_state
	   1		1			?	:	1;
	   1		0			?	:	0;
	   0		?			?	:	-;

	   x		0			0	:	-;
	   x		1			1	:	-;
	endtable
endprimitive
           

D觸發器(邊沿敏感)

primitive DFF(q_out, clk, data);
	output q_out;
	input clk, data;
	reg q_out;
	// q_out = posedge(clk) ? data : q_out;
	// - 表示保持

	table
	// 時序邏輯table格式
	// input1	input2	state 	: 	output/next_state
	// clk		data	state	:	q_out/next_state
	   (01)		0		?		:	0;
	   (01)		1		?		:	1;
	   (0?)		1		1		:	1;

	   (?0)		?		?		:	-;

	   ?		(??)	?		:	-;
	endtable
endprimitive
           

繼續閱讀