-- Engineer: David Makowka
--This block defines states of motor control
--In those states takes care
    --Detecting request on change of values as speed and duty cycle and creates pulses for motor controler
    --Multiplexing of values on display
--Actual values of speed and duty are only in motor controller

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

entity engine_speed_controller is
    Port ( --INPUTS
           clk                                                     : in std_logic;
           in_btnC                                                 : in std_logic;
           in_btnU                                                 : in std_logic;
           in_btnL                                                 : in std_logic;
           in_btnR                                                 : in std_logic;
           in_btnD                                                 : in std_logic;
           in_comparators                                          : in std_logic_vector(2 downto 0);
           --OUTPUTS
           out_display_an                                          : out std_logic_vector(3 downto 0);
           out_display_led                                         : out std_logic_vector(6 downto 0);
           
           out_pwm_driver_output                                   : out std_logic_vector(5 downto 0);
           --MEASURED SIGNALS FROM AD                                                       
           in_sense_A                                              : in std_logic_vector(9 downto 0); 
           in_sense_B                                              : in std_logic_vector(9 downto 0); 
           in_sense_C                                              : in std_logic_vector(9 downto 0); 
           in_sense_PVDD                                           : in std_logic_vector(9 downto 0); 
           in_voltage_A                                            : in std_logic_vector(9 downto 0); 
           in_voltage_B                                            : in std_logic_vector(9 downto 0); 
           in_voltage_C                                            : in std_logic_vector(9 downto 0); 
           in_temperature                                          : in std_logic_vector(9 downto 0);
           --error code
            in_error_code_reg_1                                    : in std_logic_vector(5 downto 0); 
            in_error_code_reg_2                                    : in std_logic_vector(5 downto 0);  
            in_error_code_reg_3                                    : in std_logic_vector(5 downto 0);  
            in_error_code_reg_4                                    : in std_logic_vector(5 downto 0);   
            in_values_vector                                       : in std_logic_vector(76 downto 0);  
           --diplayed value number
           out_number_select                                       : out std_logic_vector(4 downto 0);
           out_current_state                                       : out std_logic_vector(2 downto 0));
end engine_speed_controller;

architecture Behavioral of engine_speed_controller is

    type t_10_bit_array_8_items is array(0 to 7) of std_logic_vector(9 downto 0);
    
    constant c_cnt_1Hz                                             : natural := 100000000;
    constant c_cnt_10Hz                                            : natural := 10000000;
    constant c_cnt_50Hz                                            : natural := 5000000;
    constant c_cnt_100Hz                                           : natural := 1000000;
    constant c_cnt_1kHz                                            : natural := 100000;
    constant c_cnt_10kHz                                           : natural := 10000;
    constant c_cnt_100kHz                                          : natural := 1000;
    constant c_cnt_1MHz                                            : natural := 100;
    constant c_cnt_10MHz                                           : natural := 10;

