I have a problem trying to add my integer signal and trying to decode it on my segment. BTW, our project is try to display the incremented value when one switch is click. There are 3 switches (swA,swB,swC). Initially, all 3 segments are 0,0,0 if you click switchA, it will display = 1,0,0 then.. if you click switchC, it will display = 1,0,2 then.. if you click switchB, it will display = 1,3,2 then.. if you click switchC, it will display = 1,3,4
so the algorithm goes like that. my problem is the addition part. my decoder codes are fine but my sequence when clicking, jumps +4, +2, +8. I think my problem is on my addition algorithm, or im not sure maybe its on my frequency division.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity SwitchCounterModule is
port( SegmentIndicator: inout STD_LOGIC_VECTOR(6 downto 0);
SegmentA : inout STD_LOGIC_VECTOR(6 downto 0);
SegmentB : inout STD_LOGIC_VECTOR(6 downto 0);
SegmentC : inout STD_LOGIC_VECTOR(6 downto 0);
SwitchA : in STD_LOGIC;
SwitchB : in STD_LOGIC;
SwitchC : in STD_LOGIC);
end SwitchCounterModule;
architecture Behavioral of SwitchCounterModule is
signal counter :std_logic_vector(3 downto 0);
signal sumOut1: integer;
begin
process(sumOut1)
begin
sumOut1<=5;
if SwitchA = '1' then
SegmentIndicator <= "0001000"; --A
sumOut1 <= sumOut1 +1;
if(sumOut1>9)then
sumOut1<= 0;
case sumOut1 is
when 0 => SegmentA <="1000000"; -- '0'
when 1 => SegmentA <="1111001"; -- '1'
when 2 => SegmentA <="0100100"; -- '2'
when 3 => SegmentA <="0110000"; -- '3'
when 4 => SegmentA <="0011001"; -- '4'
when 5 => SegmentA <="0010010"; -- '5'
when 6 => SegmentA <="0000010"; -- '6'
when 7 => SegmentA <="1111000"; -- '7'
when 8 => SegmentA <="0000000"; -- '8'
when others => SegmentA <="0010000"; -- '9'
end case;
else
case sumOut1 is
when 0 => SegmentA <="1000000"; -- '0'
when 1 => SegmentA <="1111001"; -- '1'
when 2 => SegmentA <="0100100"; -- '2'
when 3 => SegmentA <="0110000"; -- '3'
when 4 => SegmentA <="0011001"; -- '4'
when 5 => SegmentA <="0010010"; -- '5'
when 6 => SegmentA <="0000010"; -- '6'
when 7 => SegmentA <="1111000"; -- '7'
when 8 => SegmentA <="0000000"; -- '8'
when others => SegmentA <="0010000"; -- '9'
end case;
end if;
elsif SwitchB = '1' then
SegmentIndicator <= "0000011"; --B
sumOut1 <= sumOut1 +1;
if(sumOut1=10)then
sumOut1<= 0;
case sumOut1 is
when 0 => SegmentB <="1000000"; -- '0'
when 1 => SegmentB <="1111001"; -- '1'
when 2 => SegmentB <="0100100"; -- '2'
when 3 => SegmentB <="0110000"; -- '3'
when 4 => SegmentB <="0011001"; -- '4'
when 5 => SegmentB <="0010010"; -- '5'
when 6 => SegmentB <="0000010"; -- '6'
when 7 => SegmentB <="1111000"; -- '7'
when 8 => SegmentB <="0000000"; -- '8'
when others => SegmentB <="0010000"; -- '9'
end case;
else
case sumOut1 is
when 0 => SegmentB <="1000000"; -- '0'
when 1 => SegmentB <="1111001"; -- '1'
when 2 => SegmentB <="0100100"; -- '2'
when 3 => SegmentB <="0110000"; -- '3'
when 4 => SegmentB <="0011001"; -- '4'
when 5 => SegmentB <="0010010"; -- '5'
when 6 => SegmentB <="0000010"; -- '6'
when 7 => SegmentB <="1111000"; -- '7'
when 8 => SegmentB <="0000000"; -- '8'
when others => SegmentB <="0010000"; -- '9'
end case;
end if;
elsif SwitchC = '1' then
SegmentIndicator <= "1000110"; --C
sumOut1 <= sumOut1 +1;
if(sumOut1=10)then
sumOut1<= 0;
case sumOut1 is
when 0 => SegmentC <="1000000"; -- '0'
when 1 => SegmentC <="1111001"; -- '1'
when 2 => SegmentC <="0100100"; -- '2'
when 3 => SegmentC <="0110000"; -- '3'
when 4 => SegmentC <="0011001"; -- '4'
when 5 => SegmentC <="0010010"; -- '5'
when 6 => SegmentC <="0000010"; -- '6'
when 7 => SegmentC <="1111000"; -- '7'
when 8 => SegmentC <="0000000"; -- '8'
when others => SegmentC <="0010000"; -- '9'
end case;
else
case sumOut1 is
when 0 => SegmentC <="1000000"; -- '0'
when 1 => SegmentC <="1111001"; -- '1'
when 2 => SegmentC <="0100100"; -- '2'
when 3 => SegmentC <="0110000"; -- '3'
when 4 => SegmentC <="0011001"; -- '4'
when 5 => SegmentC <="0010010"; -- '5'
when 6 => SegmentC <="0000010"; -- '6'
when 7 => SegmentC <="1111000"; -- '7'
when 8 => SegmentC <="0000000"; -- '8'
when others => SegmentC <="0010000"; -- '9'
end case;
end if;
else
sumOut1<=sumOut1;
SegmentA<=SegmentA;
SegmentB<=SegmentB;
SegmentC<=SegmentC;
end if;
end process;
end Behavioral;