Lab 3
Lab 3
Lab 3
//ex1
`timescale 1ns / 1ps
module ex1(
input wire clk, // 125 MHz clock
output reg led_red,
output reg led_blue
);
endmodule
lab 3 1
//ex2 module
module ex2(
input clk,
input in,
output reg out
);
endmodule
//tb
module ex2_tb;
reg clk;
reg in;
wire out;
ex2 uut (
.clk(clk),
.in(in),
.out(out)
);
initial begin
clk = 0;
forever #5 clk = ~clk; // 100 MHz clock
end
initial begin
lab 3 2
in = 0;
#12 in = 1;
#10 in = 0;
#20 in = 1;
#10 in = 0;
#20 $stop;
end
endmodule
//ex2 arty
module ex2(
input clk,
input in,
output reg [3:0] out
);
reg pre_in;
reg q1, q2;
initial begin
out = 4'b0000;
end
endmodule
lab 3 3
//ex3
`timescale 1ns / 1ps
module ex3(
input clk,
input [3:0] btn,
output reg [3:0] led
);
initial begin
led = 4'b0011;
end
// State encoding
localparam IDLE = 2'b00;
localparam SHIFT_RIGHT = 2'b01;
localparam SHIFT_LEFT = 2'b10;
lab 3 4
shift_enable <= 0;
end
end
case (state)
IDLE: begin
// Do nothing
end
SHIFT_RIGHT: begin
if (shift_enable) begin
led <= {led[2:0], led[3]}; // Shift right
end
end
SHIFT_LEFT: begin
if (shift_enable) begin
led <= {led[0], led[3:1]}; // Shift left
end
end
endcase
end
endmodule
lab 3 5