Código Verilog
//////////////////////////////////////
// Contador de x e y
//////////////////////////////////////
//"OJO" CUANDO USAS DOS IF, LAS CONDICIONES DEL SEGUNDO IF SOLO SE DAN SI EL PRIMERO SE CUMPLE, ES DECIR, PARA QUE Y SUCEDA X DEBE SUCEDER PRIMERO.
always @(posedge clock_out1) begin
if (x == 4'd9) begin //si x llega a 9 vuelve a contar desde cero.
x <= 4'd0;
if (y == 4'd9) begin //una vez y tambien es 9 reinicia y.
y <= 4'd0;
end else begin // si X es nueve y Y aun no es nueve y sigue contando.
y <= y + 4'd1;
end
end else begin //aqui ocurre lo mismo que el else anterior.
x <= x + 4'd1;
end
end
El codigo completo se veria de la siguiente manera:
Código Verilog
module df(
input clk,
output wire [6:0] disi,
output wire hbl
);
//////////////////////////////////////
// Declaraciones de registros y wires
//////////////////////////////////////
reg clock_out = 0;
reg clock_out1 = 0;
reg [3:0] x = 0, y = 0;
reg cou = 0;
wire [6:0] display1, display2;
//////////////////////////////////////
// Contador de x e y
//////////////////////////////////////
//"OJO" CUANDO USAS DOS IF, LAS CONDICIONES DEL SEGUNDO IF SOLO SE DAN SI EL PRIMERO SE CUMPLE.
always @(posedge clock_out1) begin
if (x == 4'd9) begin //si x llega a 9 vuelve a contar desde cero.
x <= 4'd0;
if (y == 4'd9) begin //una vez y tambien es 9 reinicia y.
y <= 4'd0;
end else begin // si X es nueve y Y aun no es nueve y sigue contando.
y <= y + 4'd1;
end
end else begin //aqui ocurre lo mismo que el else anterior.
x <= x + 4'd1;
end
end
//////////////////////////////////////
// Permutación de displays
//////////////////////////////////////
always @(posedge clock_out) begin
cou <= ~cou; // Alternar el valor de cou
end
assign disi = (cou == 1'b0) ? display2 : display1;
assign hbl = (cou == 1'b0) ? 1'b0 : 1'b1;
//////////////////////////////////////
// ROM para los displays
//////////////////////////////////////
reg [6:0] rom_display1 [9:0]; // ROM con 10 entradas
initial begin //abcdefg
rom_display1[0] = ~7'b1111110; // 0
rom_display1[1] = ~7'b0110000; // 1
rom_display1[2] = ~7'b1101101; // 2
rom_display1[3] = ~7'b1111001; // 3
rom_display1[4] = ~7'b0110011; // 4
rom_display1[5] = ~7'b1011011; // 5
rom_display1[6] = ~7'b1011111; // 6
rom_display1[7] = ~7'b1110000; // 7
rom_display1[8] = ~7'b1111111; // 8
rom_display1[9] = ~7'b1110011; // 9
end
assign display1 = rom_display1[x];
assign display2 = rom_display1[y];
//////////////////////////////////////
// Generación de reloj
//////////////////////////////////////
reg [25:0] counter = 26'd0;
reg [25:0] counter1 = 26'd0;
parameter DIVISOR1 = 26'd50_000_000; // Ajusta esto según tu necesidad
parameter DIVISOR = 26'd100_000; // Ajusta esto según tu necesidad
always @(posedge clk) begin
counter <= counter + 28'd1;
if (counter >= DIVISOR)
counter <= 26'd0;
clock_out <= (counter < DIVISOR/2) ? 1'b1 : 1'b0;
end
always @(posedge clk) begin
counter1 <= counter1 + 26'd1;
if (counter1 >= DIVISOR1)
counter1 <= 26'd0;
clock_out1 <= (counter1 < DIVISOR1/2) ? 1'b1 : 1'b0;
end
endmodule
esto seria todo espero les haya gustado.