Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library ieee;
- use ieee.std_logic_1164.all;
- use ieee.numeric_std.all;
- Entity Mealy_SM IS Port
- (
- clk_input, rst_n, x_motion, x_LT, x_ET, x_GT, ext_out : IN std_logic;
- clk_en, UD_en, ext_en, error : OUT std_logic
- );
- END ENTITY;
- Architecture SM of Mealy_SM is
- TYPE STATE_NAMES IS (STILL, MOVING, ERROR_STATE); -- list all the STATE_NAMES values but use more meaningful names
- SIGNAL current_state, next_state : STATE_NAMES; -- signals of type STATE_NAMES
- signal input_signals : std_logic_vector(4 downto 0);
- BEGIN
- input_signals(4) <= x_motion;
- input_signals(3) <= x_LT;
- input_signals(2) <= x_ET;
- input_signals(1) <= x_GT;
- input_signals(0) <= ext_out;
- --------------------------------------------------------------------------------
- --State Machine:
- --------------------------------------------------------------------------------
- -- REGISTER_LOGIC PROCESS:
- Register_Section: PROCESS (clk_input, rst_n) -- this process synchronizes the activity to a clock
- BEGIN
- IF (rst_n = '0') THEN
- current_state <= STILL;
- ELSIF(rising_edge(clk_input)) THEN
- current_state <= next_State;
- END IF;
- END PROCESS;
- -- TRANSITION LOGIC PROCESS
- Transition_Section: PROCESS (input_signals, current_state)
- BEGIN
- CASE current_state IS
- WHEN STILL =>
- IF(input_signals = "0-0-0") THEN -- pb is pressed , not equal, not extended
- next_state <= MOVING;
- ELSIF(input_signals = "0-0-1") THEN -- pb is pressed, target is not equal, extended
- next_state <= ERROR_STATE;
- ELSE
- next_state <= STILL; -- stay in the same state otherwise
- END IF;
- WHEN MOVING =>
- IF(input_signals = "1-0-0") THEN -- pb is not pressed and less than or greater than, not extended
- next_state <= STILL;
- ELSIF(input_signals = "-0100") THEN -- don't care if pressed or not, value is equal, not extended
- next_state <= STILL;
- ELSE
- next_state <= MOVING;
- END IF;
- WHEN ERROR_STATE =>
- IF(input_signals = "----0") THEN -- the only way to exit the error state is when you toggle the extender OFF
- next_state <= STILL;
- ELSE
- next_state <= ERROR_STATE; -- otherwise stay
- END IF;
- WHEN OTHERS =>
- next_state <= STILL;
- END CASE;
- END PROCESS;
- -- DECODER SECTION PROCESS
- Decoder_Section: PROCESS (input_signals,current_state)
- BEGIN
- CASE current_state IS
- WHEN STILL =>
- IF(input_signals = "1-0-0") THEN -- if pb not pressed, and val is greater than or less than, extender is not out, do nothing
- clk_en <= '0';
- UD_en <= '-';
- ext_en <= '0';
- error <= '0';
- ELSIF(input_signals = "-0100") THEN -- don't care if pb is pressed or not, if current equals target, extender is not out, enable extender
- clk_en <= '0';
- UD_en <= '-';
- ext_en <= '1';
- error <= '0';
- ELSIF(input_signals = "10101") THEN-- if the pb is not pressed and current equals target, and extender is out, disable extender
- clk_en <= '0';
- UD_en <= '-';
- ext_en <= '0';
- error <= '0';
- ELSIF(input_signals = "01000") THEN -- if the push button pressed and extender is retracted, inputs less than
- clk_en <= '1'; -- enable clock and count up
- UD_en <= '1';
- ext_en <= '0';
- error <= '0';
- ELSIF(input_signals = "00010") THEN -- if the push button pressed and extender is retracted, inputs are greater than
- clk_en <= '1'; -- enable clock and count down
- UD_en <= '0';
- ext_en <= '0';
- error <= '0';
- END IF;
- WHEN MOVING =>
- IF(input_signals= "01000") THEN -- if the push button is pressed and the value is less than, not extended, enable clock, count up
- clk_en <= '1';
- UD_en <= '1';
- ext_en <= '0';
- error <= '0';
- ELsIF(input_signals= "000010") THEN -- if the push button is pressed and the value is greater than,and not extended, then enable clock, count down
- clk_en <= '1';
- UD_en <= '0';
- ext_en <= '0';
- error <= '0';
- END IF;
- WHEN ERROR_STATE =>
- IF(input_signals = "----1") THEN--once in the error state, input with the extender toggle on gets an error output
- clk_en <= '0';
- UD_en <= '-';
- ext_en <= '0';
- error <= '1';
- END IF;
- END CASE;
- END PROCESS;
- END ARCHITECTURE SM;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement