TSTE12

Handin exercises 2024 part 2 Solutions


241001 10:35 Coding question C has a small change in the first example, it should increase the count value to "011"

Solve the handin tasks individually! No cooperation with anyone else!

Submit all Theory question answers in one submission, using the comment field of the submission system. Indicate answers using one line per question, indicating which question (A-D) and which of the multiple choices (1-4) that is your answer to each question.

To pass on the handin exercises it is required to reach 9 correct exercises of 12 on each of theory and code exercises. The handins are divided into 3 sets of questions with 4 points of theori and 4 points of coding on each. Read closely the instructions on the handin main page!

Note the time schedule!
Handin exercises must be in place at latest by the deadline on the given date. Use the commands "module load courses/TSTE12 ; TSTE12handin" to open a shell window to work from.

Handin part 2 is due by Monday 7 October 2024 at 23.30!

The results will be available in the lisam course room.

Note:
   Read the instructions at the main page!!
   Ask if any difficulties or uncertainty!!

Good luck!


Teori A

What is WRONG regarding signals in VHDL? Failed to give a correct answer, all get a free point!



Theory B

How many different architectures can be declared for an entity? 4) no defined upper limit



Theory C

Which one is not a predefined array attribute in the VHDL language? 1) 'first



Theory D

What is WRONG regarding FPGA hardware? 3) FPGA:s contain a microprocessor that is running the VHDL code



Exercise Code A

   source file: INL2_KA.vhdl   Name of the source file.
        Entity: INL2_KA        Name of the entity
  architecture: KA             Name of the architecture
        Inputs: D              data in,  bit
                R              data in,  bit
                C              data in,  bit
       Outputs: Q              data out, bit_vector(6 downto 2) 


     Behaviour: Create a negative edge trigged resettable shift register.
                When there is a falling edge on C and R='1' then set Q to
                "00000". If there is a falling edge on C and R='0' then
                left shift Q one step and put input from D into
                rightmost position in Q.

       Example: Q="10101", R='1', falling edge on C => Q="0000"
                Q="00100", R='0', D='1', falling edge on C => Q="01001"

Solution
========

entity INL2_KA is
  port (
    D : in bit;
    R : in bit;
    C : in bit;
    Q : out bit_vector(6 downto 2));
end entity;

architecture KA of INL2_KA is
begin

  process(C)
    variable shiftreg : bit_vector(6 downto 2);
  begin
    if C'event and (C='0') then
      if R='1' then
        shiftreg := (others => '0');
      else
        shiftreg := shiftreg(5 downto 2) & D;
      end if;
      Q <= shiftreg;
    end if;
  end process;

end architecture;

        



Exercise Code B

   source file: INL2_KB.vhdl   Name of the source file
        Entity: INL2_KB        Name of the entity
  architecture: KB             Name of the architecture
        Inputs: D              data in, bit_vector(2 to 4)
                C              data in, bit
                R              data in, bit
       Outputs: Q              data out, bit_vector(2 to 4)

      Behavour: Create a 3-bit positive edge triggered register
                with asynchronous reset. If R='1' then set Q to "000".
                If there is a rising edge on C and R='0' then copy
                the value on D to Q.
   
       Example: R='1' => Q="000"
                R='0', D="011", rising edge on C => Q="011"

Solution
========

entity INL2_KB is
  port (
    D : in bit_vector(2 to 4);
    C : in bit;
    R : in bit;
    Q : out bit_vector(2 to 4));
end entity;

architecture KB of INL2_KB is
begin
  
  process(C,R)
  begin
    if R='1' then
      Q <= "000";
    elsif C'event and C='1' then
      Q <= D;
    end if;
  end process;

end architecture;
  
      
    


Exercise Code C

   source file: INL2_KC.vhdl   Name of the source file
        Entity: INL2_KC        Name of the entity
  architecture: KC             Name of the architecture
        Inputs: C              data in, bit
                R              data in, bit
       Outputs: Q              data out, std_logic_vector(3 downto 1)

     Behaviour: Create a positive edge triggered 3 bit counter with
                synchronous reset. If rising edge on C and R='1' then
                Q="000". If a rising edge on C, and R='0' then
                increment Q by 1. Incrementing "111" generates "000".

       Example: R='0',Q="010",rising edge on C => Q="010"Q="011"
                R='1', rising edge on C => Q="000"
                R='0',Q="110",rising edge on C => Q="111"

Solution
========

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity INL2_KC is
  port (
    C : in bit;
    R : in bit;
    Q : out std_logic_vector(3 downto 1));
end entity;

architecture KC of INL2_KC is
begin
  
  process(C)
    variable count : unsigned(3 downto 1);
  begin
    if C'event and C='1' then
      if R='1' then
        count := "000";
      else
        count := count+1;
      end if;
      Q <= std_logic_vector(count);
    end if;
  end process;

end architecture;
      


Exercise Code D

   source file: INL2_KD.vhdl   Name of the source file
        Entity: INL2_KD        Name of the entity
  architecture: KD             Name of the architecture
        Inputs: A              data in,  std_logic
                B              data in,  std_logic
       Outputs: Y              data out, std_logic
   

      Behavour: Create a 2-input OR gate where the output strength
                (use of 0/1, L/H or X) is based on the input strength.
                If both A and B have strong values ('0' or '1') then
                output a '1' or '0' that match an or function.
                If one or more inputs have a 'L' or 'H' and the other
                input has a value of '0', '1', 'L', or 'H' then output
                a 'L' or 'H', where 'L' is seen as a logic 0, and 'H'
                is seen as a logic 1.
                If any of the inputs are not '0', '1', 'L' or 'H' then
                output 'X'.
   
       Example: A='1', B='0' => Y='1'
                A='U', B='1' => Y='X'
                A='L', B='0' => Y='L'

Solution
========

library ieee;
use ieee.std_logic_1164.all;

entity INL2_KD is
  port (
    A : in std_logic;
    B : in std_logic;
    Y : out std_logic);
end entity;

architecture KD of INL2_KD is
  signal inputs : std_logic_vector(1 to 2);
begin

  inputs <= A & B;
  with inputs select
    Y <= '0' when "00",
         '1' when "01" | "10" | "11",
         'L' when "0L" | "L0" | "LL",
         'H' when "0H" | "L1" | "LH" |
                  "1L" | "H0" | "HL" |
                  "1H" | "H1" | "HH",
         'X' when others;

end architecture;