You are on page 1of 7

Funcionamiento general del contador.

Primeramente declaran todas las variables a ocupar asi como las señales necesarias, el primero
proceso corresponde a la asignación de cada selectora del multiplexor en base a el conteo y los
pulsos del reloj, posteriormente se realiza el proceso de conteo asendente o desendente y su
posible selección en base a la variable c.

Los siguientes procesos realizados son los correspondientes al reset del conteo y al paro mas reset,
el ultimo proceso es el encargado de multplexear las señales de salida primeramente se selecciona
el canal y después se va andando cada señal de salida al display en base a la selectora
seleccionada.

library IEEE;

use IEEE.STD_LOGIC_1164.ALL; --se llama la libreria 1164

use IEEE.STD_LOGIC_ARITH.ALL; --se llama la libreria arith

use IEEE.STD_LOGIC_UNSIGNED.ALL; --se llama la libreria unsigned

-- Uncomment the following library declaration if using

-- arithmetic functions with Signed or Unsigned values

--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating

-- any Xilinx primitives in this code.

--library UNISIM;

--use UNISIM.VComponents.all;

entity contador_nexys2 is

Port ( CLK_50mhz : in STD_LOGIC; --variable para utilizar el reloj de la fpga

c : in STD_LOGIC; --variable para descendente o ascendente

r : in STD_LOGIC; --variable para reset

p : in STD_LOGIC; --variable para paro mas reset

an : out STD_LOGIC_VECTOR (3 downto 0); --selecciona el display donde se mostraran los


datos

indicador : inout STD_LOGIC; --variable para el indicador del cambio de digitos

Display : out STD_LOGIC_VECTOR (7 downto 0)); --vector de salida de los digitos

end contador_nexys2;

architecture Behavioral of contador_nexys2 is


signal bcd :STD_LOGIC_VECTOR (3 DOWNTO 0); --señal correspondiente al multiplexiado

signal bcd1 :STD_LOGIC_VECTOR (3 DOWNTO 0) := "0000"; --señal correspondiente al


bcd1

signal bcd2 :STD_LOGIC_VECTOR (3 DOWNTO 0) := "0000"; --señal correspondiente al


bcd2

signal bcd3 :STD_LOGIC_VECTOR (3 DOWNTO 0) := "0000"; --señal correspondiente al


bcd3

signal bcd4 :STD_LOGIC_VECTOR (3 DOWNTO 0) := "0000"; --señal correspondiente al


bcd4

signal temp :STD_LOGIC_VECTOR (19 DOWNTO 0) := "00000000000000000000";

signal temp1 : integer :=0;

signal sel :STD_LOGIC_VECTOR (1 DOWNTO 0) := "00"; --selectora del multiplexor

begin

relomux: process (CLK_50Mhz) --proceso para utilizar el reloj

begin

if CLK_50Mhz='1' and CLK_50Mhz'event then ---condiciones para que se active el display que
corresponda

temp <= temp + 1;

if temp = "00000000100000000000" then

if sel < "11" then --se selecciona la selectora 11 para el multplexor

sel <= sel +1; --se actualiza la selectora

else

sel <= "00"; --se actualiza la selectora a la combinacion 00

end if;

temp <="00000000000000000000";

end if;

end if;

end process;

PROCESO_CARGA_DESCARGA: process (CLK_50Mhz) --comienzo del proceso de conteo

begin

if CLK_50Mhz='1' and CLK_50Mhz'event then --condicion para cambiar de valor


--CONT ASC

if c = '1' then --condicion para aser el conteo ascendente

temp1 <= temp1 + 1; --

if temp1 = 49999999 then --

if bcd1 < "1001" then --condicion donde si el primer bcd es menor a 9

bcd1 <= bcd1 +1; -- Si es menor a 9 entonces aumenta su valor

indicador <= not indicador; --el indicador cambia de valor(prende o apaga)

else

bcd1 <= "0000"; --si el primer bcd es > a 9 entonces se actualiza su valor a 0

bcd2 <= bcd2 + 1; --el bcd posterior incrementa su valor ya que se recorre el
conteo

if bcd2 < "1001" then --condicion para restaurar el bcd 2 ya cuando llegue a 9

else

bcd2 <= "0000"; --reinicio del segundo bcd cuando llegue a 9

bcd3 <= bcd3 +1; -- se recorre el conteo al 3 bcd

if bcd3 < "1001" then ----condicion para restaurar el bcd 3 ya cuando llegue a 9

else

bcd3 <= "0000"; --reinicio del tercer bcd cuando llegue a 9

bcd4 <= bcd4 +1; -- se recorre el conteo al cuarto bcd

if bcd4 < "1001" then ----condicion para restaurar el bcd 4 ya cuando llegue a 9

else

bcd4 <= "0000"; --reinicio del cuarto bcd cuando llegue a 9

end if;

end if;

end if;

indicador <= not indicador; --el indicador cambia de valor(prende o apaga)

end if;

temp1 <=0; -- el temporizador se actualiza en 0

end if;
end if;

--CONT DES

if c = '0' then --condicion para aser el conteo ascendente

temp1 <= temp1 + 1;

if temp1 = 49999999 then

if bcd1 > "0000" then --condicion donde si el primer bcd es mayor a 0

