error in code / ALU / calculator

Discussion in 'VHDL' started by emy86evil, Jan 4, 2007.

  1. emy86evil

    emy86evil

    Joined:
    Nov 21, 2006
    Messages:
    4
    hi i have do this code for a simple calculator that do this for operations: sub, sum , Mul and div

    note in div operation for example if we have 7/4 the result is 1 and the remainder is 3/4

    the out put will display like this ===> 1 3_|4 == 1 3/4 (display as seven segment by usin An bit_vector 3 downto 0

    on the FPGA board

    and there is an error so plz I need help

    ********************

    library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    use IEEE.STD_LOGIC_ARITH.ALL;
    use IEEE.STD_LOGIC_UNSIGNED.ALL;

    -- Uncomment the following lines to use the declarations that are
    -- provided for instantiating Xilinx primitive components.
    --library UNISIM;
    --use UNISIM.VComponents.all;

    entity calculator is
    port(A,B : in integer range 0 to 7;
    clk : in bit;
    sel : in std_logic_vector(1 downto 0);
    Q : out bit_vector(6 downto 0);
    An : out bit_vector(3 downto 0));

    end calculator;

    architecture Behavioral of calculator is
    signal sub : integer range 0 to 7;
    signal sum : integer range 0 to 14;
    signal div : integer range 0 to 7;
    signal Mul : integer range 0 to 49;

    signal Qsub,Qsum1,Qsum2,Qmul,Qmul2,Qdiv :bit_vector(6 downto 0);
    signal minus : bit_vector(6 downto 0);

    signal divRemainder:bit_vector(6 downto 0);
    signal B1:bit_vector(6 downto 0);

    signal clk1: bit;


    begin

    clkDiv : process
    variable count :integer range 0 to 50000000;
    begin
    wait until clk'event and clk='1';
    count := count + 1;
    if (count = 50000000) then
    count := 0;
    elsif (count < 25000000) then
    clk1 <= '0';
    elsif (count > 25000000) then
    clk1 <= '1';
    end if;
    end process clkDiv;


    sub_opration : process(A,B)
    begin


    if(A>B) then
    sub<=A-B;
    minus<="1111111";
    case sub is
    when 0 =>Qsub <="1000000";
    when 1 =>Qsub<="1111001";
    when 2 =>Qsub<="0100100";
    when 3 =>Qsub<="0110000";
    when 4 =>Qsub<="0011001";
    when 5 =>Qsub<="0010010";
    when 6 =>Qsub<="0000010";
    when 7 =>Qsub<="1011000";
    when others => null;
    end case;

    else
    sub<=B-A;
    minus<="0111111";
    case sub is
    when 0 =>Qsub<="1000000";
    when 1 =>Qsub<="1111001";
    when 2 =>Qsub<="0100100";
    when 3 =>Qsub<="0110000";
    when 4 =>Qsub<="0011001";
    when 5 =>Qsub<="0010010";
    when 6 =>Qsub<="0000010";
    when 7 =>Qsub<="1011000";
    when others => null;
    end case;
    end if;


    end process sub_opration;

    sum_opration : process(A,B)
    begin

    sum<=A+B;

    case sum is

    when 0 =>Qsum1<="1000000";
    Qsum2<="1111111";
    when 1 =>Qsum1<="1111001";
    Qsum2<="1111111";
    when 2 =>Qsum1<="0100100";
    Qsum2<="1111111";
    when 3 =>Qsum1<="0110000";
    Qsum2<="1111111";
    when 4 =>Qsum1<="0011001";
    Qsum2<="1111111";
    when 5 =>Qsum1<="0010010";
    Qsum2<="1111111";
    when 6 =>Qsum1<="0000010";
    Qsum2<="1111111";
    when 7 =>Qsum1<="1011000";
    Qsum2<="1111111";
    when 8 =>Qsum1<="0000000";
    Qsum2<="1111111";
    when 9 =>Qsum1<="0010000";
    Qsum2<="1111111";
    when 10=>Qsum1<="1000000";
    Qsum2<="1111001";
    when 11=>Qsum1<="1111001";
    Qsum2<="1111001";
    when 12=>Qsum1<="0100100";
    Qsum2<="1111001";
    when 13=>Qsum1<="0110000";
    Qsum2<="1111001";
    when 14=>Qsum1<="0011001";
    Qsum2<="1111001";
    when others => null;
    end case;


    end process sum_opration;

    Mul_operation : process(A,B)
    variable Remm10:integer range 0 to 9;
    variable C1: integer range 1 to 7 :=7;
    begin
    Mul<= A*B;

    if(Mul<10) then
    case Mul is
    when 0 =>Qmul<="1000000";
    Qmul2<="1111111";
    when 1 =>Qmul<="1111001";
    Qmul2<="1111111";
    when 2 =>Qmul<="0100100";
    Qmul2<="1111111";
    when 3 =>Qmul<="0110000";
    Qmul2<="1111111";
    when 4 =>Qmul<="0011001";
    Qmul2<="1111111";
    when 5 =>Qmul<="0010010";
    Qmul2<="1111111";
    when 6 =>Qmul<="0000010";
    Qmul2<="1111111";
    when 7 =>Qmul<="1011000";
    Qmul2<="1111111";
    when 8 =>Qmul<="0000000";
    Qmul2<="1111001";
    when 9 =>Qmul<="0010000";
    Qmul2<="1111111";
    when others => null;
    end case;

    else
    for j in 7 downto 1 loop

    if(10*C1<Mul or 10*C1= Mul)then
    Mul<=10*C1;
    Remm10:=10*C1-Mul;
    end if;
    C1:=C1-1;

    end loop;

    case Mul is
    when 0 =>Qmul2<="1000000";
    when 1 =>Qmul2<="1111001";
    when 2 =>Qmul2<="0100100";
    when 3 =>Qmul2<="0110000";
    when 4 =>Qmul2<="0011001";
    when 5 =>Qmul2<="0010010";
    when 6 =>Qmul2<="0000010";
    when 7 =>Qmul2<="1011000";
    when 8 =>Qmul2<="0000000";
    when 9 =>Qmul2<="0010000";
    when others => null;
    end case;

    case Remm10 is
    when 0 =>Qmul<="1000000";
    when 1 =>Qmul<="1111001";
    when 2 =>Qmul<="0100100";
    when 3 =>Qmul<="0110000";
    when 4 =>Qmul<="0011001";
    when 5 =>Qmul<="0010010";
    when 6 =>Qmul<="0000010";
    when 7 =>Qmul<="1011000";
    when 8 =>Qmul<="0000000";
    when 9 =>Qmul<="0010000";
    when others => null;
    end case;

    end if;

    end process Mul_operation;

    div_operation: process(A,B)
    variable C : integer range 1 to 7 :=7;
    variable Remm:integer range 0 to 9;
    begin

    for I in 7 downto 1 loop

    if(A=B)then
    div<=1;
    Remm:=0;

    elsif(B>A)then
    div<=0;

    elsif(A>B)then
    if(B*C<A)then
    div<=B*C;
    Remm:=B*C-A; --the result will display as: div _| Remainder _| B
    end if;
    C:=C-1;
    end if;

    end loop;

    case div is
    when 0 =>Qdiv<="1000000";
    when 1 =>Qdiv<="1111001";
    when 2 =>Qdiv<="0100100";
    when 3 =>Qdiv<="0110000";
    when 4 =>Qdiv<="0011001";
    when 5 =>Qdiv<="0010010";
    when 6 =>Qdiv<="0000010";
    when 7 =>Qdiv<="1011000";
    when others => null;
    end case;

    case Remm is
    when 0 =>divRemainder<="1000000";
    when 1 =>divRemainder<="1111001";
    when 2 =>divRemainder<="0100100";
    when 3 =>divRemainder<="0110000";
    when 4 =>divRemainder<="0011001";
    when 5 =>divRemainder<="0010010";
    when 6 =>divRemainder<="0000010";
    when 7 =>divRemainder<="1011000";
    when others => null;
    end case;

    case B is
    when 0 =>B1<="1000000";
    when 1 =>B1<="1111001";
    when 2 =>B1<="0100100";
    when 3 =>B1<="0110000";
    when 4 =>B1<="0011001";
    when 5 =>B1<="0010010";
    when 6 =>B1<="0000010";
    when 7 =>B1<="1011000";
    when others => null;
    end case;

    end process div_operation;


    choice : process(clk1,sel)
    variable m : integer range 0 to 3 := 0;
    begin
    if(clk1'event and clk1 = '1') then

    case m is
    when 0 =>
    if(sel = "00") then
    Q <= Qsub;
    elsif(sel="01") then
    Q<=Qsum1;
    elsif(sel="10") then
    Q<=Qmul;
    elsif(sel="11") then
    Q<=B1;
    end if;
    An<="1110";

    when 1 =>
    if(sel = "00") then
    Q <= minus;
    elsif(sel="01") then
    Q<=Qsum2;
    elsif(sel="10") then
    Q<=Qmul2;
    elsif(sel="11") then
    Q<="1110011"; -- display _|
    end if;
    An<="1101";

    when 2 =>
    if(sel="11") then
    Q<= divRemainder;
    end if;
    An<="1011";

    when 3 =>
    if (sel="11") then
    Q<= Qdiv;
    end if;
    An<="0111";

    end case;
    m := m + 1;
    end if;
    end process choice;
    end Behavioral;


    ****************

    and the error said:
     
    emy86evil, Jan 4, 2007
    #1
    1. Advertising

  2. emy86evil

    emy86evil

    Joined:
    Nov 21, 2006
    Messages:
    4
    hmmmm !!

    i think that no one know the VHDL

    so sad

    any way thanx i solve the error !
     
    Last edited: Jan 20, 2007
    emy86evil, Jan 10, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manuel

    alu implementation

    Manuel, Feb 3, 2004, in forum: VHDL
    Replies:
    3
    Views:
    5,263
    Manuelll
    Feb 6, 2004
  2. Lily

    need help with ALU 8 BIT

    Lily, Apr 6, 2004, in forum: VHDL
    Replies:
    0
    Views:
    1,060
  3. Lily
    Replies:
    16
    Views:
    1,399
    Bob Jenkins
    May 10, 2004
  4. Cesar Andres Roldan Garcia

    Controling the ALU

    Cesar Andres Roldan Garcia, Mar 31, 2005, in forum: Python
    Replies:
    5
    Views:
    381
    Chris Smith
    Apr 2, 2005
  5. CS_

    ALU code ???

    CS_, Dec 8, 2009, in forum: VHDL
    Replies:
    6
    Views:
    1,594
    CS student
    Dec 14, 2009
Loading...

Share This Page