--=================================================================================================
-- File Name                           : seq_controller.vhd

-- Description                         : This module generates the necessary control signals
--							             for single axis motor control execution.

-- Targeted device                     : Microsemi-SoC
-- Author                              : India Solutions Team
--
-- SVN Revision Information            :
-- SVN $Revision                       :
-- SVN $Date                           :
--
-- COPYRIGHT 2016 BY MICROSEMI
-- THE INFORMATION CONTAINED IN THIS DOCUMENT IS SUBJECT TO LICENSING RESTRICTIONS FROM MICROSEMI
-- CORP. IF YOU ARE NOT IN POSSESSION OF WRITTEN AUTHORIZATION FROM MICROSEMI FOR USE OF THIS
-- FILE, THEN THE FILE SHOULD BE IMMEDIATELY DESTROYED AND NO BACK-UP OF THE FILE SHOULD BE MADE.
--
--=================================================================================================

--=================================================================================================
-- Libraries
--=================================================================================================
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.NUMERIC_STD.ALL;
USE IEEE.STD_LOGIC_SIGNED.ALL;

--=================================================================================================
-- seq_controller entity declaration
--=================================================================================================
ENTITY SEQ_CONTROLLER IS
GENERIC(
-- Generic list
    -- Specifies whether seq_controller is used for synthesis or simulation
    g_DEBUG                            : INTEGER := 0
);
PORT(
-- Port list
    -- System reset
    reset_i                            : IN STD_LOGIC;
    
    -- System clock
    sys_clk_i                          : IN STD_LOGIC;
    
    -- External fault
    fault_i                            : IN STD_LOGIC;
	
	-- Start signal to start the motor
    start_motor_i                      : IN STD_LOGIC;
	
	-- Stop signal to stop the motor
    stop_motor_i                       : IN STD_LOGIC;
	
	-- Clear all faults
    fault_clear_i                      : IN STD_LOGIC;
	
	-- Speed reference
    speed_ref_i                        : IN STD_LOGIC_VECTOR(17 DOWNTO 0);
	
	-- Speed threshold for closed loop
    speed_cl_i                         : IN STD_LOGIC_VECTOR(17 DOWNTO 0);

    -- Voltage input
    vq_i                               : IN STD_LOGIC_VECTOR(17 DOWNTO 0);

    -- Number of auto restarts after which fault is asserted
    max_ar_i                           : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
	
	-- Offset calibration done
    calib_done_i                       : IN STD_LOGIC;
	
	-- PWM midmatch
    pwm_midmatch_i                     : IN STD_LOGIC;

    -- FOC loop completed
    foc_done_i                         : IN STD_LOGIC;

    -- Configuration register
    config_reg_i                       : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
	
	-- ADC start signal
	adc_start_o                        : OUT STD_LOGIC;
	
	-- enable speed PI controllers
	cl_status_o                        : OUT STD_LOGIC;
	
	-- enable Id and Iq PI controllers
	en_idq_pi_o                        : OUT STD_LOGIC;
	
	-- enable PWM
	en_pwm_o                           : OUT STD_LOGIC;

    -- Motor stopped status
	motor_stopped_o                    : OUT STD_LOGIC;

    -- Reset rate limiter
	reset_rl_o                       : OUT STD_LOGIC;

    -- Soft stop rate limiter
	soft_stop_o                        : OUT STD_LOGIC;
	
    -- Reset signal to sensor interface block
    sensor_reset_o                     : OUT STD_LOGIC;
    
    -- FSM state
    state_o                            : OUT STD_LOGIC_VECTOR(3 DOWNTO 0)
   
);
END seq_controller;

--=================================================================================================
-- seq_controller architecture body
--=================================================================================================

ARCHITECTURE seq_controller OF seq_controller IS
`protect begin_protected
`protect version=1
`protect author="author-a", author_info="author-a-details"
`protect encrypt_agent="encryptP1735.pl", encrypt_agent_info="Synplify encryption scripts"

