+ Post New Thread
Results 1 to 7 of 7
  1. #1
    Member level 4
    Points: 1,414, Level: 8

    Join Date
    Dec 2011
    Posts
    77
    Helped
    0 / 0
    Points
    1,414
    Level
    8

    Initializing an input port and then change its value

    There is an up/down counter entity where the direction is first set to '1' to count up. Another entity can change the direction if a condition is met. So the test bench looks like

    signal c: std_logic := '0'; -- clock
    signal r: std_logic := '0'; -- reset
    signal d: std_logic := '1'; -- direction
    signal cou: integer range 0 to 7; -- count value
    ...
    u0: counter port map( c, r, d, cou ); -- in, in, in, out
    u1: reader port map( a, cou, c, d, z ); -- in, in, in, out, out

    As you can see the 'd' is initialized to '1'. So, I expect that the counter counts up. However, in the simulation the value of 'd' is U. Well it is correct that assignment is not good because the input 'd' port of the counter receives two wire (one from the initialization and the other from reader).
    The architecture of counter is

    Code:
    architecture behav of counter is	
    	signal cnt: integer range 0 to 7:= 0;
    begin
    	process( rst, clk )
    	begin
    		if (rst = '1') then
    			cnt <= 0;
    		elsif (clk'event and clk = '1') then
    			if dir = '1' then
    				cnt <= cnt + 1;
    			else
    				cnt <= cnt - 1;
    			end if;
    		end if;
    	end process;
    	z <= cnt;
    end;
    Any idea?

    •   Alt6th July 2017, 15:18

      advertising

        
       

  2. #2
    Advanced Member level 4
    Points: 4,901, Level: 16

    Join Date
    Apr 2016
    Posts
    1,034
    Helped
    184 / 184
    Points
    4,901
    Level
    16

    Re: Initializing an input port and then change its value

    why is d an output of the 'reader'? it is conflicting.

    if this up/down logic has to be part of the implemented hardware, using a constant to initialise it is a bad idea. make it a flop, add a reset.
    Really, I am not Sam.



  3. #3
    Member level 4
    Points: 1,414, Level: 8

    Join Date
    Dec 2011
    Posts
    77
    Helped
    0 / 0
    Points
    1,414
    Level
    8

    Re: Initializing an input port and then change its value

    why is d an output of the 'reader'? it is conflicting.
    Well as I said, upon a condition in reader entity, the direction will be set to down (0).



    •   Alt6th July 2017, 15:45

      advertising

        
       

  4. #4
    Advanced Member level 5
    Points: 34,876, Level: 45
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,390
    Helped
    1861 / 1861
    Points
    34,876
    Level
    45

    Re: Initializing an input port and then change its value

    If the signal "d" is connected to the ouput of a component, it will not matter what you initialised it to - it will take whatever the reader is driving, which appears to be 'U'.
    the initial value is just that - initial. The assignment from the component takes place in the 1st delta of simulation (0ns + 1delta).



  5. #5
    Advanced Member level 4
    Points: 4,901, Level: 16

    Join Date
    Apr 2016
    Posts
    1,034
    Helped
    184 / 184
    Points
    4,901
    Level
    16

    Re: Initializing an input port and then change its value

    Quote Originally Posted by mahmood.n View Post
    Well as I said, upon a condition in reader entity, the direction will be set to down (0).
    that's fine. but then it makes no sense to initialise it, ever. that's not RTL.
    Really, I am not Sam.



    •   Alt6th July 2017, 15:51

      advertising

        
       

  6. #6
    Member level 4
    Points: 1,414, Level: 8

    Join Date
    Dec 2011
    Posts
    77
    Helped
    0 / 0
    Points
    1,414
    Level
    8

    Re: Initializing an input port and then change its value

    So, I added a reset input in the reader which set the direction to 1 (up count). That direction output port is connected to the direction input port of the counter. So reader sends either 1 or 0 (down count upon a condition) to the counter.
    The reset signal in the test bench is initially 1 and the goes to 0 in the architecture of the testbench. Do you agree with that?



  7. #7
    Advanced Member level 5
    Points: 34,876, Level: 45
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,390
    Helped
    1861 / 1861
    Points
    34,876
    Level
    45

    Re: Initializing an input port and then change its value

    that would be pretty standard, if you have active high reset.



--[[ ]]--