Skip to content

Commit

Permalink
added resets to some logic in controller.v
Browse files Browse the repository at this point in the history
  • Loading branch information
faramire committed Sep 4, 2024
1 parent ef8d28c commit e17fabf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
29 changes: 20 additions & 9 deletions src/controller.v
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,47 @@ module controller (

output wire [11:0] led_mask,
output reg [ 7:0] intensity_out,
output wire [ 4:0] state_out
output reg [ 4:0] state_out
);

// State
reg inverted;
reg [3:0] led_binary;
assign state_out = {inverted, led_binary};

reg [11:0] led_mask_i; // internal, without inversion
assign led_mask = {12{inverted}} ^ led_mask_i;

// Inversion
always @(posedge clk) begin
if (push) begin
if (!res) begin
inverted <= 0;
end else begin
if (push) begin
inverted <= ~inverted;
end
end
end

// Intensity
always @(posedge clk) begin
case(intensity_in[1:0])
2'b00: intensity_out <= 8'b0000_0001;
2'b01: intensity_out <= 8'b0000_0010;
2'b10: intensity_out <= 8'b0000_1000;
2'b11: intensity_out <= 8'b0010_0000;
endcase
if (!res_n) begin
intensity_out <= 8'b0000_0001;
end else begin
case(intensity_in[1:0])
2'b00: intensity_out <= 8'b0000_0001;
2'b01: intensity_out <= 8'b0000_0010;
2'b10: intensity_out <= 8'b0000_1000;
2'b11: intensity_out <= 8'b0010_0000;
default:;
endcase
end
end

// LED
always @(posedge clk) begin
if (!res_n) begin //reset
led_mask_i <= 12'b0000_0000_0001;
state_out <= 5'b1_1111;
led_binary <= 4'b0;
inverted <= 0;
end else begin
Expand Down Expand Up @@ -74,6 +83,8 @@ module controller (
default:;
endcase

state_out <= {inverted, led_binary};

end
end

Expand Down
35 changes: 19 additions & 16 deletions src/rotary_ring_wrapper.v
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ module tt_um_faramire_rotary_ring_wrapper (
input wire rst_n // reset_n - low to reset
);

wire [11:0] led_mask;
wire [ 7:0] intensity;
wire [11:0] led_mask_wire;
wire [ 7:0] intensity_wire;

wire rot_up;
wire rot_dn;
wire rot_up_wire;
wire rot_dn_wire;

controller ctr1 (
.clk(clk),
.res_n(rst_n),
.rot_up(rot_up),
.rot_dn(rot_dn),
.rot_up(rot_up_wire),
.rot_dn(rot_dn_wire),
.push(ui_in[2]),
.led_mask(led_mask),
.intensity_in(ui_in[7:6]),
.intensity_out(intensity),

.led_mask(led_mask_wire),
.intensity_out(intensity_wire),
.state_out(uo_out[5:1])
);

Expand All @@ -42,25 +43,27 @@ module tt_um_faramire_rotary_ring_wrapper (
.res_n(rst_n),
.rotary_clk(ui_in[0]),
.rotary_dt(ui_in[1]),
.rotation_up(rot_up),
.rotation_dn(rot_dn)

.rotation_up(rot_up_wire),
.rotation_dn(rot_dn_wire)
);

led_ring_driver leddriv1 (
.clk(clk),
.res_n(rst_n),
.led_mask(led_mask),
.led_mask(led_mask_wire),
.colour(ui_in[5:3]),
.intensity(intensity),
.intensity(intensity_wire),

.led_dout(uo_out[0])
);

// All output pins must be assigned. If not used, assign to 0.
assign uo_out[7:6] = 0;
assign uio_out = 0;
assign uio_oe = 0;
assign uo_out[7:6] = 2'b0;
assign uio_out = 8'b0;
assign uio_oe = 8'b0;

// List all unused inputs to prevent warnings
wire _unused = &{ena, uio_in[7:0], 1'b0};
wire _unused = &{ena, ui_in[7:6], uio_in[7:0], 1'b0};

endmodule

0 comments on commit e17fabf

Please sign in to comment.