random sequence counter

Status
Not open for further replies.

ganauvm

Newbie
Joined
Jun 23, 2021
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
17
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
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…