Question

Here is my code for a simple ALU that adds and subtracts

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
library IEEE;
use IEEE.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity alu is
Port ( A : in  STD_LOGIC_VECTOR (15 downto 0);
       B : in  STD_LOGIC_VECTOR (15 downto 0);
          funct: in STD_LOGIC;
          op: in STD_LOGIC_VECTOR (1 downto 0);
       Result : out  STD_LOGIC_VECTOR (15 downto 0));
end alu;

architecture Behavioral of alu is
begin

process (op, funct)
 begin
  case op is
    when "00" => Result <= A+B;
    when "01" => Result <= A-B;
    when others => case funct is 
                        when "0" => Result <= A+B;
                        when "1" => Result <= A-B;
                        when others => null;
    end case;
`end case;
end process;
end Behavioral;

I am getting the following error

ERROR:HDLParsers:800 - "E:/Xilinx Projects/alu/alu.vhd" Line 51. Type of funct is     incompatible with type of 0.
ERROR:HDLParsers:800 - "E:/Xilinx Projects/alu/alu.vhd" Line 52. Type of funct is incompatible with type of 1.
ERROR:HDLParsers:163 - "E:/Xilinx Projects/alu/alu.vhd" Line 55. Unexpected symbol read: `.

I know it has something to do with type mismatches of 'funct' and 'Result' but I dont know how to resolve it, any ideas?

Était-ce utile?

La solution

This analyzes:

library ieee;
use ieee.std_logic_1164.all;
--  library ieee;  -- successive library clause has no effect
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity alu is
    port ( 
        a:      in  std_logic_vector (15 downto 0);
        b:      in  std_logic_vector (15 downto 0);
        funct:  in  std_logic;
        op:     in  std_logic_vector (1 downto 0);
        result: out std_logic_vector (15 downto 0)
    );
end alu;

architecture behavioral of alu is
begin

process (op, funct)
 begin
    case op is
        when "00" => 
            result <= a+b;
        when "01" => 
            result <= a-b;
        when others => 
            case funct is 
                when '0' => result <= a+b;  -- "0"
                when '1' => result <= a-b;  -- "1"
                when others => null;
            end case;
    end case; -- `end case;
end process;
end behavioral;

Type std_logic has enumerations using character literals and of itself is a scalar, not eligible to have a string assigned to funct. From the std_logic_1164 package declaration:

-------------------------------------------------------------------
TYPE std_ulogic IS ( 'U',  -- Uninitialized
                     'X',  -- Forcing  Unknown
                     '0',  -- Forcing  0
                     '1',  -- Forcing  1
                     'Z',  -- High Impedance
                     'W',  -- Weak     Unknown
                     'L',  -- Weak     0
                     'H',  -- Weak     1
                     '-'   -- Don't care
                   );
-------------------------------------------------------------------

and:

-------------------------------------------------------------------
SUBTYPE std_logic IS resolved std_ulogic;

-------------------------------------------------------------------

As mentioned in the comment to your question the grave accent character shouldn't be in front of the second end case;.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top