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.

OutputMeaningBuilt in
opThe operation code of the commandProblems 2, 3 and 6
respThe response codeProblems 4 and 6
chk_ok1 when the payload checksum is rightProblems 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.

1

Which commands are acceptedFix

A gate that decides which commands may run passes its bench test. Make it follow the tables for every status.

Practise: Conditions on a multi-bit signal
Builds on: Verilog Conditional Statements

Open in ChipVerify Lab →
2

The opcode decoderFix

Two commands from the datasheet were added to a decoder, and the peripheral never sees them. Find out why.

Practise: How a case compares its items
Builds on: Verilog case statement

Open in ChipVerify Lab →
3

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.

Practise: Wildcard matching and unknown values
Builds on: Verilog case statement

Open in ChipVerify Lab →
4

The response codeFix

A chain of conditions answers every command with a code, and some answers are wrong. Make it follow its table.

Practise: Priority and pairing in if-else-if
Builds on: Verilog if-else-if

Open in ChipVerify Lab →
5

Review a generated checksumReview

A generated checksum unit passes the testbench that came with it. Review it for every parameter value, and synthesize it.

Practise: Loops and generate blocks that become hardware
Builds on: Verilog for Loop, Verilog generate block

Open in ChipVerify Lab →
6

The command decoderWrite, final problem

Write the whole decoder, with its operation code, payload check and response code, for any payload size.

Practise: case, if-else-if, loops and generate together
Builds on: Verilog case statement, Verilog if-else-if, Verilog for Loop, Verilog generate block

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.

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.

Did you find what you were looking for?

Quiz

No quiz questions available for this article.