Question

In: Electrical Engineering

a) i) The following VHDL code contains erroneous syntax. Re write the code in its corrected...

a) i) The following VHDL code contains erroneous syntax. Re write the code in its corrected format onto your answer sheet. You may assume that din is a 16-bit vector and that the ld, lr and cl inputs are 1-bit wide.

lp: process(clk)
signal reg : std_logic_vector(15 downt
begin
if cl=’1’ then
reg := (others:=’0’);
else
if clk=’1’ and clkevent then
if ld=’1’
reg <= din;
end if;
if lr=’1’ then
reg := reg(14 downto 0) & “0
else
reg := ‘0’ && reg(15 downto
end if;
end if;
end process

Describe, in your own words, the functionality of the circuit
described by the corrected VHDL code from i). Your answer
must explain the purpose of the lr, ld and cl inputs.

Solutions

Expert Solution

The circuit is a 16 bit shift register with preload and asynchronous clear.

The cl input clears the register. The ld input loads the register with data from din. The lr input decides the direction of the shift, 0 for right shift and 1 for left shift.

Design:

library ieee;
use ieee.std_logic_1164.all;

entity shift is
port (
    clk : in std_logic;
    cl   : in std_logic;
    ld   : in std_logic;
    lr   : in std_logic;
    din : in std_logic_vector(15 downto 0);
    dout : out std_logic_vector(15 downto 0)
);
end shift;

architecture arch of shift is begin

lp : process (clk)
    variable reg : std_logic_vector(15 downto 0);
begin
    if (cl = '1') then
      reg := (others => '0');
    else
      if (clk'event and clk = '1') then
        if (ld = '1') then
          reg := din;
        else
          if (lr = '1') then
            reg := reg(14 downto 0) & "0";
          else
            reg := "0" & reg(15 downto 1);
          end if;
        end if;
      end if;
    end if;
    dout <= reg;
end process;
end arch;

Testbench:

library ieee;
use ieee.std_logic_1164.all;

entity tb_shift is
end tb_shift;

architecture tb of tb_shift is

    component shift
        port (clk : in std_logic;
              cl   : in std_logic;
              ld   : in std_logic;
              lr   : in std_logic;
              din : in std_logic_vector(15 downto 0);
              dout : out std_logic_vector(15 downto 0));
    end component;

    signal clk : std_logic;
    signal cl   : std_logic;
    signal ld   : std_logic;
    signal lr   : std_logic;
    signal din : std_logic_vector(15 downto 0);
    signal dout : std_logic_vector(15 downto 0);

    constant TbPeriod : time := 1000 ns;
    signal TbClock : std_logic := '0';
    signal TbSimEnded : std_logic := '0';

begin

    dut : shift
    port map (clk => clk,
              cl   => cl,
              ld   => ld,
              lr   => lr,
              din => din,
              dout => dout);

    -- Clock generation
    TbClock <= not TbClock after TbPeriod/2 when TbSimEnded /= '1' else '0';

    clk <= TbClock;

    stimuli : process
    begin
        cl <= '0';
        ld <= '0';
        lr <= '0';
        din <= "0000000000000000";

        -- Reset generation
        cl <= '1';
        wait for 100 ns;
        cl <= '0';
        wait for 100 ns;

        ld <= '1';
        din <= "1111111111111111";
        wait for 2 * TbPeriod;
      
        ld <= '0';
        lr <= '0';
        din <= "0000000000000000";
        wait for 5 * TbPeriod;

        lr <= '1';
        din <= "0000000000000000";
        wait for 5 * TbPeriod;

        -- Stop the clock and hence terminate the simulation
        TbSimEnded <= '1';
        wait;
    end process;

end tb;


Related Solutions

I am trying to write the code for an 8 bit adder in VHDL so that...
I am trying to write the code for an 8 bit adder in VHDL so that I can program it onto my Elbert V2 Spartan 3A FPGA Development Board, but I keep getting errors. Any ideas what I am doing wrong? library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity adder8bit is Port ( a : in STD_LOGIC_VECTOR(7 downto 0); b : in STD_LOGIC_VECTOR(7 downto 0); cin : in STD_LOGIC; o : out STD_LOGIC_VECTOR(7 downto 0); cout : out STD_LOGIC); end adder8bit; architecture Behavioral...
Write VHDL code (behavior model) to implement a 4-bit modulo-9 counter and simulate your VHDL code...
Write VHDL code (behavior model) to implement a 4-bit modulo-9 counter and simulate your VHDL code of 4-bit modulo-9 counter in ModelSim, and capture the screenshot of your simulated waveform. Assume clock period Tclk=100ns, initially, the counter is reset to Q3Q2Q1Q0=0000 you need to simulate a complete counting cycle plus one more additional clock period after it is reset to “0000” state.
How do I implement Image Processing using VHDL for FPGA? Please provide VHDL code
How do I implement Image Processing using VHDL for FPGA? Please provide VHDL code
Write VHDL code for the following: Use HEX-to-seven segment display converters to display the inputs and...
Write VHDL code for the following: Use HEX-to-seven segment display converters to display the inputs and results for a 4-bit adder. The inputs are unsigned 4-bit binary numbers. The outcome is a 4-bit binary adder with LED display. First you need to create a symbol for the HEX-to-seven segment display converter. Then implement a 4-bit adder using VHDL. Finally, connect three HEX-to-seven segment display converters to display input X, input Y, and sum S.
HI can I please know whats wrong in this 2to1 mux code in VHDL code also...
HI can I please know whats wrong in this 2to1 mux code in VHDL code also please type it out so theres no confusion thank you -- Code your design here library IEEE; use IEEE.std_logic_1164.all; -- entity declaration for testbench entity test mux2 is end test; --architecture Body declaration for 2to1 mux -- component declaration of source entity 2to1 mux component test mux2 is port ( sel : in std_logic ; --select input, A : in std_logic ; --data input...
Write a VHDL code to implement a Finite State Machine that with an 8 bit sequence...
Write a VHDL code to implement a Finite State Machine that with an 8 bit sequence input (can be any sequence, but lets say it is 11001000), determine how many states there are as well; so if the input sequence is correct it will show the number 1 in a 7 segment display, otherwise it will be 0 in the same 7 segment display. If the input sequence is incorrect, start from the beginning.
write the vhdl code to get the moore and mealy machine to detect the sequence 1101...
write the vhdl code to get the moore and mealy machine to detect the sequence 1101 (in c++)
Write MIPS assembly code for the following C code. for (i = 10; i < 30;...
Write MIPS assembly code for the following C code. for (i = 10; i < 30; i ++) { if ((ar[i] > b) || (ar[i] <= c)) ar[i] = 0; else ar[i] = a; }
How can I improve my code below to meet the requirements of this assignment with syntax...
How can I improve my code below to meet the requirements of this assignment with syntax add to my code to complete the assignment below: #include <iostream> #include <vector> using namespace std; class Inventory { private: int itemNumber; int quantity; double cost; double totalCost; public: Inventory() { itemNumber = 0; quantity = 0; cost = 0; totalCost = 0; } Inventory(int n, int q, double c) { itemNumber = n; quantity = q; cost = c; setTotalCost(); } void setItemNumber(int...
I need the vhdl code to display the binary number specified by an 8 input dip...
I need the vhdl code to display the binary number specified by an 8 input dip switch on a 7 segment display.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT