티스토리 뷰

alu.srcs.zip
0.01MB

Hello World느낌으로 FPGA의 led를 통해 3bit 가산기를 만들어보겠다.

FPGA Design flow

FPGA의 전체 design flow는 다음과 같다.

  • 문제 해결을 위한 알고리즘을 FSM 또는 C programming으로 작성
  • Verilog code 작성
  • synthesis
  • implementation
  • bitstream file 생성
  • FPGA동작 확인

다음과 같은 과정으로 이루어진다. 맨 처음 과정은 생략하겠다.

 

Verilog code 작성

3 bit가산기를 설계할 것이다. carray를 고려하기때문에 결과는 4 bit이다.

verilog code는 source file에 추가하면 된다.

코드는 다음과 같다.

`timescale 1ns / 1ps

module alu(
    input [2:0] a,b,
    output [3:0] sum
    );
    
    assign sum = a+b;
endmodule

이렇게 verilog code를 추가하면 elaboration을 할 수 있다. Elaboration을 완료하면 Schematic을 얻을 수 있다. 이렇게 얻은 Schematic은 실제 FPGA에서 구현되는 것이 아니라 기능적인 부분만 RTL형태로 나타낸 것이다.

Elaboration을 끝내면 Behavioral simulation을 할 수 있다. 그러기위해서는 testbench를 작성해야한다.

testbench는 Simulation Source에 추가해주면 된다.

다음은 testbench이다. 보통 tb_를 붙여서 testbench임을 표현한다고한다.

`timescale 1ns / 1ps

module tb_alu;
    reg [2:0] a,b;
    wire [3:0] sum;
    
    reg [3:0] i,j;
    
    alu u_alu(
            .a(a),
            .b(b),
            .sum(sum)
            );
    initial begin
        a=0;
        b=0;
        for(i=0;i<=7;i=i+1) begin
            for(j=0;j<7;j=j+1)begin
                #20 $display("%d + %d = %d", a, b, sum);
                    b=b+1;
                end
            a=a+1;
        end
    end
endmodule

behavioral simulation을 완료하면 다음과 같은 wave form을 얻는다. 예상된 결과를 확인할 수 있다. 단지 functional한 부분만 simulation한 것이다. wave form을 보는 것은 힘들다. 따라서 display를 활용한다.(testbench에서 $display부분)

display를 사용하면 한눈에 TcI창에서 확인이 가능하다.

C programming을 통해 작성했었다면 C program을 compile해서 얻은 결과와 비교하기도한다.

 

synthesis

다음은 합성 과정이다. 합성은 실제 FPGA의 resource를 사용하여 회로를 구성하는 과정이다. Elaboration을 완료했다면 synthesis를 한다.

Schematic을 확인하면 다음과 같다.

LUT라는 것이 있는데 Look Up Table이다. FPGA는 Combination ciruit을 실제로 구성하지 않고 각 입력에 대한 출력을 메모리에 저장한다. FPGA가 동작할 때 어떤 입력이 들어오면 메모리에서 해당하는 출력을 읽어 내보내는 방식이다. 기본적으로 메모리로 동작하므로 이를 통해 shift연산등을 최적화 할 수 있다고 한다. 이와 관련된 내용은 차차 공부해보겠다.

 

참고로 FPGA는 CLB라는 단위로 이루어져있는데 CLB안에는 LUT와 FF로 구성되어있다. Combination circuit은 LUT로 구현하고 FF와 같이 Sequential circuit을 구현한다.

 

이렇게 synthesis를 완료하면 inplementation을 해야한다. 

 

Implementation

Synsethsis는 단지 Resource를 확인한 것이라면 Implementation은 실제 port를 연결하는 과정이다. 따라서 constraint를 작성해야한다. constraint file은 모두 공개되어있다.

https://github.com/Digilent/digilent-xdc/blob/master/Zybo-Z7-Master.xdc

 

GitHub - Digilent/digilent-xdc: A collection of Master XDC files for Digilent FPGA and Zynq boards.

A collection of Master XDC files for Digilent FPGA and Zynq boards. - GitHub - Digilent/digilent-xdc: A collection of Master XDC files for Digilent FPGA and Zynq boards.

github.com

Constraints에 추가해주면 된다. constraint file은 첨부파일로 추가하겠다. led만을 사용하기때문에 Led부분의 포트만 수정하면 된다.

 

이렇게 Implementation까지 끝났다면 bitstream file을 생성하면 된다. 

 

Bitstream file 생성

Generate Bitstream을 하여 bit file을 생성한다. bit file을 읽어 FPGA는 동작하므로 실제로 보드에 올라가는 0/1로 이루어진 이진수 파일이라고 보면 된다. 후에 Open Hardware Manager를 통해 보드를 연결하고 bit file을 올리면 끝이다.

보드를 연결하고 ON switch를 올린 후 Auto Connect를 눌러 보드를 인식시킨다.

Program Device를 눌러 FPGA에 bit file을 올린다.

FPGA 동작확인

1+2 = 3 을 확인한 것이다. 

 

더 자세한 과정은 다음 링크를 참고하면 될거같다.

https://digilent.com/reference/vivado/getting_started/start

 

Getting Started with Vivado - Digilent Reference

 

digilent.com

전체 Flow를 시험삼아 해본 것이라 디테일한 부분은 차차 공부하면서 채워나가야한다.

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함