Notice
Recent Posts
Recent Comments
Link
관리 메뉴

거북이처럼 천천히

Verilog RTL 설계(7월 15일 - 1, 오전 내용 복습) 본문

RTL Design/Verilog RTL 설계

Verilog RTL 설계(7월 15일 - 1, 오전 내용 복습)

유로 청년 2024. 7. 15. 19:44

1. Sequential logic circuit은 Combinational logic circuit와 Register (D Flip - Flop)의 조합으로 이루어진다.

  • 이전 게시글 통해 알 수 있듯이Sequential logic circuit은 Combinational logic circuit와 Register (D Flip - Flop)의 조합으로 이루어져 있음을 확인할 수 있다.
  • Up / Down Counter = adder (조합 논리 회로) + D Flip Flop
  • Ring Counter = shift operator (조합 논리 회로) + D Flip Flop
  • 순차 논리 회로는 조합 논리회로와 레지스터의 조합으로 구성되어 있으며, FPGA에서는 "레지스터는 D Flip Flop"임을 의미한다.

 

2. 그럼, 왜 Combinational logic circuit은 D Flip Flop이 필요한가?

  • Combinational logic circuit의 예시로 4bit adder를 생각해보겠다. 
    A 값은 3 (0011)을 갖고, B 값은 7 (0111) 을 갖는다.

4bit adder에 3과 7의 덧셈 연산을 수행

 

  • 덧셈 연산은 바로 출력값으로 1010 (10)이 나올 것 같지만, 다음과 같은 단계를 거친다.
    1 단계) 덧셈으로 발생한 Carry 값을 고려하지 않고 연산한다. (연산 결과 : 0100)
         → Q) 왜 Carry 값을 고려하지 않았는가? 
              A) 첫번째 덧셈연산 할 때는 아직 Carry 값이 발생하지 않았으며, 발생된 Carry 값이 다음 플립플
             롭에게 전달되지 않았기 때문에 Carry 값을 고려하지 않았다. (PDT 생각할 것)

    2 단계) 첫 번째 덧셈 연산 단계에서 발생한 Carry 값을 고려하여 연산한다. (연산 결과 : 0010)
        → Q) 왜 이번에도 Carry 값을 고려하지 않았는가?  
             A) 아직 두 번째 Carry값과 덧셈 연산하여 발생한 Carry값이 생성되지 않는 동시에 다음 플립플롭
             에게 전달되지 않았기 때문에 Carry 값을 고려하지 않았다.
    3 단계) 두 번째 덧셈 연산 단계에서 발생한 Carry 값을 고려하여 연산한다. (연산 결과 : 1010)

  • 이처럼 일순간이지만, 4bit adder의 출력값으로 1010이 나오기 까지 잘못된 출력값이 출력됨을 확인할 수 있으며, 이를 방지하기 위해 대책이 필요하다.
  • 이러한 문제점을 해결하기 위해 출력값을 바로 받는 것이 아니라 어느 정도 Delay를 갖고, 출력 값을 받는다.
  • Delay time 동안 잘못된 출력 값을 보내고, 제대로 된 연산 결과값을 받는다

 

 

2.1. 어떻게 Ripple 현상을 방지할 것인가?

  • 다음 회로도 처럼 구성하게 되면 clk 값과 동기화되어 clk의 edge에서 입력값을 받고, 출력값을 내보낸다.
    ( 가정 : clk 주기는 10ns 라고 가정하겠다. )

.

  • 첫 번째 clk의 positive edge에서 입력값 A, B를 갖는다.
  • 입력값 A, B를 받아서 덧셈 연산에 대한 출력 값이 나오면 바로 받는 것이 아니라 10ns 기다렸다가 다음 clk의 positive edge에서 출력값을 받는다.
  • 왜냐하면 clk의 주기인 10ns동안 ripple effect로 인해 발생된 잘못된 출력값을 버리고, 제대로 된 출력값을 받는다.
  • Q) 만약, 제대로 된 출력값이 긴 PDT로 인해 10ns 보다 더 걸린다면 어떻게 해야하는가?
    A) clk 펄스의 주기를 늘려서 제대로 된 출력값이 나온 뒤에 받도록 한다.

 

  • 결론) Combinational logic circuit의 연산 결과는 ripple 효과로 인해 일시적이지만, 잘못된 출력값들이 출력되며, 문제를 해결하고, 입력과 출력 부분에 D Flip Flop을 추가하여 delay를 갖고, 출력 값을 받도록 한다.

 

 

 

3. Falling edge detector 설계

  • Falling edge detector는 Positive edge detector처럼 클럭의 한 주기동안 일시적으로 갖는 값을 감지하면 된다.

Timing diagram of One cycle Pulse

 

  • Positive edge detector : current 값이 1일때와 old 값이 0일때를 감지
  • Negative edge detector : current 값이 0일때와 old 값이 1일때를 감지
  • 이를 바탕으로 아래와 같이 AND Gate를 수정할 수 있다.

AND Gate for one cycle pulse

 

  • 위 AND Gate를 추가함으로서 일시적으로 특정 current 값과 old 값을 감지하면 주기가 one cycle동안 활성화된 펄스파형을 출력한다.

 

 

 

 

4. Positive edge / Negative edge Detector (Positive edge)

  • clk이 positive edge일 때, Positive edge와 Negative edge를 감지하는 코드이다. 

< Source >

// Positive edge / Negative edge detectior (Positive)
module Positive_edge_and_Negative_edge_detector_positive(
    input clk, cp, enable, reset_p,
    output positive_edge, negative_edge );
    
    reg flip_flop_current, flip_flop_old;
    
    always @ (posedge clk or posedge reset_p) begin
        if(reset_p) begin flip_flop_current <= 0; flip_flop_old <= 0; end
        else if(enable) begin 
                flip_flop_current <= cp;
                flip_flop_old <= flip_flop_current;
        end
    end
    
    assign positive_edge = ({flip_flop_current, flip_flop_old} == 2'b10) ? 1 : 0;
    assign negative_edge = ({flip_flop_current, flip_flop_old} == 2'b01) ? 1 : 0; 
    
endmodule

 

< Simulation >

 

< RTL analysis >

 

 

< Simulation >

 

 

 

 

 

 

5. Positive edge / Negative edge Detector (Negative edge)

< Source >

// Positive edge / Negative edge detector (Negative)
module Positive_edge_and_Negative_edge_detector_negative (
    input clk, cp, enable, reset_p,
    output positive_edge, negative_edge );
 
    reg flip_flop_current, flip_flop_old;
 
    always @(negedge clk or posedge reset_p) begin
        if(reset_p)  begin flip_flop_current <= 0;  flip_flop_old <= 0; end
        else if(enable) begin 
            flip_flop_current <= cp;
            flip_flop_old <= flip_flop_current;
        end
    end
    
    assign positive_edge = ({flip_flop_current, flip_flop_old} == 2'b10)? 1 : 0;
    assign negative_edge = ({flip_flop_current, flip_flop_old} == 2'b01)? 1 : 0;
    
endmodule

 

< Simulation >

 

< RTL anlaysis >

 

< Synthesis >