module count(
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'b0;
else if(set_en) //同步置位
cnt_out<=data_set;
else if(cnt==29) //30进制
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;
end
这就是一个完全符合你的要求的30进制减计数器
温馨提示:答案为网友推荐,仅供参考