数字逻辑设计基础-加减法计数器计数器是数字逻辑设计中最常见的的模块,但是也是⽐较重要的模块,在简单的时序电路中使⽤较多。
唇色发白现在要设计⼀个计数器,能够满⾜以下要求。
(1):能够根据输⼊信号,enable_cnt_up,和enable_cnt_dn进⾏加计数和减计数
(2):如果信号new_cntr_pert为⾼电平并且保持⼀个周期,那么计数器就被设置为新的预设值。(3):在pau-counting有效时,计数器值保持不变。
(4):当计数器值计数到结束⽐标志时,计数器输出端⼝ctr_expired有效。
(5):计数器值到达边界时,会⾃动重新加载预设值并且重新开始计数。
以下是计数器的信号列表:
信号I/O width
clk input1
restb input1
new_cntr_pert input1
new_cntr_pert_value input[7:0]
enable_cnt_up input1
enable_cnt_dn input1
pau_counting input1
ctr_expired output1
以下是计数器实现的Verilig代码:
module versat_updown_counter
(
clk,拔智齿后吃什么
restb,
new_cntr_pert;
new_cntr_pert_value,
enable_cnt_up,软件授权书
enable_cnt_dn,
pau_counting,
ctr_expired
)
//*********************************************************
input clk;
input restb;
input new_cntr_pert;
input [7:0] new_cntr_pert_value;
何可胜道也哉input enable_cnt_dn;
input enable_cnt_up;
input pau_counting;
output ctr_expired;
reg [7:0] count255,count255_nxt;
reg [7:0] cnt_pert_stored;
wire [7:0] cnt_pert_stored_nxt;
reg ctr_expired;
wire ctr_expired_nxt;
reg enable_cnt_dn_d1,enable_cnt_up_d1;
reg enable_cnt_dn_d1,enable_cnt_up_d1;
wire enable_cnt_up_ridge,enable_cnt_dn_ridge;
//**********************************************************
取整函数assign enable_cnt_up_ridge = enable_cnt_up&!enable_cnt_up_d1;
assign enable_cnt_dn_ridge = enable_cnt_dn&!enable_cnt_dn_d1;
assign cnt_pert_stored_nxt = new_cntr_pert?new_cntr_pert_value:cnt_pert_stored_nxt;
assign ctr_expired_nxt = enable_cnt_up?(count255_nxt == cnt_pert_stored_nxt):
(enable_cnt_dn?(count255_nxt = 'd0):1'b0);
always@(*)
begin
我们来自五湖四海count255_nxt = count255;
if(enable_cnt_dn_ridge)
count255_nxt = cnt_pert_stored //初始化最⼤值
el if(enable_cnt_up_ridge)
count255_nxt = 'd0;
el if(pau_counting)
count255_nxt = count255;
el if(enable_cnt_dn && ctr_expired)
count255_nxt = cnt_pert_stored;
el if(enable_cnt_dn)
count255_nxt = count255 - 1'b1;
el if(enable_cnt_up && ctr_expired)
count255_nxt = 'd0;
el if(enable_cnt_up)
count255_nxt = count255 + 1'b1;
end
always@(podge clk or negedge restb)
begin
if(!restb)begin
count255 <= 'd0;
女生节是哪天
邮政储蓄电话cnt_pert_stored <= 'd0;
ctr_expired <= 1'b1;
enable_cnt_up_d1 <= 1'b0;
enable_cnt_dn_d1 <= 1'b0;
end
el begin
count255 <= count255_nxt;
cnt_pert_stored <= cnt_pert_stored_nxt;
ctr_expired <= ctr_expired_nxt;
enable_cnt_dn_d1 <= enable_cnt_dn;
enable_cnt_up_d1 <= enable_cnt_up;
end
end
endmodule