--=================================================================================================
-- File Name                           : encoder_interface.vhd

-- Description                         : This module samples the output of external encoder and 
--										 generates the angle.

-- 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.std_logic_unsigned.ALL;

--=================================================================================================
-- encoder_interface entity declaration
--=================================================================================================

ENTITY ENCODER_INTERFACE IS
PORT (
-- Port List
    -- System reset
    reset_i                                     : IN STD_LOGIC;
    
    -- System clock 
    sys_clk_i                                   : IN STD_LOGIC;
    
	--Filter trigger   
    fil_trig_i                                  : IN STD_LOGIC;
    
 	--Direction configuration   
    direction_config_i                          : IN STD_LOGIC;
    
	--Clear buffer 
    clear_buffer_i                              : IN STD_LOGIC;
    
	--Sensor reset signal   
    sensor_reset_i                              : IN STD_LOGIC;
    
	--QA input from encoder 
    qa_i                                        : IN STD_LOGIC;

	--QB input from encoder
    qb_i                                        : IN STD_LOGIC;

	--Speed scaling value
    speed_factor_i                              : IN STD_LOGIC_VECTOR(17 downto 0);

	--Angle scaling value
    angle_factor_i                              : IN STD_LOGIC_VECTOR(17 downto 0);

	--Maximum angle count value (number of encoder pulse events per rotation)
    angle_count_max_i                           : IN STD_LOGIC_VECTOR(17 downto 0); 
    
    --Speed measurement time window
    speed_window_i                              : IN STD_LOGIC_VECTOR(17 downto 0); 

	--Filter factor for speed filter
    filter_factor_i                             : IN STD_LOGIC_VECTOR(3 downto 0);

	--Direction output detected from encoder signals
    dir_o                                       : OUT STD_LOGIC;
    
    --Signal indicates speed computation is ready for filtering
    speed_done_o                                : OUT STD_LOGIC;
    
    --Signal indicates speed output after filtering is valid
    speed_filter_done_o                         : OUT STD_LOGIC;

	--Speed output
    omega_out_o                                 : OUT STD_LOGIC_VECTOR(17 downto 0);

	--Angle output
    angle_out_o                                 : OUT STD_LOGIC_VECTOR(17 downto 0);

	--Encoder Line count
    line_count_o                                : OUT STD_LOGIC_VECTOR(17 downto 0)	
    
);
END encoder_interface;

--=================================================================================================
-- Architecture body
--=================================================================================================
ARCHITECTURE encoder_interface OF encoder_interface 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
K72n8SlJXXY/g7Ih+Sh1JNyBMFuEf9SH6vTcPmOACdenH4d0IDDeZkFpLMBtiDOSdcqZIu6uBVto
9IzSCL6wPD/4TT+3QNuSiyPemgLfy5lIe32NRywIiteOYIQl467b7h1b3ZW0tFEjiRxf7v0gr2+K
SqeczZ3jzwB9M2BsvodPPkIDYlGGoWO0HeaRmdpm7Up0R0n2aQVmUu9h2EuzNgg+GoCL2Z7ihir2
+fvhTYp0+fZjaRUUcAMjS0SaYMxm8cqcCObdc1xgxDvoEoIN4n901j2vsNWumQOp/pIbugI+9rkY
cVpcaN5bs9A5Xz1wDzzoQbtCljQjrueG1mJaYw==

`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
miBxpNsEvgHPJ1bz1rbCi4vMlulBcGF7JUEtrn/QKS1Q35TIUUOwbF7aarW/CuJSkq/cx/vneN+w
GN2MWJzqsvvUwPwhBXBXnM5RShpYJ15RTr1Mi8axbw1m7z6ZGp9/JiDI0b2FPbqjT2kickgTkwEA
1KPu6fNg+KovOUcGGwU=

`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
ijoYMrBttH5GpUI8JM5O9jvRFzMJqT65gSiVrGS3WVlCuYB77ZU8N2PB1VAXZGHTyZHgwd75b1KF
yuiDzLXQJjYSUcvp2QBWq4tJ8MbUvxIJfFis0CP8TpmmepcVVjpZhskxT1pC51d2Le/XHuwq49gb
2g8y9OOk9j5o8rgrWHARLAlH1fMcpf0oqgerCH28AaYz1QBEP8Neor8rHGI4710hre++NKmsOZ8G
nJ7YyjQlmNoaUELNcD24EuDWZQChlYB4bYN/2p4ncXon8Oq+62koB5vKOUJoWAohZnlzYpswxXNh
j/K+b8mqM/Wa6snCkr6q0o0qiwpK7KCgaWVynd1ZLNE12IsmeLHQ8EaIPDDC2OyshqCLvHSSWQhw
kf90tJBegfH0yh6387TO17ZSxelsb8Zdjtc/PjXvZ/jRa0OpYiMa3brL+FmPvm3vgdCSy2JZhEkX
dHgofa9OedCRv3+QI41ZW+XBQkrmuxAksI6cJ3ZjJjYKVr3w1nV3J2SW4pyzvdMqw2jLBcvDFxRh
6kgl5/qQ0qNnYtEz305dk6bkXWTixn/D8UIAtE+oQJgtW82uIFnopgl8KJhXlR6EpqCxYDCw33U4
S8W9FpN3DPoa2qlwVfcGZhnmr/umKTTC6lECRaSWFM3qdo0mWTuB8YWk9WJ2ZnLRq71X0ZacB9WO
05c4bm30+hENsxa05tz5Zdgrde2rqy4EmV4wN6YGDUqbCt3pLi73WKnmGIjOfliLDwqfQ6V3hffA
nACOTZL3XF8a9/CYTnBMrpiYMhEGp5rrvblHvDXE8G7EhFAhrdxORcAZbdasXT0HDbl1gqrl5/Z6
rB9wFy33NWFJ3uIx6CezPvO9/0nqjIVKUnjYurp2PNc7V9neD8hx7fHNLA06wozXR96a1Jk4pEUo
NUtccsMYF55K15gFxnFwC5WHy7gOmnrYN/M+UceA/kTGJGKmXq3p+v1/1C8gZjWH5mN9fKPWRHPx
X+duXUrpWMxtqV8SMFZ0xRlEn+YTv6ZvN4ewCgIjNT159mHDhHh1aMTOuiHdRf1sC9Q/d8FTdb41
VELpflq3W/7VN45EotC6HuqTQfZGTFlHMK2uB4xHjrf/Qp0oUReNT9aKgIZssETjkbSJBNU115U5
uxVRnEY2GI03+lV/g1p8Ng4aDVZ5rr+HIk6MsXFOtJM7hReEOcmxHIuGx6/U9NzzqVVxoQ4E5w9+
ZQKKEowo8rMt4cnfrVsWodICjkwUoylIMqxE2JDt1On7zn1Pr+wXu1YaNQhvQkLj

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

`protect end_protected

