/***************************************************************************
*
* File Name: C:\Users\b35258\OneDrive - Freescale Semiconductor\PMSM - DevKit\SW\MC9S12ZVML128_PMSM_Sensorless\Config\PMSMFOC_appconfig.h
*
* Description: Automatically generated file for static configuration
*              of the PMSM FOC application
*
****************************************************************************.*/

#ifndef __PMSMFOC_CONFIG_SETUP_H
#define __PMSMFOC_CONFIG_SETUP_H

/*.*************************************************************************
*
*  File generated by PMSMFOC XLS Configurator 6/8/2015
*
****************************************************************************.*/

/*                                               
* Application Scales                             
*/                                               
#define I_MAX                                    (10.0)
#define U_DCB_MAX                                (25.0)
#define U_MAX                                    (25.0)
#define MOTOR_I_PH_NOM                           (5.8)
#define W_MAX                                    (4000.0)
#define TEMP_MAX                                 (645.2)

/*                                               
Motor Parameters                                 
*  Stator resistance, MOTOR_RS                   =0.1498[O]
*  Direct axis inductance, MOTOR_LD              =0.000131[H]
*  Quadrature axis inductance, MOTOR_LQ          =0.000131[H]
*  Back-EMF constant, MOTOR_KE                   =0.001769[V.sec.rad-1]
*  Torque constant, MOTOR_KT                     =0.010614[Nm/A]
*  Number of pole-pairs, MOTOR_PP                =4[-]
*  Inertia, MOTOR_J                              =0.0000005[kg.m2]
*  Friction, MOTOR_B                             =0[Nm/rad/sec]
*  Nominal continuous phase current(Amplitude), MOTOR_I_PH_NOM
                                                 =5.8[A]
*  Nominal angular velocity, MOTOR_W_NOM         =3769[rad.sec-1]
*  Angular velocity measurement scale, W_MAX     =4000[rad.sec-1]
*/                                               
#define MOTOR_KE                                 FRAC16(0.001769)
#define EMF_COUPLING_GAIN                        FRAC16(0.56608)
#define EMF_COUPLING_SHIFT                       (-1)

/*                                               
* Mechanical alignment                           
*/                                               
#define ALIGN_DURATION                           (30000)
#define ALIGN_VOLTAGE                            FRAC16(0.1200)

/*                                               
* Current Loop Control                           
* ---------------------------                    
*  Loop bandwidth                                =400 [Hz]
*  Loop attenuation                              =0.9 [-]
*  Loop sample time                              =100 [µs]
*/                                                
// D - axis controller                           
#define D_CC1SC                                  FRAC16(0.3873627359)
#define D_CC2SC                                  FRAC16(-0.3211653252)
#define D_NSHIFT                                 (0)

// Q - axis controller                           
#define Q_CC1SC                                  FRAC16(0.387362736)
#define Q_CC2SC                                  FRAC16(-0.321165325)
#define Q_NSHIFT                                 (0)

// D - axis zero cancelation                     
#define D_B0                                     FRAC16(0.0196799885)
#define D_B1                                     FRAC16(0.0)
#define D_A1                                     FRAC16(-0.1053200115)

// Q - axis zero cancelation                     
#define Q_B0                                     FRAC16(0.0196799885)
#define Q_B1                                     FRAC16(0.0)
#define Q_A1                                     FRAC16(-0.1053200115)

/*                                               
* Speed oop Control                              
* ---------------------------                    
*  Loop sample time                              =1 [ms]
*  Loop bandwidth                                =10 [Hz]
*  Loop attenuation                              =1 [-]
*/                                                
#define SPEED_LOOP_CNTR                          10
#define SPEED_RAMP_UP                            (101198)
#define SPEED_RAMP_DOWN                          (101198)
#define SPEED_PI_PROP_GAIN                       FRAC16(0.591971482)
#define SPEED_PI_PROP_GAIN_SHIFT                 (1)
#define SPEED_PI_INTEG_GAIN                      FRAC16(0.595114643)
#define SPEED_PI_INTEG_GAIN_SHIFT                (-5)

