Bugs case

2023. 6. 20. 00:10FPGA/HDLBits

728x90

Problem Statement

For each bit in an 8-bit vector, detect when the input signal changes from 0 in one clock cycle to 1 the next (similar to positive edge detection). The output bit should be set the cycle after a 0 to 1 transition occurs.

Here are some examples. For clarity, in[1] and pedge[1] are shown separately.

 

module top_module (
    input [7:0] code,
    output reg [3:0] out,
    output reg valid );//

    always @(*)begin
        out = 0;
    	valid = 1;
        case (code)
            8'h45: out = 0;
            8'h16: out = 1;
            8'h1e: out = 2;
            8'h26: out = 3;
            8'h25: out = 4;
            8'h2e: out = 5;
            8'h36: out = 6;
            8'h3d: out = 7;
            8'h3e: out = 8;
            8'h46: out = 9;
            default: valid = 0;
        endcase
    end
endmodule

 

 


8'd26: out = 3; -> 8'h26

6'h46: out = 9; -> 8'h46

valid와 out의 초기값은 always문 안에 넣어, 구문 시작 시 계속 적용되게 한다.

 

'FPGA > HDLBits' 카테고리의 다른 글

Vector100r  (0) 2023.06.20
Gates100  (0) 2023.06.20
Exams/ece241 2013 q7  (0) 2023.06.19
Exams/ece241 2014 q4  (0) 2023.06.19
Exams/2014 q4a  (0) 2023.06.19