`protect key_keyowner="Synplicity", key_keyname="SYNP05_001", key_method="rsa"
`protect encoding=(enctype="base64", line_length=76, bytes=256)
`protect key_block
pPwdWB9UFDqIdJmD+0fXbqfGwo5x0Es5CG/E6KU6lJIWrcnP6yc8gwimfokYladB2SAjAX+bKgBv
0C4rKCrYyOW66vVI/VXk80CkX6XQSVqTuklYBmm9JMzCyp1YNHJVQ5MSW3bY4ySbCCKG/S1UiPLu
tiubmq2IPYHhv9GV3IuwyW3/n+kXCADK6rVyMAEOFkR/U34pzjwWNQLz7AkVrrzlJ0ETAcQi6+Fg
Pl+Mjfs9IK9gTxZlpLJ0RrZLvPdE8iuQ8ADg1XGFEg5ZLw4pRF9DCULK2tmNAth0pIkxZTtuFVQr
b6PYyyrEoHUjtTgOil6ssvvaFL2gVOiXQq77dQ==

`protect key_keyowner="Mentor Graphics Corporation", key_keyname="MGC-VERIF-SIM-RSA-1", key_method="rsa"
`protect encoding=(enctype="base64", line_length=76, bytes=128)
`protect key_block
FA5zmvmF0s4EnS3OEzgO89nR5Nk8i5pLVgaNI8EHOdmxZkxCzN7COPHl5N3CQWgF3scRosX/wwiY
4gKvkLRkRvaO68UGRhDph2yxWwuAVlAQY8mwWiYm40pJEZY7iAboiWDME5++rtaaA+w8rKO+AhNb
F1Y80vBmim2i0qoGj64=

`protect key_keyowner="Microsemi Corporation", key_keyname="MSC-IP-KEY-RSA", key_method="rsa"
`protect encoding=(enctype="base64", line_length=76, bytes=960)
`protect key_block
HSct0AqGcsG4/SN1D9R1T+a/2+7RcY6SEnATyxudUWjCrbpPfbXXiDGR39BZsTjEBp8jDFnDwewj
KCEorUUKcDTHuEJ5nmpk9sAy1fee2g0twtqpj2cTEfTa4vU4QH4fQmVVQHuu419RIu69k1HlGbz5
vFrTC0Iayez9HHwbqVXjyF7Grs/pVsR5Ofy4y3PHbIyQAQZOCuus9xEPmQ71UoeAHJNkeOagZhUe
wv89YrwoQIioIxQhIYWrMYXEggXjANExUwC6c8CQdaBoMG/1mUFvbdx7pwCDb0bEoAPmA7+9Mjtc
uvdKnly7zdj8a8L0O2ahOmvyD5Q2l1B1ExMe06HqX3arYhW7hFJlepx+P1hk+VdrUt3ESxUxp+KU
8VycC7pFjnWqCn2XpaXDuDWEiiXpkuO25kJoR/kuxoGeTu0b4Umal7wkJoGkmF1/tPK40xzoX/I2
KJjA+2rJ0yytU4FEQv7MEXT3xk3DGdhuFY81qGVDirjQMcjyL1qaitHb0MKBaTXGMboU5skLMwzU
dR4diu/cDk4shhAdWhAMb7Lsx28KkaHc1vB8EYIITuKeET2b45nui/9/7V1V0HsfKIZ9XFpVcUlG
mkvjB454KW4vO1bMko1/7761XbcZVrlIf4y4AKtlV5FOCq96v13h3fz8UgYsel9Jhu8vwGsOXCYl
j4xV1oS5tAEqnsUo9/tCRHEtZopfO0Vp/0ra06zQJvxIxAXDi5sEmDeb/kzGm1ev1RhclLIuM5qE
ouOi7bCuubK9HUebrCZ//vg3Y7mDtBPHwVdhkavK2ho1xbBfFwjOvq6v6gXnk7O8G6djCZ6OBb67
TcGlpAxwwVWYmrc9pTcJgpAZ4ACBNKwqvxtr/Ruz7+TZuxTH5CdhCDmBix7I1pYyTynjZnYzSr6I
jLAcC0MErdZpkzYna/WiVRoof734lDbrsTUaEyW3UocfS2wcq/i+ZU+o/IUaHjV2mq0BAGl5Zqcd
vyXKFV5JLfweKqgBukHzmw7NDg1f8j0W3JFn0730CywJCsedbpQNFq91qPw+84k4GAbSswCWYTtC
YmbEpfHLTZfhRgzcees8scQnJp3qBa+xhLHAsjJonRTN5IIeCaJfiopqCc3QnNgqZFDVLCQj4Aot
kPeNz2xwAl2XPAPx/iiQzrWJYSmJnEEyfz/AIH49ot/ev2QVCZXaqU1NPBvJAA7d7amRMWjx4WHH
7fMubp/VFanZuBwdVCu2PmEe9z4FrCnRLc/QGia0IZbphNI2uSBKwI8jQaJEqjNl

`protect data_keyowner="ip-vendor-a", data_keyname="fpga-ip", data_method="aes128-cbc"
`protect encoding=(enctype="base64", line_length=76, bytes=15552)
`protect data_block
[encoded data, 20736 characters]

`protect end_protected

