File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
src/main/scala/hdlbits/building_larger_circuits Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments