FaMAF - Leccion Clase VHDL 07

35
CURSO VHDL LECCIÓN 07 Lección 7: SEÑALES Y VARIABLES 7_1 – CONSTANT 7_2 – SIGNAL 7_3 – VARIABLE 7_4 – SIGNAL VERSUS VARIABLE 7_5 – NÚMERO DE REGISTROS

Transcript of FaMAF - Leccion Clase VHDL 07

Page 1: FaMAF - Leccion Clase VHDL 07

CURSO VHDL LECCIÓN 07

• Lección 7: SEÑALES Y VARIABLES

– 7_1 – CONSTANT

– 7_2 – SIGNAL

– 7_3 – VARIABLE

– 7_4 – SIGNAL VERSUS VARIABLE

– 7_5 – NÚMERO DE REGISTROS

Page 2: FaMAF - Leccion Clase VHDL 07

SEÑALES Y VARIABLES 1/3

• DATOS ESTÁTICOS:– CONSTANT Y GENERIC

• DATOS NO ESTÁTICOS:– SIGNAL Y VARIABLE

Page 3: FaMAF - Leccion Clase VHDL 07

SEÑALES Y VARIABLES 2/3

• CONSTANT Y SIGNAL:– PUEDEN SER GLOBALES Y PUEDEN SER

USADAS EN EL CÓDIGO SECUENCIAL Y EN EL CÓDIGO CONCURRENTE

Page 4: FaMAF - Leccion Clase VHDL 07

SEÑALES Y VARIABLES 3/3

• VARIABLE:– SON LOCALES A LOS CÓDIGOS

SECUENCIALES: PROCEDURES, FUNCTIONS Y PROCESS

Page 5: FaMAF - Leccion Clase VHDL 07

Curso VHDL Lección 07

• Lección 7: SEÑALES Y VARIABLES

– 7_1 – CONSTANT

– 7_2 – SIGNAL

– 7_3 – VARIABLE

– 7_4 – SIGNAL VERSUS VARIABLE

– 7_5 – NÚMERO DE REGISTROS

Page 6: FaMAF - Leccion Clase VHDL 07

7_1 CONSTANT 1/2

• CONSTANT NOMBRE: TIPO :=VALOR;

• EJEMPLOS:

• constant set_bit: bit := ‘1’;

• constant data_memory: memory

• := ((‘0’, ‘0’, ‘0’, ‘0’),

• (‘0’, ‘0’, ‘0’, ‘0’),

• (‘0’, ‘0’, ‘0’, ‘0’));

Page 7: FaMAF - Leccion Clase VHDL 07

7_1 CONSTANT 2/2

• Pueden ser declarados dentro de: PACKAGES,

• ENTITY,

• ARCHITECTURES

Page 8: FaMAF - Leccion Clase VHDL 07

Curso VHDL Lección 07

• Lección 7: SEÑALES Y VARIABLES

– 7_1 – CONSTANT

– 7_2 – SIGNAL

– 7_3 – VARIABLE

– 7_4 – SIGNAL VERSUS VARIABLE

– 7_5 – NÚMERO DE REGISTROS

Page 9: FaMAF - Leccion Clase VHDL 07

7_2 SIGNAL 1/4

• SIRVEN PARA PASAR VALORES HACIA DENTRO O FUERA DEL SISTEMA O BIEN ENTRE MÓDULOS INTERNOS.

• SON LOS “CABLES”

• LOS PORTS SON SIGNALS

Page 10: FaMAF - Leccion Clase VHDL 07

7_2 SIGNAL 2/4

• SIGNAL NOMBRE:

• TYPE [RANGE] [:= INITIAL VALUE];

• signal control: bit := ‘0’;

• signal count: integer range 0 to 100 :=14;

• signal y: std_logic_vector (7 downto 0)

• := “10001001”;

Page 11: FaMAF - Leccion Clase VHDL 07

7_2 SIGNALS 3/4

.

Page 12: FaMAF - Leccion Clase VHDL 07

7_2 SIGNALS 4/4

.

Page 13: FaMAF - Leccion Clase VHDL 07

Curso VHDL Lección 07

• Lección 7: SEÑALES Y VARIABLES

– 7_1 – CONSTANT

– 7_2 – SIGNAL

– 7_3 – VARIABLE

– 7_4 – SIGNAL VERSUS VARIABLE

– 7_5 – NÚMERO DE REGISTROS

Page 14: FaMAF - Leccion Clase VHDL 07

7_3 VARIABLE 1/4

• SON LOCALES A LOS FUNCTIONS, PROCESS O PROCEDUREES Y SOLO PUEDEN DECLARARSE DENTRO DE LOS MIMOS, (DENTRO DE CÓDIGO SECUENCIAL)

• NO SE PUEDEN USAR PARA PASAR VALORES HACIA EL EXTERIOR DIRECTAMENTE

Page 15: FaMAF - Leccion Clase VHDL 07

7_2 VARIABLE 2/4

• VARIABLE NOMBRE:

