A Moore machine is a simple way to design a system that changes states based on inputs and gives outputs based only on its current state.
Moore machine implementation in VHDL
library ieee; use ieee.std_logic_1164.all; entity moore_machine is port( clk : in std_logic; reset : in std_logic; input_signal : in std_logic; output_signal : out std_logic ); end moore_machine; architecture behavioral of moore_machine is type state_type is (S0, S1, S2); signal current_state, next_state : state_type; begin process(clk, reset) begin if reset = '1' then current_state <= S0; elsif rising_edge(clk) then current_state <= next_state; end if; end process; process(current_state, input_signal) begin case current_state is when S0 => if input_signal = '1' then next_state <= S1; else next_state <= S0; end if; when S1 => if input_signal = '1' then next_state <= S2; else next_state <= S0; end if; when S2 => next_state <= S0; end case; end process; process(current_state) begin case current_state is when S0 => output_signal <= '0'; when S1 => output_signal <= '1'; when S2 => output_signal <= '0'; end case; end process; end behavioral;
The Moore machine output depends only on the current_state, not on inputs.
Use separate processes for state update, next state logic, and output logic for clarity.
type state_type is (IDLE, WORK, DONE); signal current_state, next_state : state_type;
process(clk, reset) begin if reset = '1' then current_state <= IDLE; elsif rising_edge(clk) then current_state <= next_state; end if; end process;
process(current_state, input_signal) begin case current_state is when IDLE => if input_signal = '1' then next_state <= WORK; else next_state <= IDLE; end if; when WORK => next_state <= DONE; when DONE => next_state <= IDLE; end case; end process;
process(current_state) begin case current_state is when IDLE => output_signal <= '0'; when WORK => output_signal <= '1'; when DONE => output_signal <= '0'; end case; end process;
This program implements a Moore machine with three states. It changes states on clock edges and outputs depend only on the current state. The output is '1' only in state S1.
library ieee; use ieee.std_logic_1164.all; entity moore_machine is port( clk : in std_logic; reset : in std_logic; input_signal : in std_logic; output_signal : out std_logic ); end moore_machine; architecture behavioral of moore_machine is type state_type is (S0, S1, S2); signal current_state, next_state : state_type; begin process(clk, reset) begin if reset = '1' then current_state <= S0; elsif rising_edge(clk) then current_state <= next_state; end if; end process; process(current_state, input_signal) begin case current_state is when S0 => if input_signal = '1' then next_state <= S1; else next_state <= S0; end if; when S1 => if input_signal = '1' then next_state <= S2; else next_state <= S0; end if; when S2 => next_state <= S0; end case; end process; process(current_state) begin case current_state is when S0 => output_signal <= '0'; when S1 => output_signal <= '1'; when S2 => output_signal <= '0'; end case; end process; end behavioral;
Remember to reset the machine to a known state before starting.
Moore machines have outputs that change only on state changes, making timing easier to manage.
Use meaningful state names to keep your code clear.
A Moore machine's output depends only on its current state.
Use separate processes for state update, next state logic, and output logic.
Reset your machine to a known state to avoid unpredictable behavior.
Practice
Solution
Step 1: Understand Moore machine output behavior
Moore machine outputs depend solely on the current state, not on inputs directly.Step 2: Compare options with Moore machine definition
Only 'Output depends only on the current state' matches Moore machine behavior.Final Answer:
Output depends only on the current state -> Option AQuick Check:
Moore output = current state only [OK]
- Confusing Moore with Mealy machine output
- Thinking output changes immediately with input
- Assuming output depends on input signals
Solution
Step 1: Identify state update mechanism in Moore machine
The current state updates synchronously on clock edges, typically rising edge.Step 2: Match process type to state update
Only a clocked process triggered on rising clock edge updates state correctly.Final Answer:
Clocked process triggered on rising edge of clock -> Option CQuick Check:
State update = clocked process [OK]
- Using combinational process for state update
- Ignoring clock in state transition
- Confusing output process with state update
process(current_state)
begin
case current_state is
when S0 => output_signal <= '0';
when S1 => output_signal <= '1';
when others => output_signal <= '0';
end case;
end process;What is the output when current_state = S1?Solution
Step 1: Analyze the case statement for current_state = S1
When current_state is S1, output_signal is assigned '1'.Step 2: Confirm output assignment
The process explicitly sets output_signal to '1' for S1 state.Final Answer:
'1' -> Option BQuick Check:
State S1 output = '1' [OK]
- Assuming output is '0' for all states
- Confusing 'others' case with S1
- Missing output assignment in process
process(clk)
begin
if clk = '1' then
current_state <= next_state;
end if;
end process;Solution
Step 1: Check clock condition in process
The process checks if clk = '1' but does not detect clock edge (rising_edge(clk)).Step 2: Understand importance of edge detection
Without edge detection, state updates continuously when clk is high, causing incorrect behavior.Final Answer:
Missing edge detection on clock signal -> Option AQuick Check:
Use rising_edge(clk) for proper clock sync [OK]
- Using clk = '1' instead of rising_edge(clk)
- Ignoring reset signal importance
- Leaving sensitivity list empty
Solution
Step 1: Recall Moore machine output rule
Moore machine output depends only on current state, not inputs directly.Step 2: Determine correct output assignment
Output must be assigned in a process sensitive to current state, not inputs or next state logic.Final Answer:
Output assigned in state process based only on current state -> Option DQuick Check:
Moore output = function of current state only [OK]
- Assigning output from inputs directly
- Using next state logic for output
- Assigning output asynchronously
Ready to prove it?
Pass the test and this pattern moves unknown
