-
Notifications
You must be signed in to change notification settings - Fork 383
/
encoder.v
44 lines (35 loc) · 886 Bytes
/
encoder.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//--------------------------------------------------------------------------------
// encoder.v
// Konstantin Pavlov, pavlovconst@gmail.com
//--------------------------------------------------------------------------------
// INFO --------------------------------------------------------------------------------
// Digital encoder
/*encoder E1(
.clk(),
.nrst(),
.incA(),
.incB(),
.plus1(),
.minus1()
);*/
module encoder(clk,nrst,incA,incB,plus1,minus1);
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