• TYPE [RANGE] [:= INITIAL VALUE];

• variable control: bit := ‘0’;

• variable count: integer range 0 to 100 :=14;

• variable y: std_logic_vector (7 downto 0)

• := “10001001”;

Page 16: FaMAF - Leccion Clase VHDL 07

7_2 VARIABLE 3/4

. • ---------------------------------------------------------------

• LIBRARY IEEE;

• USE IEEE.STD_LOGIC_1164.ALL;

• ---------------------------------------------------------------

• ENTITY COUNT_ONES IS

• PORT(

• DIN: IN STD_LOGIC_VECTOR(7 DOWNTO 0));

• ONES: OUT INTEGER RANGE 0 TO 8);

• END COUNT_ONES;

Page 17: FaMAF - Leccion Clase VHDL 07

7_2 VARIABLES 4/4

.

Page 18: FaMAF - Leccion Clase VHDL 07

Curso VHDL Lección 07

• Lección 7: SEÑALES Y VARIABLES

– 7_1 – CONSTANT

– 7_2 – SIGNAL

– 7_3 – VARIABLE

– 7_4 – SIGNAL VERSUS VARIABLE

– 7_5 – NÚMERO DE REGISTROS

Page 19: FaMAF - Leccion Clase VHDL 07

7_4: Singal Versus Variable 1/15

Page 20: FaMAF - Leccion Clase VHDL 07

7_4: Singal Versus Variable 2/15

• --Ejemplo de mal uso de signal y buen uso de variable:

• ---------------------------------------------------• Library ieee;• Use ieee.std_logic_1164.all;

Page 21: FaMAF - Leccion Clase VHDL 07

7_4: Singal Versus Variable 3/15

• Entity mux is

• Port(a,b,c,d,s1,s0: in std_logic; y: out std_logic);

• End mux;

• Architecture not_ok of mux is

• signal sel: integer range 0 t0 3;

• Begin

• Process(a,b,c,d,s0,s1)

• begin

• ……..

• end process;

• end not_ok;

Page 22: FaMAF - Leccion Clase VHDL 07

7_4: Signal Versus Variable 4/15• Architecture not_ok of mux is

• signal sel: integer range 0 t0 3;

• Begin

• Process(a,b,c,d,s0,s1)

• begin

• sel<=0;

• if(s0=‘1’) then sel<=sel+1; end if;

• if (s1=‘1’) then sel<=sel+2; end if;

• case sel is

• when 0 => y<=a;

• when 1 => y<=b;

• when 2 => y<=c;

• when 3 => y<=d;

• end case;

• end process;

• end not_ok;

Page 23: FaMAF - Leccion Clase VHDL 07

7_4: Singal Versus Variable 5/15

• Entity mux is

• Port(a,b,c,d,s1,s0: in std_logic; y: out std_logic);

• End mux;

• Architecture ok of mux is

• Begin

• Process(a,b,c,d,s0,s1)

• variable sel: integer range 0 to 3;

• begin

• ……..

• end process;

• end ok;

Page 24: FaMAF - Leccion Clase VHDL 07

7_4: Signal Versus Variable 6/15• Architecture ok of mux is

• Begin

• Process(a,b,c,d,s0,s1)

• variable sel: integer range 0 to 3;

• begin

• sel:=0;

• if(s0=‘1’) then sel<=sel+1; end if;

• if (s1=‘1’) then sel<=sel+2; end if;

• case sel is

• when 0 => y<=a;

• when 1 => y<=b;

• when 2 => y<=c;

• when 3 => y<=d;

• end case;

• end process;

• end ok;

Page 25: FaMAF - Leccion Clase VHDL 07

7_4: Singal Versus Variable 7/15

• --Otro Ejemplo comparando el uso de signal y de variable:

• ---------------------------------------------------• Library ieee;• Use ieee.std_logic_1164.all;

Page 26: FaMAF - Leccion Clase VHDL 07

7_4: Singal Versus Variable 8/15

Page 27: FaMAF - Leccion Clase VHDL 07

7_4: Singal Versus Variable 9/15

Page 28: FaMAF - Leccion Clase VHDL 07

7_4: Singal Versus Variable 10/15

Page 29: FaMAF - Leccion Clase VHDL 07

7_4: Singal Versus Variable 11/15

Page 30: FaMAF - Leccion Clase VHDL 07

7_4: Singal Versus Variable 12/15

• Otro Ejemplo: Explicar porqué funciona bien el código siguiente:

Page 31: FaMAF - Leccion Clase VHDL 07

7_4: Singal Versus Variable 13/15

Page 32: FaMAF - Leccion Clase VHDL 07

7_4: Singal Versus Variable 14/15

Page 33: FaMAF - Leccion Clase VHDL 07

7_4: Singal Versus Variable 15/15

Page 34: FaMAF - Leccion Clase VHDL 07

7_4: Singal Versus Variable 14/7

Page 35: FaMAF - Leccion Clase VHDL 07

7_4: Singal Versus Variable 14/7