Intermedio > Circuitos integrados > Logica secuencial VHDL

Logica secuencial VHDL

Objetivos

  1. Poder desarrollar circuitos digitales usando la herramienta de Edición de texto en Lógica secuencial mediante el ISE de Xilinx.
  2. Poder simular circuitos digitales usando el software de simulación
  3. Analizar he interpretar los resultados de la simulación.

Procedimiento

PRIMERA PARTE: Maquina de estado tipo MOORE

Analizar el código, hacer su simulación y dibujar las máquinas de estado del funcionamiento.

  • ENTITY Diagrama_estados is
  • PORT ( rst : in STD_LOGIC;
  • CLK : in STD_LOGIC;
  • a : out STD_LOGIC;
  • b : out STD_LOGIC;
  • state: out STD_lOGIC_VECTOR(3 downto 0)
  • );
  • end Diagrama_estados;
  • architecture synth of Diagrama_estados is
  • SIGNAL pstate : std_logic_vector(3 downto 0);
  • SIGNAL n_state: std_logic_vector (3 downto 0);
  • BEGIN
  • --maquina de estados
  • PROCESS (clk, rst)
  • BEGIN
  • IF rst = '1' then
  • pstate <= "0000";
  • ELSIF clk = '1' AND clk'event then
  • pstate <= n_state;
  • END IF;
  • END PROCESS;
  • state <= pstate;
  • n_state <= "0001" when (pstate = "0000") ELSE
  • "0010" when (pstate = "0001") ELSE
  • "0011" when (pstate = "0010") ELSE
  • "0100" when (pstate = "0011") ELSE
  • "0101" when (pstate = "0100") ELSE
  • "0011" when (pstate = "0101") ELSE
  • "0111" when (pstate = "0011") ELSE
  • "1000" when (pstate = "0111") ELSE
  • "1001" when (pstate = "1000") ELSE
  • "0000";
  • a <='1' when pstate = "0000" else --0
  • '0' when pstate="0001" ELSE -1
  • '0' when pstate="0010" ELSE -2
  • '1' when pstate="0011" ELSE -3
  • '1' when pstate="0100" ELSE -4
  • '1' when pstate="0101" ELSE -5
  • '1' when pstate="0110" ELSE -6
  • '1' when pstate="0111" ELSE -7
  • '1' when pstate="1000" ELSE -8
  • '1' when pstate="1001" ELSE -9
  • '0';
  • b <='1' when pstate = "0000" else --0
  • '1' when pstate="0001" ELSE -1
  • '1' when pstate="0010" ELSE -2
  • '1' when pstate="0011" ELSE -3
  • '1' when pstate="0100" ELSE -4
  • '0' when pstate="0101" ELSE -5
  • '0' when pstate="0110" ELSE -6
  • '1' when pstate="0111" ELSE -7
  • '1' when pstate="1000" ELSE -8
  • '1' when pstate="1001" ELSE -9
  • '0';
  • END synth;
    1. LIBRARY ieee;
    2. USE ieee.std_logic_1164.ALL;
    3. ENTITY test_bench13 IS
    4. END test_bench13;
    5. ARCHITECTURE behavior OF test_bench13 IS
    6. COMPONENT implementacion13
    7. PORT(
    8. rst : IN std_logic;
    9. clk : IN std_logic;
    10. a : OUT std_logic;
    11. b : OUT std_logic;
    12. state: OUT std_logic_vector(3 downto 0)
    13. );
    14. END COMPONENT;
    15. --Inputs
    16. SIGNAL rst : std_logic := '0';
    17. SIGNAL clk : std_logic := '0';
    18. --Outputs
    19. SIGNAL a : std_logic;
    20. SIGNAL b : std_logic;
    21. SIGNAL state : std_logic_vector(3 downto 0);
    22. BEGIN
    23. -- Instantiate the Unit Under Test (UUT)
    24. utt : implementacio13 PORT MAP(
    25. rst => rst,
    26. clk => clk,
    27. a => a,
    28. b => b,
    29. state => state
    30. );
    31. stim_proc : process
    32. begin
    33. clk <= '1';
    34. rst <= '1';
    35. wait for 10 ns;
    36. clk <= '0';
    37. rst <= '1';
    38. wait for 10 ns;
    39. clk <= '1';
    40. wait for 10 ns
    41. clk <= '0';
    42. wait for 10 ns
    43. clk <= '1';
    44. wait for 10 ns
    45. clk <= '0';
    46. wait for 10 ns
    47. clk <= '1';
    48. rst <= '0';
    49. wait for 10 ns;
    50. clk <= '0';
    51. wait for 10 ns;
    52. clk <= '1';
    53. wait for 10 ns;
    54. clk <= '0';
    55. wait for 10 ns;
    56. clk <= '1';
    57. wait for 10 ns
    58. clk <= '0';
    59. wait for 10 ns;
    60. clk <= '1';
    61. wait for 10 ns
    62. clk <= '0';
    63. wait for 10 ns;
    64. clk <= '1';
    65. wait for 10 ns
    66. end process;
    67. END;


    SEGUNDA PARTE: Maquina de estado tipo MOORE

    Con el ejemplo anterior escribir y simular en VHDL el siguiente diagrama de estado.

    1. library IEEE;
    2. use IEEE.STD_LOGIC_1164.ALL;
    3. entity implementation is
    4. Port (
    5. RST : in std_logic;
    6. up_down : in std_logic;
    7. clk : in std_logic;
    8. Q0,Q1 : oue std_logic
    9. state: out std_logic_vector (1 downto 0)
    10. );
    11. end implementation;
    12. architecture behavior of implementation is
    13. SIGNAL pstate: std_logic_vector (1 downto 0);
    14. SIGNAL n_state : std_logic_vector (1 downto 0);
    15. begin
    16. process (RST, clk)
    17. begin
    18. if RST ='1' then
    19. pstate <= "00";
    20. elsif clk = '1' and clk'event then
    21. pstate <= n_state;
    22. end if;
    23. end process;
    24. n_state<= "01" when (pstate="00" and upd_down='1') else
    25. "11" when (pstate="01" and up_down='1') else
    26. "10" when (pstate="11" and up_down='1') else
    27. "10" when (pstate="00" and up_down='0') else
    28. "11" when (pstate="10" and up_down='0') else
    29. "01" when (pstate="11" and up_down='0') else
    30. "00";
    31. Q0 <= '0' when pstate="00" else
    32. '1' when pstate="01" else
    33. '0' when pstate="10" else
    34. '1';
    35. Q1 <= '0' when pstate="00" else
    36. '0' when pstate="01" else
    37. '1' when pstate="10" else
    38. '1';
    39. end behavior;

    1. LIBRARY ieee;
    2. use ieee.std_logic_1164.ALL;
    3. ENTITY simula IS
    4. END simula;
    5. ARCHITECTURE behavior OF simula IS
    6. COMPONENT implementacion
    7. PORT(
    8. RST : IN std_logic;
    9. up_down : IN std_logic;
    10. clk : IN std_logic;
    11. Q0 : OUT std_logic;
    12. Q1 : OUT std_logic;
    13. state : OUT std_logic_vector (1 downto 0)
    14. );
    15. END COMPONENT;
    16. --Inputs
    17. SIGNAL RST : std_logic := '0';
    18. SIGNAL up_down : std-logic := '0';
    19. SIGNAL clk : std_logic := '0';
    20. --Outputs
    21. SIGNAL Q0 : std_logic;
    22. SIGNAL Q1 : std_logic;
    23. SIGNAl state : std_logic_vector (1 downto 0);
    24. BEGIN
    25. uut : implementacion PORT MAP(
    26. RST => RST,
    27. up_down => up_down,
    28. clk => clk,
    29. Q0 => Q0,
    30. Q1 => Q1,
    31. state => state
    32. );
    33. stim_proc : process
    34. begin
    35. clk <= '1';
    36. RST <= '1';
    37. up_down <= '0';
    38. wait for 10 ns;
    39. clk <= '0';
    40. RST <= '1';
    41. wait for 10 ns;
    42. clk <= '1';
    43. wait for 10 ns;
    44. clk <= '0';
    45. wait for 10 ns
    46. clk <= '1';
    47. wait for 10 ns
    48. clk <= '0';
    49. wait for 10 ns;
    50. clk <='1';
    51. RST <= '0';
    52. up_down<='0'
    53. wait for 10 ns;
    54. clk <= '0';
    55. up_down <= '0';
    56. wait for 10 ns;
    57. clk <= '1';
    58. up_down <= '0';
    59. wait for 10 ns;
    60. clk <= '0';
    61. up_down <= '0';
    62. wait for 10 ns;
    63. clk <= '1';
    64. up_down <= '1';
    65. wait for 10 ns;
    66. clk <= '0';
    67. up_down <= '1';
    68. wait for 10 ns;
    69. clk <= '1';
    70. up_down <= '1';
    71. wait for 10 ns
    72. clk <= '0';
    73. up_down <= '1';
    74. wait dor 10 ns;
    75. end process;
    76. END;

    TERCERA PARTE: Maquina de estado tipo Mealy

    Con el primer ejemplo, codificar, escribir y simular en VHDL el siguiente diagrama de estado

    Le damos valores a las salidas ( codificamos)

    • S0 = 00
    • S1 = 01
    • S2 = 10
    • S3 = 11

    1. library IEEE;
    2. use IEEE.std_logic_1164.ALL;
    3. entity imple is
    4. Port ( y : in std_logic;
    5. rst : in std_logic;
    6. clk : in std_logic;
    7. z : in std_logic;
    8. Q0: out std_logic;
    9. Q1 : out std_logic;
    10. state : out std_logic_vector(1 downto 0));
    11. end imple;
    12. architecture behavioral of imple is
    13. signal pstate : std_logic_vector (1 downto 0);
    14. signal n_state : std_logic_vector (1 downto 0);
    15. begin
    16. process (rst, clk)
    17. begin
    18. if RST ='1' then
    19. pstate <= "00";
    20. elsif clk ='1' and clk'event then
    21. pstate <= n_state;
    22. end if;
    23. end process;
    24. state <= pstate;
    25. n_state <= "01" when (pstate="00" and y='1' and z='1') else
    26. "10" when (pstate="01" and y='1' and z='0') else
    27. "11" when (pstate="10" and y='1' and z='1') else
    28. "00" when (pstate="11" and y='1' and z='1') else
    29. pstate;
    30. Q0 <= '0' when pstat ="00" else
    31. '1' when pstat ="01" else
    32. '0' when pstat ="10" else
    33. '1';
    34. Q1 <= '0' when pstat ="00" else
    35. '0' when pstat ="01" else
    36. '1' when pstat ="10" else
    37. '1';
    38. end behavioral;

    1. LIBRARY ieee;
    2. use ieee.std_logic_1164.ALL;
    3. ENTITY simula IS
    4. END simula;
    5. ARCHITECTURE behavior OF simula IS
    6. COMPONENT imple
    7. PORT(
    8. rst : IN std_logic;
    9. y : IN std_logic;
    10. clk : IN std_logic;
    11. z : in std_logc;
    12. Q0 : OUT std_logic;
    13. Q1 : OUT std_logic;
    14. state : OUT std_logic_vector (1 downto 0)
    15. );
    16. END COMPONENT;
    17. --Inputs
    18. SIGNAL y : std_logic := '0';
    19. SIGNAL rst : std-logic := '0';
    20. SIGNAL clk : std_logic := '0';
    21. SIGNAL z : std_logic := '0';
    22. --Outputs
    23. SIGNAL Q0 : std_logic;
    24. SIGNAL Q1 : std_logic;
    25. SIGNAl state : std_logic_vector (1 downto 0);
    26. BEGIN
    27. uut : imple PORT MAP(
    28. y => y,
    29. rst => rst,
    30. clk => clk,
    31. z => z,
    32. Q0 => Q0,
    33. Q1 => Q1,
    34. state => state
    35. );
    36. stim_proc : process
    37. begin
    38. clk <= '1';
    39. rst <= '1';
    40. wait for 10 ns;
    41. clk <= '0';
    42. rst <= '1';
    43. wait for 10 ns;
    44. clk <= '1';
    45. wait for 10 ns;
    46. clk <= '0';
    47. wait for 10 ns
    48. clk <= '1';
    49. wait for 10 ns
    50. clk <= '0';
    51. wait for 10 ns;
    52. clk <='1';
    53. rst <= '0';
    54. y <='0'
    55. z <='0';
    56. wait for 10 ns;
    57. clk <= '0';
    58. y <= '1';
    59. z <= '1';
    60. wait for 10 ns;
    61. clk <= '1';
    62. y <= '0';
    63. z <= '1';
    64. wait for 10 ns;
    65. clk <= '0';
    66. y <= '1';
    67. z <= '0';
    68. wait for 10 ns;
    69. clk <= '1';
    70. y <= '0';
    71. z <= '0';
    72. wait for 10 ns;
    73. clk <= '0';
    74. y <= '1';
    75. z <= '1';
    76. wait for 10 ns;
    77. clk <= '1';
    78. y <= '0';
    79. z <= '0';
    80. wait for 10 ns
    81. y <= '1';
    82. z <= '1';
    83. wait dor 10 ns;
    84. end process;
    85. END;

    Aplicación de lo aprendido

    Realice el diseño de un contador ascendente/ descendente de 8 bits controlable mediante un bit para el cual en cero cuente descendentemente y en 1 ascendentemente. Usando contadores o máquina de estados.

    1. library IEEE;
    2. use IEEE.STD_LOGIC_1164.ALL;
    3. use IEEE.STD_LOGIC_ARITH.ALL
    4. use IEEE.STD_LOGIC_UNSIGNED.ALL
    5. use IEEE.NUMERIC_STD.ALL
    6. entity imple is
    7. port ( clk: in STD_LOGIC;
    8. conteo: in STD_LOGIC;
    9. salida: out STD_LOGIC_vector(7downto 0)
    10. );
    11. end imple;
    12. architecture behavioral od imple is
    13. SIGNAL cuenta: STD_LOGIC_VECTOR (7 downt 0) :="00000000";
    14. begin
    15. process (clk)
    16. begin
    17. if clk ='1' and clk'event then
    18. if conteo ='1' then
    19. cuenta <= cuenta +1;
    20. else
    21. cuenta <= cuenta - 1;
    22. end if;
    23. end if;
    24. end process;
    25. salida <= cuenta;
    26. end behavioral;

    1. LIBRARY ieee;
    2. USE ieee.std_logic_1164.ALL;
    3. ENTITY imple_TB is
    4. END imple_TB;
    5. ARCHITECTURE behavior OF imple_TB IS
    6. --Component Declaration for the Unit Under Test (UUT)
    7. COMPONENT imple
    8. PORT(
    9. clk : IN std_logic;
    10. conteo: IN std_logic;
    11. salida : OUT std_logic_vector(7 downto 0)
    12. );
    13. END COMPONENT;
    14. --Inputs
    15. signal clk : std_logic := '0';
    16. signal conteo : std_logic := '0';
    17. -- Outputs
    18. signal salida : std_logic_vecto (7 downto 0);
    19. BEGIN
    20. -- Instatiate the Unit Under Test (UUT)
    21. utt: imple PORT MAP (
    22. clk => clk,
    23. conteo => conteo,
    24. salida => salida
    25. );
    26. --Stimulus process
    27. stim_proc: process
    28. begin
    29. clk <= '0',
    30. conteo <= '1';
    31. wait for 10 ns;
    32. clk <= '1',
    33. conteo <= '1';
    34. wait for 10 ns;
    35. clk <= '0',
    36. conteo <= '1';
    37. wait for 10 ns;
    38. clk <= '1',
    39. conteo <= '1';
    40. wait for 10 ns;
    41. clk <= '0',
    42. conteo <= '1';
    43. wait for 10 ns;
    44. clk <= '1',
    45. conteo <= '1';
    46. wait for 10 ns;
    47. clk <= '0',
    48. conteo <= '1';
    49. wait for 10 ns;
    50. clk <= '1',
    51. conteo <= '1';
    52. wait for 10 ns;
    53. clk <= '0',
    54. conteo <= '1';
    55. wait for 10 ns;
    56. clk <= '1',
    57. conteo <= '1';
    58. wait for 10 ns;
    59. clk <= '0',
    60. conteo <= '1';
    61. wait for 10 ns;
    62. clk <= '1',
    63. conteo <= '1';
    64. wait for 10 ns;
    65. clk <= '0',
    66. conteo <= '1';
    67. wait for 10 ns;
    68. clk <= '1',
    69. conteo <= '1';
    70. wait for 10 ns;
    71. clk <= '0',
    72. conteo <= '1';
    73. wait for 10 ns;
    74. clk <= '1',
    75. conteo <= '1';
    76. wait for 10 ns;
    77. wait;
    78. end process;
    79. END;

    Pueden descargar los archivos de ISE desde el siguiente enlace:https://github.com/mokuzaru/vhdl_labs

Linksappsclose