Chisel Practice
Build fluency with short Chisel problems. Edit the circuit generator, run the chiseltest testbench, then submit your solution.
Your drafts and solved problems stay in this browser.
Jump to a chapter
A Module, its IO, and the := connection
1 problemRead a Chisel module as a Scala class that builds a circuit, tell the connection := apart from a Scala name, predict what the testbench prints, run it, then change one parameter and see a different circuit.
Bool, UInt, and the operators
1 problemTell a one-bit Bool from a multi-bit UInt, apply the bitwise, bit-field, Cat and reduction operators to an 8-bit value by hand, run the operator example, see what shifts, arithmetic and comparisons build and how wide their results are, then build a parity frame.
Widths, SInt, and arithmetic
2 problemsGive a port a width with .W, read the width Chisel assigns to a literal, follow a signed value through a connection and a cast, then see why + loses a carry that +& keeps.
Mux, when, Wire, and a default for every path
1 problemChoose between values with Mux and when, give a Wire a default, read the last-connection-wins rule off a trace, and see what happens to a path nothing drives.
Selecting with MuxCase, MuxLookup, PriorityMux and Mux1H
3 problemsChoose among many inputs with MuxCase, MuxLookup, PriorityMux and Mux1H, and decide which one a selection calls for by how its selectors behave.
- 20VerificationRepair the burst-length tableFind why a MuxLookup burst-length table returns the wrong beat count for two codes.
- 21ImplementationCheckpoint A: select one of four operationsWrite a combinational ALU slice from scratch: a 2-bit sel picks which of four bitwise operations on a and b reaches y.
- 22ImplementationGrant the lowest requestSelect the data of the lowest-numbered requester, with an explicit 0 when nobody asks.
Conditional update, hold, and reset
1 problemUpdate a register only under a when and let it hold otherwise, decide which registers a reset changes from how each was created, see that the implicit reset acts at a clock edge, and write priority as source order.
RegNext, delays, and waveforms
3 problemsDelay a signal by one edge with RegNext and by two with a second one, build a rising-edge detector from the delayed copy, then read reset, pokes, and register changes off a recorded waveform.
- 11ImplementationCount rising edges, not high cyclesGive an event counter a registered copy of its input so it counts each 0-to-1 transition once.
- 29ImplementationLatch a PWM duty at the period boundaryLoad the duty register only at the edge that ends a period, and confirm the timing against count and level in the waveform.
- 30VerificationKeep a tick divider's phase across pausesTicks after a pause land in the wrong cycles; find in the waveform what phase does while en is low.
Bundles and Vecs
2 problemsGroup named fields in a Bundle and indexed elements in a Vec, read the bit layout that asUInt and asTypeOf follow, tell a Scala index from a hardware index, and use Flipped to put one interface declaration on both ends of a link.
Child modules, parameters, and generators
3 problemsPlace a module inside another with Module(new ...), drive every child input, build a family of definitions from one parameterized class with require and desiredName, call a module through a companion apply, and read a generator written with for and def by counting what it built.
- 02VerificationFind the parameter a generator loop ignoresCount the ELABORATE lines to find why one gain output is wrong while the other is right.
- 09ImplementationSort three values with child modulesComplete a three-input sorter by instantiating and wiring one more two-input sorter.
- 10VerificationGive every lane its own unitFind why four lanes of absolute differences all report the same value.
ChiselEnum and state machines
2 problemsGive each state a name with ChiselEnum, hold it in a register, branch on it with switch and is, convert between an enum and raw bits safely, and read the width Chisel picked.
Design from a requirement
1 problemTurn a written requirement into ports, a register with a reset value, a when chain whose order is the priority, and a wrapping add, keep the functional clear apart from the implicit reset, and check the design against a cycle table before grading.
Memories
2 problemsRead-only tables with VecInit and Counter, the combinational-read Mem, the synchronous-read SyncReadMem with its one-cycle latency and undefined-read cases, write masks and the SRAM API, and how to choose between them.
Interfaces and connections
2 problemsDescribe an interface as a Bundle, connect two of them in bulk with <>, see what happens to a field with no partner, and run a ready-valid link with Decoupled.
- 16VerificationKeep a tag with its requestFind why a one-cycle retiming stage delivers each request with the next request's tag.
- 17ImplementationClose a ready-valid valve in both directionsDrive the backward ready signal of a gated Decoupled stage so that producer and consumer agree on every transfer.
Polymorphism and parameterization
2 problemsSeparate Scala type parameters and their upper bounds from value parameters, then use type templates, configuration objects, optional ports, and by-name module arguments to build related circuits.
Printing from hardware
2 problemsPrint from inside the circuit with printf and the cf interpolator, tell hardware printing from elaboration-time println, and read the signal names the compiler gives your vals.
- 25ImplementationTurn a hex digit into its ASCII characterMap digits 10 to 15 to the letters a to f, checking each cycle with a printf that shows %x next to %c.
- 26VerificationRestart a frame checksum on its start byteRead the printf trace to see why a new frame keeps adding to the previous frame's sum.
Testbench techniques
2 problemsRead a failed expectation down to the step that produced it, wait for an event without hanging the test, and use the idle-cycle timeout to tell a slow design from a stuck one.
- 27ImplementationStretch a trigger into a three-cycle pulseImplement the counter behind a pulse stretcher and use the step number in each failed expect to find the cycle that is still wrong.
- 28VerificationFix a countdown that never reports doneA wait loop hits its idle-cycle timeout; use the WAIT trace to find where the counter stops.