Aqui estan algunos còdigos de los que hemos desarrollado en clase
Este por ejemplo hace un barrido, eta compuesto por 3 módulos:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.NUMERIC_STD.ALL;-- PARA TRABAJAR KN COMPUERTAS IF OR...ETC
entity cronometro is
Port ( clk : in STD_LOGIC;
go,clr : in STD_LOGIC;
d2,d1,d0 : out STD_LOGIC_VECTOR (3 downto 0));
end cronometro;
architecture Behavioral of cronometro is
constant DVSR: integer:=5000000;
signal ms_reg, ms_next: unsigned(22 downto 0);
signal d2_reg, d1_reg, d0_reg : unsigned (3 downto 0);
signal d2_next, d1_next, d0_next: unsigned (3 downto 0);
signal ms_tick: STD_LOGIC;
begin
-- REGISTRO
process (clk)
begin
if(clk'event and clk='1') then
ms_reg <= ms_next;
d2_reg <= d2_next;
d1_reg <= d1_next;
d0_reg <= d0_next;
end if;
end process;
--hacemos el siguiente estado logico para producir la señal de 0.1 segundos
ms_next<=(others=> '0') when clr='1' or (ms_reg= DVSR and go='1') else
ms_reg+1 when go='1' else
ms_reg;
ms_tick<= '1' when ms_reg = DVSR else '0';
--incrementar de 3 digitos
process (d0_reg, d1_reg, d2_reg, ms_tick, clr)
begin
--valores x defecto
d0_next<=d0_reg;
d1_next<=d1_reg;
d2_next<=d2_reg;
if clr='1' then
d0_next<= "0000";
d1_next<="0000";
d2_next<="0000";
elsif ms_tick='1' then
if(d0_reg /= 9) then -- /= diferente
d0_next<=d0_reg+ 1;
else --ya alcanzo XX9
d0_next<="0000";
if(d1_reg /= 9) then -- /= diferente
d1_next<=d1_reg+ 1;
else --ya alcanzo el estado X99
d1_next<="0000";
if(d2_reg /= 9) then -- /= diferente
d2_next<=d2_reg+ 1;
else --ya alcanzo el estado 999
d2_next<="0000";
end if;
end if;
end if;
end if;
end process;
-- LA SALIDA LOGICA
d0<=STD_LOGIC_VECTOR (d0_reg);
d1<=STD_LOGIC_VECTOR (d1_reg);
d2<=STD_LOGIC_VECTOR (d2_reg);
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.NUMERIC_STD.ALL;
entity disp_mux is
Port ( clk, reset : in STD_LOGIC;
bcd0, bcd1, bcd2, bcd3 : in STD_LOGIC_VECTOR (3 downto 0);
dp_in : in STD_LOGIC_VECTOR (3 downto 0);
sseg : out STD_LOGIC_VECTOR (7 downto 0);
comun : out STD_LOGIC_VECTOR (3 downto 0));
end disp_mux;
architecture Behavioral of disp_mux is
constant N: integer:=18;--tamaño de bits para bajar de frecuencia
signal q_reg, q_next: unsigned ((N-1) downto 0);
signal sel:STD_LOGIC_VECTOR (1 downto 0);
signal bcd:STD_LOGIC_VECTOR (3 downto 0);
signal dp:STD_LOGIC;
begin
-- REGISTRO:
process (clk, reset)
begin
if reset = '1' then
q_reg<=(others =>'0');
elsif (clk'event and clk='1') then
q_reg<=q_next;
end if;
end process;
-- PROXIMO ESTADO LOGICO DEL CONTADOR
q_next<= q_reg + 1;
--utilizamos los 2 bits mas signidficativos de las señales
--del registro para hacer el control de la multiplexaion
sel<=std_LOGIC_VECTOR (q_reg(N-1 downto N-2));
process(sel, bcd0,bcd1,bcd2, bcd3)
begin
case sel is
when "00"=>
comun <="1110";
bcd<=bcd0;
dp<=dp_in(0);
when "01"=>
comun <="1101";
bcd<=bcd1;
dp<=dp_in(1);
when "10"=>
comun <="1011";
bcd<=bcd2;
dp<=dp_in(2);
when others =>
comun <="0111";
bcd<=bcd3;
dp<=dp_in(3);
end case;
end process;
-- DECODIFICADOR DE BCD A 7 SEGMENTOS
with bcd select
sseg(6 downto 0) <=
--para catodo comun --gfdecba
"0111111"when "0000",--0
"0000110"when "0001",--1
"1011011"when "0010",
"1001111"when "0011",
"1100110"when "0100",
"1101101"when "0101",
"1111101"when "0110",
"0000111"when "0111",
"1111111"when "1000",
"1101111"when "1001",
"0000000"when others ;
sseg(7)<=dp;
end Behavioral;
Este es el módulo principal:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity cronostop is
Port ( clk : in STD_LOGIC;
b : in STD_LOGIC_VECTOR (3 downto 0);
comun : out STD_LOGIC_VECTOR (3 downto 0);
sseg : out STD_LOGIC_VECTOR (7 downto 0));
end cronostop;
architecture Behavioral of cronostop is
signal d2, d1 , d0: STD_LOGIC_VECTOR (3 downto 0);
begin
disp_uit: entity work.disp_mux
port map(
clk=>clk, reset=>'1',
bcd3=>"0000",bcd2=>d2, --- para catodo creo 1111
bcd1=>d1,bcd0=>d0,
dp_in => "0010", comun=>comun,sseg=>sseg ); -- anodo 1101
crono_unit: entity work.cronometro
port map (
clk => clk, go=>b(1), clr=> b(0),
d2=>d2, d1=>d1, d0=>d0 );
end Behavioral;
Super Las practicas en VHDL con XILINX
ResponderEliminar