Question

In: Electrical Engineering

Write a Huffman decoder in verilog that inputs a text file with testbench.

Write a Huffman decoder in verilog that inputs a text file with testbench.

Solutions

Expert Solution

verilog module code

module huffman_decoder(

input clk,

input reset,

input start,

input [2:0] in,

output reg [3:0] out

);

// SIGNAL DECLARATIONS

localparam s0 = 3'd0;

localparam s1 = 3'd1;

localparam s2 = 3'd2;

localparam s3 = 3'd3;

localparam s4 = 3'd4;

localparam s5 = 3'd5;

localparam s6 = 3'd6;

localparam s7 = 3'd7;

reg [2:0] buffer;

// FSM SIGNALS

reg [2:0] ps, ns;

// PRESENT STATE LOGIC

always@(posedge clk, posedge reset)

begin

if(reset)

begin

ps <= s0;

end

else

begin

ps <= ns;

end

end

// NEXT STATE LOGIC

always@*

begin

ns = ps;

case(ps)

s0 : begin

if(start)

begin

buffer = in;

ns = s1;

end

else

begin

ns = s0;

end

end

s1 : begin

if(buffer[2] == 1'b0)

ns = s2;

else if(buffer[1] == 1'b1)

ns = s3;

else

ns = s0;

end

s2 : begin

if(buffer[1] == 1'b0)

ns = s4;

else if(buffer[1] == 1'b1)

ns = s5;

else

ns = s0;

end

s3 : begin

if(buffer[1] == 1'b0)

ns = s6;

else if(buffer[1] == 1'b1)

ns = s7;

else

ns = s0;

end

s4 : begin

if(buffer[0] == 1'b0)

begin

out = 4'b1010;

ns = s0;

end

else if(buffer[0] == 1'b1)

begin

out = 4'b1011;

ns = s0;

end

else

begin

ns = s0;

end

end

s5 : begin

if(buffer[0] == 1'b0)

begin

out = 4'b1100;

ns = s0;

end

else if(buffer[1] == 1'b1)

begin

out = 4'b1101;

ns = s0;

end

else

begin

ns = s0;

end

end

s6 : begin

if(buffer[0] == 1'b0)

begin

out = 4'b1110;

ns = s0;

end

else if(buffer[1] == 1'b1)

begin

out = 4'b1111;

ns = s0;

end

else

begin

ns = s0;

end

end

s7 : begin

if(buffer[0] == 1'b0)

begin

out = 4'b1000;

ns = s0;

end

end

default : begin

ns = s0;

end

endcase

end

endmodule

-------------------

verilog module test bench

module huffman_decoder_tb;

// Inputs

reg clk;

reg reset;

reg start;

reg [2:0] in;

// Outputs

//wire ready;

//wire done_tick;

wire [3:0] out;

// Instantiate the Unit Under Test (UUT)

huffman_decoder uut (

.clk(clk),

.reset(reset),

.start(start),

.in(in),

//.ready(ready),

//.done_tick(done_tick),

.out(out)

);

initial begin

// Initialize Inputs

clk = 0;

reset = 0;

start = 0;

in = 0;

// Wait 100 ns for global reset to finish

#100;

  

// Add stimulus here

end

always #100 clk = ~clk;

initial begin

#1000 reset = 1'b1;

#1000 reset = 1'b0;

#1000 start = 1'b1;

#1000 in = 3'b000;

#1000 in = 3'b001;

#1000 in = 3'b010;

#1000 in = 3'b011;

#1000 in = 3'b100;

#1000 in = 3'b101;

#1000 in = 3'b110;

end

  

endmodule

Example Considered in Code

Character Huffman Code Decoded Output

A 000 1010

B 001 1011

C 010 1100

D 011 1101

E 100 1110

F 101 1111

0 110 1000


Related Solutions

Write a c or matlab text code(to be copied ) for Huffman coder and Huffman decoder...
Write a c or matlab text code(to be copied ) for Huffman coder and Huffman decoder that asks the user to enter the string and output the Huffman code for every letter and a code for encoding that will have every letter and its Huffman code and output all the possibilities for the real string. you must show a screen of an input and the output for both the encoder and the decoder
Code a 2:4 decoder with registered out. Also write a testbench of the decoder.
Code a 2:4 decoder with registered out. Also write a testbench of the decoder.
Write down the VERILOG code for an XOR gate and the testbench code to test it
Write down the VERILOG code for an XOR gate and the testbench code to test it
Create a testbench in Verilog for the following module (logic). Verify the testbench works in your...
Create a testbench in Verilog for the following module (logic). Verify the testbench works in your answer. I'll upvote correct answers. This module does the following. The algorithm takes an input between 0 and 255 (in unsigned binary and counts the number of ones in each number (ex. 01010101 has 4 ones). Then the output would be 00000100 (4 in binary because there are 4 ones. The test bench would need to verify the inputs and outputs of each number....
Create a testbench in Verilog for the following module (logic). Verify the testbench works in your...
Create a testbench in Verilog for the following module (logic). Verify the testbench works in your answer. I'll upvote correct answers. This module does the following. The algorithm takes an input between 0 and 255 (in unsigned binary and counts the number of ones in each number (ex. 01010101 has 4 ones). Then the output would be 00000100 (4 in binary because there are 4 ones. The test bench would need to verify the inputs and outputs of each number....
Design and write a verilog code and testbench for a 16-bit RISC MIPS Processor on vivado...
Design and write a verilog code and testbench for a 16-bit RISC MIPS Processor on vivado and show waveform.
(Write/Design) both the RTL and Testbench using the Verilog HDL language of the five input majority...
(Write/Design) both the RTL and Testbench using the Verilog HDL language of the five input majority using the structure modeling approach. NOTE: Design means RTL code and Testbench covering all possible corner cases
Verilog code for Traffic light controller. Need a block diagram, Verilog codes used with testbench, and...
Verilog code for Traffic light controller. Need a block diagram, Verilog codes used with testbench, and the waveforms screen-prints.
Design an 8-bit adder. Show Verilog code and testbench.
Design an 8-bit adder. Show Verilog code and testbench.
Verilog counter problem: Using the attached 4-bit up-counter module and testbench as a template, write a...
Verilog counter problem: Using the attached 4-bit up-counter module and testbench as a template, write a Verilog module that implements a certain 4-bit counter. The module should include two more input variables: “updown” and “count2”. If “updown” is 1, the circuit should count up (by 1s); if it is 0 it should count down (by 1s). If “count2” has a value of 1, the circuit should instead count up by 2s; otherwise it will have no effect (the circuit counts...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT