title: How to run VHDL Components in a sequential fashion?
body: <p>I'm making a simple TicTacToe game (computer vs user) in VHDL and the code is almost finished, but there is something that I can't figure out how to handle it. </p>
  
  <p>Overall there are three main modules, computer move based on the current grid, grid status that takes in which cell to be filled either by computer or by user, a main module that retrieves the grid from the grid module and handle these components as well as the user move.</p>
  
  <p>So, in this main module, I have a Component that sends the move (either by computer or user) to the grid module and in return updates its current grid Signal in this main module, then the second component (computer move) takes in the grid status (which is the Signal) and make a move based on that. Therefore, this also needs to get sent to the grid module for it to be updated. However, this doesn't really work in action when it comes to functioning in this order. </p>
  
  <p>In a nutshell, my question is, how may I go about updating this main Signal in the order of the Components execution or more generally, how may I have a Signal be updated by a Component that needs to become the input of another Component respectively?</p>
  
  <p>Thanks for your help. </p>
  
  <p><strong>Edit</strong></p>
  
  <p>Here is part of the main module code</p>
  
  <pre class="lang-vhdl prettyprint-override"><code>ENTITY currentstate IS
    PORT (to_occupy_cell : IN TO_SELECT;   --user choice
          start : IN STD_LOGIC;     --initialize the grid
          by_user : IN STD_LOGIC;   --how to fill the grid (X or O)
          difficulty : IN STD_LOGIC;     --difficulty
          winner_state : OUT INTEGER RANGE 0 to 2;     --who is the winner? 
          currentgrid : OUT GRID (1 TO 3, 1 TO 3));  --outputs status of the grid after compmove to be displayed
  END currentstate;
  ---------------------------------
  ARCHITECTURE statearch OF currentstate IS
    SIGNAL comp_occupy : TO_SELECT;
    SIGNAL grid_status : GRID (1 TO 3, 1 TO 3);
  
    COMPONENT grid IS   -------saves the grid status
      PORT (to_occupy_cell : IN TO_SELECT; start : IN STD_LOGIC; by_user : IN STD_LOGIC; currentgrid : OUT GRID (1 TO 3, 1 TO 3));
    END COMPONENT;
  
    COMPONENT compmove IS
      PORT (current : IN GRID (1 TO 3, 1 TO 3); dif : IN STD_LOGIC; compsel : OUT TO_SELECT);
    END COMPONENT;
  BEGIN
  
    U1: grid PORT MAP (to_occupy_cell, start, by_user ,grid_status);
  
    U2: compmove PORT MAP (grid_status, difficulty, comp_occupy); 
  </code></pre>
  
  <p>Here is the grid module</p>
  
  <pre class="lang-vhdl prettyprint-override"><code>ENTITY grid IS
    PORT (to_occupy_cell : IN TO_SELECT;   --user choice
          start : IN STD_LOGIC;     --initialize the grid
          by_user : IN STD_LOGIC;   --how to fill the grid ( X or O)
          currentgrid : OUT GRID (1 TO 3, 1 TO 3));  --outputs status of the grid after compmove to be displayed
  END grid;
  ---------------------------------
  ARCHITECTURE gridstatus OF grid IS
  BEGIN
      PROCESS (to_occupy_cell, start)
      VARIABLE temp_grid : GRID (1 TO 3, 1 TO 3);
    BEGIN
      IF (start = '1' AND start'EVENT) THEN
        temp_grid := (others =&gt; (others=&gt;0));
      END IF;
      IF (by_user = '1') THEN 
        temp_grid(to_occupy_cell(0), to_occupy_cell(1)) := 1; 
      ELSIF (by_user = '0') THEN 
        temp_grid(to_occupy_cell(0), to_occupy_cell(1)) := 2;
      END IF;
  
      currentgrid &lt;= temp_grid;
    END PROCESS;
  END gridstatus;
  </code></pre>
  
  <p>And entity of the computer move module</p>
  
  <pre class="lang-vhdl prettyprint-override"><code>---------------------------------
  ENTITY compmove IS
    PORT(current : IN GRID (1 TO 3, 1 TO 3);  --takes in the grid status
         dif : IN STD_LOGIC;     --difficulty
         compsel : OUT TO_SELECT);
  END compmove;
  ---------------------------------
  </code></pre>
  
  <p>So, what happens is that, the Signal grid_status should automatically be updated first by the user move and then when it is updated it gets piped into the <code>compmove</code> module for the computer to decide which cell to fill. Afterwards, the grid_status should get updated again. Also, '1' is the user move, '2' is the computer move in the grid.</p>
  
  <p>Hope this clears what I'm after.</p>
  
  <p>(image referenced from <a href="https://i.imgur.com/ZWBMazJ.jpg" rel="nofollow noreferrer" title="link">link</a> added)</p>
  
  <p><img src="https://i.stack.imgur.com/53bOX.jpg" alt="sequential components"></p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>Thanks to the help of David and fru1tbat I could actually get it to work! Turns out I had missed making compmove sensitive to grid_status. 
  However, now it is only working for the first round but not the second round if the user selects another cell. Below are the updated codes:</p>
  
  <p>Main module (currentstate)</p>
  
  <pre><code>ENTITY currentstate IS
    PORT (to_occupy_cell : IN TO_SELECT;   --user choice
          start : IN STD_LOGIC;     --initialize the grid
          by_user : IN STD_LOGIC;   --how to fill the grid ( X or O)
          difficulty : IN STD_LOGIC;     --difficulty
          winner_state : OUT INTEGER RANGE 0 to 2);     --who is the winner? 
  END currentstate;
  ---------------------------------
  ARCHITECTURE statearch OF currentstate IS
    SIGNAL occupy_to_grid : TO_SELECT;
    SIGNAL comp_occupy : TO_SELECT;
    SIGNAL user_move : STD_LOGIC;
    SIGNAL grid_status : GRID (1 TO 3, 1 TO 3);
  
    COMPONENT grid_ IS   -------saves the grid status
      PORT (to_occupy_cell : IN TO_SELECT; start : IN STD_LOGIC; by_user : IN STD_LOGIC; currentgrid : OUT GRID (1 TO 3, 1 TO 3));
    END COMPONENT;
  
    COMPONENT compmove IS
      PORT (current : IN GRID (1 TO 3, 1 TO 3); by_user : IN STD_LOGIC; dif : IN STD_LOGIC; compsel : OUT TO_SELECT);
    END COMPONENT;
  
  BEGIN
  
    U1: grid_ PORT MAP (occupy_to_grid, start, user_move,grid_status);
  
    U2: compmove PORT MAP (grid_status, user_move, difficulty, comp_occupy); 
  
    PROCESS(comp_occupy, to_occupy_cell)
    BEGIN
      IF to_occupy_cell'EVENT THEN
        occupy_to_grid &lt;= to_occupy_cell;
        user_move &lt;= by_user;
      END IF;
      IF comp_occupy'EVENT THEN
        occupy_to_grid &lt;= comp_occupy;
        user_move &lt;= '0';
      END IF;
    END PROCESS;
  END statearch;
  </code></pre>
  
  <p>The grid_ module</p>
  
  <pre><code>ENTITY grid_ IS
    PORT (to_occupy_cell : IN TO_SELECT;   --user choice
          start : IN STD_LOGIC;     --initialize the grid
          by_user : IN STD_LOGIC;   --how to fill the grid ( X or O)
          currentgrid : OUT GRID (1 TO 3, 1 TO 3));  --outputs status of the grid after compmove to be displayed
  END grid_;
  ---------------------------------
  ARCHITECTURE gridstatus OF grid_ IS
  BEGIN
      PROCESS (to_occupy_cell, start)
      VARIABLE temp_grid : GRID (1 TO 3, 1 TO 3);
    BEGIN
      IF (start = '1' AND start'EVENT) THEN
        temp_grid := (others =&gt; (others=&gt;0));
      END IF;
      IF (by_user = '1') THEN 
        temp_grid(to_occupy_cell(0), to_occupy_cell(1)) := 1; 
      ELSIF (by_user = '0') THEN 
        temp_grid(to_occupy_cell(0), to_occupy_cell(1)) := 2;
      END IF;
  
      currentgrid &lt;= temp_grid;
    END PROCESS;
  END gridstatus;
  </code></pre>
  
  <p>Initial part of compmove</p>
  
  <pre><code>ENTITY compmove IS
    PORT(current : IN GRID (1 TO 3, 1 TO 3);  --takes in the grid status
         by_user : IN STD_LOGIC;   --to only gets triggered when user selects a cell
         dif : IN STD_LOGIC;     --difficulty
         compsel : OUT TO_SELECT);
  END compmove;
  ---------------------------------
  ARCHITECTURE comparch OF compmove IS  
  BEGIN
  
    PROCESS(by_user, current)
      VARIABLE tempsel : TO_SELECT := (0,0);
      VARIABLE occ_count : INTEGER := 0;
      VARIABLE unocc : INTEGER := 0;
    BEGIN
      IF (dif = '0' AND current'EVENT AND by_user = '1') THEN
        --------------bunch of codes here
  </code></pre>
  
  <p>It is almost there, I believe just a small change perhaps in the sensitivity list of compmove would do the trick for it to retrieve the updated grid_status correspondingly, because currently after the first round it doesn't take in the updated grid_status and comp_occupy remains unchanged!</p>