Skip to content

Commit 5e4ba6d

Browse files
committed
1 parent 87a5d12 commit 5e4ba6d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package hdlbits.building_larger_circuits
2+
3+
import chisel3._
4+
import chisel3.util._
5+
6+
// _root_ disambiguates from package chisel3.util.circt if user imports chisel3.util._
7+
import _root_.circt.stage.ChiselStage
8+
9+
// Generate Verilog sources and save it in file ExamsReview2015Count1k.sv
10+
object HdlBitsExamsReview2015Count1k extends App {
11+
ChiselStage.emitSystemVerilogFile(
12+
new HdlBitsExamsReview2015Count1k,
13+
firtoolOpts = Array(
14+
"-disable-all-randomization",
15+
"-strip-debug-info"
16+
),
17+
args = Array("--target-dir", "gen/hdlbits/building_larger_circuits")
18+
)
19+
}
20+
21+
// https://hdlbits.01xz.net/wiki/Exams/review2015_count1k
22+
class HdlBitsExamsReview2015Count1k extends RawModule {
23+
val clk = IO(Input(Clock()))
24+
val reset = IO(Input(Bool())) // Synchronous reset
25+
val q = IO(Output(UInt(10.W)))
26+
27+
val counter = withClockAndReset(clk, reset) { RegInit(0.U(10.W)) }
28+
29+
when(counter === 999.U) {
30+
counter := 0.U
31+
}.otherwise {
32+
counter := counter + 1.U
33+
}
34+
35+
q := counter
36+
}

0 commit comments

Comments
 (0)