Problems

7. Up/down counter with load

EasyWrite the moduleAbout 15 minFree
sequentialcounterspriority

Build a 4-bit counter that can count up or down and can be loaded with a value.

On each rising clock edge, in this order of priority: 1. rst = 1: q becomes 0. 2. load = 1: q becomes d (whatever en is). 3. en = 1: q goes up by 1 when up = 1, or down by 1 when up = 0. It wraps: 15 + 1 is 0 and 0 - 1 is 15. 4. Otherwise q keeps its value.

rst is synchronous and active high.

Ports

Module updown4

PortDirBitsWhat it is
clkin1Clock.
rstin1Synchronous reset, active high.
enin1Count enable.
upin11 counts up, 0 counts down.
loadin1Load d into q (beats en).
din4Value to load.
qout4The count.

Example

After reset q = 0. With en = 1 and up = 0, the next edge gives q = 15. With load = 1 and d = 9, the next edge gives q = 9 even if en is 1.

Stuck? . Sign in to save your progress. You can solve the free problems without an account.

Verilogupdown4.v
14px
Loading the editor…

Submit your answer to have it graded. The hidden test runs on the server; you see whether it passes and, if not, the first case it gets wrong.

Up/down counter with load: Verilog interview question | breadboardhub