This problem set closes the Functions, Tasks & Utility Functions chapter. Each article's practice exercise and drills cover one function or task; these 6 problems use them in a design and in the testbench that drives it.

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

  • Give a function the width and the value its callers expect
  • Compute and round constants when the design is compiled
  • Size a counter from a parameter
  • Write tasks that drive signals over time and can overlap

What You'll Build

Across the set you build a checksum unit, the block that checks data before it leaves a link or a memory.

Each problem adds or fixes one piece: the checksum function, the error codes, a scale factor, a block counter and the tasks that drive the unit in a test. The last problem writes the unit for any block size.

OutputMeaningBuilt in
sumThe checksumProblems 1 and 6
count, doneThe bytes of a blockProblems 4 and 6
levelThe fill level, scaled at compile timeProblems 3 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

The checksumFix

A checksum built from a function passes its bench test. Make it right for any four bytes.

Practise: What a function returns
Builds on: Verilog Functions

Open in ChipVerify Lab →
2

Review a generated status decoderReview

A generated function passes the testbench that came with it. Review what it returns when there is nothing to report.

Practise: A value on every path through a function
Builds on: Verilog Functions

Open in ChipVerify Lab →
3

The scale factorFix

A fixed-point factor is computed at compile time and passes its bench test. Make it right for any fraction.

Practise: Constants from integers and reals
Builds on: Verilog Conversion Functions

Open in ChipVerify Lab →
4

Counting to NFix

A counter sized with $clog2 passes its bench test. Make it work for every block size.

Practise: Widths computed from a parameter
Builds on: Verilog Math Functions

Open in ChipVerify Lab →
5

The bus driverFix

The tasks of a testbench driver never put a byte on the bus. Make them work, also when a test runs both at once.

Practise: Task arguments and overlapping calls
Builds on: Verilog Task

Open in ChipVerify Lab →
6

The checksum unitWrite, final problem

Write the whole unit, with its checksum, parity and fill level, for any block size.

Practise: Functions and computed constants together
Builds on: Verilog Functions, Verilog Math Functions, Verilog Conversion Functions

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 thousands of values at several parameter settings, and calls the tasks of Problem 5 alone and at the same time. The designs are also synthesized to check that they contain no latches.

When a check fails, the console ends with a short list of what to look into. Each item explains the mistake and names the article section that covers it.

Before You Start

The problems use the ideas from the articles in this chapter, especially function return values, static and automatic tasks, and $clog2. If a problem stops you, the article it builds on is the place to look.

After This Chapter

The checksum unit already holds its results in registers. The Sequential Logic & Flip-Flops chapter goes further into registers, resets and enables.

Did you find what you were looking for?

Quiz

No quiz questions available for this article.