--    type state is (reset, start_engine, speed_control, power_control, display_control);
--    signal s_control_section, s_next_control_section               : state := reset;
     
     
    --**********************************************************************************************
    --      NUMBER VARIABLES                                                                       *
    --********************************************************************************************** 
    --signal s_engine_rotaty_pwm_speed                               : natural range 0 to 255 := 1;
    signal s_engine_power_pwm_speed                                : natural range 0 to 255 := 1;
    signal s_engine_power_pwm_duty                                 : natural range 0 to 255 := 1;
    
    signal s_engine_rotaty_pwm_speed_conv                          : std_logic_vector(15 downto 0);
    signal s_engine_power_pwm_speed_conv                           : std_logic_vector(7 downto 0);
    signal s_engine_power_pwm_duty_conv                            : std_logic_vector(7 downto 0);
    
    signal s_control_state                                         : natural range 0 to 15   := 0;
    signal s_control_state_conv                                    : std_logic_vector(4 downto 0);
    
    signal s_out_number_select                                     : std_logic_vector(7 downto 0);
    
    --**********************************************************************************************
    --      CLOCK FOR BUTTONS                                                                      *
    --**********************************************************************************************
    signal buttons_clock                                           : std_logic;
    signal change_speed_button_clock                               : std_logic;
        
    --**********************************************************************************************
    --      BUTTONS                                                                                *
    --**********************************************************************************************
    signal s_out_buttons_pulse                                     : std_logic_vector (4 downto 0);
    signal s_out_buttons_continuous                                : std_logic_vector (4 downto 0);
    
    --trigger used in preposition phase

    signal s_speed_increase                                        : std_logic;
    signal s_speed_decrease                                        : std_logic;
    
    signal s_duty_increase                                         : std_logic; 
    signal s_duty_decrease                                         : std_logic;
    
    signal s_time_between_commutation_in_pulses                    : std_logic_vector(15 downto 0);
    
    signal s_current_state                                         : std_logic_vector(2 downto 0);
    
    --ARRAY WITH REGISTER AND VALUES TO SET TO DRV8305
    signal s_ADC_output_values_array                     : t_10_bit_array_8_items := (
        "0000000000", "0000000000", "0000000000", "0000000000",
        "0000000000", "0000000000", "0000000000", "0000000000");  
    
    --**********************************************************************************************
    --      DIVIDER FOR TRIGERRING THE TRANSMITTER COMPONENT                                       *
    --**********************************************************************************************
    component buttons_debouncer
    Port (      --INPUTS
                clk                                                : in std_logic;
                in_btn_Mid                                         : in std_logic;
                in_btnU                                            : in std_logic;
                in_btnD                                            : in std_logic;
                in_btnL                                            : in std_logic;
                in_btnR                                            : in std_logic;
                --OUTPUTS
                out_buttons_pulse                                  : out std_logic_vector (4 downto 0);
                out_buttons_continuous                             : out std_logic_vector (4 downto 0));
    end component;	

    component motor_control_with_start_sequence
    Port (  --INPUTS
            clk                                                    : in std_logic;
            in_control_state                                       : in std_logic_vector(4 downto 0);
            in_comparators                                         : in std_logic_vector (2 downto 0);
            in_speed_increase                                      : in std_logic;
            in_speed_decrease                                      : in std_logic;
            in_duty_increase                                       : in std_logic;
            in_duty_decrease                                       : in std_logic;
            out_engine_rotaty_pwm_speed                            : out std_logic_vector(15 downto 0);
            out_engine_power_pwm_duty                              : out std_logic_vector(7 downto 0); 
            in_engine_power_pwm_speed                              : in std_logic_vector(7 downto 0);
            --MEASURED VALUES
            in_sense_PVDD                                          : in std_logic_vector(9 downto 0); 
            in_voltage_A                                           : in std_logic_vector(9 downto 0); 
            in_voltage_B                                           : in std_logic_vector(9 downto 0); 
            in_voltage_C                                           : in std_logic_vector(9 downto 0); 
            --OUTPUTS
            out_pwm_driver_output                                  : out std_logic_vector(5  downto 0);
            
            out_time_between_commutation_in_pulses                 : out std_logic_vector(15 downto 0);
            out_current_state                                      : out std_logic_vector(2 downto 0));
    end component;

    component clk_divider
    generic (MAX : positive); 
	Port(   --INPUTS
	        clk                                                    : in STD_LOGIC;
	        divider_clock_multiplier                               : in STD_LOGIC_VECTOR(7 downto 0);
	        --OUTPUTS
            divider_clock_output                                   : out STD_LOGIC; 
            divider_pulse_output                                   : out STD_LOGIC);
	end component;
	
	component divider_with_increase
       generic( bits                                               : positive);
       port(    clk                                                : in  std_logic;
                in_increase                                        : in  std_logic_vector(bits-1 downto 0);
                out_pulse                                          : out std_logic);
    end component;

    --**********************************************************************************************
    --      DISPLAY COMPONENT                                                                      *
    --**********************************************************************************************
    component display
    Port(   --INPUTS
            clk                                                    : in   std_logic;
            in_reset                                               : in   std_logic;
            --------------------------------------------------------------------------------------------
	        in_engine_rotaty_pwm_speed                             : in   std_logic_vector(15  downto 0) := "0000000000000000";
	        in_engine_power_pwm_speed                              : in   std_logic_vector(7  downto 0) := "00000000";
	        in_engine_power_pwm_duty                               : in   std_logic_vector(7  downto 0) := "00000000";
	        --------------------------------------------------------------------------------------------
	        in_recieved_SPI                                        : in   std_logic_vector(15 downto 0) := (others => '0');
	        in_recieved_COM_PORT                                   : in   std_logic_vector(15 downto 0) := (others => '0');
	        --------------------------------------------------------------------------------------------
	        in_number_select                                       : in   std_logic_vector(7  downto 0) := "00000000";
            --MEASURED VALUES BY ADC
            in_sense_A                                             : in std_logic_vector(9 downto 0);
            in_sense_B                                             : in std_logic_vector(9 downto 0);
            in_sense_C                                             : in std_logic_vector(9 downto 0);
            in_sense_PVDD                                          : in std_logic_vector(9 downto 0);
            in_voltage_A                                           : in std_logic_vector(9 downto 0);
            in_voltage_B                                           : in std_logic_vector(9 downto 0);
            in_voltage_C                                           : in std_logic_vector(9 downto 0);
            in_temperature                                         : in std_logic_vector(9 downto 0);
            in_error_code_reg_1                                    : in std_logic_vector(5 downto 0); 
            in_error_code_reg_2                                    : in std_logic_vector(5 downto 0);  
            in_error_code_reg_3                                    : in std_logic_vector(5 downto 0);  
            in_error_code_reg_4                                    : in std_logic_vector(5 downto 0);
            in_values_vector                                       : in std_logic_vector(76 downto 0);     
            --TIME BETWEEN LAST COMMUTATION       
            in_time_between_commutation_in_pulses                  : in std_logic_vector(15 downto 0); 
            --CURRENT STATE FOR DETERMINING FREE PHASE TO SHOW
            in_current_state                                      : in std_logic_vector(2 downto 0);
            --OUTPUTS
            out_display_an                                         : out  std_logic_vector(3  downto 0);
		    out_display_led                                        : out  std_logic_vector(6  downto 0));    
    end component;
    
