Created
November 28, 2021 22:12
-
-
Save urish/b8b92e9945638b22c8f32b52dd306a76 to your computer and use it in GitHub Desktop.
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
`default_nettype none | |
`timescale 1ns/1ns | |
module encoder ( | |
input clk, | |
input reset, | |
input a, | |
input b, | |
output reg [7:0] value | |
); | |
reg old_a; | |
reg old_b; | |
wire [3:0] inputs = {a, old_a, b, old_b}; | |
always @(posedge clk) begin | |
if (reset) begin | |
old_a <= 0; | |
old_b <= 0; | |
value <= 0; | |
end else begin | |
if (inputs == 4'b1000 || inputs == 4'b0111) begin | |
value <= value + 1; | |
end else if (inputs === 4'b0010 || inputs == 4'b1101) begin | |
value <= value - 1; | |
end | |
old_a = a; | |
old_b = b; | |
end | |
end | |
endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment