Verilog code 단순화? > 과학기술Q&A

본문 바로가기

Verilog code 단순화?

페이지 정보

알고리듬 작성일2018-05-11 02:28

본문

module Billboard(
    output reg [7:0] LAMP,
    input wire      enable,
    input wire      nrst,
    input wire      clk);
   
parameter [3:0] START = 4'd0,
                    S0    = 4'd1,
                    S1    = 4'd2,
                    S2    = 4'd3,
                    S3    = 4'd4,
                    S4    = 4'd5,
                    S5    = 4'd6,
                    S6    = 4'd7,
                    S7    = 4'd8,
                    S8    = 4'd9,
                    S9    = 4'd10;
                   
reg [3:0] state;
reg [3:0] cnt;

always @(posedge clk or negedge nrst) begin
    if(!nrst) begin
        state <= START;
    end
    else begin
        case(state)
            START: begin
                LAMP <= 8'b0;
                cnt <= 4'b0;
               
                if(enable)    state <= S0;
                else      state <= START;
            end
           
            S0: begin
                LAMP[0] <= 1'b1;
                state <= S1;
            end
           
            S1: begin
                LAMP[1] <= 1'b1;
                state <= S2;
            end
           
            S2: begin
                  LAMP[2] <= 1'b1;
                  state <= S3;
            end
           
            S3: begin
                  LAMP[3] <= 1'b1;
                  state <= S4;
            end
           
            S4: begin
                  LAMP[4] <= 1'b1;
                  state <= S5;
            end
           
            S5: begin
                  LAMP[5] <= 1'b1;
                  state <= S6;
            end
           
            S6: begin
                  LAMP[6] <= 1'b1;
                  state <= S7;
            end
           
            S7: begin
                  LAMP[7] <= 1'b1;
                  state <= S8;
            end
           
            S8: begin
                  LAMP <= 8'b0;
                 
                  if(cnt < 5)  state <= S9;
                  else      state <= START;
            end
           
            S9: begin
                  LAMP <= 8'b11111111;
                 
                  cnt <= cnt + 4'd1;
                  state <= S8;
            end
        endcase   
        end
        end                                                                         
endmodule

광고판에 불을 들어오게하는 간단한 코드입니다.
이 코드를 간략하게 줄여서 작성이 가능하다는데
도저히 머리를 싸매도 간략하게 줄이는 방법을 모르겠습니다.
선배님들께 도움을 요청합니다ㅠㅠ

댓글 3

토루크막토님의 댓글

토루크막토

그 디지털회로 강의때 배운 카누맵이나 최적화 방법론 같은것들 기억나시죠? 이럴때 쓰라고 있는겁니다. 필요없는 state 들을  optimization하는게 최선인데 코드라인이 많이줄지는 않을것같네요.

알고리듬님의 댓글

알고리듬 댓글의 댓글

감사합니다!!

달빛연구자님의 댓글

달빛연구자

얼른 봐서는 for문으로 단순화 할 수 있을 것 같은데요.

과학기술Q&A

SLIDE UP

모바일에서는 읽기만 가능합니다.
PC 버전 보기
© 2002 - 2015 scieng.net