Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

random sequence counter

Status
Not open for further replies.

ganauvm

Newbie
Newbie level 1
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top