/*                                               
* Back EMF PI controllers                        
* ---------------------------                    
*  Bandwidth                                     =400 [Hz]
*  Attenuation                                   =0.85 [-]
*  Sample time                                   =100 [µs]
*/                                               
#define EMF_KP_GAIN                              FRAC16(0.708528061)
#define EMF_KI_GAIN                              FRAC16(0.529579285)
#define EMF_KP_SCALE                             (1)
#define EMF_KI_SCALE                             (4)

/*                                               
Sensorless - plant constants                     
*/                                               
#define K1_SlsPlant                              FRAC16(0.856281682)
#define K2_SlsPlant                              FRAC16(0.358953281)
#define K3_SlsPlant                              FRAC16(0.856281682)
#define K4_SlsPlant                              FRAC16(0.897383203)
#define Kscale_SlsPlant                          (0)
#define Ki_SlsAto                                FRAC16(0)

/*                                               
* Error Frame Optimizer                          
* ---------------------------                    
*  Bandwidth                                     =30 [Hz]
*  Attenuation                                   =0.85 [-]
*  Sample time                                   =100 [µs]
*/                                               
#define TO_KP_GAIN                               FRAC16(0.503349824)
#define TO_KI_GAIN                               FRAC16(0.714384615)
#define TO_KP_SCALE                              (1)
#define TO_KI_SCALE                              (-9)
#define TO_INTEG_C1                              FRAC16(0.063661977)
#define TO_INTEG_NSHIFT                          (0)

#define TO_CC1SC                                 FRAC16(0.2530701947)
#define TO_CC2SC                                 FRAC16(-0.2502796298)
#define TO_NSHIFT                                (0)



/*                                               
* Open Loop to Sensroless transient              
* ---------------------------                    
*  Transition is performed at speed of           =113.07[rad.sec-1]
*/                                               
#define MATCHING_W_EL                            FRAC16(0.0282675)

/*                                               
* Open Loop to Sensroless transient              
* ---------------------------                    
*  Current Limit in OpenLoop Mode                =2 [A]
*  Current Limit in Sensorless mode              =5.8 [A]
*/                                               
#define CUR_LIM_OPENLOOP                         FRAC16(0.1)
#define CUR_LIM_SENSORLESS                       FRAC16(0.29)


/*                                               
* TRIPS/FAULTD Setup                             
* ---------------------------                    
*  Trip DC-bus over-voltage                      =16[V]
*  Fault DC-bus over-voltage                     =17[V]
*  Trip DC-bus under-voltage                     =9[V]
*  Fault DC-bus over-voltage                     =8[V]
*  Trip Phase over-current                       =7.54[A]
*  Fault Phase over-current                      =9.28[A]
*  Trip overheating                              =100[C]
*  Fault overheating                             =110[C]
*/                                               
#define U_DCB_OVERVOLTAGE_TRIP                   (16.0)
#define U_DCB_OVERVOLTAGE_FAULT                  (17.0)
#define U_DCB_UNDERVOLTAGE_TRIP                  (9.0)
#define U_DCB_UNDERVOLTAGE_FAULT                 (8.0)
#define I_PH_OVERCURRENT_TRIP                    (7.5)
#define I_PH_OVERCURRENT_FAULT                   (9.3)
#define TEMP_TRIP                                (100.0)
#define TEMP_FAULT                               (110.0)


/*                                               
* FreeMASTER Scale Variables                     
* note: scaled at input = 1000                   
*/                                               
#define FM_I_SCALE                               (20000)
#define FM_U_SCALE                               (25000)
#define FM_UDCB_SCALE                            (25000)
#define FM_SPEED_RAD_EL_SCALE                    (4000000)
#define FM_SPEED_RMP_MECH_SCALE                  (9549297)
#define FM_POSITION_DEG_SCALE                    (180000)
#define FM_SPEED_RAMP_RPM_SCALE                  (224884)

/*.         End of autogenerated code
********************************************************************** ..*/
#endif
