user3420628
user3420628

Reputation: 1

How to use conditional assignment when portmapping

I am trying to create a very simple calculator with the use of an adder and subtractor as components. i want the results to be displayed on seven segment displays. The problem is i dont know how to select addition or subtraction using add_sub.

LIBRARY ieee;
USE ieee.std_logic_1164.all;

ENTITY CONVERTOR IS 
PORT (  
            A,B             :IN BIT;
            CIN,ADD_SUB     :IN BIT;
            cout,carryborrow    :OUT BIT
        );  

END CONVERTOR;

ARCHITECTURE CONVERTOR_ARCH OF CONVERTOR IS

COMPONENT SUBTRACTOR_ASSIGNMENT IS 
PORT (  
            A1,B1   :IN STD_LOGIC;
            CIN1    :IN STD_LOGIC;
            diff1,borrow1   :OUT STD_LOGIC
                    );  
END COMPONENT;

COMPONENT ADDER_ASSIGNMENT IS 
PORT (  
            A2,B2           :IN STD_LOGIC;
            CIN2            :IN STD_LOGIC;
            sum_2,cout2     :OUT STD_LOGIC

      );
END COMPONENT;

SIGNAL E,F,G,H,P,Q,R,S: STD_LOGIC;

BEGIN 
        E <= A   WHEN add_sub = '1' ELSE '0';
        F <= B   WHEN add_sub = '1' ELSE '0';
        G <= CIN WHEN add_sub = '1' ELSE '0'; 


        H <= A   WHEN add_sub = '0' ELSE '0'; 
        I <= B   WHEN add_sub = '0' ELSE '0';
        J <= CIN WHEN add_sub = '0' ELSE '0'; 

        AD1: SUBTRACTOR_ASSIGNMENT PORT MAP(E,F,G,cout,carryborrow);
        AD2: SUBTRACTOR_ASSIGNMENT PORT MAP(E,F,G,cout,carryborrow);
        AD3: SUBTRACTOR_ASSIGNMENT PORT MAP(E,F,G,cout,carryborrow);
        AD4: SUBTRACTOR_ASSIGNMENT PORT MAP(E,F,G,cout,carryborrow);




        SB1: ADDER_ASSIGNMENT PORT MAP(H,I,J,cout,carryborrow);
        SB1: ADDER_ASSIGNMENT PORT MAP(H,I,J,cout,carryborrow);
        SB1: ADDER_ASSIGNMENT PORT MAP(H,I,J,cout,carryborrow);
        SB1: ADDER_ASSIGNMENT PORT MAP(H,I,J,cout,carryborrow);




END CONVERTOR_ARCH;

Upvotes: 0

Views: 447

Answers (2)

heisenBug
heisenBug

Reputation: 955

Can you give us an error message you are getting, or the output? Based on what you are saying, it looks like you are trying to use "ADD_SUB" in your port to switch between addition and subtraction.

Also worth noting: do you want your design to be clocked? Right now, it doesn't look like you have a clock going into your port. If you wanted to update your display synchronously, you would need to add in a clock by using something like:

if (rising_edge(my_clock)) then
     -- make the magic happen
end if;

Upvotes: 1

Jim Lewis
Jim Lewis

Reputation: 3963

Did you draw a picture of your hardware? You need multiplexors on the outputs of the Adder and Subtractor, but it is ok to connect your A, B, CIN to both your adder and subtractor.

Make sure to mind your types. If you are using std_ulogic, then use it everywhere and not type bit.

Upvotes: 0

Related Questions