0 Replies Latest reply on Dec 23, 2012 9:46 AM by ramnath.r.k

    Design 1 Code

    ramnath.r.k

       `define UP 0

         

      `define DOWN 0

         

       

         

      module up_down_counter(

         

       

         

      input clock,

         

      input reset,

         

      input load,

         

      input roll_enable,

         

      input[3:0] load_val,

         

       

         

      output reg[3:0] count_out,

         

      output max,

         

      output min

         

      );

         

       

         

      parameter up_down = 0;

         

       

         

      wire halt = (!roll_enable) & (((count_out == 4'h0) & up_down) | ((count_out == 4'hF) & !up_down));

         

       

         

       

         

      assign max = (count_out == 4'hF);

         

      assign min = (count_out == 4'h0); 

         

       

         

      always@(posedge clock or negedge reset) begin

         

      if(!reset)

         

      count_out <= 4'b0;

         

      else if(load)

         

      count_out <= load_val;

         

      else if(~halt)

         

      if(up_down == `UP)

         

      count_out <= count_out + 1'b1;

         

      else

         

      count_out <= count_out - 1'b1;

         

      end

         

       

         

      endmodule