-
Notifications
You must be signed in to change notification settings - Fork 0
/
trip_behav.sv
114 lines (107 loc) · 2.15 KB
/
trip_behav.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
module trip_behav (input logic clock,nRst,nTrip,nFork,
output logic[3:0]hour,
output logic[9:0]mins);
logic [19:0] count_time,count_time_temp;
logic [5:0] min;
//logic [3:0] hour_temp;
enum logic [1:0] {init,count1,count2,calcu} state;
timeunit 1ns;
timeprecision 100ps;
assign mins = {4'b0000,min};
always_ff @(posedge clock, negedge nRst)
begin:SEQ
if(!nRst)
begin
state <= init;
count_time <= '0;
min <= '0;
hour <= '0;
count_time_temp <= '0;
end
else
begin
unique case(state)
init: begin
if (count_time >= 768000) //60sec
begin
min <= min + 1;
count_time <= count_time - 768000;
if (min == 59)
begin
min <= '0;
hour <= hour + 1;
if(hour == 9)
begin
hour <= '0;
end
end
end
count_time_temp <= count_time_temp + 1;
state <= count1;
if(!nTrip)
begin
state <= init;
count_time <= '0;
count_time_temp <= '0;
min <= '0;
hour <= '0;
end
end
count1: begin
if(nFork)
count_time_temp <= count_time_temp + 1;
else
begin
state <= count2;
end
if(!nTrip)
begin
state <= init;
count_time <= '0;
count_time_temp <= '0;
min <= '0;
hour <= '0;
end
end
count2: begin
if(!nFork)
count_time_temp <= count_time_temp + 1;
else
begin
state <= calcu;
end
if(!nTrip)
begin
state <= init;
count_time <= '0;
count_time_temp <= '0;
min <= '0;
hour <= '0;
end
//count_time_temp <= count_time_temp + 1;
end
calcu: begin
if(count_time_temp <= 64000) //max time per ratote
begin
count_time <= count_time + count_time_temp;
state <= init;
count_time_temp <= '0;
end
else
begin
state <= init;
count_time_temp <= '0;
end
if(!nTrip)
begin
state <= init;
count_time <= '0;
count_time_temp <= '0;
min <= '0;
hour <= '0;
end
end
endcase
end
end
endmodule