位置:51电子网 » 技术资料 » EDA/PLD

Verilog HDL行为建模具体实例

发布时间:2008/5/28 0:00:00 访问次数:560

7.4 行为建模具体实例
以上面的频率计数器为例,其中的 hex2led 和 cnt_4b 模块采用行为建模。
2004-08-16 第37页,共41页
版权所有,侵权必究


绝密
verilog hdl 入门教程请输入文档编号

cnt_4b 模块对应的文件 cnt_4b.v 的内容如下:

module cnt_4b (clk, enable, reset, full, q);
input clk;
input enable;
input reset;
output full;
output [3:0] q;

wire clk;
wire enable;
wire reset;
wire full;
wire [3:0] q;


// add your declarations here
reg [3:0] qint;


always @(posedge reset or posedge clk)
begin
if (reset)

qint = 4'b0000;
else if (enable)
begin

if (qint == 9)
qint = 4'b0000;
else
qint = qint + 4'b1;

end
end
assign q = qint;
assign full = (qint == 9) ? 1'b1 : 1'b0;


endmodule
该模块实现一个模10 的计数器。

hex2led 模块对应的文件hex2led.v 的内容为:
module hex2led (hex, led);

2004-08-16 第38页,共41页
版权所有,侵权必究


绝密
verilog hdl 入门教程请输入文档编号

input [3:0] hex;

output [6:0] led;

wire [3:0] hex;

reg [6:0] led;

// add your declarations here
always @(hex)
begin


case (hex)
4'b0001 : led = 7'b1111001; // 1
4'b0010 : led = 7'b0100100; // 2
4'b0011 : led = 7'b0110000; // 3
4'b0100 : led = 7'b0011001; // 4
4'b0101 : led = 7'b0010010; // 5
4'b0110 : led = 7'b0000010; // 6
4'b0111 : led = 7'b1111000; // 7
4'b1000 : led = 7'b0000000; // 8
4'b1001 : led = 7'b0010000; // 9
4'b1010 : led = 7'b0001000; // a
4'b1011 : led = 7'b0000011; // b
4'b1100 : led = 7'b1000110; // c
4'b1101 : led = 7'b0100001; // d
4'b1110 : led = 7'b0000110; // e
4'b1111 : led = 7'b0001110; // f
default :led = 7'b1000000; // 0


endcase
end


endmodule

该模块实现模10 计数器的值到 7段码的译码。

至此,整个频率计数器的系统设计由4个模块(4个文件)我们已设计完毕。这就是hdl 的自
顶向下的设计方式和hdl的多种建模方式的应用。



7.4 行为建模具体实例
以上面的频率计数器为例,其中的 hex2led 和 cnt_4b 模块采用行为建模。
2004-08-16 第37页,共41页
版权所有,侵权必究


绝密
verilog hdl 入门教程请输入文档编号

cnt_4b 模块对应的文件 cnt_4b.v 的内容如下:

module cnt_4b (clk, enable, reset, full, q);
input clk;
input enable;
input reset;
output full;
output [3:0] q;

wire clk;
wire enable;
wire reset;
wire full;
wire [3:0] q;


// add your declarations here
reg [3:0] qint;


always @(posedge reset or posedge clk)
begin
if (reset)

qint = 4'b0000;
else if (enable)
begin

if (qint == 9)
qint = 4'b0000;
else
qint = qint + 4'b1;

end
end
assign q = qint;
assign full = (qint == 9) ? 1'b1 : 1'b0;


endmodule
该模块实现一个模10 的计数器。

hex2led 模块对应的文件hex2led.v 的内容为:
module hex2led (hex, led);

2004-08-16 第38页,共41页
版权所有,侵权必究


绝密
verilog hdl 入门教程请输入文档编号

input [3:0] hex;

output [6:0] led;

wire [3:0] hex;

reg [6:0] led;

// add your declarations here
always @(hex)
begin


case (hex)
4'b0001 : led = 7'b1111001; // 1
4'b0010 : led = 7'b0100100; // 2
4'b0011 : led = 7'b0110000; // 3
4'b0100 : led = 7'b0011001; // 4
4'b0101 : led = 7'b0010010; // 5
4'b0110 : led = 7'b0000010; // 6
4'b0111 : led = 7'b1111000; // 7
4'b1000 : led = 7'b0000000; // 8
4'b1001 : led = 7'b0010000; // 9
4'b1010 : led = 7'b0001000; // a
4'b1011 : led = 7'b0000011; // b
4'b1100 : led = 7'b1000110; // c
4'b1101 : led = 7'b0100001; // d
4'b1110 : led = 7'b0000110; // e
4'b1111 : led = 7'b0001110; // f
default :led = 7'b1000000; // 0


endcase
end


endmodule

该模块实现模10 计数器的值到 7段码的译码。

至此,整个频率计数器的系统设计由4个模块(4个文件)我们已设计完毕。这就是hdl 的自
顶向下的设计方式和hdl的多种建模方式的应用。



相关IC型号

热门点击

 

推荐技术资料

声道前级设计特点
    与通常的Hi-Fi前级不同,EP9307-CRZ这台分... [详细]
版权所有:51dzw.COM
深圳服务热线:13692101218  13751165337
粤ICP备09112631号-6(miitbeian.gov.cn)
公网安备44030402000607
深圳市碧威特网络技术有限公司
付款方式


 复制成功!