Вы находитесь на странице: 1из 17

Diseño lógico con VHDL

“ Lógica secuencial”
Danilo A. García Hansen
FF D
Forma de detectar flancos de reloj
Entity FFD is
port ( D, clk: in std_logic;
Q: out std_logic);
End FFD;

Architecture ARC_FFD of FFD is


Begin
Process (clk) begin
If (clk’ event and clk=‘1’) then
Q<=D;
End if;
End process;
End ARC_FFD;
FF JK
entity FFJK is
Port ( J,K,clk : in STD_LOGIC;
Q, NO_Q : inout STD_LOGIC);
end FFJK;

architecture arq_ffjk of FFJK is


begin
process(clk,J,K) begin
if (clk' event and clk='1') then
if (J='1' and K='1') then
Q<= not Q;
elsif (J='0' and K='0') then
Q<= Q;
elsif (J='1' and K='0') then
Q<= '1';
else
Q<= '0';
end if;
end if;
end process;
NO_Q<=not Q;
end arq_ffjk;
FF JK con Preset y Clear asincronos
entity FFJK_PR_CLR is
Port ( clk,J,K,PR,CLR : in STD_LOGIC;
Q : inout STD_LOGIC);
end FFJK_PR_CLR;

architecture ARQ_FFJK of FFJK_PR_CLR is


begin
process(clk,J,K,PR,CLR) begin
if (PR='1' and CLR='0') then
Q<='1';
elsif (PR='0' and CLR='1') then
Q<='0';
else
if (clk' event and clk='1') then
if (J='1' and K='1') then
Q<= not Q;
elsif (J='0' and K='0') then
Q<= Q;
elsif (J='1' and K='0') then
Q<= '1';
else
Q<= '0';
end if;
end if;
end if;
end process;
end ARQ_FFJK;
Contador Binario
Contador Binario
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL; --obligatorio en contadores

entity ContadorHex is
Port ( reloj : in STD_LOGIC;
hab : in STD_LOGIC;
salida : inout STD_LOGIC_VECTOR (3 downto 0));
end ContadorHex;

architecture Behavioral of ContadorHex is


begin
process (reloj,hab)
begin
if (reloj' event and reloj='1') then
if (hab='1') then
salida<=salida+1;
end if;
end if;
end process;
end Behavioral;
Protocolo serial sincrono KBD PS2
Teclado al host(1)

Imagen tomada de http://www.beyondlogic.org/keyboard/keybrd.htm

(1) Se considera host el dispositivo que recibirá los datos del teclado
Registro de desplazamiento
Registro de desplazamiento
Concatenación:

 Izquierda:
Temp <= Temp (6 downto 0) & SI;

 Derecha:
Temp <= SI & Temp (7 downto 1);
MAQUINAS DE ESTADOS
(MOORE)
MAQUINAS DE ESTADOS
(MEALY)
Máquinas de estados
(Diagrama de estados)
Máquinas de estados (codificación I)
entity FSM2 is
Port ( CLK : in STD_LOGIC;
X : in STD_LOGIC;
Z : out STD_LOGIC);
end FSM2;

architecture FSM of FSM2 is


TYPE ESTADOS IS (D0,D1,D2,D3);
SIGNAL EDO_PRE, EDO_FUT: ESTADOS;
BEGIN
Máquinas de estados (codificación II)
PROCESO1: PROCESS (EDO_PRE, X)
BEGIN
CASE EDO_PRE IS
WHEN D0 => Z<='0';
IF X='1' THEN EDO_FUT<=D1;
ELSE EDO_FUT<=D0;
END IF;
WHEN D1 => Z<='0';
IF X='1' THEN EDO_FUT<=D2;
ELSE EDO_FUT<=D1;
END IF;
WHEN D2 => Z<='0';
IF X='1' THEN EDO_FUT<=D3;
ELSE EDO_FUT<=D0;
END IF;
WHEN D3 =>
IF X='1' THEN EDO_FUT<=D0;
Z<='1';
ELSE EDO_FUT<=D3;
Z<='0';
END IF;
END CASE;
END PROCESS PROCESO1;
Máquinas de estados (codificación III)
PROCESO2: PROCESS(CLK)
BEGIN
IF (CLK' EVENT AND CLK= '1') THEN
EDO_PRE<=EDO_FUT;
END IF;
END PROCESS PROCESO2;

end FSM;
Divisor de frecuencia
signal Divisor : integer range 0 to 2500;

-- La definición de la variable Divisor se debe ubicar antes del BEGIN de la


-- definición de la Arquitectura

process(Clk) --divisor
begin
if (Clk'event and Clk='1') then
if(Divisor = 2500)then
Divisor<=0;
CLKo <= not CLKo;
else
Divisor <= Divisor + 1;
end if;
end if;
end Process;
Bibliografía:
 VHDL El arte de programar sistemas digitales. David G. Maxinez,
Jessica Alcalá, CECSA - Tec de Monterrey. 2007
 http://toolbox.xilinx.com/docsan/xilinx4/data/docs/xst/hdlcode.html
 FPGA prototyping by VHDL examples. Pong P. Chu. 2008

Вам также может понравиться