bcd1 <= bcd1 -1; --si es mayor a 0 entonces comienza el desenso

indicador <= not indicador; --indicador cambia su valor logico

else

bcd1 <= "1001"; --bcd1 se hace 9

bcd2 <= bcd2 - 1; --bcd 2 comienza el conteo

if bcd2 > "0000" then --condicion para cambiar el conteo al bcd3

else

bcd2 <= "1001"; --bcd2 se hace 9

bcd3 <= bcd3 -1; --bcd3 comienzo en desenso

if bcd3 > "0000" then --condicion para cambiar el conteo al bcd4

else

bcd3 <= "1001"; --bcd3 se hace 9

bcd4 <= bcd4 -1; --bcd4 comienzo en desenso

if bcd4 > "0000" then --condicion para iniciar el conteo

else

bcd4 <= "1001"; --bcd4 de hace 9

end if;

end if;

end if;

indicador <= not indicador; --indicador cambia su valor

end if;

temp1 <=0; --temporizador se hace 0

end if;
end if;

--RESET

if r = '1' then --condicion para activar el reset

bcd1 <= "0000"; --bcd1 cambia su valor a 0 por el reset

bcd2 <= "0000"; --bcd2 cambia su valor a 0 por el reset

bcd3 <= "0000"; --bcd3 cambia su valor a 0 por el reset

bcd4 <= "0000"; --bcd4 cambia su valor a 0 por el reset

indicador <= '0'; --indicador tambien cambia su valor a 0 por el reset

end if;

--PARO + RESET

if p = '1' then --condicion para detener el conteo

bcd1 <= bcd1; --bcd1 se detiene al tomar el valor que ya tenia

bcd2 <= bcd2; --bcd2 se detiene al tomar el valor que ya tenia

bcd3 <= bcd3; --bcd3 se detiene al tomar el valor que ya tenia

bcd4 <= bcd4; --bcd4 se detiene al tomar el valor que ya tenia

indicador <= '0'; --indicador se vuelve 0

if r = '1' then --condicion para activar el reset

bcd1 <= "0000"; --bcd1 cambia su valor a 0 por el reset

bcd2 <= "0000"; --bcd2 cambia su valor a 0 por el reset

bcd3 <= "0000"; --bcd3 cambia su valor a 0 por el reset

bcd4 <= "0000"; --bcd4 cambia su valor a 0 por el reset

indicador <= '0'; --indicador tambien cambia su valor a 0 por el reset

end if;

end if;

end if;

end process;

Multiplexor: process (sel,bcd1,bcd2,bcd3,bcd4) --comienza el proce de multiplexiado para sacar la


informacion

begin
case sel is --se usa un selector de casos, en base a el valor de cada selectora

when "00" => bcd <= bcd1; an<= "1110"; --se selecciona el primer bcd, la variable an
toma valores correspondientes a la salida de un multplexor con salidas negadas

when "01" => bcd <= bcd2; an<= "1101"; -- se selecciona el segundo bcd, pasando el
valor de bcd 2 a bcd

when "10" => bcd <= bcd3; an<= "1011"; -- se selecciona el tercer bcd, pasando el valor de
bcd 3 a bcd

when "11" => bcd <= bcd4; an<= "0111"; -- se selecciona el cuarto bcd, pasando el
valor de bcd 4 a bcd

when others => bcd <= "0000"; --se le da el valor 0000 para otros
casos osea cuando termine el conteo

end case;

end process;

with bcd select --despliege de resultados en base a la selectora, tipo switch case

display <= "11111001" when "0001", --asignacion del vector de salida para el numero 1

"10100100" when "0010", ----asignacion del vector de salida para el numero 2

"10110000" when "0011", --asignacion del vector de salida para el numero3

"10011001" when "0100", --asignacion del vector de salida para el numero4

"10010010" when "0101", --asignacion del vector de salida para el numero5

"10000010" when "0110", --asignacion del vector de salida para el numero6

"11111000" when "0111", --asignacion del vector de salida para el numero7

"10000000" when "1000", --asignacion del vector de salida para el numero8

"10010000" when "1001", --asignacion del vector de salida para el numero9

"11000000" when others; --asignacion del vector de salida para el numero0

end Behavioral;

UCF

NET "c" LOC="R17"; --asignacion del interruptor r17 para seleccionar el conteo asendente o
desendente

NET "r" LOC="H13"; --asignacion del interruptor h13 para hacer el reset

NET "p" LOC="E18"; --asignacion del interruptor e18 para hacer el paro
NET an<3> LOC="F15"; -- seleccion de cada display de salida por la variable an

NET an<2> LOC="C18";

NET an<1> LOC="H17";

NET an<0> LOC="F17";

NET "indicador" LOC="R4"; --asignacion del led r4 al indicador

NET Display<7> LOC="C17"; --asignacion de la señal de salida para cada led de los
display

NET Display<0> LOC="L18";

NET Display<1> LOC="F18";

NET Display<2> LOC="D17";

NET Display<3> LOC="D16";

NET Display<4> LOC="G14";

NET Display<5> LOC="J17";

NET Display<6> LOC="H14";

NET "CLK_50mhz" LOC="B8"; --asignacion del reloj en el modulo b8

You might also like