-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClock.scala
91 lines (74 loc) · 2.44 KB
/
Clock.scala
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
package MySpinalHardware
import spinal.core._
import spinal.lib._
import spinal.lib.fsm._
case class Clock() extends Component {
val io = new Bundle {
val PPS = in Bool()
val IncMinutes = in Bool()
val IncHours = in Bool()
val Seconds1 = out Bits(4 bits)
val Seconds10 = out Bits(4 bits)
val Minutes1 = out Bits(4 bits)
val Minutes10 = out Bits(4 bits)
val Hours1 = out Bits(4 bits)
val Hours10 = out Bits(4 bits)
}
val Seconds1 = Reg(UInt(4 bit)) init(0)
val Seconds10 = Reg(UInt(4 bit)) init(0)
val Minutes1 = Reg(UInt(4 bit)) init(0)
val Minutes10 = Reg(UInt(4 bit)) init(0)
val Hours1 = Reg(UInt(4 bit)) init(0)
val Hours10 = Reg(UInt(4 bit)) init(0)
val IncSeconds10 = False
val IncMinutes1 = False
val IncMinutes10 = False
val IncHours1 = False
io.Seconds1 := Seconds1.asBits
io.Seconds10 := Seconds10.asBits
io.Minutes1 := Minutes1.asBits
io.Minutes10 := Minutes10.asBits
io.Hours1 := Hours1.asBits
io.Hours10 := Hours10.asBits
when(io.PPS.rise){
when(Seconds1 === 9){
Seconds1 := 0
IncSeconds10 := True
}elsewhen( io.IncHours | io.IncMinutes){
Seconds1 := 0
}otherwise{
Seconds1 := Seconds1 + 1
}
when(Seconds10 === 5 && IncSeconds10){
IncMinutes1 := True
Seconds10 := 0
}elsewhen( io.IncHours | io.IncMinutes){
Seconds10 := 0
}elsewhen(IncSeconds10){
Seconds10 := Seconds10 + 1
}
when((Minutes1 === 9 && IncMinutes1) | (Minutes1 === 9 && io.IncMinutes)){
IncMinutes10 := True
Minutes1 := 0
}elsewhen(IncMinutes1 | io.IncMinutes){
Minutes1 := Minutes1 + 1
}
when(Minutes10 === 5 && IncMinutes10){
when(!io.IncMinutes){
IncHours1 := True
}
Minutes10 := 0
}elsewhen(IncMinutes10){
Minutes10 := Minutes10 + 1
}
when((Hours1 === 9 && IncHours1) | (Hours1 === 9 && io.IncHours)){
Hours1 := 0
Hours10 := Hours10 + 1
}elsewhen((Hours1 === 4 && Hours10 === 2 && IncHours1) | (Hours1 === 4 && Hours10 === 2 && io.IncHours)){
Hours1 := 0
Hours10 := 0
}elsewhen(IncHours1 | io.IncHours){
Hours1 := Hours1 + 1
}
}
}