level 1
HAILONG00HX
楼主
一个30进制的减计数器,同步计数,异步清零,置数,有借位
module HL(input clk,input rst_n,input clr,input [9:0]data_set,input set_en,output reg[9:0]cnt_out);
reg [5:0]cnt;
always@(posedge clk or negedge rst_n)
begin if(!rst_n)
cnt_out<=10'd1023;
else if(clr)
cnt_out<=10'd1023;
else if(set_en)
cnt_out<=data_set;
else if(cnt==29)
cnt_out<= cnt_out-10'b1;
end
always@(posedge clk or negedge rst_n)
begin if (!rst_n)
cnt<=0;
else if(cnt==29)
cnt<=0;
else
cnt<=cnt+1;
endmodule
2015年01月15日 09点01分
1
module HL(input clk,input rst_n,input clr,input [9:0]data_set,input set_en,output reg[9:0]cnt_out);
reg [5:0]cnt;
always@(posedge clk or negedge rst_n)
begin if(!rst_n)
cnt_out<=10'd1023;
else if(clr)
cnt_out<=10'd1023;
else if(set_en)
cnt_out<=data_set;
else if(cnt==29)
cnt_out<= cnt_out-10'b1;
end
always@(posedge clk or negedge rst_n)
begin if (!rst_n)
cnt<=0;
else if(cnt==29)
cnt<=0;
else
cnt<=cnt+1;
endmodule