-
-
Save DonDrews/cd14d55def2f3abf6d5aed5ac0b41703 to your computer and use it in GitHub Desktop.
Quadrature with Reset Line
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
module quad(clk, rst, quadA, quadB, count); | |
input clk, rst, quadA, quadB; | |
output [7:0] count; | |
reg [2:0] quadA_delayed; | |
reg [2:0] quadB_delayed; | |
always @(posedge clk) quadA_delayed <= {quadA_delayed[1:0], quadA}; | |
always @(posedge clk) quadB_delayed <= {quadB_delayed[1:0], quadB}; | |
wire count_enable = quadA_delayed[1] ^ quadA_delayed[2] ^ quadB_delayed[1] ^ quadB_delayed[2]; | |
wire count_direction = quadA_delayed[1] ^ quadB_delayed[2]; | |
reg [7:0] count; | |
always @(posedge clk) begin | |
if(rst) begin | |
count <= 0; | |
end | |
else if(~rst & count_enable) | |
begin | |
if(count_direction) count<=count+1; else count<=count-1; | |
end | |
end | |
endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment