I'm building a PIPO register to implement on a fpga. I have written the code below, but there is something wrong with my register module I believe.
The value of Q won't save. My intention was that Q would save the value of D until enable is changed. But Q is constantly changing itself to match the value of D.
I've posted a link to what the project should look like. Thanks for the help.
`timescale 1ns / 1ps
module register (
input clk,
input en,
input [7:0] D,
output reg [7:0] Q
);
//always @ (posedge(clk),posedge(en))
always @ (en)
begin
if (en == 1)
Q <= 8'b00000000;
else
Q <= D;
end
endmodule
module mux (
input Sel,
input [7:0] I0,
input [7:0] I1,
output reg [7:0] led
);
always @ (Sel,I0,I1)
begin
if (Sel == 1)
led <= I1;
else
led <= I0;
end
endmodule
module pipo(
//input clk,
input en,
input [7:0] sw,
input Sel,
input [7:0] I0,
output [7:0] led
);
wire [7:0] sData;
register piporeg(
//.clk(clk),
.en(en),
.D(sw),
.Q(sData)
);
mux pipomux(
.Sel(Sel),
.I0(sw),
.I1(sData),
.led(led)
);
endmodule
```