mubase

Hamster FPGA tutorials. 4 bit adder, does this look right?

Recommended Posts

Hi all. I recieved my LogicStart today so as I have a few hours spare I thought I'd get cracking wth Hamster's PDF of tutorials and info. :)

I've just finished making a 4 bit adder using the swithces and LEDs of the board and would like to know if my code looks right. It seems to work.. From right to left, the switches in 2 groups of 4 seem to add up all the way to 15.

The code is here:

entity switches_leds is   Port ( switches : in STD_LOGIC_VECTOR(7 downto 0);LEDs : out STD_LOGIC_VECTOR(7 downto 0));end switches_leds;architecture Behavioral of switches_leds issignal x		: STD_LOGIC_VECTOR (3 downto 0);signal y		: STD_LOGIC_VECTOR (3 downto 0);signal carry : STD_LOGIC_VECTOR (3 downto 0);signal result : STD_LOGIC_VECTOR (4 downto 0);beginLEDs <= "000" & result;x <= switches (3 downto 0);y <= switches ( 7 downto 4 );result(0) <= x(0) XOR y(0);carry(0) <= x(0) AND y(0);result(1) <= x(1) XOR y(1) XOR carry(0);carry(1) <= (x(1) AND y(1)) OR (carry(0) AND x(1)) OR (carry(0) AND y(1));result(2) <= x(2) XOR y(2) XOR carry(1);carry(2) <= (x(2) AND y(2)) OR (carry(1) AND x(2)) OR (carry(1) AND y(2));result(3) <= x(3) XOR y(3) XOR carry(2);carry(3) <= (x(3) AND y(3)) OR (carry(2) AND x(3)) OR (carry(2) AND y(3));--result(4) <= x(4) XOR y(4) XOR carry(3);--carry(4) <= x(4) AND y(4) OR (carry(3) AND x(4)) OR (carry(3) AND y(4));end Behavioral;

 

I have some boolean experience having gone to college to do an access course in Audio electronics/music technology and being thrown in the deep end of boolean logic. :s

At the time all of us in the class were wondering where it all fitted in with Audio systems electronics but I am glad of it now. :)

If someone could verify this for me I'd be much appreciative.

All the best,

Steve.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now