Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are thinking along the right basic lines, but there are various things not-quite-right with your state machine - as the other answers say - and these are easy to discover in simulation.</p> <p>For example</p> <pre><code> when READ_X =&gt; SPI_Tx_buf &lt;= query_x; -- Load in command y_data &lt;= "00000" &amp; SPI_Rx_buf(11 downto 1); SPI_send &lt;= '1'; SPI_action &lt;= READ_Y; </code></pre> <p>Now if SPI_Busy stays low for a second cycle, this will clearly not stay in state READ_X but transition directly to READ_Y which is probably not what you want.</p> <p>A more normal state machine would treat the states as outermost, and interpret the input signals differently for each state :</p> <pre><code> case SPI_Action is when READ_X =&gt; if SPI_Busy = '0' then -- Wait here if busy SPI_Tx_buf &lt;= query_x; -- Load in command y_data &lt;= "00000" &amp; SPI_Rx_buf(11 downto 1); SPI_send &lt;= '1'; SPI_action &lt;= READING_X; end if; when READING_X =&gt; if SPI_Busy = '1' then -- command accepted SPI_action &lt;= READ_Y; -- ready to send next one end if; when READ_Y =&gt; if SPI_Busy = '0' then -- Wait here if busy </code></pre> <p>You can see that this version treats the Busy signal as a handshake, and only progresses when Busy changes state. I am certain you can make your approach (IF outermost) work if you want, but you will have tofigure out how to apply the handshaking principle yourself.</p> <p>There is also no "Idle" state where neither X or Y is being read; this SM will read X and Y alternately as fast as it can. Commonly you would read them both, then return to Idle until some other Start signal commanded you to leave Idle and perform a fresh set of reads.</p> <p>You can possibly also make the state machine more robust with a "when others" clause. It's not a must, if you guarantee to cover all your defined states, but it can make maintenance easier. On the other hand, without such a clause, the compilers will let you know of any uncovered states, guarding against mistakes.</p> <p>There is a myth that a "when others" clause is essential and synthesis tools generate safer but less optimal state machines from a "when others" clause. However there are synthesis attributes or command line options to control how synth tools generate state machines.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload