library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
USE IEEE.numeric_std.ALL;

entity Inverse_Park_transformation is
    Port (
        d : in signed (15 downto 0); 
        q : in signed (15 downto 0); 
        sin : in signed (15 downto 0);
        cos : in signed (15 downto 0);
        alfa : out signed (15 downto 0); 
        beta : out signed (15 downto 0) 
    );
end Inverse_Park_transformation;

architecture Behavioral of Inverse_Park_transformation is

signal mul_temp1 : signed (31 downto 0);
signal mul_temp2 : signed (31 downto 0);
signal mul_temp3 : signed (31 downto 0);
signal mul_temp4 : signed (31 downto 0);
signal add_temp1 : signed (31 downto 0);
signal add_temp2 : signed (31 downto 0);

begin
  
mul_temp1 <= cos * d;
mul_temp2 <= sin * q;
mul_temp3 <= sin * d;
mul_temp4 <= cos * q;
add_temp1 <= mul_temp1 - mul_temp2;
add_temp2 <= mul_temp3 + mul_temp4;
--alfa <= resize(add_temp1(31 downto 15),16);
--beta <= resize(add_temp2(31 downto 15),16);
alfa(15) <= add_temp1(31);
alfa(14 downto 0) <= add_temp1(29 downto 15);
beta(15) <= add_temp2(31);
beta(14 downto 0) <= add_temp2(29 downto 15);  
end Behavioral;
