Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Projekt 1
- -- Łukasz Przeniosło, EiT3
- -- 26.12.2012
- 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 proj1counter is
- port (
- -- OUT's
- leds : out STD_LOGIC_VECTOR (6 downto 0);
- anodes : out STD_LOGIC_VECTOR (3 downto 0);
- colon : out STD_LOGIC;
- debug_led : out STD_LOGIC_VECTOR (0 to 5);
- -- IN's
- pb1 : in STD_LOGIC;
- pb2 : in STD_LOGIC;
- CLK : in STD_LOGIC
- );
- end proj1counter;
- architecture Behavioral of proj1counter is
- -- types:
- type led_array is array (15 downto 0) of STD_LOGIC_VECTOR (6 downto 0);
- -- signals:
- signal base_prescaler : STD_LOGIC_VECTOR (24 downto 0); -- base frequency prescaler
- signal display_prescaler : STD_LOGIC_VECTOR (24 downto 0); -- display frequency prescaler
- signal display_nr : STD_LOGIC_VECTOR (1 downto 0); -- used to chose active display
- signal key_lock, key_lock2 : BIT; -- debounce help signal.
- -- flag signals:
- signal counter_full : BIT := '1'; -- 1 means full;
- signal digit_clear : BIT; -- 1 means clear.
- signal lcd_stop : BIT; -- 1 means lcd stop.
- signal db_pb1, db_pb2 : BIT;
- signal digit0, digit1, digit2, digit3 : integer range 0 to 15;
- signal lfsr0 : STD_LOGIC_VECTOR (3 downto 0) := "0001"; -- Linear feedback shift register 0
- signal lfsr1 : STD_LOGIC_VECTOR (3 downto 0) := "1110"; -- Linear feedback shift register 1
- signal lfsr2 : STD_LOGIC_VECTOR (3 downto 0) := "1100"; -- Linear feedback shift register 2
- signal lfsr3 : STD_LOGIC_VECTOR (3 downto 0) := "1010"; -- Linear feedback shift register 3
- constant my_led_array : led_array := ("0001110", -- F
- "0000110", -- E
- "0100001", -- d
- "1000110", -- C
- "0000011", -- b
- "0001000", -- A
- "0010000", -- 9
- "0000000", -- 8
- "1111000", -- 7
- "0000010", -- 6
- "0010010", -- 5
- "0011001", -- 4
- "0110000", -- 3
- "0100100", -- 2
- "1111001", -- 1
- "1000000"); --0
- -- DEBOUNCE
- type State_Type is (S0, S1);
- -- 1
- signal State : State_Type := S0;
- signal DPB, SPB : STD_LOGIC;
- signal DReg : STD_LOGIC_VECTOR (7 downto 0);
- -- 2
- signal State2 : State_Type := S0;
- signal DPB2, SPB2 : STD_LOGIC;
- signal DReg2 : STD_LOGIC_VECTOR (7 downto 0);
- -- ###########################################################################################
- begin
- -- switches the lcd panels, controls the dot, freezes/ defreezes the lcd.
- display_switch : process (CLK)
- begin
- if rising_edge(CLK) then
- -- Fibonacci LFSR
- lfsr3(3) <= (lfsr1(1) xor (lfsr0(3) xor (lfsr0(0) xor lfsr0(2))));
- lfsr3(2) <= lfsr3(3);
- lfsr3(1) <= lfsr3(2);
- lfsr3(0) <= lfsr3(1);
- lfsr2(3) <= lfsr3(0);
- lfsr2(2) <= lfsr2(3);
- lfsr2(1) <= lfsr2(2);
- lfsr2(0) <= lfsr2(1);
- lfsr1(3) <= lfsr2(0);
- lfsr1(2) <= lfsr1(3);
- lfsr1(1) <= lfsr1(2);
- lfsr1(0) <= lfsr1(1);
- lfsr0(3) <= lfsr0(0);
- lfsr0(2) <= lfsr0(3);
- lfsr0(1) <= lfsr0(2);
- lfsr0(0) <= lfsr0(1);
- display_prescaler <= display_prescaler + 1;
- if (display_prescaler = 100000) then
- display_prescaler <= (others => '0');
- case display_nr is
- when "00" =>
- leds <= my_led_array(digit0);
- anodes <= "0111";
- colon <= '1';
- when "01" =>
- leds <= my_led_array(digit1);
- anodes <= "1011";
- colon <= '1';
- when "10" =>
- leds <= my_led_array(digit2);
- anodes <= "1101";
- colon <= '1';
- when "11" =>
- leds <= my_led_array(digit3);
- anodes <= "1110";
- colon <= '1';
- when others => null;
- end case;
- display_nr <= display_nr + 1; -- self pb2 after display_nr = 3.
- end if;
- end if;
- end process display_switch;
- -- ###########################################################################################
- -- debounce elimination for pb1.
- debouncing1 : process (CLK, pb1)
- variable SDC : integer;
- constant Delay : integer := 50000;
- begin
- if CLK'Event and CLK = '1' then
- -- Double latch input signal
- DPB <= SPB;
- SPB <= pb1;
- case State is
- when S0 =>
- DReg <= DReg(6 downto 0) & DPB;
- SDC := Delay;
- State <= S1;
- when S1 =>
- SDC := SDC - 1;
- if SDC = 0 then
- State <= S0;
- end if;
- when others =>
- State <= S0;
- end case;
- if DReg = X"FF" then
- db_pb1 <= '1';
- elsif DReg = X"00" then
- db_pb1 <= '0';
- end if;
- end if;
- end process debouncing1;
- -- ###########################################################################################
- -- buttons actions.
- buttons : process (CLK)
- begin
- if CLK'Event and CLK = '1' then
- if key_lock = '0' and db_pb1 = '1' then
- key_lock <= '1';
- debug_led <= "100000";
- digit0 <= conv_integer(unsigned(lfsr3));
- digit1 <= conv_integer(unsigned(lfsr2));
- digit2 <= conv_integer(unsigned(lfsr1));
- digit3 <= conv_integer(unsigned(lfsr0));
- -- btn pressed
- elsif key_lock = '1' and db_pb1 = '0' then
- key_lock <= '0';
- debug_led <= "000000";
- -- btn released
- end if;
- end if;
- end process buttons;
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement