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.

Help me jump over counter values in a code

Status
Not open for further replies.

kaiser

Newbie level 5
Joined
Jul 5, 2005
Messages
9
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,452
module CONTROL( ld, clk_c, rst_c);
output [3:0] ld;
input clk_c;
input rst_c;
reg [3:0] ld;

reg [2:0] count;

always @ (posedge clk_c or posedge rst_c)
begin
if (rst_c)
begin
count<= 3'd0;
ld <= 4'b0;
end
else

begin
count <= count +1 ;
case (count)
3'd1 : ld[0] <= 1;
3'd2 : ld[1] <= 1;
3'd3 : ld[2] <= 1;
3'd4 : ld[3] <= 1;
default : begin
ld <= 4'b0;
count <= 3'b0;
end
endcase
end
end
endmodule

in the above code.....how can I jump over 3'd5,3'd6,3'd7 values of the counter....?
This code light 4 led ....and when the values of counter > 4 the all leds are closed
3 periods.....how can make leds stay closed 1 period?
 

Help need

You need to reset the counter when its value is 4 to jump over the values which are greater than 4.
So:
......
begin

if (count == 3'd4)
count <= 3'd0;
else
count <= count +1 ;

case (count)
..............
 

Re: Help need

I think this is what you want to do!!!
Hope this helps!

Code:
module CONTROL( ld, clk_c, rst_c);
   output [3:0] ld;
   input       clk_c;
   input       rst_c;
   reg [3:0]   ld;
   reg [3:0] ld_nx;
    
   always @ (posedge clk_c or posedge rst_c) begin
      if (rst_c) begin
         ld <= 4'b0;
      end else begin
         ld <= ld_nx;
      end
   end // always @ (posedge clk_c or posedge rst_c)
   
   always@(ld) begin
      ld_nx = 0;
      case(ld)
        0 : ld_nx[0] = 1'b1;
        1 : ld_nx[1] = 1'b1;
        2 : ld_nx[2] = 1'b1;
        4 : ld_nx[3] = 1'b1;
        8 : ld_nx[0] = 1'b1;
      endcase // case(ld)
    end
endmodule
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top