librAry lpm; library IEEE; use lpm.lpm_components.all; use ieee.std_logic_unsigned.all; use IEEE.std_logic_1164.all; use ieee.std_logic_arith.all; entity fsm is generic ( --====================== generic pwm ================================= DC: time :=17 ms; clock_period: time := 20 ns; max_pulse: time := 1 ms; min_pulse: time := 2 ms; neutral_pulse: time := 1.5 ms ); port ( --====================== fsm ports =========================================== System_Clk_50MHz : in std_logic; System_N_Reset : in std_logic; seven_seg1 : out std_logic_vector(6 downto 0); seven_seg2 : out std_logic_vector(6 downto 0); -- FSM_enable_led : out std_logic; -- FSM_init_led : out std_logic; -- FSM_type_led : out std_logic; -- FSM_distance_value_led : out std_logic; -- FSM_stop_led : out std_logic; -- FSM_angle_value_led : out std_logic; --====================== communication ports =========================================== UART_baud_sel : in std_logic_vector(2 downto 0); UART_rx : in std_logic; UART_tx : out std_logic; led_sec : out std_logic; UART_rxerr_led : out std_logic; UART_txbusy : out std_logic; UART_rx_done : buffer std_logic; UART_dout : buffer std_logic_vector(7 downto 0); UART_ready_tx : in std_logic; --====================== motion encoder ports =========================================== M_E_done : out std_logic; M_E_DataIn : in std_logic; --====================== steer encoder ports =========================================== S_E_done : out std_logic_vector (2 downto 0); S_E_DataIn : in std_logic_vector (1 downto 0); --====================== motion pwm ports =========================================== M_P_Pwm : out std_logic; --====================== steer pwm ports =========================================== S_P_Pwm : out std_logic ); attribute altera_chip_pin_lc : string; attribute altera_chip_pin_lc of System_Clk_50MHz : signal is "@n2"; -- 50 MHZ clock attribute altera_chip_pin_lc of System_N_Reset : signal is "@g26"; -- pushb 0 attribute altera_chip_pin_lc of seven_seg1 : signal is "@V13, @V14, @AE11, @AD11, @AC12, @AB12, @AF10"; attribute altera_chip_pin_lc of seven_seg2 : signal is "@AB24, @AA23, @AA24, @Y22, @W21, @V21, @V20"; -- attribute altera_chip_pin_lc of seven_seg3 : signal is "@Y24, @AB25, @AB26, @AC26, @AC25, @V22, @AB23"; -- attribute altera_chip_pin_lc of seven_seg4 : signal is "@W24, @U22, @Y25, @Y26, @AA26, @AA25, @Y23"; -- attribute altera_chip_pin_lc of seven_seg5 : signal is "@T3, @R6, @R7, @T4, @U2, @U1, @U9"; -- -- attribute altera_chip_pin_lc of FSM_enable_led : signal is "@Y18"; --ledg7 -- attribute altera_chip_pin_lc of FSM_init_led : signal is "@AA20"; --ledg6 -- attribute altera_chip_pin_lc of FSM_type_led : signal is "@U17"; --ledg5 -- attribute altera_chip_pin_lc of FSM_distance_value_led : signal is "@U18"; --ledg4 -- attribute altera_chip_pin_lc of FSM_angle_value_led : signal is "@AC22"; --ledr 3 -- attribute altera_chip_pin_lc of FSM_stop_led : signal is "@V18"; --ledg3 --====================== pin assignment uart --========================= attribute altera_chip_pin_lc of UART_baud_sel : signal is "@p25, @n26, @n25"; -- sw2 sw1 sw0 attribute altera_chip_pin_lc of UART_rx : signal is "@d25"; -- io0 attribute altera_chip_pin_lc of UART_tx : signal is "@G23"; -- io1 attribute altera_chip_pin_lc of led_sec : signal is "@y12"; --ledg8 attribute altera_chip_pin_lc of UART_rxerr_led : signal is "@AD12"; --ledr17 attribute altera_chip_pin_lc of UART_dout : signal is "@AE12, @AE13, @AF13, @AE15, @AD15, @AC14, @AA13, @Y13"; -- ledr (16 - 9) attribute altera_chip_pin_lc of UART_txbusy : signal is "@AA14"; --ledr8 attribute altera_chip_pin_lc of UART_rx_done : signal is "@AE22"; --ledg0 attribute altera_chip_pin_lc of UART_ready_tx : signal is "@AF22"; --ledg1 --====================== pin assignment distance encoder --========================= attribute altera_chip_pin_lc of M_E_done : signal is "@W19"; --ledg2 attribute altera_chip_pin_lc of M_E_DataIn : signal is "@E26"; --io2 --====================== pin assignment pwm --========================= attribute altera_chip_pin_lc of M_P_Pwm : signal is "@E25"; -- io3 attribute altera_chip_pin_lc of S_P_Pwm : signal is "@J22"; -- io1 --====================== pin assignment angle encoder --========================= attribute altera_chip_pin_lc of S_E_done : signal is "@AB21,@AF23,@AE23 "; -- ledr 2 - 0 attribute altera_chip_pin_lc of S_E_DataIn : signal is "@F24, @J21"; -- io12 io10 end entity fsm; architecture arc_fsm of fsm is component Steer_Pwm is generic ( DC: time:=17 ms; -- changeable clock_period: time:=20 ns; -- changeable max_pulse: time:= 1 ms; -- changeable min_pulse: time:= 2 ms; -- changeable neutral_pulse: time:= 1.5 ms -- changeable ); port ( Rst : In std_logic; -- joined Rst to the FSM system Clk : In std_logic; -- joined clock to the FSM system Enable : in std_logic; -- Enable Steer motor Pwm : Out std_logic; -- PWM pulse pulse_length : in integer ); end component Steer_Pwm; component Motion_Pwm is generic ( DC: time:=17 ms; -- changeable clock_period: time:=20 ns; -- changeable max_pulse: time:= 1 ms; -- changeable min_pulse: time:= 2 ms; -- changeable neutral_pulse: time:= 1.5 ms -- changeable ); port ( Rst : In std_logic; Clk : In std_logic; Enable : in std_logic; Pwm : Out std_logic; pulse_length : in integer ); end component Motion_Pwm; constant duty_cycle : integer:= DC/clock_period; --850000 number of cycles for PWM control pulse needed constant min_cycle : integer:= min_pulse/clock_period; --50000 number of cycles for min PWM control pulse needed constant max_cycle : integer:= max_pulse/clock_period; --100000 number of cycles for max PWM control pulse needed constant neutral_cycle : integer:= neutral_pulse/clock_period; --75000 number of cycles for neutral PWM control pulse needed component Steer_Encoder is port ( done: out std_logic_vector (2 downto 0); Rst: in std_logic; Enable: in std_logic; Clk: in std_logic; DataIn: in std_logic_vector (1 downto 0); angle: in integer; slot_number: in integer; spare: out integer; turns_number: out integer; res: in integer; spare_flag: in std_logic; turn_flag: in std_logic; turn_pulse: in integer ); end component Steer_Encoder; component Motion_Encoder is port ( done: out std_logic; Rst: in std_logic; Enable: in std_logic; Clk: in std_logic; DataIn: in std_logic; distance: in integer; slot_number: in integer; wheel_radius: in integer ); end component Motion_Encoder; component Communication is generic ( ndbits : natural := 8); port ( Clk : in std_logic; Rst : in std_logic; baud_sel : in std_logic_vector(2 downto 0); rx : in std_logic; tx : out std_logic; led_sec : out std_logic; rxerr_led : out std_logic; txbusy : out std_logic; rx_done : out std_logic; dout : out std_logic_vector(7 downto 0); ready_tx : in std_logic; din : in std_logic_vector(7 downto 0) ); end component Communication; --====================== Fsm signals ============================== constant bit_low: std_logic := '0'; constant bit_high: std_logic := '1'; type motin_state_type is (idle_to_enable_st,enable_st,idle_to_initialize_st,initialize_st,idle_to_command_st,command_type_st,idle_to_distance_value_st,distance_value_st, idle_to_angle_value_st,angle_value_st,initialize_turn_st, turn_st,set_turn_angle_st,stright_heading_st,finish_turn_st,execute_st,stop_st,wait_st); signal curr_st : motin_state_type; signal S_FSM_slot_number : integer; signal S_FSM_wheel_radius : integer; signal max_counter : std_logic_vector (27 downto 0); -- ===== signals related to pwm components ====================== signal S_FSM_S_P_pulse_length : integer; signal S_FSM_M_P_pulse_length : integer; signal S_P_En : std_logic; signal M_P_En : std_logic; signal S_FSM_M_P_En : std_logic; signal S_FSM_S_P_En : std_logic; signal S_FSM_M_P_CEn : std_logic; signal S_FSM_S_P_CEn : std_logic; -- ===== signals related to angle state ====================== signal S_FSM_rt_flag : std_logic; signal S_FSM_lt_flag : std_logic; signal S_FSM_turn_flag : std_logic; signal S_FSM_spare_flag : std_logic; --====================== communication related signals ============================== signal S_FSM_dout_reg : std_logic_vector (7 downto 0); signal S_Uart_rx_done : std_logic; signal S_FSM_rx_done : std_logic_vector (2 downto 0); --====================== motion encoder related signals ============================== signal S_FSM_distance : integer; signal M_E_En : std_logic; signal S_FSM_M_E_En : std_logic; signal S_FSM_M_E_CEn : std_logic; signal S_M_E_done : std_logic; --====================== steer encoder related signals ============================== signal S_E_En : std_logic; signal S_FSM_S_E_En : std_logic; signal S_FSM_S_E_CEn : std_logic; signal S_FSM_angle : integer; signal S_FSM_spare_angle : integer; signal S_FSM_res : integer; signal S_FSM_turns_number : integer; signal S_FSM_turn : integer; signal S_FSM_turn_pulse : integer; signal S_S_E_done : std_logic_vector (2 downto 0); --====================== Seven seg display ============================== signal state_number1,state_number2 :integer; begin steer_pwm_comp: Steer_Pwm generic map ( DC => 17 ms, clock_period => 20 ms, max_pulse => 1 ms, min_pulse => 2 ms, neutral_pulse => 1.5 ms ) port map ( Rst => System_N_Reset, Clk => System_Clk_50MHz, Enable => S_P_En, Pwm => S_P_Pwm, pulse_length => S_FSM_S_P_pulse_length ); motion_pwm_comp:Motion_Pwm generic map ( DC => 17 ms, clock_period => 20 ms, max_pulse => 1 ms, min_pulse => 2 ms, neutral_pulse => 1.5 ms ) port map ( Rst => System_N_Reset, Clk => System_Clk_50MHz, Enable => M_P_En, Pwm => M_P_Pwm, pulse_length => S_FSM_M_P_pulse_length ); Uart_comp:communication generic map ( ndbits => 8 ) port map ( Clk => System_Clk_50MHz, Rst => System_N_Reset, baud_sel => UART_baud_sel, rx => UART_rx, tx => UART_tx, led_sec => led_sec, rxerr_led => UART_rxerr_led, txbusy => UART_txbusy, rx_done => UART_rx_done, dout => UART_dout, ready_tx => UART_ready_tx, din => S_FSM_dout_reg ); M_Encoder_comp:Motion_Encoder port map ( done => S_M_E_done, Rst => System_N_Reset, Enable => M_E_En, Clk => System_Clk_50MHz, DataIn => M_E_DataIn, distance => S_FSM_distance, slot_number => S_FSM_slot_number, wheel_radius => S_FSM_Wheel_radius ); S_Encoder_comp:Steer_Encoder port map ( done => S_S_E_done, Rst => System_N_Reset, Enable => S_E_En, Clk => System_Clk_50MHz, DataIn => S_E_DataIn, angle => S_FSM_angle, slot_number => S_FSM_slot_number, spare => S_FSM_spare_angle, turns_number => S_FSM_turns_number, res => S_FSM_res, spare_flag => S_FSM_spare_flag, turn_pulse => S_FSM_turn_pulse, turn_flag => S_FSM_turn_flag ); M_E_Done <= S_M_E_done; S_E_Done <= S_S_E_done; --====================================================================================== --================= FSM CODE (MODULES: UART,D_E,PWM) ========================== --====================================================================================== rx_done_reg: process (System_Clk_50MHz,System_N_Reset) begin if (System_N_Reset = bit_low) then S_FSM_rx_done(0) <= bit_low; S_FSM_rx_done(1) <= bit_low; S_FSM_rx_done(2) <= bit_low; elsif rising_edge (System_Clk_50MHz) then S_FSM_rx_done(0) <= UART_rx_done; S_FSM_rx_done(1) <= S_FSM_rx_done(0); S_FSM_rx_done(2) <= S_FSM_rx_done(1); end if; end process rx_done_reg; S_Uart_rx_done <= S_FSM_rx_done(1) and (not S_FSM_rx_done(2)); Fsm_logic: process (System_Clk_50Mhz,System_N_Reset) variable temp: integer := 0; variable next_st: motin_state_type; begin if (System_N_Reset = bit_low) then max_counter <= (others => bit_low); curr_st <= idle_to_enable_st; S_FSM_dout_reg <= (others => bit_low); state_number1 <= 0; state_number2 <= 0; S_FSM_wheel_radius <= 7; S_FSM_turn_pulse <= 22; S_FSM_slot_number <= 90; S_FSM_M_P_pulse_length <= 0; S_FSM_S_P_pulse_length <= 0; M_P_En <= bit_low; S_P_En <= bit_low; M_E_En <= bit_low; S_E_En <= bit_low; S_FSM_M_P_En <= bit_low; S_FSM_S_P_En <= bit_low; S_FSM_M_E_En <= bit_low; S_FSM_S_E_En <= bit_low; S_FSM_S_P_CEn <= bit_low; S_FSM_M_P_CEn <= bit_low; S_FSM_S_E_CEn <= bit_low; S_FSM_M_E_CEn <= bit_low; S_FSM_rt_flag <= bit_low; S_FSM_lt_flag <= bit_low; -- S_FSM_turn_flag <= bit_low; -- S_FSM_spare_flag <= bit_low; -- FSM_enable_led <= bit_low; -- FSM_init_led <= bit_low; -- FSM_type_led <= bit_low; -- FSM_distance_value_led <= bit_low; -- FSM_angle_value_led <= bit_low; -- FSM_stop_led <= bit_low; elsif rising_edge(System_Clk_50Mhz) then next_st := curr_st; if (S_M_E_done = bit_high) then S_FSM_M_P_pulse_length <= neutral_cycle; end if; if (S_S_E_done(2) = bit_high) then S_FSM_S_P_pulse_length <= neutral_cycle; end if; case curr_st is -- idle until components enable recived when idle_to_enable_st => state_number1 <= 0; state_number2 <= 0; -- FSM_enable_led <= bit_high; -- FSM_stop_led <= bit_low; S_FSM_S_P_CEn <= bit_low; S_FSM_M_P_CEn <= bit_low; S_FSM_S_E_CEn <= bit_low; S_FSM_M_E_CEn <= bit_low; if (S_Uart_rx_done = bit_high) then S_FSM_dout_reg <= UART_dout; next_st := enable_st; else next_st := idle_to_enable_st; end if; -- enable components from communication command state when enable_st => state_number1 <= 1; state_number2 <= 0; if (S_FSM_dout_reg = "11111111") then -- all active S_FSM_M_P_En <= bit_high; S_FSM_M_E_En <= bit_high; S_FSM_S_E_En <= bit_high; S_FSM_S_P_En <= bit_high; next_st := idle_to_initialize_st; elsif (S_FSM_dout_reg = "00000000") then next_st := idle_to_enable_st; else if (S_FSM_dout_reg(0) = bit_high) then S_FSM_M_P_En <= bit_high; end if; if (S_FSM_dout_reg(1) = bit_high) then S_FSM_M_E_En <= bit_high; end if; if (S_FSM_dout_reg(2) = bit_high) then S_FSM_S_P_En <= bit_high; end if; if (S_FSM_dout_reg(3) = bit_high) then S_FSM_S_E_En <= bit_high; end if; next_st := idle_to_initialize_st; end if; -- idle untill initialization to Robot components are recived when idle_to_initialize_st => state_number1 <= 2; state_number2 <= 0; -- FSM_init_led <= bit_high; -- FSM_enable_led <= bit_low; if (S_Uart_rx_done = bit_high) then S_FSM_dout_reg <= UART_dout; next_st := initialize_st; else next_st := idle_to_initialize_st; end if; -- initialization of Robot components from communication command state when initialize_st => state_number1 <= 3; state_number2 <= 0; if (S_FSM_dout_reg(0) = bit_high) then -- wheel radius S_FSM_wheel_radius <= 7; -- 2.75 inch -- S_FSM_pulse_number <= 22; else S_FSM_wheel_radius <= 13; -- 5 inch -- S_FSM_pulse_number <= 22; end if; if (S_FSM_dout_reg(1) = bit_high) then -- encoder slot number S_FSM_slot_number <= 90; -- 90 slots S_FSM_turn_pulse <= 22; -- we need to take the larger resulation from the encoder or from the wheel tooth of the steering transmission S_FSM_res <= 4; else S_FSM_slot_number <= 180; -- 180 slots just an example for different resulotion S_FSM_turn_pulse <= 6; S_FSM_res <= 2; end if; next_st := idle_to_command_st; -- wait for command type state when idle_to_command_st => state_number1 <= 4; state_number2 <= 0; -- FSM_angle_value_led <= bit_low; -- FSM_distance_value_led <= bit_low; -- FSM_type_led <= bit_high; -- FSM_init_led <= bit_low; -- FSM_stop_led <= bit_low; -- FSM_distance_value_led <= bit_low; if (S_Uart_rx_done = bit_high) then S_FSM_dout_reg <= UART_dout; next_st := command_type_st; else next_st := idle_to_command_st; end if; -- command type detection state when command_type_st => state_number1 <= 5; state_number2 <= 0; if (S_FSM_dout_reg = "00000000") then -- command number 0 is stop - stop S_FSM_M_P_pulse_length <= neutral_cycle; S_FSM_S_P_pulse_length <= neutral_cycle; S_FSM_M_P_CEn <= bit_high; S_FSM_S_P_CEn <= bit_high; S_FSM_M_E_CEn <= bit_high; S_FSM_S_E_CEn <= bit_high; next_st := idle_to_command_st; elsif (S_FSM_dout_reg = "00000001") then -- command number 1 is forward - fd S_FSM_M_P_pulse_length <= max_cycle; S_FSM_M_P_CEn <= bit_high; S_FSM_M_E_CEn <= bit_high; next_st := idle_to_distance_value_st; elsif (S_FSM_dout_reg = "00000010") then -- command number 2 is backward - bk S_FSM_M_P_pulse_length <= min_cycle; S_FSM_M_P_CEn <= bit_high; S_FSM_M_E_CEn <= bit_high; next_st := idle_to_distance_value_st; elsif (S_FSM_dout_reg = "00000011") then -- command number 3 is rotate left -rl S_FSM_S_P_pulse_length <= max_cycle; S_FSM_S_P_CEn <= bit_high; S_FSM_S_E_CEn <= bit_high; S_FSM_M_P_CEn <= bit_high; S_FSM_M_E_CEn <= bit_high; S_FSM_lt_flag <= bit_high; next_st := idle_to_angle_value_st; elsif (S_FSM_dout_reg = "00000100") then -- command number 4 is rotate right - rr S_FSM_S_P_pulse_length <= min_cycle; S_FSM_S_P_CEn <= bit_high; S_FSM_S_E_CEn <= bit_high; S_FSM_M_P_CEn <= bit_high; S_FSM_M_E_CEn <= bit_high; S_FSM_rt_flag <= bit_high; next_st := idle_to_angle_value_st; else next_st := idle_to_command_st; end if; -- idle untill recived value for angle when idle_to_angle_value_st => state_number1 <= 6; state_number2 <= 0; -- FSM_angle_value_led <= bit_high; -- FSM_type_led <= bit_low; if (S_Uart_rx_done = bit_high) then S_FSM_dout_reg <= UART_dout; next_st := angle_value_st; else next_st := idle_to_angle_value_st; end if; -- angle state set the steering encoder angle detection: S_S_E_angle when angle_value_st => -- every pulse is 15 degree and the maximum degree for every direction is 90 degree meanning 6 pulse maximum state_number1 <= 7; state_number2 <= 0; if (S_FSM_slot_number = 90) then temp := conv_integer(S_FSM_dout_reg); S_FSM_angle <= temp ; next_st := initialize_turn_st; else next_st := idle_to_command_st; end if; -- initialize turn angle values when initialize_turn_st => state_number1 <= 8; state_number2 <= 0; S_FSM_turn <= conv_integer(S_FSM_turns_number); next_st := turn_st; -- count turn and spare angle for the seth , rt and lt commands when turn_st => -- every pulse is 4 degree and the maximum degree for every direction is 90 degree meanning 23 pulse maximum state_number1 <= 9; state_number2 <= 0; S_FSM_S_P_CEn <= bit_high; S_FSM_S_E_CEn <= bit_high; if (S_FSM_turn /= 0) then S_FSM_turn <= S_FSM_turn - 1; next_st := set_turn_angle_st; S_FSM_turn_flag <= bit_high; S_FSM_spare_flag <= bit_low; S_FSM_distance <= 90 * S_FSM_wheel_radius; elsif (S_FSM_spare_angle /= 0) and (S_FSM_spare_flag = bit_low)then S_FSM_turn_flag <= bit_low; S_FSM_spare_flag <= bit_high; S_FSM_distance <= S_FSM_spare_angle * S_FSM_wheel_radius; next_st := set_turn_angle_st; else if (S_FSM_lt_flag = bit_high) then S_FSM_S_P_pulse_length <= min_cycle; S_FSM_lt_flag <= bit_low; elsif (S_FSM_rt_flag = bit_high) then S_FSM_S_P_pulse_length <= max_cycle; S_FSM_rt_flag <= bit_low; end if; next_st := stright_heading_st; end if; -- execute robot steer and wait untill it finish when set_turn_angle_st => state_number1 <= 0; state_number2 <= 1; if (S_FSM_S_P_CEn = bit_high) and (S_FSM_S_P_En = bit_high) and (S_FSM_S_E_CEn = bit_high) and (S_FSM_S_E_En = bit_high) then S_E_En <= bit_high; S_P_En <= bit_high; end if; if (S_S_E_done(2) = bit_high) then S_FSM_S_P_pulse_length <= neutral_cycle; S_FSM_M_P_pulse_length <= min_cycle; S_FSM_S_P_CEn <= bit_low; S_FSM_S_E_CEn <= bit_low; S_FSM_M_P_CEn <= bit_high; S_FSM_M_E_CEn <= bit_high; S_E_En <= bit_low; S_P_En <= bit_low; next_st := finish_turn_st; else next_st := set_turn_angle_st; end if; -- execute robot turn and wait untill it finish when finish_turn_st => state_number1 <= 1; state_number2 <= 1; if (S_FSM_M_P_CEn = bit_high) and (S_FSM_M_E_CEn = bit_high) and (S_FSM_M_P_En = bit_high) and (S_FSM_M_E_En = bit_high) then M_E_En <= bit_high; M_P_En <= bit_high; end if; if (S_M_E_done = bit_high) then next_st := turn_st; S_FSM_M_P_pulse_length <= neutral_cycle; S_FSM_M_P_CEn <= bit_low; S_FSM_M_E_CEn <= bit_low; M_E_En <= bit_low; M_P_En <= bit_low; else next_st := finish_turn_st; end if; -- execute defualt robot heading and wait untill it finish when stright_heading_st => state_number1 <= 2; state_number2 <= 1; if (S_FSM_S_P_CEn = bit_high) and (S_FSM_S_P_En = bit_high) and (S_FSM_S_E_CEn = bit_high) and (S_FSM_S_E_En = bit_high) then S_E_En <= bit_high; S_P_En <= bit_high; end if; if (S_S_E_done(2) = bit_high) then S_FSM_S_P_pulse_length <= neutral_cycle; next_st := stop_st; S_FSM_spare_flag <= bit_low; else next_st := stright_heading_st; end if; -- idle untill recived value for distance when idle_to_distance_value_st => state_number1 <= 3; state_number2 <= 1; -- FSM_distance_value_led <= bit_high; -- FSM_type_led <= bit_low; if (S_Uart_rx_done = bit_high) then S_FSM_dout_reg <= UART_dout; next_st := distance_value_st; else next_st := idle_to_distance_value_st; end if; -- distance state set the motion encoder distance detection: S_FSM_distance when distance_value_st => state_number1 <= 4; state_number2 <= 1; if (S_FSM_wheel_radius = 7) then -- fd 1 distance 11[cm] with 2.75 inch wheel size radius temp := conv_integer(S_FSM_dout_reg); S_FSM_distance <= temp *s_fsm_slot_number ; next_st := wait_st; else next_st := idle_to_command_st; end if; when wait_st => next_st := execute_st; -- execute state start robot action after enable,initialization and command were active at least once when execute_st => state_number1 <= 5; state_number2 <= 1; M_E_En <= bit_high; M_P_En <= bit_high; if (S_FSM_M_E_CEn = bit_high) and (S_FSM_M_E_En = bit_high) and (S_FSM_M_P_CEn = bit_high) and (S_FSM_M_P_En = bit_high) then if (S_M_E_done = bit_high) then S_FSM_M_P_pulse_length <= neutral_cycle; next_st := stop_st; else next_st := execute_st; end if; elsif (S_FSM_M_E_CEn = bit_low) and (S_FSM_M_E_En = bit_low) and (S_FSM_M_P_CEn = bit_low) and (S_FSM_M_P_En = bit_low) then S_FSM_M_P_pulse_length <= neutral_cycle; next_st := stop_st; else next_st := execute_st; end if; -- stop robot and reset signals back to idle_to_command_st - waiting for user command when stop_st => state_number1 <= 6; state_number2 <= 1; -- FSM_stop_led <= bit_high; -- FSM_distance_value_led <= bit_low; -- FSM_angle_value_led <= bit_low; if (max_counter = max_cycle) then M_E_En <= bit_low; M_P_En <= bit_low; S_FSM_M_P_CEn <= bit_low; S_FSM_M_E_CEn <= bit_low; S_E_En <= bit_low; S_P_En <= bit_low; S_FSM_S_P_CEn <= bit_low; S_FSM_S_E_CEn <= bit_low; next_st := idle_to_command_st; else max_counter <= max_counter + 1; next_st := stop_st; end if; when others => next_st := idle_to_enable_st; end case; curr_st <= next_st; end if; end process Fsm_logic; seven_reg1: process (System_Clk_50MHz,System_N_Reset) BEGIN if (System_N_Reset = '0') then seven_seg1 <="1111111"; elsif rising_edge (System_Clk_50MHz) then case state_number1 is when 0 => seven_seg1 <="1000000"; -- '0' when 1 => seven_seg1 <="1111001"; -- '1' when 2 => seven_seg1 <="0100100"; -- '2' when 3 => seven_seg1 <="0110000"; -- '3' when 4 => seven_seg1 <="0011001"; -- '4' when 5 => seven_seg1 <="0010010"; -- '5' when 6 => seven_seg1 <="0000011"; -- '6' when 7 => seven_seg1 <="1111000"; -- '7' when 8 => seven_seg1 <="0000000"; -- '8' when 9 => seven_seg1 <="0011000"; -- '9' when others=> seven_seg1 <="0000000"; end case; end if; end process seven_reg1; seven_reg2: process (System_Clk_50MHz,System_N_Reset) BEGIN if (System_N_Reset = '0') then seven_seg2 <="1111111"; elsif rising_edge (System_Clk_50MHz) then case state_number2 is when 0 => seven_seg2 <="1000000"; -- '0' when 1 => seven_seg2 <="1111001"; -- '1' when 2 => seven_seg2 <="0010010"; -- '2' when 3 => seven_seg2 <="0000110"; -- '3' when 4 => seven_seg2 <="1001100"; -- '4' when 5 => seven_seg2 <="0110000"; -- '5' when 6 => seven_seg2 <="1100000"; -- '6' when 7 => seven_seg2 <="0001111"; -- '7' when 8 => seven_seg2 <="0000000"; -- '8' when 9 => seven_seg2 <="0001100"; -- '9' when others=> seven_seg2 <="0000000"; end case; end if; end process seven_reg2; end architecture arc_fsm;