ganauvm
Newbie
How to generate the sequence 1,2,3,4,5,6,7,6,5,4,4,3,2,1
Code:
module top(
input clk,rst,
output logic [2:0] dout
);
typedef enum {up,down} state_type;
state_type state = up;
integer count = 0;
always@(posedge clk)
begin
if(rst == 1'b1) begin
//dout <= 0;
count <= 0;
end
else begin
case(state)
up:
begin
if(count == 7) begin
count <= count - 1;
state <= down;
end
else begin
state <= up;
count <= count - 1;
end
end
down: begin
if(count == 0) begin
count <= count + 1;
state <= up;
end
else begin
state <= down;
count <= count - 1;
end
end
default: begin
state <= up;
count <= 0;
end
endcase
end
end
assign dout = count;
endmodule