-2

The logic gate in the RTL view was a latch previously. As an answer suggests, I assign each input with outputs. And the latch turns into a logic gate. I don't know whether it is a correct way to solve the problem. There is also an adder connected to the counter. I want to eliminate the adder and the logic gate. (??? T^T). What should I modify?


library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use IEEE.std_logic_unsigned.all;

entity mux8x1 is port(  input: in std_logic_vector( 7 downto 0);    clk: in std_logic;  --s: buffer std_logic;  --rst : in std_logic;   --d: buffer std_logic;  q: out std_logic_vector (7 downto 0)    --o: buffer std_logic_vector (3 downto 0)   ); end mux8x1;
                 architecture mux of mux8x1 is signal count : std_logic_vector(3 downto 0);
--signal count_state: std_logic_vector (3 downto 0); signal serial: std_logic;
--shiftregister

signal internal: std_logic_vector (7 downto 0); signal d: std_logic;

    begin   --【The counter】     process(clk)    --variable internal: std_logic_vector (7 downto 0);     --variable d: std_logic;    --variable initial: std_logic_vector (7 downto 0) :="01010101";
        begin
    
          
          if (clk'event and clk = '1') then
    count <= count + 1;
          end if;
         end process;
         --count_state <= count;    --To divide the counter
            --section1 for the counter          --8x1 multiplxer combined with counter

        process(count,input,clk)    --variable serialin: std_logic;     begin   --serialin:='0';      if (count(3) <='0') then          case  count(2 downto 0) is --8 possible states for PToS
                when "000"=> serial <=input(0);
                when "001"=> serial <=input(1);
                when "010"=> serial <=input(2);
                when "011"=> serial <=input(3);
                when "100"=> serial <=input(4);
                when "101"=> serial <=input(5);
                when "110"=> serial <=input(6);
                when "111"=> serial <=input(7);
                when others => serial <= '0';           end case;       else            serial <='0';
       end if;      --serial<=serialin;     end process;

--      end if; end mux;

The following is the RTL viewer. enter image description here

  • 1
    First, do you really need variables? – Fra93 Nov 22 '22 at 13:06
  • Should I change to signals? I am not clear about it but variables can be modified immediately. – RoseLegend Nov 22 '22 at 13:31
  • 1
    can you indent the code a little better? It's super confusing. However it seems that serial is not in a clocked process, so how can you expect to be a reg? – Fra93 Nov 22 '22 at 13:35
  • 2
    If you want a register, then all code that needs to be registeres needs to be inside a `if rising_edge(clk) then` branch. – Tricky Nov 22 '22 at 13:36
  • as a rule of thumb, never use variables if not for static compile time calculations, use signals if you want things to be assigned to signals, it's free, the synthetizer will know how to optimize thing anyway. – Fra93 Nov 22 '22 at 13:36
  • Also many other issues. `elsif (count_state(3)<='1') then` is true when `count_state(3)` is '0', 'X' or 'U'. `if (count_state(3) <='0') then` is only true when `count_state(3)` is 'U' or 'X'. Please review your code. – Tricky Nov 22 '22 at 13:37
  • IEEE Std 1076.6-2004 RTL Synthesis (withdrawn) 6.2.1.1 Level-sensitive storage from process with sensitivity list "A level-sensitive storage element shall be modeled for a signal (or variable) when all the following apply: a) The signal (or variable) has an explicit assignment. b) The signal (or variable) does not have an execution path with as a condition. c) There are executions of the process that do not execute an explicit assignment (via an assignment statement) to the signal (or variable)." Identity assignments don't count. Hence the latches. – user16145658 Nov 22 '22 at 14:48
  • Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange network, you've granted a non-revocable right, under the [CC BY-SA 4.0 license](https://creativecommons.org/licenses/by-sa/4.0/), for Stack Exchange to distribute that content (i.e. regardless of your future choices). By Stack Exchange policy, the non-vandalized version of the post is the one which is distributed. Thus, any vandalism will be reverted. If you want to know more about deleting a post please see: [How does deleting work?](https://meta.stackexchange.com/q/5221) – Adriaan Nov 24 '22 at 08:09

1 Answers1

1

The reason that you get a latch, is because you do not apply a signal value to "serial" in any case when the process is started: Then "serial" keeps its old value which leads to a latch at synthesis, where this kept value is taken from. So it is a good idea to assign a default value to any signal you assign values to in a process. When you want to get a register (triggered by a clock edge) you must use a process which is only sensitive to a clock signal (and a reset signal) and uses as a condition "rising_edge(clk)". Of course you do not need a default assignment here.

  • Sorry. Could you tell me more about how to modify the latch? T^T . Is that correct that using case-when statements means a latch? – RoseLegend Nov 22 '22 at 16:38
  • Getting a latch has nothing to do about your control statements (as case, when, if). Getting a latch is always caused, when you have a process which does not use rising_edge() and does not assign a value to a signal in all cases. – Matthias Schweikart Nov 22 '22 at 17:25
  • Thanks! I have modified the latch. But it turn into a logic gate. I am trying to eliminate it. – RoseLegend Nov 22 '22 at 18:09
  • I have edited the question. Could you give me more advice (^▽^)コ – RoseLegend Nov 22 '22 at 18:29
  • I am not sure what your question is. Are you asking how to eliminate the adder?! But there is a adder in your VHDL code. Please look into the guidelines and create an exact question. – Matthias Schweikart Nov 23 '22 at 07:32
  • Thank you! I have reviewed your answer and I have solved the problem. – RoseLegend Nov 23 '22 at 11:09