Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module bcdcounter_ms(rst, clk, valor, ss,sf);
- input rst, clk,ss,sf;
- output reg[15:0] valor=0;
- reg [15:0] valor_siguiente=0;
- wire d0_9;//indica si llega de 0 a 9
- wire d1_9;//indica si llega de 0 a 9
- wire d2_9;//indica si llega de 0 a 9
- wire d3_9;//indica si llega de 0 a 9
- wire clk2;
- reg clk3;
- assign d0_9=(valor[3:0]==4'd9);
- assign d1_9=(valor[7:4]==4'd9);
- assign d2_9=(valor[11:8]==4'd9);
- assign d3_9=(valor[15:12]==4'd9);
- clk_dos m2(clk,clk2);
- always@(*)begin
- if(sf)
- clk3=clk2;
- else
- clk3=clk;
- end
- always@(*)begin
- case({d0_9,ss})
- 2'b00: valor_siguiente[3:0] = valor[3:0] + 4'd1;
- 2'b01: valor_siguiente[3:0] = valor[3:0] - 4'd1;
- default: valor_siguiente[3:0] = 4'd0;
- endcase
- end
- always@(*)begin
- case({ss,d1_9,d0_9})
- 3'b001:valor_siguiente[7:4] = valor[7:4] + 4'd1;
- 3'b011:valor_siguiente[7:4] = 4'd0;
- 3'b101:valor_siguiente[7:4] = valor[7:4] - 4'd1;
- 3'b111:valor_siguiente[7:4] = 4'd0;
- default:valor_siguiente[7:4] = valor[7:4];
- endcase
- end
- always@(*)begin
- case({ss,d2_9,d1_9,d0_9})
- 4'b0011:valor_siguiente[11:8] = valor[11:8] + 4'd1;
- 4'b0111:valor_siguiente[11:8] = 4'd0;
- 4'b1011:valor_siguiente[11:8] = valor[11:8] - 4'd1;
- 4'b1111:valor_siguiente[11:8] = 4'd0;
- default:valor_siguiente[11:8] = valor[11:8];
- endcase
- end
- always@(*)begin
- case({ss,d3_9,d2_9,d1_9,d0_9})
- 5'b00111:valor_siguiente[15:12] = valor[15:12] + 4'd1;
- 5'b01111:valor_siguiente[15:12] = 4'd0;
- 5'b10111:valor_siguiente[15:12] = valor[15:12] - 4'd1;
- 5'b11111:valor_siguiente[15:12] = 4'd0;
- default:valor_siguiente[15:12] = valor[15:12];
- endcase
- end
- always@(posedge clk3)begin
- if(rst)
- valor <= 12'd0;
- else valor <= valor_siguiente;
- end
- endmodule
- module clk_dos(clk,clk_out);
- input clk;
- output clk_out;
- reg a=0;
- reg b;
- always @(*)
- b=a+1;
- always @(posedge clk)begin
- a<=b;
- end
- assign clk_out=a;
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement