Documente Academic
Documente Profesional
Documente Cultură
use ieee.std_logic_1164.all;
entity dff is
port(clk,d:in std_logic;
q:out std_logic);
end dff;
library ieee;
use ieee.std_logic_1164.all;
entity dff is
port(clk,d:in std_logic;
reset:in std_logic;
q,q':out std_logic);
end dff;
library ieee;
use ieee.std_logic_1164.all;
entity myNAND is
port(a,b:in std_logic;
c:out std_logic);
end myNAND;
entity my_trigate is
port(a,en:in std_logic;
c:out std_logic);
end my_trigate;
entity mydecoder_8 is
port(d:in std_logic_vector(7 downto 0);
q:out std_logic_vector(2 downto 0));
end mydecoder_8;
entity t_trigger is
port(t,clk:in std_logic;
q,qb: out std_logic);
end t_trigger;
library ieee;
use ieee.std_logic_1164.all;
entity mychooser is
port(s0,s1:in std_logic;
d0,d1,d2,d3:in std_logic;
y:out std_logic);
end mychooser;
library ieee;
use ieee.std_logic_1164.all;
entity mycompare is
port(a:in std_logic;
b:in std_logic;
y:out std_logic_vector(2 downto 0));
end mycompare;
library ieee;
use ieee.std_logic_1164.all;
entity led2 is
port
(
led:out std_logic_vector(2 downto 0)
);
end entity;
library ieee;
use ieee.std_logic_1164.all;
entity led2 is
port
(
key:in std_logic;
led:out std_logic_vector(2 downto 0)
);
end entity;
architecture behave of led2 is
begin
process(key)
begin
if (key = '1') then
led<="000";
else
led<="111";
end if;
end process;
end behave;
library ieee;
use ieee.std_logic_1164.all;
entity led2 is
port
(
key:in std_logic_vector(2 downto 0);
led:out std_logic_vector(2 downto 0)
);
end entity;
entity led2 is
port
(
clk:in std_logic;
led:out std_logic_vector(2 downto 0);
sound:out std_logic
);
end entity;
begin
P1:process(clk)
variable div_1:integer range 0 to 99999999;
begin
if clk'event and clk = '1'then
frequency_flag <= '0';
div_1 := div_1 + 1;
end if;
if div_1 >= 99999999 then
frequency_flag <= '1';
div_1 := 1;
end if;
end process P1;
P2:process(frequency_flag)
variable count:integer range 0 to 8;
begin
if frequency_flag = '1' then
count := count + 1;
sound_flag <= '0';
end if;
if count >= 8 then
count := 0;
sound_flag <= '1';
end if;
case count is
when 0 => led <= "111";
when 1 => led <= "110";
when 2 => led <= "101";
when 3 => led <= "100";
when 4 => led <= "011";
when 5 => led <= "010";
when 6 => led <= "001";
when 7 => led <= "000";
when others => led <= "XXX";
end case;
end process P2;
P3:process(sound_flag)
begin
if sound_flag = '1' then
sound <= '0';
else
sound <= '1';
end if;
end process P3;
end behave;
library ieee;
use ieee.std_logic_1164.all;
entity led2 is
port
(
clk:in std_logic;
led:out std_logic_vector(2 downto 0)
);
end entity;
end behave;
//Program 6. Mode Modulation!
library ieee;
use ieee.std_logic_1164.all;
entity led2 is
port
(
clk:in std_logic;
mode:in std_logic;
reset:in std_logic;
led:out std_logic_vector(2 downto 0)
);
end entity;
begin
P1:process(clk)
variable div_1:integer range 0 to 29999999;
begin
if clk'event and clk = '1' then
frequency_flag <= '0';
div_1 := div_1 + 1;
end if;
if div_1 >= 29999999 then
frequency_flag <= '1';
div_1 := 1;
end if;
end process P1;
P2:process(frequency_flag)
variable count:integer range 0 to 8;
begin
if frequency_flag = '1' then
count := count + 1;
if count >= 8 then
count := 0;
end if;
if mode = '1' then
case count is
when 0 => led <= "111";
when 1 => led <= "110";
when 2 => led <= "101";
when 3 => led <= "100";
when 4 => led <= "011";
when 5 => led <= "010";
when 6 => led <= "001";
when 7 => led <= "000";
when others => led <= "XXX";
end case;
end if;
if mode = '0' then
case count is
when 0 => led <= "000";
when 1 => led <= "001";
when 2 => led <= "010";
when 3 => led <= "011";
when 4 => led <= "100";
when 5 => led <= "101";
when 6 => led <= "110";
when 7 => led <= "111";
when others => led <= "XXX";
end case;
end if;
end if;
if reset = '0' then
led <= "000";
end if;
end process P2;
end behave;
entity led2 is
port
(
clk:in std_logic;
pulse:in std_logic;
led:out std_logic
);
end entity;
P1:process(clk)
variable div_1:integer range 0 to 9999999;
begin
if clk'event and clk = '1'then
frequency_flag <= '0';
div_1 := div_1 + 1;
end if;
if div_1 >= 9999999 then
frequency_flag <= '1';
div_1 := 1;
end if;
end process P1; -- Setting Gate Period
P2:process(frequency_flag,pulse)
variable count:integer range 0 to 9999999;
begin
if pulse 'event and pulse = '1' then
count := count + 1;
end if;
if frequency_flag = '1' then
count := 0;
end if;
capture:process(pulse)
begin
if pulse 'event and pulse = '1' then
on_flag <= '1';
off_flag <= '0';
elsif pulse 'event and pulse = '0' then
on_flag <= '0';
off_flag <= '1';
end if;
end process capture;
P3:process(on_flag,off_flag,clk)
variable pwm_on:integer range 0 to 9999999;
variable pwm_period:integer range 0 to 9999999;
variable chance:integer range 0 to 1;
begin
if on_flag = '1' then
chance := chance + 1;
if chance = 1 then
if clk 'event and clk = '1' then
pwm_on := pwm_on + 1;
pwm_period := pwm_period + 1;
end if;
end if;
if chance > 1 then
pwm_on := 0;
pwm_period := 0;
chance := 0;
end if;
end if;
[1] System
library ieee;
use ieee.std_logic_1164.all;
entity system is
port
(
clk_in:in std_logic;
mode:in std_logic;
reset:in std_logic;
led:out std_logic_vector(2 downto 0)
);
end entity;
component clock_div_for_timer
port
(
clk_in:in std_logic;
clk_div_timer:out std_logic
);
end component;
component clock_div_for_pwm
port
(
clk_in:in std_logic;
clk_div_pwm:out std_logic
);
end component;
component mode_led
port
(
clk_div_timer:in std_logic;
clk_div_pwm:in std_logic;
mode:in std_logic;
reset:in std_logic;
led:out std_logic_vector(2 downto 0)
);
end component;
signal clk_div_timer:std_logic;
signal clk_div_pwm:std_logic;
begin
system_clock_div_for_timer:clock_div_for_timer
port map
(
clk_in => clk_in,
clk_div_timer => clk_div_timer
);
system_clock_div_for_pwm:clock_div_for_pwm
port map
(
clk_in => clk_in,
clk_div_pwm => clk_div_pwm
);
system_mode_led:mode_led
port map
(
clk_div_timer => clk_div_timer,
clk_div_pwm => clk_div_pwm,
mode => mode,
reset => reset,
led => led
);
end structure;
[2] clock_div_for_timer
library ieee;
use ieee.std_logic_1164.all;
entity clock_div_for_timer is
port
(
clk_in:in std_logic;
clk_div_timer:out std_logic
);
end entity;
begin
P1:process(clk_in)
variable count : integer range 0 to 9999999;
begin
if clk_in 'event and clk_in = '1' then
count := count + 1;
frequency_timer <= '0';
end if;
if count >= 9999999 then
count := 0;
frequency_timer <= '1';
end if;
end process P1;
P2:process(frequency_timer)
begin
if frequency_timer = '1' then
clk_div_timer <= '1';
else
clk_div_timer <= '0';
end if;
end process P2;
end structure;
[3] clock_div_for_pwm
library ieee;
use ieee.std_logic_1164.all;
entity clock_div_for_pwm is
port
(
clk_in:in std_logic;
clk_div_pwm:out std_logic
);
end entity;
end structure;
[4] mode_led
library ieee;
use ieee.std_logic_1164.all;
entity mode_led is
port
(
clk_div_timer:in std_logic;
clk_div_pwm:in std_logic;
mode:in std_logic;
reset:in std_logic;
led:out std_logic_vector(2 downto 0)
);
end entity;
P1:process(clk_div_timer)
variable count : integer range 0 to 8;
begin
if clk_div_timer 'event and clk_div_timer = '1' then
count := count + 1;
if count >= 8 then
count := 0;
end if;
if reset = '1' then
led <= "111";
end if;
if mode = '0' then
case count is
when 0 => led(0) <= '1';
led(1) <= '1';
led(2) <= '1';
when 1 => led(0) <= clk_div_pwm;
led(1) <= '1';
led(2) <= '1';
when 2 => led(0) <= '1';
led(1) <= clk_div_pwm;
led(2) <= '1';
when 3 => led(0) <= clk_div_pwm;
led(1) <= clk_div_pwm;
led(2) <= '1';
when 4 => led(0) <= '1';
led(1) <= '1';
led(2) <= clk_div_pwm;
when 5 => led(0) <= clk_div_pwm;
led(1) <= '1';
led(2) <= clk_div_pwm;
when 6 => led(0) <= '1';
led(1) <= clk_div_pwm;
led(2) <= clk_div_pwm;
when 7 => led(0) <= clk_div_pwm;
led(1) <= clk_div_pwm;
led(2) <= clk_div_pwm;
when others => led <= "XXX";
end case;
end if;
end if;
end process P1;
end structure;