-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdetect_edge.sv
More file actions
69 lines (56 loc) · 1.39 KB
/
Copy pathdetect_edge.sv
File metadata and controls
69 lines (56 loc) · 1.39 KB
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
68
69
/*
* Detector module: edge
* Waits for an edge of a single input pin, generates a trigger signal
*/
module detect_edge(
input rst,
input clk,
input target,
input arm,
output reg trigger
);
parameter TRIG_CYCLES=1;
parameter RISING_EDGE=1;
// IDLE is waiting for the arm signal
// WAIT is armed, waiting for the target's signal to go inactive
// ARMED is armed, waiting fo the active edge
// ACTIVE is holding the output trigger high
// FINISHED is waiting for the arm signal to return to inactive
enum reg [2:0] { IDLE, WAIT, ARMED, ACTIVE, FINISHED } state;
reg [4:0] triggered_cycles;
always @(posedge clk) begin
if (rst) begin
state <= IDLE;
triggered_cycles <= 0;
trigger <= 0;
end
else begin
if (state == IDLE) begin
if (arm) begin
state <= WAIT;
triggered_cycles <= 0;
end
end
else if (state == WAIT) begin
if (target != RISING_EDGE) state <= ARMED;
end
else if (state == ARMED) begin
if (target == RISING_EDGE) begin
state <= ACTIVE;
trigger <= 1;
triggered_cycles <= 1;
end
end
else if (state == ACTIVE) begin
if (triggered_cycles >= TRIG_CYCLES) begin
state <= FINISHED;
trigger <= 0;
end
else triggered_cycles <= triggered_cycles + 1;
end
else if (state == FINISHED) begin
if (!arm) state <= IDLE;
end
end
end
endmodule