-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtarget_control_power.sv
86 lines (71 loc) · 2.08 KB
/
target_control_power.sv
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Target control module: Power
* Grounds or connects the target's main power feed
*/
module target_control_power(
input rst,
input clk,
input trigger, // High to reset target device
output target_power, // High to enable target's power feed
output target_throttle // High to ground target's power feed
);
// Cycles of the fast clock.
// At 48MHz, 100ms is 4800000 cycles
// GUARD_CYCLES are maintained between powering and grounding the target, to prevent short circuit.
parameter GUARD_CYCLES=100;
parameter RESET_CYCLES=4800000;
// Safeguard against short circuit
reg request_power;
reg request_throttle;
assign target_power = request_power & !request_throttle;
assign target_throttle = request_throttle & !request_power;
// IDLE has the device powered up
// DRAINING has power pin floating
// LOW has power pin forced to ground
// GUARDING has power pin floating
enum reg [2:0] { IDLE, DRAINING, LOW, GUARDING } state;
reg [31:0] elapsed_cycles;
always @(posedge clk) begin
if (rst) begin
// Start in the floating state, counting down to power up the target device
state <= GUARDING;
elapsed_cycles <= RESET_CYCLES + GUARD_CYCLES;
request_power <= 0;
request_throttle <= 0;
end
else begin
if (state != IDLE) begin
elapsed_cycles <= elapsed_cycles + 1;
end
if (state == IDLE) begin
if (trigger) begin
state <= DRAINING;
elapsed_cycles <= 1;
request_power <= 0;
request_throttle <= 0;
end
end
else if (state == DRAINING) begin
if (elapsed_cycles >= GUARD_CYCLES) begin
state <= LOW;
request_power <= 0;
request_throttle <= 1;
end
end
else if (state == LOW) begin
if (elapsed_cycles >= (RESET_CYCLES - GUARD_CYCLES)) begin
state <= GUARDING;
request_power <= 0;
request_throttle <= 0;
end
end
else if (state == GUARDING) begin
if (elapsed_cycles >= RESET_CYCLES) begin
state <= IDLE;
request_power <= 1;
request_throttle <= 0;
end
end
end
end
endmodule