---
# System prepended metadata

title: Hierarchical Design of 3-8 decoder

---

# Hierarchical Design of 3-8 decoder
> 資工二1 黃柏芸
> 指導老師：林宏益

### 實驗目的:
使用EDA Plaground做出3對8解碼器後，顯示出其波型。

### 程式碼:
```verilog=
module decoder(E , In , Out);
input E;
input [2:0] In;
output [7:0] Out;
wire [7:0] Out;
assign Out = E ? (8'b1 << In) : 8'h0;
endmodule

module clkgen(clka, clkb, clka_out, clkb_out);
input clka, clkb;
output clka_out, clkb_out;
reg clka_out, clkb_out;
always @(clka) begin
clka_out = clka;
end
always @(clkb) begin
clkb_out = clkb;
end
endmodule
```

```verilog=
module decoder_3_8_tb;
reg E_tb;
reg clka, clkb;
reg [2:0] In_tb;
wire [7:0] Out_tb;
wire clka_out, clkb_out;
decoder decoder_1(.E(E_tb), .In(In_tb), .Out(Out_tb));
clkgen clkgen_1(.clka(clka), .clkb(clkb), .clka_out(clka_out), .clkb_out(clkb_out));
initial begin
clka = 1'b0; clkb = 1'b0;
end
always begin
#10 clka = ~clka;
end
always begin
#20 clkb = ~clkb;
end
  
initial begin
	#0 E_tb = 0; In_tb = 3'b000;
	#10 E_tb = 1; In_tb = 3'b000;
	#10 E_tb = 1; In_tb = 3'b001;
	#10 E_tb = 1; In_tb = 3'b010;
	#10 E_tb = 1; In_tb = 3'b011;
	#10 E_tb = 1; In_tb = 3'b100;
	#10 E_tb = 1; In_tb = 3'b101;
	#10 E_tb = 1; In_tb = 3'b110;
	#10 E_tb = 1; In_tb = 3'b111;
	#10 $finish;
end
initial begin
$dumpfile("decoder.vcd");
$dumpvars(0, decoder_1);
$dumpvars(0, clkgen_1);
end
endmodule
```
### 實驗結果:
![](https://i.imgur.com/TYcbYG0.png)



### 分析:

input [2:0] In; 代表該模組有3bits的輸入匯流排
output [7:0] Out; 代表該模組有8bits的輸出匯流排
wire [7:0] Out; 代表該模組有8bits的接線
input clka, clkb; 代表該模組有兩個1bit的時脈輸入埠
output clka_out, clkb_out; 代表該模組有兩個1bit的時脈輸出埠
reg clka_out, clkb_out; 代表兩者皆為reg敘述的變數
```verilog=
#0 E_tb = 0; In_tb = 3'b000;
#10 E_tb = 1; In_tb = 3'b000;
#10 E_tb = 1; In_tb = 3'b001;
#10 E_tb = 1; In_tb = 3'b010;
#10 E_tb = 1; In_tb = 3'b011;
#10 E_tb = 1; In_tb = 3'b100;
#10 E_tb = 1; In_tb = 3'b101;
#10 E_tb = 1; In_tb = 3'b110;
#10 E_tb = 1; In_tb = 3'b111;
#10 $finish;
```
"#"後面的數字代表在第幾秒後做後面的敘述，例如第二行是指在10秒過後將E的值設為1，將In的值設成長度為3、二進制數值為000的值。

### 心得:
第一次接觸HackMD、EDA Playground和Github等等的工具，由於不熟悉這些工具，因此找了很多關於使用方法的資料，雖然途中有點挫敗，但每當完成一小部分時，就會很開心。
