type your search

Tuesday, January 10, 2012

Simple 4 : 1 multiplexer using case statements

Here is the code for 4 : 1 MUX using case statements.The module contains 4 single bit input lines and one 2 bit select input.The output is a single bit line.


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity multiplexer4_1 is
port (
      i0 : in std_logic;
      i1 : in std_logic;
      i2 : in std_logic;
      i3 : in std_logic;
     sel : in std_logic_vector(1 downto 0);
     bitout : out std_logic
     );
end multiplexer4_1;

architecture Behavioral of multiplexer4_1 is
begin

process(i0,i1,i2,i3,sel)
begin
case sel is
  when "00" => bitout <= i0;
  when "01" => bitout <= i1;
  when "10" => bitout <= i2;
  when others => bitout <= i3;
end case;
end process;

end Behavioral;

The testbench code used for testing the code is given below:

  LIBRARY ieee;
  USE ieee.std_logic_1164.ALL;

  ENTITY testbench IS
  END testbench;

  ARCHITECTURE behavior OF testbench IS
          SIGNAL i0,i1,i2,i3,bitout :  std_logic:='0';
          SIGNAL sel :  std_logic_vector(1 downto 0):="00";
  BEGIN
    UUT : entity work.multiplexer4_1 port map(i0,i1,i2,i3,sel,bitout);

     tb : PROCESS
     BEGIN
            i0<='1';
            i1<='0';
            i2<='1';
            i3<='0';
            sel <="00";
            wait for 2 ns;
            sel <="01";
            wait for 2 ns;
            sel <="10";
             wait for 2 ns;
             sel <="11";
              wait for 2 ns;
            --more input combinations can be given here.
     END PROCESS tb;

  END;

     The simulated testbench waveform is shown below:

  The code was synthesized using XILINX ISE XST . The RTL schematic of the design is shown below.


Note :- Use RTL Viewer to get a closer look on how your design is implemented in hardware.

5 comments:

  1. Hi Aravind,

    A really interesting, clear and easily readable Simple 4 : 1 multiplexer using case statements article of interesting and different perspectives. I will clap. So much is so well covered here.

    However, when .ebignore is present in yout project directory, the EB CLI doesn't use git commands and semantics to create your source bundle. This means that EB CLI ignores files specified in .ebignore, and includes all other files. In particular, it includes uncommitted source files.

    Anyways great write up, your efforts are much appreciated.


    Grazie,
    Abhiram

    ReplyDelete
  2. Hi Aravind,

    Simple 4: 1 multiplexer using case statements being contrived to exist for many projects simply so it can be run will be the first to hit the wall, but those projects where the functions to make existing transactions cheaper in real world applications will find the elusive `real-world demand.
    A few months ago, I shut everything down in AWS. I didn't close the account because I wanted to spin some things back up down the road when I had the time. A month later, I got a final bill for services that had been running mid-month when I closed them. Being somewhat Type A, I went into the Billing Console to review the charges and confirm what they were. Should have been the end of the story.

    When an instance is stopped, it performs a normal shutdown and then transitions to a paused state AWS Tutorial . When an instance is terminated, it performs a normal shutdown, then the attached Amazon EBS volumes are deleted unless the volume’s deleteOnTermination attribute is set to false.

    I read multiple articles and watched many videos about how to use this tool - and was still confused! Your instructions were easy to understand and made the process simple.

    Cheers,
    Kevin

    ReplyDelete
  3. Hello Arvind,


    Best thing I have read in a while on this Simple 4 : 1 multiplexer using case statements . There should be a standing ovation button. This is a great piece. AWS Tutorial


    When creating a crawler that reads from S3, it would be nice if you could specify the Athena table name. At the moment it takes the name of the S3 folder it crawls.

    By the way do you have any YouTube videos, would love to watch it. I would like to connect you on LinkedIn, great to have experts like you in my connection (In case, if you don’t have any issues).

    Shukran,
    Radhey

    ReplyDelete
  4. Hi Aravind,

    I learnt so much in such little time about Simple 4 : 1 multiplexer using case statements. Even a toddler could become smart reading of your amazing articles.

    I am currently working on a project that does not include storyboards and I am trying to create a user authentication and sign-in method. I was initially going to use FireBase but they did not have Carthage support so I decided to try out AWS. I initially tried using AWSCognitoIdentityProvider framework with my custom UI but the passwordauthentication method for signing in would not trigger a result. I moved onto the AWSAuthUI framework (plus AWSAuthCore, AWSFacebookSignIn, AWSGoogleSignIn, AWSUserPoolsSignIn) with the built in UI but I keep getting the error below before even getting to the login screen.

    Amazon Elastic Compute Cloud (Amazon EC2) is an Amazon Web service that provides resizable (scalable) computing capacity in the cloud. You can configure security and networking as well as manage storage. It also helps in obtaining and configuring capacity using minimal friction AWS Training . You can use it to launch as many virtual servers as you need.

    Anyways great write up, your efforts are much appreciated.

    Merci,
    Kevin

    ReplyDelete
  5. Hi Bru,

    I’ve often thought about this Simple 4 : 1 multiplexer using case statements. Nice to have it laid out so clearly. Great eye opener.

    I'd like to make a suggestion to improve the user experience for setting up a Reserved Instance. This comes from my own experience of using RIs on both EC2 and RDS (which is why I haven't put this in a product specific forum). AWS Training USA

    But nice Article Mate! Great Information! Keep up the good work!

    Thanks a heaps,
    Radhey

    ReplyDelete