generated from efabless/caravel_user_project
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8ca557
commit 659984c
Showing
6 changed files
with
217 additions
and
22 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
module piso #( | ||
parameter WIDTH = 8 // Parameter to define the bit width | ||
)( | ||
input wire clk1, // Clock signal | ||
input wire clk2, | ||
input wire rst, // Reset signal | ||
input wire load, // Load signal to load parallel data | ||
input wire [WIDTH-1:0] parallel_in, // Parallel input data | ||
output wire serial_out // Serial output | ||
); | ||
|
||
genvar i; | ||
reg [WIDTH-1:0] shift_reg; | ||
|
||
generate | ||
for (i = WIDTH-1; i > 0; i = i - 1) begin : piso_bits | ||
// Master-slave latch pair for each bit (excluding the first bit) | ||
MasterSlaveLatch msl ( | ||
.clk1(clk1), | ||
.clk2(clk2), | ||
.rst(rst), | ||
.d(load ? parallel_in[i] : shift_reg[i-1]), // Load or shift data | ||
.q(shift_reg[i]) | ||
); | ||
end | ||
endgenerate | ||
|
||
// First latch in the chain (handle the 0th bit) | ||
MasterSlaveLatch msl0 ( | ||
.clk1(clk1), | ||
.clk2(clk2), | ||
.rst(rst), | ||
.d(load ? parallel_in[0] : 1'b0), // Load or shift in 0 | ||
.q(shift_reg[0]) | ||
); | ||
|
||
// Serial output is the last bit of the shift register | ||
assign serial_out = shift_reg[WIDTH-1]; | ||
|
||
endmodule | ||
|
||
// Master-Slave latch with synchronous reset | ||
module MasterSlaveLatch( | ||
input wire clk1, | ||
input wire clk2, | ||
input wire rst, | ||
input wire d, | ||
output wire q | ||
); | ||
|
||
wire master_q, slave_q; | ||
|
||
// Master latch: Transparent when clk is low | ||
Latch master ( | ||
.enable(clk1), // Master latch is enabled when clk is low | ||
.rst(rst), | ||
.d(d), | ||
.q(master_q) | ||
); | ||
|
||
// Slave latch: Transparent when clk is high | ||
Latch slave ( | ||
.enable(clk2), // Slave latch is enabled when clk is high | ||
.rst(rst), | ||
.d(master_q), | ||
.q(slave_q) | ||
); | ||
|
||
// Output of the slave latch is the output of the master-slave pair | ||
assign q = slave_q; | ||
|
||
endmodule | ||
|
||
// Simple latch module with reset | ||
module Latch( | ||
input wire enable, | ||
input wire rst, | ||
input wire d, | ||
output reg q | ||
); | ||
|
||
always @(*) begin | ||
if (rst) begin | ||
q <= 1'b0; // Reset the latch | ||
end else if (enable) begin | ||
q <= d; // Capture input when enabled | ||
end | ||
end | ||
|
||
endmodule | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
module sipo #( | ||
parameter WIDTH = 8 // Parameter to define the bit width | ||
)( | ||
input wire clk1, // Clock signal | ||
input wire clk2, | ||
input wire rst, // Reset signal | ||
input wire serial_in, // Serial input | ||
input wire load, // Load the output | ||
output wire [WIDTH-1:0] parallel_out // Parameterized parallel output | ||
); | ||
|
||
genvar i; | ||
wire [WIDTH-1:0] shift_reg; | ||
reg [WIDTH-1:0] parallel_shadow; | ||
|
||
generate | ||
for (i = 0; i < WIDTH; i = i + 1) begin : sipo_bits | ||
if (i == 0) begin | ||
// First master-slave latch pair receives the serial input | ||
MasterSlaveLatch msl ( | ||
.clk1(clk1), | ||
.clk2(clk2), | ||
.rst(rst), | ||
.d(serial_in), | ||
.q(shift_reg[i]) | ||
); | ||
end else begin | ||
// Each subsequent master-slave latch pair takes the output of the previous stage | ||
MasterSlaveLatch msl ( | ||
.clk1(clk1), | ||
.clk2(clk2), | ||
.rst(rst), | ||
.d(shift_reg[i-1]), | ||
.q(shift_reg[i]) | ||
); | ||
end | ||
end | ||
endgenerate | ||
|
||
// Connect the shift register to the output | ||
assign parallel_shadow = shift_reg; | ||
always @(clk) begin | ||
if(rst) parallel_shadow <= {WIDTH{1'b0}} | ||
else begin | ||
if (load) begin | ||
parallel_out <= parallel_shadow; | ||
end | ||
end | ||
|
||
end | ||
|
||
endmodule | ||
|
||
// Master-Slave latch with synchronous reset | ||
module MasterSlaveLatch( | ||
input wire clk1, | ||
input wire clk2, | ||
input wire rst, | ||
input wire d, | ||
output wire q | ||
); | ||
|
||
wire master_q, slave_q; | ||
|
||
// Master latch: Transparent when clk is low | ||
Latch master ( | ||
.enable(clk1), // Master latch is enabled when clk is low | ||
.rst(rst), | ||
.d(d), | ||
.q(master_q) | ||
); | ||
|
||
// Slave latch: Transparent when clk is high | ||
Latch slave ( | ||
.enable(clk2), // Slave latch is enabled when clk is high | ||
.rst(rst), | ||
.d(master_q), | ||
.q(slave_q) | ||
); | ||
|
||
// Output of the slave latch is the output of the master-slave pair | ||
assign q = slave_q; | ||
|
||
endmodule | ||
|
||
// Simple latch module with reset | ||
module Latch( | ||
input wire enable, | ||
input wire rst, | ||
input wire d, | ||
output reg q | ||
); | ||
|
||
always @(*) begin | ||
if (rst) begin | ||
q <= 1'b0; // Reset the latch | ||
end else if (enable) begin | ||
q <= d; // Capture input when enabled | ||
end | ||
end | ||
|
||
endmodule | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters