VHDL ±¸¹®°ú µðÁöÅРȸ·Î

±¹ÀÏÈ£
goodkook@csvlsi.kyunghee.ac.kr
http://www.csvlsi.kyunghee.ac.kr


¾ð¾î·Î¼­ VHDLÀÇ ±¸¹®Àº ¼±¾ð¹®(declare), ÇÒ´ç¹®(assign), Á¦¾î¹®(control)À¸·Î ³ª´· ¼ö ÀÖ´Ù. ENTITY¿Í ARCHITECTURE ¹× Function, Procedure, Package ¹× Package Body ¿Í °°Àº sub-design ¸ðµâ°ú SIGNAL, VARIABLE, CONSTANT¿Í °°Àº °´Ã¼µéÀÇ ¼±¾ðÀÌ ÀÖÀ¸¸ç ÇÒ´ç¹®ÀÇ °æ¿ì SIGNALÇÒ´ç(<=)°ú ¼øÂ÷ÀûÀÎ VARIABLEÇÒ´ç(:=)À¸·Î ³ª´µ¾î Áø´Ù. Á¦¾î¹®Àº Á¶°Ç¹®(conditional statement), ¼±Åù®(selectional statement), ¹Ýº¹¹®(loop statement)µîÀÌ ÀÖ´Ù. HDLÀº ¼øÂ÷±¸¹®(sequential statement)°ú º´·Ä±¸¹®(concurrent statement)À» ¸ðµÎ Áö¿ø ÇÏ°í ÀÖÀ¸¹Ç·Î °¢°¢ ±¸¹®¿¡ ´ëÇÏ¿© »ç¿ëÇÒ ¼ö ÀÖ´Â Á¦¾î¹®ÀÌ ´Ù¸£´Ù. À̹ø¿¡´Â À̵é Á¦¾î¹®ÀÇ Á¾·ù¿Í »ç¿ë¹æ¹ý ±×¸®°í Á¦¾î±¸¹®°ú µðÁöÅРȸ·ÎÀÇ °ü°è¿¡ ´ëÇÏ¿© »ìÆ캸±â·Î ÇÑ´Ù. ÀÌ¹Ì ¾ð±ÞÇÑ ¹Ù¿Í °°ÀÌ VHDLÀÇ ±¸¹®»ó º´·Ä±¸¹®°ú ¼øÂ÷±¸¹®ÀÌ °ð µðÁöÅРȸ·ÎÀÇ Á¶ÇÕȸ·Î¿Í ¼øÂ÷ȸ·Î¸¦ À§¹ÌÇÏ´Â °ÍÀº ¾Æ´Ï´Ù. ±â¼úÇÏ´Â ¹æ¹ý¿¡ µû¶ó º´·Ä±¸¹®, ¼øÂ÷±¸¹® ¸ðµÎ Á¶ÇÕȸ·Î ȤÀº ¼øÂ÷ȸ·ÎÀÇ Ç¥ÇöÀÌ °¡´ÉÇϸç VHDL¿¡¼­ ¼øÂ÷±¸¹®°ú º´·Ä±¸¹®À» ±¸ºÐÇϱâ À§ÇÏ¿© ¼øÂ÷±¸¹®Àº ¹Ýµå½Ã PROCESS ºí·Ï ³»¿¡¼­ ¸¸ ±â¼úµÈ´Ù´Â Á¡À» ±â¾ïÇÏÀÚ.

 

1. Á¶°Ç¹® (Conditional Statements)

Á¶°Ç¹®Àº ³í¸®¿¬»êÀÇ °á°ú(TRUE/FALSE)¿¡ µû¶ó ±¸¹® ¼öÇàÀÇ º¯È­¸¦ °®´Â ±¸¹®µéÀÌ´Ù. VHDLÀÇ Á¶°Ç¹®Àº ´ÙÀ½°ú °°´Ù.

Data Flow Á¶°Ç¹® (º´·Ä±¸¹®)Àº WHEN~ELSEÀÇ ÇüÅÂÀÌ´Ù.

-------------------------------------------------------
        signal_out <= signal_0 WHEN condition_0 ELSE
                      signal_1 WHEN condition_1 ELSE
                      signal_2;
-------------------------------------------------------

condition_0°¡ "Âü(TRUE)" ÀÏ °æ¿ì signal_0ÀÌ signal_ouit¿¡ ÇÒ´çµÇ¸ç condition_1ÀÌ "Âü(TRUE)" ÀÏ °æ¿ì signal_1°¡ signal_out¿¡ ÇÒ´çµÇ°í ±× ÀÌ¿ÜÀÇ °æ¿ì signal_2°¡ signal_out¿¡ ÇÒ´çµÈ´Ù.

Behavioral Á¶°Ç¹® (¼øÂ÷±¸¹®)Àº IF~THEN~ELSE~END IFÀÇ ÇüÅ·μ­ ´ÙÀ½°ú °°ÀÌ ±â¼úÇÑ´Ù.

-------------------------------------------------------
        IF condition_0 THEN
            signal_out <= signal_0;
        ELSIF condition_1 THEN
            signal_out <= signal_1;
        ELSE
            signal_out <= signal_2;
        END IF;
-------------------------------------------------------

ELSEÀÇ »ç¿ëÀº Á¶°Ç¹®¿¡¼­ ¹Ýµå½Ã ÇÊ¿äÇÑ °ÍÀº ¾Æ´Ï´Ù. ´Ù¸¸ ELSE¸¦ »ç¿ëÇÏÁö ¾ÊÀº °æ¿ì Á¶°Ç½ÄÀÌ "°ÅÁþ(FALSE)" À̸é ÇÒ´çµÉ °ªÀÌ ¾ø´Ù´Â °ÍÀ» ÀǹÌÇϸç ÀÌ´Â °ð, Á¶°Ç½ÄÀÌ "Âü(TRUE)"ÀÏ ¶§ ±îÁö ÀÌÀüÀÇ °ªÀ» À¯ÁöÇØ¾ß ÇÑ´Ù´Â ¶æÀ̹ǷΠLatchȤÀº F/F°ú °°Àº ¼øÂ÷ȸ·Î°¡ µÈ´Ù. ´ÙÀ½Àº Á¶°Ç¹®ÀÇ »ç¿ë ¿¹ ÀÌ´Ù. °¢ ¿¹ÀÇ ÇÕ¼º°á°ú¸¦ Àß »ìÆ캸ÀÚ. ELSEÀÇ ±â¼ú ¿©ºÎ¿¡ µû¶ó LatchȤÀº F/FÀÌ Çü¼ºµÈ °ÍÀ» º¼ ¼ö ÀÖ´Ù.

[¿¹Á¦ 1] Data Flow Á¶°Ç¹®ÀÇ ¿¹
library ieee;
use ieee.std_logic_1164.all;
ENTITY test_conditional IS
PORT (
    x : IN std_logic_vector(7 DOWNTO 0);
    y : IN std_logic_vector(7 DOWNTO 0);
    z : IN std_logic_vector(7 DOWNTO 0);
    a : IN integer range 0 to 3;
    output_signal : OUT std_logic_vector(7 DOWNTO 0) );
END test_conditional;
ARCHITECTURE DataFlow OF test_conditional IS
BEGIN
    output_signal <= x WHEN a=1 ELSE
                     y WHEN a=2 ELSE
                     z WHEN a=3 ELSE
                     (others=>'0');
END DataFlow;

 

[¿¹Á¦ 2] Behavioral Á¶°Ç¹®ÀÇ ¿¹
library ieee;
use ieee.std_logic_1164.all;
ENTITY test_conditional IS
PORT (
    x : IN std_logic_vector(7 DOWNTO 0);
    y : IN std_logic_vector(7 DOWNTO 0);
    z : IN std_logic_vector(7 DOWNTO 0);
    a : IN integer range 0 to 3;
    output_signal : OUT std_logic_vector(7 DOWNTO 0) );
END test_conditional;
ARCHITECTURE Behavioral OF test_conditional IS
BEGIN
    PROCESS (x, y, z, a)
    BEGIN
        IF (a=1) THEN
            output_signal <= x;
        ELSIF (a=2) THEN
            output_signal <= y;
        ELSIF (a=3) THEN
            output_signal <= z;
        ELSE
            output_signal <= (others=>'0');
        END IF;
    END PROCESS;
END Behavioral;

 

À§ÀÇ Á¶°Ç¹® ¿¹Á¦ 1°ú 2´Â ÇÕ¼ºÇÒ °æ¿ì µ¿ÀÏÇÑ È¸·Î°¡ µÈ´Ù. ÇÕ¼º °á°ú´Â ±×¸² 1°ú °°´Ù.

±×¸² 1. Á¶°Ç¹®ÀÇ ÇÕ¼º¿¹

 

[¿¹Á¦ 3] ELSE°¡ ¾ø´Â Á¶°Ç¹®

Á¶°Ç¹®¿¡¼­ ELSE°¡ ¾ø´Â°æ¿ì latch°¡ µÉ¼ö ÀÖÀ½¿¡ À¯ÀÇÇØ¾ß ÇÑ´Ù. ÇÕ¼º °á°ú´Â ±×¸² 2¿Í °°´Ù.
library ieee;
use ieee.std_logic_1164.all;
ENTITY test_conditional IS
PORT (
    x : IN std_logic_vector(7 DOWNTO 0);
    y : IN std_logic_vector(7 DOWNTO 0);
    z : IN std_logic_vector(7 DOWNTO 0);
    a : IN integer range 0 to 3;
    output_signal : OUT std_logic_vector(7 DOWNTO 0) );
END test_conditional;
ARCHITECTURE DataFlow OF test_conditional IS
BEGIN
    output_signal <= x WHEN a=1 ELSE
                     y WHEN a=2 ELSE
                     z WHEN a=3;
END DataFlow;

 
library ieee;
use ieee.std_logic_1164.all;
ENTITY test_conditional IS
PORT (
    x : IN std_logic_vector(7 DOWNTO 0);
    y : IN std_logic_vector(7 DOWNTO 0);
    z : IN std_logic_vector(7 DOWNTO 0);
    a : IN integer range 0 to 3;
    output_signal : OUT std_logic_vector(7 DOWNTO 0) );
END test_conditional;
ARCHITECTURE Behavioral OF test_conditional IS
BEGIN
    PROCESS (x, y, z, a)
    BEGIN
        IF (a=1) THEN
            output_signal <= x;
        ELSIF (a=2) THEN
            output_signal <= y;
        ELSIF (a=3) THEN
            output_signal <= z;
        END IF;
    END PROCESS;
END Behavioral;

 

±×¸² 2. ELSE °¡ ¾ø´Â Á¶°Ç¹®ÀÇ ÇÕ¼º¿¹

 

[¿¹Á¦ 4] ¿¡Áö Æ®¸®°Å Çø³ Ç÷Ó

ELSE°¡ ¾ø´Â Á¶°Ç¹®¿¡ ÀÇÇÏ¿© ¿¡Áö Æ®¸®°Å Çø³ Ç÷Ó(Edge-Trigger)À» Ç¥ÇöÇÒ ¼ö ÀÖ´Ù. [¿¹Á¦ 3]ÀÇ °æ¿ì´Â Level-Sensitive Latch¸¦ Ç¥ÇöÇÑ °ÍÀÌ´Ù. ¿¡Áö Æ®¸®°Å Çø³ Ç÷ÓÀ» Ç¥ÇöÇϱâ À§Çؼ­´Â SGINALÀÇ event¼Ó¼º(attribute)À» ÀÌ¿ëÇÑ´Ù. event ¼Ó¼ºÀ» »ç¿ëÇÑ ¿¡ÁöÆ®¸®°Å Çø³Ç÷ÓÀ» Ç¥ÇöÇÑ Á¶°Ç¹®Àº ELSE¸¦ »ç¿ëÇϸé ÇÕ¼º ºÒ°¡´ÉÀÌ´Ù.
Data Flow Á¶°Ç¹®¿¡ ÀÇÇÑ ¿¡Áö Æ®¸®°Å ´Â ´ÙÀ½°ú °°´Ù.
library ieee;
use ieee.std_logic_1164.all;
ENTITY test_conditional IS
PORT (
    x : IN std_logic_vector(7 DOWNTO 0);
    clk: IN std_logic;
    output_signal : OUT std_logic_vector(7 DOWNTO 0) );
END test_conditional;
ARCHITECTURE DataFlow OF test_conditional IS
BEGIN
    output_signal <= x WHEN clk'event and clk='1';
END DataFlow;

 
ÇÕ¼º±â¿¡ µû¶ó Data Flow Á¶°Ç¹®¿¡¼­ 'event ¼Ó¼ºÀ» Áö¿øÇÏÁö ¾Ê´Â °æ¿ìµµ ÀÖÀ¸¹Ç·Î Behavioral Á¶°Ç¹®À» ÀÌ¿ëÇϵµ·ÏÇÑ´Ù.
library ieee;
use ieee.std_logic_1164.all;
ENTITY test_conditional IS
PORT (
    x : IN std_logic_vector(7 DOWNTO 0);
    clk : IN std_logic;
    output_signal : OUT std_logic_vector(7 DOWNTO 0) );
END test_conditional;
ARCHITECTURE Behavioral OF test_conditional IS
BEGIN
    PROCESS (clk, x)
    BEGIN
        IF (clk'event and clk='1') THEN
            output_signal <= x;
        END IF;
    END PROCESS;
END Behavioral;


¿¡Áö Æ®¸®°Å Á¶°ÇÀ» Á¤ÇÒ ¶§ (clk'event and clk='1') ÀÌ¸é »ó½Â ¿¡Áö(rising edge) À̸ç, (clk'event and clk='0') À̸é ÇÏ°­ ¿¡Áö(falling edge) °¡ µÈ´Ù. ±×·¯³ª (clk'event) ¸¸À» Á¶°ÇÀ¸·Î ÁÖ¸é ÇÕ¼º ºÒ°¡´ÉÀÌ´Ù. »ó½Â ¿¡Áö Æ®¸®°Å Çø³ Ç÷ÓÀÇ ÇÕ¼º °á°ú´Â ±×¸² 3°ú °°´Ù.

±×¸² 3. »ó½Â ¿¡ÁöÆ®¸®°Å(rising edge-trigger) Çø³ Ç÷Ó(Flip-Flop)

 

2. ¼±Åù® (Selectional Statements)

¼±Åù®Àº swich~case¹®°ú °°Àº ÇüÅÂÀÌ´Ù. VHDLÀÇ Á¶°Ç¹®Àº º´·Ä±¸¹®°ú ¼øÂ÷±¸¹®À¸·Î ³ª´µ¾îÁø´Ù.
Data Flow ¼±Åù®(º´·Ä±¸¹®)Àº WITH~SELECT~WHENÀÇ ÇüÅÂÀÌ´Ù.

-------------------------------------------------------
        WITH signal_sel SELECT
            signal_out <=
                signal_0 WHEN constant_0,
                signal_1 WHEN constant_1,
                signal_2 WHEN constant_2,
                ......
                signal_others WHEN OTHERS;
-------------------------------------------------------

Behavioral ¼±Åù®(¼øÂ÷±¸¹®)Àº CASE~WHENÀÇ ÇüÅ·μ­ ´ÙÀ½°ú °°ÀÌ ±â¼úÇÑ´Ù.

-------------------------------------------------------
        CASE sig_var_sel IS
            WHEN constant_0 =>
                signal_out <= signal_0;
            WHEN constant_1 =>
                signal_out <= signal_1;
            WHEN constant_2 =>
                signal_out <= signal_2;
            ......
            WHEN OTHERS =>
                signal_out <= signal_others;
        END CASE;
-------------------------------------------------------

sig_var_selÀÌ »ó¼ö constant_0ÀÇ Á¶°Ç¿¡ ¸ÂÀ» ¶§ signal_0°¡ signal_outÀ¸·Î ÇÒ´ç µÈ´Ù. ¼øÂ÷±¸¹®ÀÎ Behavioral ¼±Åù®¿¡¼­ Á¶°Ç½ÅÈ£ÀÇ ¸ðµç °æ¿ì¿¡ ´ëÇÏ¿© WHEN¿¡ ÁöÁ¤µÇ¾î ÀÖÁö ¾ÊÀ» °æ¿ì ±âŸÁ¶°ÇÀ» ³ªÅ¸³»´Â WHEN OTHERS°¡ ¾øÀ¸¸é ·¡Ä¡°¡ µÉ ¼ö ÀÖÀ¸¹Ç·Î ÁÖÀÇÇÏ¿©¾ß ÇÑ´Ù.

 

[¿¹Á¦ 5] Data Flow ¼±Åù® ¿¹

Data Flow ¼±Åù®ÀÇ ¿¹´Â ´ÙÀ½°ú °°´Ù. 3ºñÆ® ¼±ÅýÅÈ£ "sel"¿¡ ´ëÇÏ¿© 3°³ÀÇ Á¶°Ç¸¸À» »ç¿ëÇÏ°í ÀÖ´Ù. ±×·¯³ª º´·Ä±¸¹®¿¡¼­´Â ±âŸÁ¶°ÇÀ» WHEN OTHERS¸¦ »ç¿ëÇÏ¿© ³ªÅ¸³»Áö ¾Ê´õ¶óµµ ºÒÇÊ¿äÇÑ ·¡Ä¡¸¦ »ý¼ºÇÏÁö´Â ¾Ê´Â´Ù. ±×·¯³ª ÇÕ¼º±â¿¡ µû¶ó ´Ù¸¦¼ö ÀÖÀ¸¸ç '-'(don't care)·Î ÇÒ´çÇØ ÁÜÀ¸·Î¼­ ³í¸® ÃÖÀûÈ­¿¡ À¯¸®ÇÒ¼ö ÀÖÀ¸¹Ç·Î WHEN OTHERS¸¦ »ç¿ëÇÏ´Â °ÍÀÌ ÁÁ´Ù. ÇÕ¼º °á°ú´Â ±×¸² 4¿Í °°´Ù.

 
library ieee;
use ieee.std_logic_1164.all;
ENTITY test_selection IS
PORT (
    x : IN std_logic_vector(7 DOWNTO 0);
    y : IN std_logic_vector(7 DOWNTO 0);
    z : IN std_logic_vector(7 DOWNTO 0);
    sel : IN std_logic_vector(2 DOWNTO 0);
    mux_out : OUT std_logic_vector(7 DOWNTO 0);
    latch_out : OUT std_logic_vector(7 DOWNTO 0) );
END test_selection;
ARCHITECTURE DataFlow OF test_selection IS
BEGIN
    WITH sel SELECT
        mux_out <=
            x WHEN "000",
            y WHEN "010",
            z WHEN "100",
            (others=>'-') WHEN OTHERS;
    WITH sel SELECT
        latch_out <=
            y WHEN "000",
            z WHEN "010",
            x WHEN "100";
END DataFlow;

 

±×¸² 4. Data Flow ¼±Åù® ÇÕ¼º °á°ú

[¿¹Á¦ 6] Behavioral ¼±Åù® ¿¹

¼øÂ÷±¸¹®ÀÎ Behavioral ¼±Åù®ÀÇ ¿¹´Â ´ÙÀ½°ú °°´Ù. PROCESS ºí·Ï¿¡ ¼øÂ÷±¸¹®À» »ç¿ëÇÏ¸é »ó´çÈ÷ º¹ÀâÇÑ ±â¼úÀÌ °¡´ÉÇÏ´Ù. Data FlowÀÇ °æ¿ì 1°³ÀÇ ½ÅÈ£¿¡ ´ëÇÑ ÇÒ´ç¹®À» »ç¿ëÇÒ ¼ö ÀÖ´Â ¹Ý¸é ¼øÂ÷±¸¹® ºí·Ï¿¡¼­´Â ¿©·¯ ÇÒ´ç¹®ÀåÀÇ ±â¼úÀÌ °¡´ÉÇÏ´Ù. ¼øÂ÷±¸¹®¿¡¼­´Â ±âŸÁ¶°ÇÀ» WHEN OTHERS¸¦ »ç¿ëÇÏ¿© ³ªÅ¸³»Áö ¾ÊÀ» °æ¿ì ·¡Ä¡¸¦ »ý¼ºÇÑ´Ù´Â Á¡¿¡ À¯ÀÇÇϵµ·Ï ÇÑ´Ù. ÇÕ¼º °á°ú´Â ±×¸² 5¸¦ º¸¸é WHEN OTHERÇÒ´ç¿¡ '0'¸¦ »ç¿ëÇÏ´Â °æ¿ì 4ÀÔ·Â 8ºñÆ® MUXÀε¥ ºñÇÏ¿© '-'(don't care)¸¦ »ç¿ëÇÏ´Â °æ¿ì 3ÀÔ·Â MUX·Î ÃÖÀûÈ­ µÇ¾úÀ½À» ¾Ë ¼ö ÀÖ´Ù.

 
library ieee;
use ieee.std_logic_1164.all;
ENTITY test_selection IS
PORT (
    x : IN std_logic_vector(7 DOWNTO 0);
    y : IN std_logic_vector(7 DOWNTO 0);
    z : IN std_logic_vector(7 DOWNTO 0);
    sel : IN std_logic_vector(2 DOWNTO 0);
    mux_out : OUT std_logic_vector(7 DOWNTO 0);
    latch_out : OUT std_logic_vector(7 DOWNTO 0) );
END test_selection;
ARCHITECTURE Behavioral OF test_selection IS
BEGIN
    process(x, y, z, sel)
    begin
        CASE sel IS
            WHEN "000" =>
                mux_out <= x;
                latch_out <= y;
            WHEN "010" =>
                mux_out <= y;
                latch_out <= z;
            WHEN "100" =>
                mux_out <= z;
                latch_out <= x;
            WHEN OTHERS =>
                mux_out <= (OTHERS=>'-');
        END CASE;
    END PROCESS;
END Behavioral;

 

(a) WHEN OTHERS¿¡ '0'À» ÇÒ´çÇÑ °æ¿ì

(b)WHEN OTHERS¿¡ '-'À» ÇÒ´çÇÑ °æ¿ì

±×¸² 5. Behavioral ¼±Åù® ÇÕ¼º °á°ú

 

3. ¹Ýº¹¹® (Loop Statementss)

VHDLÀÇ ¹Ýº¹¹®Àº FOR LOOP ¿Í WHILE LOOP°¡ ÀÖ´Ù. 1ºñÆ® ¿¬»êȸ·Î¸¦ n ºñÆ® Â¥¸®·Î È®ÀåÇϰųª ½¬ÇÁÆ®·¹Áö½ºÅ͸¦ ¸¸µé°Å³ª ÇÒ¶§ ó·³ ¹Ýº¹ÀûÀÎ ¿¬»êȸ·Î¿¡ ¸¹ÀÌ »ç¿ëµÈ´Ù. ÀÌ·¯ÇÑ ¹Ýº¹¹®Àº ¼øÂ÷±¸¹®(behavior)¿¡¼­¸¸ »ç¿ëÇÒ ¼ö ÀÖ´Ù.

FOR LOOP ¹Ýº¹±¸¹®Àº ´ÙÀ½°ú °°´Ù.

-------------------------------------------------------
        FOR loop_var IN loop_range LOOP
            -- Statements
        END LOOP;
-------------------------------------------------------

¹Ýº¹¿¡ »ç¿ëµÇ´Â loop_varÀº FOR LOOP~ END LOOP¿¡ À¯È¿ÇÑ °ÍÀ¸·Î ¼±¾ð µÇÁö ¾Ê°í »ç¿ëÇÑ´Ù.

WHILE LOOP ±¸¹®Àº ´ÙÀ½°ú °°´Ù.

-------------------------------------------------------
        WHILE (condition) LOOP
            -- Statements;
        END LOOP;
-------------------------------------------------------

Á¶°Ç½ÄÀÌ "Âü(TRUE)"ÀÏ µ¿¾È WHLE LOOP°¡ ¹Ýº¹µÈ´Ù. ÀÌ´ë Á¶°Ç½Ä¿¡ »ç¿ëµÇ´Â º¯¼ö´Â VARIABLE·Î ¼±¾ð µÇ¾î¾ß ÇÑ´Ù.

FOR/WHLE ¹Ýº¹±¸¹®Àº Á¦ÇÑÀûÀ¸·Î ÇÕ¼º °¡´ÉÇÏ´Ù. FOR LOOP ÀÇ °æ¿ì ¹Ýº¹ ¹üÀ§°¡ ÁöÁ¤µÇ¾î ÀÖÀ¸¹Ç·Î ÀϹÝÀûÀ¸·Î ÇÕ¼º°¡´É ÇÏÁö¸¸ WHILE LOOPÀÇ °æ¿ì ¹Ýº¹ ¼öÇ൵Áß ¹Ýº¹ º¯¼ö°¡ »õ·Î °»½ÅµÇ´Â °æ¿ì¿¡´Â ÇÕ¼ºÀÌ ºÒ°¡´ÉÇØÁø´Ù. ÀÌ´Â ÀÌ¹Ì ¸¸µé¾îÁø Çϵå¿þ¾î¸¦ »õ·Î Á¶Á¤ÇÏ´Â °æ¿ì¿Í °°±â ¶§¹®ÀÌ´Ù. ¼øÂ÷±¸¹®À¸·Î¼­ ¹Ýº¹À» Áß´ÜÇϱâ À§Çؼ­ LOOP ³»¿¡ NEXT ¶Ç´Â EXIT ±¸¹®À» »ç¿ëÇÒ ¼ö ÀÖÁö¸¸ ÇÕ¼ºÀ» À§Çؼ­´Â ¹Ù¶÷Á÷ÇÏÁö ¾Ê´Ù.

º´·Ä±¸¹®(Data Flow)¿¡¼­´Â FOR GENERATE ¹Ýº¹±¸¹®À» »ç¿ëÇÒ¼ö ÀÖ´Ù. º´·Ä±¸¹®À̹ǷΠ¹Ýº¹ Áß°£¿¡ EXIT/NEXTµîÀº »ç¿ë ºÒ°¡´ÉÇϸç ÇÕ¼º °¡´ÉÇÑ ±¸¹®ÀÌ´Ù.

-------------------------------------------------------
        FOR loop_var IN loop_range GENERATE
            -- Concurrent Statements
        END LOOP;
-------------------------------------------------------

[¿¹ 7] 8ºñÆ® °¡»ê±â

FOR LOOP ¹Ýº¹¹®À» ÀÌ¿ëÇÏ¿© 8ºñÆ® °¡»ê±â¸¦ Ç¥ÇöÇÑ ¿¹ÀÌ´Ù. ÇÕ¼º °á°ú´Â ±×¸² 6°ú °°´Ù.

 
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY test_for IS
    PORT( C_in : IN std_logic;
          L_val, R_val : IN std_logic_vector(7 downto 0);
          Sum_out : OUT std_logic_vector(7 downto 0);
          C_out : OUT std_logic );
END test_for;
ARCHITECTURE behave OF test_for IS
BEGIN
    PROCESS(C_in, R_val, L_val)
    VARIABLE carry : STD_LOGIC_VECTOR(8 DOWNTO 0);
    VARIABLE sum   : STD_LOGIC_VECTOR(7 DOWNTO 0);
    BEGIN
        carry(0) := C_in;
        FOR i IN 0 TO 7 LOOP
            sum(i)   := L_val(i) XOR R_val(i) XOR carry(i) ;
            carry(i+1) := (L_val(i) AND R_val(i)) OR
                          (L_val(i) AND carry(i)) OR
                          (R_val(i) AND carry(i)) ;
        END LOOP ;
        Sum_out <= sum;        
        C_out <= carry(8);
    END PROCESS;
END behave;

 

±×¸² 6. FOR LOOP¸¦ ÀÌ¿ëÇÑ 8ºñÆ® °¡»ê±â ÇÕ¼º°á°ú

 

[¿¹ 8] WHILE LOOPÀÇ EXIT/NEXTÀÇ ¿¹

´ÙÀ½ÀÇ ¿¹´Â WHILE LOOP¿¡¼­ EXIT/NEXT ±¸¹®À» »ç¿ëÇÑ ¿¹ÀÌ´Ù. ¾Æ·¡ÀÇ ¿¹´Â ÀϺΠÇÕ¼º±â¿¡¼­ ÇÕ¼º°¡´É ÇÏÁö¸¸ ÀϹÝÀûÀ¸·Î ±ÇÀåÇÒ¸¸ÇÑ ±â¼ú¹æ¹ýÀÌ ¾Æ´Ï´Ù. ±×¸²

 
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY test_while IS
    PORT( ena : IN std_logic;
          input_sig : IN std_logic_vector(7 downto 0);
          result : OUT std_logic_vector(7 downto 0) );
END test_while;
ARCHITECTURE behave OF test_while IS
BEGIN
    PROCESS(ena, input_sig)
    VARIABLE i : integer;
    BEGIN
        i:=0;
        WHILE TRUE LOOP
            i:=i+1;
            EXIT WHEN (i>5);
            if (input_sig(i-1)='0') then
                result(i-1) <= '0';
                next;
            end if;
            result(i-1) <= ena;
        END LOOP;
    END PROCESS;
END behave;

 

±×¸² 7. WHILE LOOP¿¡¼­ EXIT/NEXT»ç¿ë ¿¹ÀÇ ÇÕ¼º°á°ú

[¿¹ 9] FOR GENERATEÀÇ ¿¹

FOR GENERATE´Â º´·Ä±¸¹®¿¡¼­ »ç¿ëµÅ´Â ¹Ýº¹¹®À̹ǷΠ´Ù¼öÀÇ COMPONENTµéÀ» »ç¿ëÇÒ ¼ö ÀÖ´Ù. ÇÕ¼º °á°ú´Â ±×¸² 8°ú °°´Ù.

 
library ieee;
use ieee.std_logic_1164.all;
entity test_shift is 
    port( clk : in std_logic;
          s : in std_logic;
          q : out std_logic );
end test_shift;
architecture behave of test_shift is
component d_ff
    port( clk : in std_logic;
          d : in std_logic;
          q : out std_logic );
end component;
signal q_i : std_logic_vector(7 downto 0);
begin
    q_i(0) <= s;
    q <= q_i(7);
    sh : for i in 7 downto 1 generate
        u_dff : d_ff port map ( clk, q_i(i-1), q_i(i));
    end generate sh;
end behave;

 

±×¸² 8. FOR GENERATE±¸¹®À» ÀÌ¿ëÇÑ COMPONENTÀÇ »ç¿ë¿¹¿¡´ëÇÑ ÇÕ¼º°á°ú

 

 

4. ³¡À¸·Î

VHDLÀÇ °¢Á¾ Á¦¾î±¸¹®°ú ÀÌµé ±¸¹®°ú ÇÕ¼ºÈÄÀÇ È¸·Î¿¡ ´ëÇÏ¿© »ìÆ캸¾Ò´Ù. VHDL±¸¹®¿¡ ÀÇÇÑ µðÁöÅРȸ·ÎÀÇ ±â¼ú¿¡ À־ º´·Ä±¸¹®°ú ¼øÂ÷±¸¹®ÀÇ Â÷À̸¦ ÀÌÇØÇÏ´Â °Í°ú ÀÌ¿¡ µû¸¥ Á¶ÇÕ µðÁöÅРȸ·Î ȤÀº ¼øÂ÷ µðÁöÅРȸ·ÎÀÇ °ü°è¿¡ ´ëÇÑ ÀÌÇØ°¡ Áß¿äÇÏ´Ù. ¾ð¾î¿¡ ÀÇÇÑ È¸·Î ¼³°è´Â ½ºÄɸ¶Æ½ ¼³°è¿Í °°ÀÌ ±¸¼º¿ä¼Ò¸¦ ÀÌ¿ëÇÏ´Â °ÍÀÌ ¾Æ´Ñ, ȸ·ÎÀÇ ÇൿÀ» ¹¦»çÇÏ´Â °ÍÀ̹ǷΠ½ÇÁ¦ ȸ·Î·Î ÇÕ¼ºµÇ¾úÀ» ¶§ ¼³°èÀÚÀÇ Àǵµ¿Í ´Ù¸£°Ô µÉ ¼ö ÀÖ´Ù. ÇÕ¼º °á°ú °¡Àå Å« ¹®Á¦°¡ µÇ´Â ºÎºÐÀº ºÒÇÊ¿äÇÑ ·¡Ä¡³ª Çø³ Ç÷ÓÀÇ »ý¼ºÀ̹ǷΠÁ¦¾î¹®¿¡ ƯÈ÷ ÁÖÀǸ¦ ±â¿ï¿©¾ß ÇÑ´Ù.

´ÙÀ½´Þ¿¡´Â ÁÁÀº ÇÕ¼º °á°ú¸¦ ¾ò±â À§ÇÑ ÀûÀýÇÑ VHDL±â¼ú¹æ¹ý(coding style)¿¡ ´ëÇÏ¿© »ìÆ캸°í ÇÕ¼º°á°ú¸¦ ºñ±³ÇØ º¸±â·Î ÇÑ´Ù.