FPGA电路逻辑的Verilog HDL编程方式设计与验证
上一篇是讲述了原理图的设计方式,这次使用Verilog HDL编程的方式进行设计和验证, 在EDA工具中重新应用一次。
- 实验1:拼接 4-16译码器
- 实验2A : 设计M=12的计数器
- 实验2B : 设计M=20的计数器
- 0-9往复的计数器
实验1:拼接 4-16译码器
Verilog HDL设计4-16译码器:
module text_416(in_abc, out_d);
input [:] in_abc;
output out_d;
reg[:] out_d;
[email protected](in_abc)
begin
case(in_abc)
'b0000 : out_d = 'hfffe;
'b0001 : out_d = 'hfffd;
'b0010 : out_d = 'hfffb;
'b0011 : out_d = 'hfff7;
'b0100 : out_d = 'hffef;
'b0101 : out_d = 'hffdf;
'b0110 : out_d = 'hffbf;
'b0111 : out_d = 'hff7f;
'b1000 : out_d = 'hfeff;
'b1001 : out_d = 'hfdff;
'b1010 : out_d = 'hfbff;
'b1011 : out_d = 'hf7ff;
'b1100 : out_d = 'hefff;
'b1101 : out_d = 'hdfff;
'b1110 : out_d = 'hbfff;
'b1111 : out_d = 'h7fff;
endcase
end
endmodule
仿真结果如下图:
实验2A : 设计M=12的计数器
Verilog HDL设计M=12计数器:
module text2a_12(CLK, Qabcd, CO);
input CLK;
output Qabcd,CO;
reg[3:0] Qabcd,count;
reg CO;
[email protected](posedge CLK )
begin
if(count==)
count <= ;
else
count <= count + ;
end
[email protected](count )
begin
Qabcd = count;
if(count == 11)
CO = 1;
else CO= 0;
end
endmodule
仿真结果如下图:
实验2B : 设计M=20的计数器
Verilog HDL设计M=20计数器:
module text2b_20(clk,Q,co);
input clk;
output Q,co;
reg[:] Q,count;
reg co;
[email protected](posedge clk )
begin
if(count == )
count <= ;
else
count <= count + ;
end
[email protected](count)
begin
Q = count;
if(count==)
CO = ;
else CO = ;
end
endmodule
仿真结果如下图:
附加实验 : 设计0-9往复计数器
Verilog HDL设计0-9往复计数器:
module text3_jiajian(clk,outq);
input clk;
output outq;
reg[:] outq;
reg[:] count;
reg[:] count1;
always @ ( negedge clk )
begin
if(count1 == )
begin
count <= count + ;
if(count == )
begin
count1 <= count;
count <= count - ;
end
end
if(count1 == )
begin
count <= count - ;
if(count == )
begin
count1 <= count;
end
end
outq <= count;
end
endmodule
仿真结果如下图:
通过以上实验,可以看到,使用FPGA芯片,可以用Verilog HDL语言进行编程实现,能够直接对电路功能进行设计, 更直接明了。