2016-01-01 22:39:14 +03:00
|
|
|
//--------------------------------------------------------------------------------
|
2019-02-23 00:20:06 +03:00
|
|
|
// encoder.v
|
2016-01-01 22:39:14 +03:00
|
|
|
// Konstantin Pavlov, pavlovconst@gmail.com
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// INFO --------------------------------------------------------------------------------
|
2019-02-23 00:20:06 +03:00
|
|
|
// Digital encoder
|
2016-12-12 11:41:56 +03:00
|
|
|
|
2016-01-01 22:39:14 +03:00
|
|
|
|
2019-02-23 00:20:06 +03:00
|
|
|
/*encoder E1(
|
2016-01-01 22:39:14 +03:00
|
|
|
.clk(),
|
|
|
|
.nrst(),
|
|
|
|
.incA(),
|
|
|
|
.incB(),
|
|
|
|
.plus1(),
|
|
|
|
.minus1()
|
|
|
|
);*/
|
|
|
|
|
|
|
|
|
2019-02-23 00:20:06 +03:00
|
|
|
module encoder(clk,nrst,incA,incB,plus1,minus1);
|
2016-01-01 22:39:14 +03:00
|
|
|
|
|
|
|
input wire clk;
|
|
|
|
input wire nrst;
|
|
|
|
input wire incA, incB; // present input values
|
|
|
|
output reg plus1 = 0, minus1 = 0;
|
|
|
|
|
|
|
|
reg bufA = 0, bufB = 0; // previous inputvalues
|
|
|
|
|
|
|
|
always @ (posedge clk) begin
|
|
|
|
if (~nrst) begin
|
|
|
|
bufA <= 0;
|
|
|
|
bufB <= 0;
|
|
|
|
plus1 <= 0;
|
|
|
|
minus1 <= 0;
|
|
|
|
end
|
|
|
|
else begin
|
|
|
|
plus1 <= (bufA^incB)&~(incA^bufB);
|
|
|
|
minus1 <= (incA^bufB)&~(bufA^incB);
|
|
|
|
bufA <= incA;
|
|
|
|
bufB <= incB;
|
|
|
|
end // if
|
|
|
|
end
|
|
|
|
|
|
|
|
endmodule
|