cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

Anonymous
Not applicable

 `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

0 Likes
Reply
0 Replies