--    component adc_values_convertor
--    Port (  --INPUTS
--            clk                          : in STD_LOGIC;
--            in_sense_A                   : in std_logic_vector(9 downto 0);
--            in_sense_B                   : in std_logic_vector(9 downto 0);
--            in_sense_C                   : in std_logic_vector(9 downto 0);
--            in_sense_PVDD                : in std_logic_vector(9 downto 0);
--            in_voltage_A                 : in std_logic_vector(9 downto 0);
--            in_voltage_B                 : in std_logic_vector(9 downto 0);
--            in_voltage_C                 : in std_logic_vector(9 downto 0);
--            in_temperature               : in std_logic_vector(9 downto 0);
--            --OUTPUTS
--            out_sense_A                  : out std_logic_vector(9 downto 0);
--            out_sense_B                  : out std_logic_vector(9 downto 0);
--            out_sense_C                  : out std_logic_vector(9 downto 0);
--            out_sense_PVDD               : out std_logic_vector(9 downto 0);
--            out_voltage_A                : out std_logic_vector(9 downto 0);
--            out_voltage_B                : out std_logic_vector(9 downto 0);
--            out_voltage_C                : out std_logic_vector(9 downto 0);
--            out_temperature              : out std_logic_vector(9 downto 0));
--end component;


begin
    out_number_select <= "00000";-- & s_out_number_select;
    out_current_state <= s_current_state;
    --**********************************************************************************************
    --      BUTTON CONTROL PROCESS                                                                 *
    --**********************************************************************************************
    process(clk)
    begin
       if rising_edge(clk) then     
             --**********************************************************************************************
             --      CONVERSION OF INTEGERS TO STD_LOGIC_VECTOR                                             *
             --**********************************************************************************************
             s_engine_power_pwm_speed_conv    <= std_logic_vector(to_unsigned(s_engine_power_pwm_speed, s_engine_power_pwm_speed_conv'length)); 
        
             --******************************************************************************************
             --      PRECHOD MEZI STAVY                                                                 *
             --******************************************************************************************
             
             -- State 0 ("0000") - RESET
             -- State 1 ("0001") - PREPOSITION PHASE
             -- State 2 ("0010") - FORCED SYNCHRONOUS MODE
             
             -- State 3 ("0011") - SHOW SPEED
             -- State 4 ("0100") - SHOW PWM DUTY
             -- State 5 ("0101") - SHOW SPEED OF PWM
             if (s_control_state = 3 OR s_control_state = 4 OR s_control_state = 5 OR s_control_state = 6) then  
                 if (s_out_buttons_pulse(3) = '1') then  --button right, when button is pressed in giver every second 10 presses
                     if (s_control_state < 6) then
                        s_control_state <= s_control_state + 1;  
                     end if;
                     
                     --temporary solution until case number 7 is removed - precislovani
                     if (s_control_state = 6 AND s_out_buttons_pulse(3) = '1') then
                        s_control_state <= 8;
                     end if;
                     
                                          
                 elsif (s_out_buttons_pulse(2) = '1') then  --button left, when button is pressed in giver every second 10 presses
                     if (s_control_state > 3) then
                        s_control_state <= s_control_state - 1;
                     end if;
                 end if;     
             end if;            
    
             --******************************************************************************************
             --      RESET                                                                              *
             --****************************************************************************************** 
             if (s_out_buttons_pulse(4) = '1') then
                 s_control_state <= 0;
             end if; 
       
             --******************************************************************************************
             --      STATE MACHINE THAT CONTROLS ENGINE PARAMETERS IN TIME                              *
             --****************************************************************************************** 
             --sending state machine state to engine control
             s_control_state_conv <= std_logic_vector(to_unsigned(s_control_state, s_control_state_conv'length));
             
             --**********************************************************************************************
             --      MULTIPLEXING DIFFERENT INPUT NUMBERS ONTO DISPLAY                                      *
             --      000 MOTOR SPEED
             --      001 PWM DUTY
             --      010 PWM SPEED
             --**********************************************************************************************
             
             case s_control_state is
                 when 0 =>
                 --******************************************************************************************
                 --      RESET STATE                                                                        *
                 --******************************************************************************************
                     s_engine_power_pwm_speed   <= 50;
                 
                     s_out_number_select <= "00000111";
                     if (s_out_buttons_pulse(3) = '1') then --here is button put through debouncer, because we need just one pulse
                         s_control_state <= 1;
                     end if; 
                 
                 --******************************************************************************************
                 --      PREPOSITION PHASE                                                                  *
                 --******************************************************************************************            
                 when 1 =>
                     s_out_number_select <= "00000001";  --SHOW PWM DUTY CYCLE WHEN IN PREPOSITION CURRENT STATE
                         
--                     if(s_engine_power_pwm_duty_conv >= "01100100") then --detection that motor controller raised pwm value
--                        s_control_state <= 2;
--                     end if;      
                     
                     --for debug***********************************************
                     s_duty_increase <= '0'; 
                     s_duty_decrease <= '0'; 
                     
                     if ( buttons_clock = '1' ) then
                         --Zvysovani a snizovani hodnoty    
                         if (s_out_buttons_continuous(0) = '1') then  --button up
                             s_duty_increase <= '1';                         
                         elsif (s_out_buttons_continuous(1) = '1') then  --button down
                             s_duty_decrease <= '1';
                         end if;
                      end if;  
                         if (s_out_buttons_pulse(3) = '1') then --detection that motor controller raised pwm value
                         s_control_state <= 7;
                     end if; 
                     --********************************************************

                             
                 --******************************************************************************************
                 --      CHANGE OF ROTATY PWM IN TIME - from array values                                   *
                 --******************************************************************************************
                 when 7 =>
                     s_out_number_select <= "00000001";  --information about control section to leds

                    --for debug***********************************************
                     s_duty_increase <= '0'; 
                     s_duty_decrease <= '0'; 
                     
                     if ( buttons_clock = '1' ) then
                         --Zvysovani a snizovani hodnoty    
                         if (s_out_buttons_continuous(0) = '1') then  --button up
                             s_duty_increase <= '1';                         
                         elsif (s_out_buttons_continuous(1) = '1') then  --button down
                             s_duty_decrease <= '1';
                         end if;
                      end if;  
                      
                     --********************************************************
                    
                     if (s_out_buttons_pulse(3) = '1') then
                        s_control_state <= 2;  --next control section
                     end if;
                 --******************************************************************************************
                 --      CHANGE OF ROTATY PWM IN TIME - with constant value                                 *
                 --******************************************************************************************
                 when 2 =>
                     s_out_number_select <= "00000000";  --information about control section to leds
                     
       
                     if (s_engine_rotaty_pwm_speed_conv >= std_logic_vector(to_unsigned(16000, 16))) then
                        s_control_state <= 3;  --next control section
                     end if;
                     
                 --******************************************************************************************
                 --      ROTATY PWM SPEED - A                                                               *
                 --******************************************************************************************
                 when 3 =>
                     s_out_number_select <= "00000000";  --information about control section to leds
                    
                     s_speed_increase <= '0'; 
                     s_speed_decrease <= '0'; 
                            
                     if ( change_speed_button_clock = '1' ) then
                         --Zvysovani a snizovani hodnoty    
                         if (s_out_buttons_continuous(0) = '1') then  --button up
                             s_speed_increase <= '1';                         
                         elsif (s_out_buttons_continuous(1) = '1') then  --button down
                             s_speed_decrease <= '1';
                         end if;
                     end if; 

                  --******************************************************************************************
                  --      POWER DUTY - B                                                                   *
                  --******************************************************************************************           
                  when 4 =>
                      s_out_number_select <= "00000001";  --information about control section to leds
                     
                     s_duty_increase <= '0'; 
                     s_duty_decrease <= '0'; 
                     
                     if ( buttons_clock = '1' ) then
                         --Zvysovani a snizovani hodnoty    
                         if (s_out_buttons_continuous(0) = '1') then  --button up
                             s_duty_increase <= '1';                         
                         elsif (s_out_buttons_continuous(1) = '1') then  --button down
                             s_duty_decrease <= '1';
                         end if;
                     end if; 

                  --******************************************************************************************
                  --      POWER PWM SPEED - C                                                                *
                  --******************************************************************************************           
                   when 5 =>
                       s_out_number_select <= "00000010";  --information about control section to leds
                     
                     if ( buttons_clock = '1' ) then
                         --Zvysovani a snizovani hodnoty    
                         if (s_out_buttons_continuous(0) = '1') then  --button up
                                 s_engine_power_pwm_speed <= s_engine_power_pwm_speed + 1;                     
                         elsif (s_out_buttons_continuous(1) = '1') then  --button down
                                 s_engine_power_pwm_speed <= s_engine_power_pwm_speed - 1;   
                         end if; 
                     end if;
                     
                  --******************************************************************************************
                  --  SHOW VALUES COMING FROM ADC USING UP AND DOWN ARROWS, ALSO LIST INF REG OF DRV8305     *
                  --******************************************************************************************           
                   when 6 => 
                     --put to correct inteval if out of interval that this thing controls
                     --if higher than max controlled display value or lower that lowerst control display value
                     if (s_out_number_select > "00010101" OR s_out_number_select < "00001000") then
                        s_out_number_select <= "00001000";
                     end if;
                     
                     if ( buttons_clock = '1' ) then
                         --Zvysovani a snizovani hodnoty    
                         if (s_out_buttons_continuous(0) = '1') then  --button up
                             if (s_out_number_select < "00010101") then --maximum
                                 s_out_number_select <= std_logic_vector(to_unsigned(to_integer(unsigned(s_out_number_select))+1, s_out_number_select'length)); 
                             end if;                     
                         elsif (s_out_buttons_continuous(1) = '1') then  --button down
                             if (s_out_number_select > "00001000") then --minimum
                                 s_out_number_select <= std_logic_vector(to_unsigned(to_integer(unsigned(s_out_number_select))-1, s_out_number_select'length)); 
                             end if;  
                         end if; 
                     end if;
                      
                  --******************************************************************************************
                  --      LISTING THROUGH THE CONTROL REGISTERS OF DRV8305                                   *
                  --******************************************************************************************           
                   when 8 =>  
                       --put to correct inteval if out of interval that this thing controls
                     --if higher than max controlled display value or lower that lowerst control display value
                     if (s_out_number_select > "01000000" OR s_out_number_select < "00100000") then
                        s_out_number_select <= "00100000";
                     end if;
                       
                       if ( buttons_clock = '1' ) then
                         --Zvysovani a snizovani hodnoty    
                         if (s_out_buttons_continuous(0) = '1') then  --button up
                             if (s_out_number_select < "01000000") then
                                 s_out_number_select <= std_logic_vector(to_unsigned(to_integer(unsigned(s_out_number_select))+1, s_out_number_select'length)); 
                             end if;                     
                         elsif (s_out_buttons_continuous(1) = '1') then  --button down
                             if (s_out_number_select > "00100000") then
                                 s_out_number_select <= std_logic_vector(to_unsigned(to_integer(unsigned(s_out_number_select))-1, s_out_number_select'length)); 
                             end if;  
                         end if; 
                     end if;
                   when others =>
                       null;
             end case;   
         end if;    
     end process;

    --**********************************************************************************************
    --      DISPLAY INSTANTIATION                                                                  *
    --**********************************************************************************************   
        
    display_module : display
        PORT MAP(  clk                                  => clk,
                   in_reset                             => '0',
                    ----------------------
                   in_engine_rotaty_pwm_speed           => s_engine_rotaty_pwm_speed_conv,
                   in_engine_power_pwm_speed            => s_engine_power_pwm_speed_conv,
                   in_engine_power_pwm_duty             => s_engine_power_pwm_duty_conv,
                   -----------------------
                   in_recieved_SPI                      => OPEN,
                   in_recieved_COM_PORT                 => OPEN,
                   -----------------------
                   in_number_select                     => s_out_number_select,
                   --MEASURED VALUES BY ADC
                   in_sense_A                           => in_sense_A,    
                   in_sense_B                           => in_sense_B,    
                   in_sense_C                           => in_sense_C,    
                   in_sense_PVDD                        => in_sense_PVDD, 
                   in_voltage_A                         => in_voltage_A,  
                   in_voltage_B                         => in_voltage_B,  
                   in_voltage_C                         => in_voltage_C,  
                   in_temperature                       => in_temperature,
                   in_error_code_reg_1                  => in_error_code_reg_1,
                   in_error_code_reg_2                  => in_error_code_reg_2,
                   in_error_code_reg_3                  => in_error_code_reg_3,
                   in_error_code_reg_4                  => in_error_code_reg_4,
                   in_values_vector                     => in_values_vector,
                   in_time_between_commutation_in_pulses => s_time_between_commutation_in_pulses,
                   in_current_state                     => s_current_state,
                   out_display_an                       => out_display_an,
                   out_display_led                      => out_display_led); 
    
    --**********************************************************************************************
    --      DIVIDER FOR TRIGERRING THE TRANSMITTER COMPONENT                                       *
    --**********************************************************************************************
    buttons_debouncer_instance : buttons_debouncer
        PORT MAP( clk                                   => clk,
                  in_btn_Mid                            => in_btnC,
                  in_btnU                               => in_btnU,
                  in_btnD                               => in_btnD,
                  in_btnL                               => in_btnL,
                  in_btnR                               => in_btnR,
                  out_buttons_pulse                     => s_out_buttons_pulse,
                  out_buttons_continuous                => s_out_buttons_continuous);
                  
    buttons_speed_instance : clk_divider  --sets how fast when pressing button values change
        GENERIC MAP( max => c_cnt_10Hz) 
        PORT MAP(    clk                                => clk,
                     divider_clock_multiplier           => "00000001",
                     divider_clock_output               => open,
                     divider_pulse_output               => buttons_clock);
                     
    change_speed_button_clock_instance : clk_divider  --sets how fast when pressing button values change
        GENERIC MAP( max => c_cnt_100Hz) 
        PORT MAP(    clk                                => clk,
                     divider_clock_multiplier           => "00000001",
                     divider_clock_output               => open,
                     divider_pulse_output               => change_speed_button_clock);
    
    pwm_vhdl_instance : motor_control_with_start_sequence
        PORT MAP( --INPUTS
                  clk                                   => clk,
                  in_control_state                      => s_control_state_conv,
                  in_comparators                        => in_comparators,
                  --speed control
                  in_speed_increase                     => s_speed_increase,
                  in_speed_decrease                     => s_speed_decrease,
                  --duty control
                  in_duty_increase                      => s_duty_increase,   
                  in_duty_decrease                      => s_duty_decrease,
                  out_engine_rotaty_pwm_speed           => s_engine_rotaty_pwm_speed_conv,
                  out_engine_power_pwm_duty             => s_engine_power_pwm_duty_conv,
                  in_engine_power_pwm_speed             => s_engine_power_pwm_speed_conv,
                  --MEASURED VALUES
                  in_sense_PVDD                        => in_sense_PVDD, 
                  in_voltage_A                         => in_voltage_A,  
                  in_voltage_B                         => in_voltage_B,  
                  in_voltage_C                         => in_voltage_C, 
                  --OUTPUTS
                  out_pwm_driver_output                => out_pwm_driver_output,
                  
                  out_time_between_commutation_in_pulses   => s_time_between_commutation_in_pulses,
                  out_current_state                    => s_current_state);
                       
--    adc_values_convertor_instance : adc_values_convertor                   
--        PORT MAP (  clk                                 => clk,
--                    in_sense_A                          => in_sense_A,    
--                    in_sense_B                          => in_sense_B,    
--                    in_sense_C                          => in_sense_C,    
--                    in_sense_PVDD                       => in_sense_PVDD, 
--                    in_voltage_A                        => in_voltage_A,  
--                    in_voltage_B                        => in_voltage_B,  
--                    in_voltage_C                        => in_voltage_C,  
--                    in_temperature                      => in_temperature,
--                    out_sense_A                         => s_ADC_output_values_array(0),
--                    out_sense_B                         => s_ADC_output_values_array(1),
--                    out_sense_C                         => s_ADC_output_values_array(2),
--                    out_sense_PVDD                      => s_ADC_output_values_array(3),
--                    out_voltage_A                       => s_ADC_output_values_array(4),
--                    out_voltage_B                       => s_ADC_output_values_array(5),
--                    out_voltage_C                       => s_ADC_output_values_array(6),
--                    out_temperature                     => s_ADC_output_values_array(7));
  
end Behavioral;
