An example of importing Embedded Coder code into the mbed IDE. Currently doesn't connect IO to PWM, ADC, and Encoder, instead provides random inputs and measures execution time.
Dependencies: mbed-dsp mbed Nucleo_pmsmfoc
rtwdemo_pmsmfoc.h
- Committer:
- paulcox
- Date:
- 2014-11-25
- Revision:
- 2:bbc155b0b886
- Parent:
- 0:70d27fec6d71
File content as of revision 2:bbc155b0b886:
/* * File: rtwdemo_pmsmfoc.h * * Code generated for Simulink model 'rtwdemo_pmsmfoc'. * * Model version : 1.2949 * Simulink Coder version : 8.7 (R2014b) 11-Aug-2014 * C/C++ source code generated on : Sat Oct 11 00:06:05 2014 * * Target selection: ert.tlc * Embedded hardware selection: Generic->32-bit Embedded Processor * Code generation objective: Execution efficiency * Validation result: Not run */ #ifndef RTW_HEADER_rtwdemo_pmsmfoc_h_ #define RTW_HEADER_rtwdemo_pmsmfoc_h_ #include "rtwtypes.h" #include <float.h> #include <math.h> #include <string.h> #ifndef rtwdemo_pmsmfoc_COMMON_INCLUDES_ # define rtwdemo_pmsmfoc_COMMON_INCLUDES_ #include "rtwtypes.h" #endif /* rtwdemo_pmsmfoc_COMMON_INCLUDES_ */ /* Macros for accessing real-time model data structure */ /* Forward declaration for rtModel */ typedef struct tag_RTM RT_MODEL; #ifndef _DEFINED_TYPEDEF_FOR_EnumErrorType_ #define _DEFINED_TYPEDEF_FOR_EnumErrorType_ typedef enum { NoError = 0, /* Default value */ MeasuredVelocityError } EnumErrorType; #endif #ifndef _DEFINED_TYPEDEF_FOR_EnumCommandType_ #define _DEFINED_TYPEDEF_FOR_EnumCommandType_ typedef enum { Torque = 0, /* Default value */ Velocity, Position } EnumCommandType; #endif #ifndef _DEFINED_TYPEDEF_FOR_EnumControllerMode_ #define _DEFINED_TYPEDEF_FOR_EnumControllerMode_ typedef enum { StandBy = 0, /* Default value */ Startup, TorqueControl, VelocityControl, PositionControl } EnumControllerMode; #endif #ifndef _DEFINED_TYPEDEF_FOR_SENSORS_STRUCT_ #define _DEFINED_TYPEDEF_FOR_SENSORS_STRUCT_ typedef struct { uint16_T adc_phase_currents[2]; uint16_T encoder_valid; uint16_T encoder_counter; } SENSORS_STRUCT; #endif #ifndef _DEFINED_TYPEDEF_FOR_CTRLPARAMS_STRUCT_ #define _DEFINED_TYPEDEF_FOR_CTRLPARAMS_STRUCT_ typedef struct { real32_T Current_P; real32_T Current_I; real32_T Velocity_P; real32_T Velocity_I; real32_T Position_P; real32_T Position_I; real32_T StartupAcceleration; real32_T StartupCurrent; real32_T RampToStopVelocity; real32_T AdcZeroOffsetDriverUnits; real32_T AdcDriverUnitsToAmps; real32_T EncoderToMechanicalZeroOffsetRads; real32_T PmsmPolePairs; } CTRLPARAMS_STRUCT; #endif /* Block signals and states (auto storage) for system '<Root>' */ typedef struct { real32_T Merge; /* '<S5>/Merge' */ real32_T position; /* '<S63>/Integrate_To_Position' */ real32_T velocity_command; /* '<S1>/Controller_Mode_Scheduler' */ real32_T position_command; /* '<S1>/Controller_Mode_Scheduler' */ real32_T torque_command; /* '<S1>/Controller_Mode_Scheduler' */ real32_T Integrator_DSTATE; /* '<S17>/Integrator' */ real32_T Integrator_DSTATE_l; /* '<S18>/Integrator' */ real32_T Velocity_Delay_DSTATE; /* '<S58>/Velocity_Delay' */ real32_T Integrate_To_Position_DSTATE;/* '<S63>/Integrate_To_Position' */ real32_T Integrate_To_Velocity_DSTATE;/* '<S63>/Integrate_To_Velocity' */ real32_T Integrator_DSTATE_lc; /* '<S42>/Integrator' */ real32_T Integrator_DSTATE_f; /* '<S45>/Integrator' */ int32_T Position_Delay_DSTATE; /* '<S55>/Position_Delay' */ EnumErrorType error_l; /* '<Root>/Data Store Memory' */ int16_T DelayInput1_DSTATE; /* '<S13>/Delay Input1' */ uint16_T Position_Valid; /* '<S49>/Wait_For_Valid_Position' */ int8_T Integrator_PrevResetState; /* '<S17>/Integrator' */ int8_T SwitchCase_ActiveSubsystem; /* '<S5>/Switch Case' */ int8_T Integrator_PrevResetState_c; /* '<S18>/Integrator' */ uint8_T is_active_c2_rtwdemo_pmsmfoc;/* '<S49>/Wait_For_Valid_Position' */ uint8_T is_c2_rtwdemo_pmsmfoc; /* '<S49>/Wait_For_Valid_Position' */ uint8_T temporalCounter_i1; /* '<S49>/Wait_For_Valid_Position' */ uint8_T is_c1_rtwdemo_pmsmfoc; /* '<S1>/Controller_Mode_Scheduler' */ uint8_T is_Motor_On; /* '<S1>/Controller_Mode_Scheduler' */ uint8_T is_Motor_Control; /* '<S1>/Controller_Mode_Scheduler' */ boolean_T RelationalOperator_a; /* '<S51>/Relational Operator' */ boolean_T Lo_to_Hi_Rate_Transition3_Buffe;/* '<S6>/Lo_to_Hi_Rate_Transition3' */ boolean_T OpenLoopPosition_MODE; /* '<S51>/Open Loop Position' */ } D_Work; /* Constant parameters (auto storage) */ typedef struct { /* Computed Parameter: Lookup_Table_table * Referenced by: '<S28>/Lookup_Table' */ uint16_T Lookup_Table_table[7]; } ConstParam; /* Real-time Model Data Structure */ struct tag_RTM { /* * Timing: * The following substructure contains information regarding * the timing information for the model. */ struct { struct { uint8_T TID[2]; } TaskCounters; } Timing; }; /* Block signals and states (auto storage) */ extern D_Work DWork; /* Constant parameters (auto storage) */ extern const ConstParam ConstP; /* * Exported Global Signals * * Note: Exported global signals are block signals with an exported global * storage class designation. Code generation will declare the memory for * these signals and export their symbols. * */ extern real32_T phase_currents[2]; /* '<S48>/Product' */ extern real32_T rotor_position; /* '<S49>/Add' */ extern real32_T velocity_measured; /* '<S55>/Scale_Output' */ extern real32_T d_current_error; /* '<S12>/Sum2' */ extern real32_T q_current_command; /* '<S5>/Lo_to_Hi_Rate_Transition1' */ extern real32_T q_current_measured; /* '<S22>/Add' */ extern real32_T q_current_error; /* '<S12>/Sum' */ extern real32_T phase_voltages[3]; /* '<S27>/Select_Sector' */ extern real32_T velocity_error; /* '<S11>/Sum2' */ extern EnumControllerMode controller_mode;/* '<S1>/Controller_Mode_Scheduler' */ /* * Exported Global Parameters * * Note: Exported global parameters are tunable parameters with an exported * global storage class designation. Code generation will declare the memory for * these parameters and exports their symbols. * */ extern CTRLPARAMS_STRUCT ctrlParams; /* Variable: ctrlParams * Referenced by: * '<S1>/Controller_Mode_Scheduler' * '<S48>/ADC_Driver_Units_To_Amps' * '<S48>/ADC_Zero_Offset' * '<S49>/Offset_Between_Encoder_Zero_And_Mechanical_Zero' * '<S14>/number_of_pole_pairs' * '<S42>/Integral Gain' * '<S42>/Proportional Gain' * '<S45>/Integral Gain' * '<S45>/Proportional Gain' * '<S63>/Startup_Acceleration_Constant' * '<S17>/Integral Gain' * '<S17>/Proportional Gain' * '<S18>/Integral Gain' * '<S18>/Proportional Gain' */ /* Model entry point functions */ extern "C" void Controller_Init(void); /* Customized model step function */ extern "C" EnumErrorType Controller(uint16_T motor_on, EnumCommandType command_type, real32_T current_request, SENSORS_STRUCT *sensors, uint16_T pwm_compare[3]); /* Real-time Model object */ extern RT_MODEL *const M; /*- * The generated code includes comments that allow you to trace directly * back to the appropriate location in the model. The basic format * is <system>/block_name, where system is the system number (uniquely * assigned by Simulink) and block_name is the name of the block. * * Use the MATLAB hilite_system command to trace the generated code back * to the model. For example, * * hilite_system('<S3>') - opens system 3 * hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3 * * Here is the system hierarchy for this model * * '<Root>' : 'rtwdemo_pmsmfoc' * '<S1>' : 'rtwdemo_pmsmfoc/Mode_Scheduler' * '<S2>' : 'rtwdemo_pmsmfoc/Model Info' * '<S3>' : 'rtwdemo_pmsmfoc/Motor_Control' * '<S4>' : 'rtwdemo_pmsmfoc/Mode_Scheduler/Controller_Mode_Scheduler' * '<S5>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller' * '<S6>' : 'rtwdemo_pmsmfoc/Motor_Control/Phase_Voltages_to_PWM_Compare_Values' * '<S7>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units' * '<S8>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control' * '<S9>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Position_Control' * '<S10>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Torque_Control' * '<S11>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Velocity_Control' * '<S12>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Current_Controllers' * '<S13>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Detect_Change' * '<S14>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Rotation_Coefficients_Sin_Cos' * '<S15>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_ABC_to_dq' * '<S16>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC' * '<S17>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Current_Controllers/Direct_Current_Control' * '<S18>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Current_Controllers/Quadrature_Current_Control' * '<S19>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Current_Controllers/Direct_Current_Control/Clamping circuit' * '<S20>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Current_Controllers/Quadrature_Current_Control/Clamping circuit' * '<S21>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_ABC_to_dq/Clarke_Transform' * '<S22>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_ABC_to_dq/Park_Transform' * '<S23>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC' * '<S24>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Inverse_Park_Transform' * '<S25>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Inverse_Clarke_Transform' * '<S26>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation' * '<S27>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages' * '<S28>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Determine_Sector' * '<S29>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Phase_Advanced_Inverse_Clarke' * '<S30>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Va_Sectors_1_and_4' * '<S31>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Va_Sectors_2_and_5' * '<S32>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Va_Sectors_3_and_6' * '<S33>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Vb_Sectors_1_and_4' * '<S34>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Vb_Sectors_2_and_5' * '<S35>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Vb_Sectors_3_and_6' * '<S36>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Vc_Sectors_1_and_4' * '<S37>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Vc_Sectors_2_and_5' * '<S38>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Vc_Sectors_3_and_6' * '<S39>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Determine_Sector/Compare_VA_To_Zero' * '<S40>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Determine_Sector/Compare_VB_To_Zero' * '<S41>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Determine_Sector/Compare_VC_To_Zero' * '<S42>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Position_Control/Position_Control' * '<S43>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Position_Control/Wrap_Error_pi' * '<S44>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Position_Control/Position_Control/Clamping circuit' * '<S45>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Velocity_Control/Rotor_Speed_Control' * '<S46>' : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Velocity_Control/Rotor_Speed_Control/Clamping circuit' * '<S47>' : 'rtwdemo_pmsmfoc/Motor_Control/Phase_Voltages_to_PWM_Compare_Values/Enumerated_Constant' * '<S48>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/ADC_Level_to_Phase_Current' * '<S49>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Encoder_To_Position' * '<S50>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity' * '<S51>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Startup_Open_Loop_Control' * '<S52>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Encoder_To_Position/Wait_For_Valid_Position' * '<S53>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Explicit_Angle_Wrap' * '<S54>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Explicit_Angle_Wrap_With_Error' * '<S55>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Implicit_Integer_Wrap_With_Error' * '<S56>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Explicit_Angle_Wrap_With_Error/Detect_Velocity_Error' * '<S57>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Explicit_Angle_Wrap_With_Error/Detect_Velocity_Error/Generate_Error' * '<S58>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Implicit_Integer_Wrap_With_Error/Detect_Velocity_Error' * '<S59>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Implicit_Integer_Wrap_With_Error/Detect_Velocity_Error/Enumerated_Constant' * '<S60>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Implicit_Integer_Wrap_With_Error/Detect_Velocity_Error/Generate_Error' * '<S61>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Implicit_Integer_Wrap_With_Error/Detect_Velocity_Error/Generate_Error/Enumerated_Constant' * '<S62>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Startup_Open_Loop_Control/Enumerated Constant' * '<S63>' : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Startup_Open_Loop_Control/Open Loop Position' */ /*- * Requirements for '<Root>': rtwdemo_pmsmfoc */ #endif /* RTW_HEADER_rtwdemo_pmsmfoc_h_ */ /* * File trailer for generated code. * * [EOF] */