-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tachometer.v
67 lines (60 loc) · 1.42 KB
/
Tachometer.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer: Brent Clancy
//
// Create Date: 12:27:05 03/05/2014
// Design Name:
// Module Name: Tachometer_PWM
// Project Name:
// Target Devices:
// Tool versions:
// Description: Takes in a Tachometer input and compares it to re-adjust for
// a dynamic value based off of input.
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module AngularEncoder(
input AE_CLK,
input PWM_CLK,
input [7:0] Duty_In,
input TachometerA, // White wire
output PWM_Out,
output [7:0] Rate
);
reg [7:0] NewDuty, Counter, Rate_;
reg First;
assign Rate = Rate_;
initial begin
First = 1;
NewDuty = 0;
Counter = 0;
Rate_ = 0;
end
// Measured frequencies:
// 0 to 145 Hz
always @ (posedge Tachometer_CLK) begin
if(First) begin // first check on posedge
if(TachometerA) begin
Counter <= Counter+1; // increment counter
end else begin
First <= 0; // end of pulse
Rate_ <= Counter;
end
end else if(TachometerA) begin
First <= 1; // Allow for next pulse
Counter <= 1; // Count this pulse
end
end
PWM pwm1 (
.CLK(PWM_CLK),
//.DUTY_CYCLE(NewDuty),
.DUTY_CYCLE(Rate_),
.PWM_OUT(PWM_Out)
);
endmodule