This problem set closes the Conditionals & Loops chapter. Each article's practice exercise and drills cover one idea; these 6 problems put conditions, case statements and loops in one design, so part of the work is deciding which rule applies.
Most problems hand you code to fix or review rather than a blank file. Each one runs in ChipVerify Lab, and when your design fails, the grader explains what went wrong and which article covers it.
6 problems | Beginner Level
What You'll Learn
- Write conditions that test the bits you mean
- Match case items to their expression, and ignore bits on purpose
- Give overlapping conditions the right priority
- Write loops that synthesis can unroll
- Cover every parameter value in a generate block
What You'll Build
Across the set you build the command decoder of a small peripheral, the block that looks at every command byte and decides whether it may run.
Each problem adds or fixes one piece: the gate, the opcode decoder, the response code and the payload checksum. The last problem puts them together into a decoder for any payload size.
| Output | Meaning | Built in |
|---|---|---|
op | The operation code of the command | Problems 2, 3 and 6 |
resp | The response code | Problems 4 and 6 |
chk_ok | 1 when the payload checksum is right | Problems 5 and 6 |
The Problems
Work through the problems in order: later problems reuse what you built in earlier ones. Each starts with a short spec and a testbench you can run before you submit.
Which commands are acceptedFix
A gate that decides which commands may run passes its bench test. Make it follow the tables for every status.
Open in ChipVerify Lab →The opcode decoderFix
Two commands from the datasheet were added to a decoder, and the peripheral never sees them. Find out why.
Open in ChipVerify Lab →Review a generated decoderReview
A generated command decoder passes the testbench that came with it. Review how it behaves on a bus nobody drives yet.
Open in ChipVerify Lab →The response codeFix
A chain of conditions answers every command with a code, and some answers are wrong. Make it follow its table.
Open in ChipVerify Lab →Review a generated checksumReview
A generated checksum unit passes the testbench that came with it. Review it for every parameter value, and synthesize it.
Open in ChipVerify Lab →The command decoderWrite, final problem
Write the whole decoder, with its operation code, payload check and response code, for any payload size.
Open in ChipVerify Lab →How Your Solution Is Graded
Every problem has a visible testbench that you can run and edit. When you submit, a hidden grading testbench checks every input combination or thousands of random ones, at several parameter values where there are any, and the design is synthesized to check that it contains no latches.
When a check fails, the console ends with a short list of what to look into. Each item explains the mistake in terms of the hardware and names the article section that covers it.
Before You Start
The problems use the ideas from the articles in this chapter, especially case statements, if-else-if chains and for loops. If a problem stops you, the article it builds on is the place to look.
- Verilog Conditional Statements
- Verilog if-else-if
- Verilog case statement
- Verilog for Loop
- Verilog generate block
After This Chapter
The decoder is combinational logic from end to end. The Combinational Logic chapter goes further into how such logic is built and how to keep it free of latches.