Menu
Coddy logo textTech

Decoder Design

Part of the Fundamentals section of Coddy's Verilog journey — lesson 85 of 90.

challenge icon

Challenge

A decoder takes a binary number as input and turns on exactly one output based on that number. The output that turns on is called "one-hot" because only one bit is hot (1), and all others are cold (0).

Truth Table (2-to-4 Decoder)

Input (in)out0out1out2out3
001000
010100
100010
110001

Module Interface

PortDirectionWidthDescription
ininput2 bitsBinary input (0 to 3)
out0output1 bitActive when in = 00
out1output1 bitActive when in = 01
out2output1 bitActive when in = 10
out3output1 bitActive when in = 11

Your task is to complete the module below using a case statement.

What to do:

  1. When in = 2'b00, out0 = 1, all others 0
  2. When in = 2'b01, out1 = 1, all others 0
  3. When in = 2'b10, out2 = 1, all others 0
  4. When in = 2'b11, out3 = 1, all others 0

Try it yourself

module decoder (
  input [1:0] in,
  output reg out0,
  output reg out1,
  output reg out2,
  output reg out3
);
  
  // TODO: Add always @(*) block with case (in)
  // 2'b00: out0=1, others 0
  // 2'b01: out1=1, others 0
  // 2'b10: out2=1, others 0
  // 2'b11: out3=1, others 0

endmodule

All lessons in Fundamentals