///simple counter
module counter(clk,count,reset);
input clk,reset;
output [1:0] count;
reg [1:0] count;
always @ (posedge clk or posedge reset)//posedge
if (reset)
count<=2'b00;
else if (count==2'b11)
count<=2'b01;
else
count<=count+1'b1;
// onehot coder
module count_ring(clk,in_count,out_count, reset);
input clk;
input reset;
input [1:0] in_count, in_count_f1, in_count_f2;
output [2:0] out_count;
reg [2:0] out_count;
always @ (posedge clk or negedge reset)
begin
if (~ reset)
begin
in_count_f1 <= 2'b0;
in_count_f2 <= 2'b0;
end
else
begin
in_count_f1 <= in_count;
in_count_f2 <= in_count_f1;
end
end
always @ (posedge clk)//posedge
case (in_count_f2 )
2'b01: out_count<=3'b001;
2'b10: out_count<=3'b010;
2'b11: out_count<=3'b100;
default : out_count<=3'b000;
endcase
endmodule