Question

This code selects either the leds or the 7 segment display to show it's 8-bit data that i feed in through the switches. I select the led or the 7 segment through a push button. When I try to run it on my nexys2 board the led part works fine but as i press the pushbutton the selected 7segment glows and changes its value with the led glowing as well. Also the 7 segment changes it's value only when i press the pushbuton again. I am a newbie and i think I am having trouble making a good logic or what is the issue? any help would be appreciated!

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;


entity selector is 
Port ( clk: in STD_LOGIC;
sel : in  STD_LOGIC;
comb : in STD_LOGIC_VECTOR (7 downto 0);
segment : out  STD_LOGIC_VECTOR (3 downto 0);
number : out  STD_LOGIC_VECTOR (6 downto 0);
led: out STD_LOGIC_VECTOR (7 downto 0));
end selector;

architecture Behavioral of selector is

begin
process (clk, comb, sel) begin
    if (clk'event and clk = '1') then
        if sel = '1' then
            segment <= "1110";
                case (comb) is 
            when "00000000" => number <= "0000001"; --0
            when "00000001" => number <= "1001111"; --1
            when "00000010" => number <= "0010010"; --2
            when "00000011" => number <= "0000110"; --3
            when "00000100" => number <= "1001100"; --4
            when "00000101" => number <= "0100100"; --5
            when "00000110" => number <= "0100000"; --6
            when "00000111" => number <= "0001111"; --7
            when "00001000" => number <= "0000000"; --8
            when "00001001" => number <= "0000100"; --9
            when others => number <= "1111111"; -- off
        end case;
    elsif sel = '0' then 
                case (comb) is 
            when "00000000" => led <= "00000000"; --0
            when "00000001" => led <= "00000001"; --1
            when "00000010" => led <= "00000011"; --2
            when "00000011" => led <= "00000111"; --3
            when "00000100" => led <= "00001111"; --4
            when "00000101" => led <= "00011111"; --5
            when "00000110" => led <= "00111111"; --6
            when "00000111" => led <= "01111111"; --7
            when "00001000" => led <= "11111111"; --8
            when others => led <= "00000000"; -- off
                end case;
    end if;
end if;
end process;

end Behavioral;
Was it helpful?

Solution

You are not changing the value for the output that is not selected, so it remains in the state it has been assigned last.

Also, your code your code will only ever have an effect on the rising edge of the clock, so the sensitivity list can be reduced to (clk) (at which point, clk'event is implied).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top