383
Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Embed Size (px)

Citation preview

Page 1: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Kinetis Motor Suite API Reference Manual

Kinetis Motor Suite v1.2.0

Document Number: KMSRMRev. 3

Nov 2017

Page 2: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017
Page 3: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

ContentsChapter 1

Kinetis Motor Suite

1.1 Firmware Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.2 Field Oriented Control Data Flow . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1.3 Interrupt Service Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

1.4 Additional Control Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

Chapter 2User

2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

2.2 Sensorless Velocity Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302.2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302.2.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322.2.2.1 struct USER_config_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322.2.2.2 struct USER_internal_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332.2.2.3 struct USER_command_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332.2.2.4 struct USER_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342.2.2.5 struct USER_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342.2.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 352.2.3.1 SCM_CHANGE_TIME_COUNT . . . . . . . . . . . . . . . . . . . . . . . . 352.2.3.2 SCM_HI_SCM_THD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352.2.3.3 SCM_LO_SCM_THD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352.2.3.4 SCM_LS_OFF_TIME_COUNT . . . . . . . . . . . . . . . . . . . . . . . . . 352.2.3.5 SCM_LS_STEADY_STATE_TIME_COUNT . . . . . . . . . . . . . . . . . 352.2.3.6 SCM_PM_STEADY_STATE_TIME_COUNT . . . . . . . . . . . . . . . . . 352.2.3.7 SCM_RS_STEADY_STATE_TIME_COUNT . . . . . . . . . . . . . . . . . 362.2.4 Enumeration Type Documentation . . . . . . . . . . . . . . . . . . . . . . . . . 362.2.4.1 USER_state_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362.2.5 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362.2.5.1 USER_cfgBrake . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

NXP SemiconductorsKinetis Motor Suite API Reference Manual

iii

Page 4: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

2.2.5.2 USER_cfgInertia . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362.2.5.3 USER_cfgSCM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372.2.5.4 USER_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372.2.5.5 USER_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382.2.5.6 USER_initStructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382.2.5.7 USER_OnEntry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392.2.5.8 USER_onEntryBrake . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392.2.5.9 USER_onEntryCurrent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402.2.5.10 USER_onEntryDuty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402.2.5.11 USER_onEntryFault . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412.2.5.12 USER_onEntryIdle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412.2.5.13 USER_onEntryInertia . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422.2.5.14 USER_onEntryPlan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422.2.5.15 USER_onEntryScm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422.2.5.16 USER_onEntrySpeed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432.2.5.17 USER_onEntryVoltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432.2.5.18 USER_OnExit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442.2.5.19 USER_resetDRVCommands . . . . . . . . . . . . . . . . . . . . . . . . . . . 442.2.5.20 USER_runBrakeStateFastTick . . . . . . . . . . . . . . . . . . . . . . . . . . 452.2.5.21 USER_runBrakeStateSlowTick . . . . . . . . . . . . . . . . . . . . . . . . . 452.2.5.22 USER_runCurrentState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462.2.5.23 USER_runDutyState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472.2.5.24 USER_runFaultState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472.2.5.25 USER_runIdleState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482.2.5.26 USER_runInertiaState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482.2.5.27 USER_runPlanState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492.2.5.28 USER_runScmState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502.2.5.29 USER_runSpeedState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512.2.5.30 USER_runStartupRetry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512.2.5.31 USER_runVoltageState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512.2.5.32 USER_selfCommissioningState . . . . . . . . . . . . . . . . . . . . . . . . . 522.2.5.33 USER_setInertiaOutput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522.2.5.34 USER_updateFastTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522.2.5.35 USER_updateSlowTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532.2.6 Variable Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532.2.6.1 brake . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532.2.6.2 inertia . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542.2.6.3 pVelPlan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542.2.6.4 scm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542.2.6.5 VelPlan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

2.3 Sensored Velocity Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

2.4 Sensored Position Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

ivKinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 5: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

Chapter 3Self Commissioning

3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

3.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613.2.1 struct SCM_config_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613.2.2 struct SCM_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623.2.3 struct SCM_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

3.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 623.3.1 SCM_PRV_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

3.4 Enumeration Type Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 633.4.1 SCM_state_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

3.5 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633.5.1 SCM_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633.5.2 SCM_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633.5.3 SCM_measureStatorInductanceCurrent . . . . . . . . . . . . . . . . . . . . . . . 633.5.4 SCM_resetOutputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643.5.5 SCM_updateFastTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643.5.6 SCM_updateSlowTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

Chapter 4Inertia

4.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

4.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684.2.1 struct INERTIA_config_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684.2.2 struct INERTIA_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 694.2.3 struct INERTIA_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 694.2.4 struct INERTIA_Status_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

4.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 704.3.1 INERTIA_PRV_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

4.4 Enumeration Type Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 704.4.1 INERTIA_Status_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

4.5 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704.5.1 INERTIA_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704.5.2 INERTIA_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

NXP SemiconductorsKinetis Motor Suite API Reference Manual

v

Page 6: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

4.5.3 INERTIA_reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714.5.4 INERTIA_run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714.5.5 INERTIA_setOutput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

Chapter 5Brake

5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

5.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 755.2.1 struct BRAKE_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 755.2.2 struct BRAKE_config_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 765.2.3 struct BRAKE_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

5.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 775.3.1 BRAKE_PRV_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

5.4 Enumeration Type Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 775.4.1 BRAKE_type_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

5.5 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775.5.1 BRAKE_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775.5.2 BRAKE_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775.5.3 BRAKE_run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

Chapter 6Drive State Machine

6.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

6.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 826.2.1 struct DSM_faultThresholds_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . 826.2.2 union DSM_clrFaults_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836.2.3 struct DSM_clrFaults_t::DSM_clrFaultsBits_s . . . . . . . . . . . . . . . . . . . 836.2.4 union DSM_nonClrFaults_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 866.2.5 struct DSM_nonClrFaults_t::DSM_nonClrFaultsBits_s . . . . . . . . . . . . . . 866.2.6 struct DSM_internal_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 876.2.7 struct DSM_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886.2.8 union DSM_clrFaults_u . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886.2.9 union DSM_nonClrFaults_u . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

6.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 896.3.1 DSM_PK_CURRENT_FAULT_COUNTER . . . . . . . . . . . . . . . . . . . . 89

viKinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 7: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

6.3.2 DSM_RESET_LINE_HOLD_TIME . . . . . . . . . . . . . . . . . . . . . . . . 89

6.4 Typedef Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 896.4.1 bitfield_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

6.5 Enumeration Type Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 896.5.1 DRV_control_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 896.5.2 DSM_state_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

6.6 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906.6.1 DSM_configFaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906.6.2 DSM_faultState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906.6.3 DSM_idleState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906.6.4 DSM_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 916.6.5 DSM_resetFaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 916.6.6 DSM_runTimeMonitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 926.6.7 DSM_startState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 926.6.8 DSM_updateAtFastTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 936.6.9 DSM_updateSlowTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 936.6.10 DSMS_CalculateTemperature . . . . . . . . . . . . . . . . . . . . . . . . . . . . 946.6.11 DSMS_ClearableFaultsReset . . . . . . . . . . . . . . . . . . . . . . . . . . . . 946.6.12 DSMS_GetClearableFaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 946.6.13 DSMS_GetNonClearableFaults . . . . . . . . . . . . . . . . . . . . . . . . . . . 946.6.14 DSMS_hwFaultReset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 956.6.15 DSMS_Init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 956.6.16 InitSPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

6.7 Variable Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 966.7.1 g_sM1Driver3ph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 966.7.2 g_sM1Driver3phInit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

Chapter 7Field Oriented Control

7.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

7.2 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 997.2.1 FULL_SCALE_CURRENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 997.2.2 FULL_SCALE_FLUX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 997.2.3 FULL_SCALE_INDUCTANCE . . . . . . . . . . . . . . . . . . . . . . . . . . 997.2.4 FULL_SCALE_POWER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 997.2.5 FULL_SCALE_RESISTANCE . . . . . . . . . . . . . . . . . . . . . . . . . . . 1007.2.6 FULL_SCALE_SPEED_RPM . . . . . . . . . . . . . . . . . . . . . . . . . . . 1007.2.7 FULL_SCALE_SPEED_WE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100

NXP SemiconductorsKinetis Motor Suite API Reference Manual

vii

Page 8: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

7.2.8 FULL_SCALE_TORQUE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1007.2.9 FULL_SCALE_VOLTAGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100

7.3 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1007.3.1 DRV_forceToIdle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1007.3.2 DRV_getDcbBusUnderVoltageThreshold . . . . . . . . . . . . . . . . . . . . . . 1017.3.3 DRV_getDcbBusVoltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1017.3.4 DRV_getIsFaultActive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1017.3.5 DRV_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1017.3.6 DRV_motorStall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1017.3.7 DRV_updateSlowTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1027.3.8 UpdateAtFastTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

7.4 Variable Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1027.4.1 flashSysParamsHeader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

Chapter 8Trajectory - Velocity

8.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103

8.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1078.2.1 struct TRAJVEL_config_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1078.2.2 struct TRAJVEL_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1078.2.3 struct TRAJVEL_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

8.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 1088.3.1 TRAJVEL_PRV_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

8.4 Enumeration Type Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 1088.4.1 TRAJVEL_CurveType_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1088.4.2 TRAJVEL_Status_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

8.5 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1098.5.1 TRAJVEL_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1098.5.2 TRAJVEL_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1098.5.3 TRAJVEL_reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1098.5.4 TRAJVEL_run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

Chapter 9Trajectory - Position

9.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

viiiKinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 9: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

9.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1159.2.1 struct TRAJPOS_config_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1159.2.2 struct TRAJPOS_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1169.2.3 struct TRAJPOS_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

9.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 1179.3.1 TRAJPOS_PRV_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

9.4 Enumeration Type Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 1179.4.1 TRAJPOS_CurveType_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1179.4.2 TRAJPOS_ProfileType_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1179.4.3 TRAJPOS_Status_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

9.5 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1189.5.1 TRAJPOS_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1189.5.2 TRAJPOS_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1189.5.3 TRAJPOS_reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1189.5.4 TRAJPOS_run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118

Chapter 10Speed Control

10.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121

10.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12410.2.1 struct SPEED_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12410.2.2 struct SPEED_config_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12410.2.3 struct SPEED_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

10.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 12510.3.1 SPEED_PRV_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

10.4 Enumeration Type Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 12510.4.1 SPEED_status_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

10.5 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12510.5.1 SPEED_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12510.5.2 SPEED_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12610.5.3 SPEED_reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12610.5.4 SPEED_run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12610.5.5 SPEED_set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127

NXP SemiconductorsKinetis Motor Suite API Reference Manual

ix

Page 10: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

Chapter 11Position Control

11.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

11.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13111.2.1 struct POSITION_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13111.2.2 struct POSITION_config_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13211.2.3 struct POSITION_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

11.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 13311.3.1 POSITION_PRV_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

11.4 Enumeration Type Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 13311.4.1 POSITION_status_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

11.5 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13311.5.1 POSITION_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13311.5.2 POSITION_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13411.5.3 POSITION_reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13411.5.4 POSITION_run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

Chapter 12Field Weakening

12.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

12.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13712.2.1 struct FW_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13712.2.2 struct FW_config_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13712.2.3 struct FW_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137

12.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 13712.3.1 FW_PRV_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137

12.4 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13812.4.1 FW_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13812.4.2 FW_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13812.4.3 FW_resetController . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13812.4.4 FW_run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

xKinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 11: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

Chapter 13Feedback

13.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139

13.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14113.2.1 struct FEEDBACK_internal_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14113.2.2 struct FEEDBACK_calib_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14213.2.3 struct FEEDBACK_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14213.2.4 struct ADC_results_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14213.2.5 struct FEEDBACK_gains_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14313.2.6 struct FEEDBACK_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

13.3 Enumeration Type Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 14413.3.1 FEEDBACK_State_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

13.4 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14413.4.1 FEEDBACK_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14413.4.2 FEEDBACK_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14413.4.3 FEEDBACK_run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

13.5 Analog to Digital Converter Interface . . . . . . . . . . . . . . . . . . . . . . . . 14613.5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14613.5.2 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14613.5.2.1 ADCS_clearIRQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14613.5.2.2 ADCS_clearPDBError . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14613.5.2.3 ADCS_disableInt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14613.5.2.4 ADCS_disablePDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14713.5.2.5 ADCS_enableInt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14713.5.2.6 ADCS_enablePDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14713.5.2.7 ADCS_getUserSamples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14713.5.2.8 ADCS_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14813.5.2.9 ADCS_readRawADC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148

Chapter 14Clarke Transform

14.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

14.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15114.2.1 struct CLARKE_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15114.2.2 struct CLARKE_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151

NXP SemiconductorsKinetis Motor Suite API Reference Manual

xi

Page 12: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

14.3 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15114.3.1 CLARKE_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15114.3.2 CLARKE_run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

Chapter 15Park Transform

15.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153

15.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15515.2.1 struct PARK_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15515.2.2 struct PARK_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

15.3 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15515.3.1 PARK_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15515.3.2 PARK_run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156

Chapter 16Startup

16.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

16.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16116.2.1 struct STARTUP_config_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16116.2.2 struct STARTUP_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16216.2.3 struct STARTUP_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162

16.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 16216.3.1 STARTUP_PRV_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162

16.4 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16316.4.1 STARTUP_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16316.4.2 STARTUP_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16316.4.3 STARTUP_reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16316.4.4 STARTUP_setAngle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16316.4.5 STARTUP_updateFastTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16416.4.6 STARTUP_updateSlowTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

Chapter 17Sensorless Estimator

17.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165

xiiKinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 13: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

17.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16817.2.1 struct EST_config_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16817.2.2 struct EST_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16817.2.3 struct EST_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

17.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 16917.3.1 EST_PRV_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

17.4 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17017.4.1 EST_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17017.4.2 EST_getStatorVoltageAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17017.4.3 EST_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17017.4.4 EST_reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17017.4.5 EST_updateFastTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17117.4.6 EST_updateSlowTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171

17.5 Flux Estimator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17217.5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17217.5.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17317.5.2.1 struct FLUXEST_config_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17317.5.2.2 struct FLUXEST_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17417.5.2.3 struct FLUXEST_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17417.5.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 17517.5.3.1 FLUXEST_PRV_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17517.5.4 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17517.5.4.1 FLUXEST_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17517.5.4.2 FLUXEST_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17517.5.4.3 FLUXEST_reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17517.5.4.4 FLUXEST_updateFastTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17617.5.4.5 FLUXEST_updateSlowTick . . . . . . . . . . . . . . . . . . . . . . . . . . . 176

Chapter 18Encoder

18.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

18.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17918.2.1 struct ENC_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17918.2.2 struct ENC_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179

18.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 17918.3.1 ENC_PRV_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179

18.4 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179

NXP SemiconductorsKinetis Motor Suite API Reference Manual

xiii

Page 14: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

18.4.1 ENC_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17918.4.2 ENC_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18018.4.3 ENC_reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18018.4.4 ENC_run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180

18.5 Quadrature Encoder Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18218.5.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18218.5.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18218.5.2.1 struct QEI_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18218.5.2.2 struct QEI_internal_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18318.5.2.3 struct QEI_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18318.5.3 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18318.5.3.1 QEI_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18318.5.3.2 QEI_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18418.5.3.3 QEI_resetEncoderAngle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18418.5.3.4 QEI_updateAtFastTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18418.5.3.5 QEIS_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18418.5.3.6 QEIS_initHallInputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18518.5.3.7 QEIS_readHallInputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18518.5.3.8 QEIS_readPositionCounter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18518.5.3.9 QEIS_swapTracks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18518.5.3.10 QEIS_writePositionCounter . . . . . . . . . . . . . . . . . . . . . . . . . . . 186

Chapter 19Hall-Effect Sensor

19.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

19.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18919.2.1 struct HALL_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18919.2.2 struct HALL_config_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18919.2.3 struct HALL_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18919.2.4 struct HALL_values_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190

19.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 19019.3.1 HALL_PRV_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190

19.4 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19019.4.1 HALL_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19019.4.2 HALL_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19019.4.3 HALL_run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19119.4.4 HALL_runIdentify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191

xivKinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 15: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

Chapter 20Current

20.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193

20.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19520.2.1 struct CURRENT_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19520.2.2 struct CURRENT_config_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19520.2.3 struct CURRENT_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196

20.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 19620.3.1 CURRENT_PRV_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196

20.4 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19620.4.1 CURRENT_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19620.4.2 CURRENT_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19720.4.3 CURRENT_resetController . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19720.4.4 CURRENT_resetFilters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19720.4.5 CURRENT_run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19820.4.6 CURRENT_setIntegrator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198

Chapter 21Inverse Park Transform

21.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199

21.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20121.2.1 struct IPARK_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20121.2.2 struct IPARK_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201

21.3 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20221.3.1 IPARK_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20221.3.2 IPARK_reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20221.3.3 IPARK_run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202

Chapter 22Space Vector Pulse Width Modulation

22.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205

22.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20722.2.1 struct SVPWM_config_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207

NXP SemiconductorsKinetis Motor Suite API Reference Manual

xv

Page 16: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

22.2.2 struct SVPWM_output_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20722.2.3 struct SVPWM_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208

22.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 20822.3.1 SVPWM_PRV_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208

22.4 Enumeration Type Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 20822.4.1 SVPWM_sector_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20822.4.2 SVPWM_state_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209

22.5 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20922.5.1 SVPWM_config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20922.5.2 SVPWM_disable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20922.5.3 SVPWM_enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20922.5.4 SVPWM_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20922.5.5 SVPWM_update2Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21022.5.6 SVPWM_updateFastTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21022.5.7 SVPWM_zeroVector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210

22.6 Pulse Width Modulation Interface . . . . . . . . . . . . . . . . . . . . . . . . . . 21122.6.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21122.6.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21122.6.2.1 struct PWMS_duty_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21122.6.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 21222.6.3.1 PWM_SYS_MIN_DEADTIME_US . . . . . . . . . . . . . . . . . . . . . . . 21222.6.4 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21222.6.4.1 PWMS_disable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21222.6.4.2 PWMS_enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21222.6.4.3 PWMS_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21222.6.4.4 PWMS_setDuties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213

Chapter 23Motion Sequence

23.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215

23.2 SpinTAC™ Velocity Plan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21823.2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21823.2.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22523.2.2.1 struct ST_PlanError_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22523.2.2.2 struct ST_VelPlan_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22623.2.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 22723.2.3.1 __ST_PLAN_ENUM__ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22723.2.3.2 __ST_PLAN_ERROR__ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227

xviKinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 17: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

23.2.3.3 ST_VEL_PLAN_ACT_DWORDS . . . . . . . . . . . . . . . . . . . . . . . . 22723.2.3.4 ST_VEL_PLAN_COND_DWORDS . . . . . . . . . . . . . . . . . . . . . . 22723.2.3.5 ST_VEL_PLAN_STATE_DWORDS . . . . . . . . . . . . . . . . . . . . . . 22723.2.3.6 ST_VEL_PLAN_TRAN_DWORDS . . . . . . . . . . . . . . . . . . . . . . . 22723.2.3.7 ST_VEL_PLAN_VAR_DWORDS . . . . . . . . . . . . . . . . . . . . . . . 22723.2.4 Typedef Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22723.2.4.1 ST_VELPLAN_Handle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22723.2.5 Enumeration Type Documentation . . . . . . . . . . . . . . . . . . . . . . . . . 22723.2.5.1 ST_PlanActOptn_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22723.2.5.2 ST_PlanActTrgr_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22723.2.5.3 ST_PlanComp_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22823.2.5.4 ST_PlanCond_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22823.2.5.5 ST_PlanFsmState_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22923.2.5.6 ST_PlanStatus_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22923.2.5.7 ST_PlanVar_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22923.2.5.8 ST_VelPlan_ErrorCode_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23023.2.5.9 ST_VelPlan_ErrorId_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23123.2.6 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23123.2.6.1 STVELCTL_getOutputMaximum . . . . . . . . . . . . . . . . . . . . . . . . 23123.2.6.2 STVELPLAN_addCfgAct . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23223.2.6.3 STVELPLAN_addCfgCond . . . . . . . . . . . . . . . . . . . . . . . . . . . 23323.2.6.4 STVELPLAN_addCfgState . . . . . . . . . . . . . . . . . . . . . . . . . . . 23323.2.6.5 STVELPLAN_addCfgTran . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23423.2.6.6 STVELPLAN_addCfgVar . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23423.2.6.7 STVELPLAN_addCfgVarCond . . . . . . . . . . . . . . . . . . . . . . . . . 23523.2.6.8 STVELPLAN_delCfgAct . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23523.2.6.9 STVELPLAN_delCfgCond . . . . . . . . . . . . . . . . . . . . . . . . . . . 23523.2.6.10 STVELPLAN_delCfgState . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23623.2.6.11 STVELPLAN_delCfgTran . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23623.2.6.12 STVELPLAN_delCfgVar . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23623.2.6.13 STVELPLAN_delCfgVarCond . . . . . . . . . . . . . . . . . . . . . . . . . . 23723.2.6.14 STVELPLAN_getAccelerationLimit . . . . . . . . . . . . . . . . . . . . . . . 23723.2.6.15 STVELPLAN_getCfg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23723.2.6.16 STVELPLAN_getCfgAct . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23823.2.6.17 STVELPLAN_getCfgActNum . . . . . . . . . . . . . . . . . . . . . . . . . . 23823.2.6.18 STVELPLAN_getCfgCond . . . . . . . . . . . . . . . . . . . . . . . . . . . 23923.2.6.19 STVELPLAN_getCfgCondNum . . . . . . . . . . . . . . . . . . . . . . . . . 23923.2.6.20 STVELPLAN_getCfgError . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24023.2.6.21 STVELPLAN_getCfgHaltState . . . . . . . . . . . . . . . . . . . . . . . . . 24023.2.6.22 STVELPLAN_getCfgState . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24123.2.6.23 STVELPLAN_getCfgStateNum . . . . . . . . . . . . . . . . . . . . . . . . . 24123.2.6.24 STVELPLAN_getCfgTran . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24123.2.6.25 STVELPLAN_getCfgTranNum . . . . . . . . . . . . . . . . . . . . . . . . . 24223.2.6.26 STVELPLAN_getCfgVar . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24223.2.6.27 STVELPLAN_getCfgVarCond . . . . . . . . . . . . . . . . . . . . . . . . . . 243

NXP SemiconductorsKinetis Motor Suite API Reference Manual

xvii

Page 18: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

23.2.6.28 STVELPLAN_getCfgVarNum . . . . . . . . . . . . . . . . . . . . . . . . . . 24323.2.6.29 STVELPLAN_getCurrentState . . . . . . . . . . . . . . . . . . . . . . . . . . 24423.2.6.30 STVELPLAN_getCurrentTimerValue_tick . . . . . . . . . . . . . . . . . . . 24423.2.6.31 STVELPLAN_getCurrentTransition . . . . . . . . . . . . . . . . . . . . . . . 24423.2.6.32 STVELPLAN_getEnable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24523.2.6.33 STVELPLAN_getErrorID . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24523.2.6.34 STVELPLAN_getFsmState . . . . . . . . . . . . . . . . . . . . . . . . . . . 24523.2.6.35 STVELPLAN_getJerkLimit . . . . . . . . . . . . . . . . . . . . . . . . . . . 24623.2.6.36 STVELPLAN_getReset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24623.2.6.37 STVELPLAN_getStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24623.2.6.38 STVELPLAN_getVar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24723.2.6.39 STVELPLAN_getVelocitySetpoint . . . . . . . . . . . . . . . . . . . . . . . 24723.2.6.40 STVELPLAN_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24723.2.6.41 STVELPLAN_reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24823.2.6.42 STVELPLAN_run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24823.2.6.43 STVELPLAN_runTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24823.2.6.44 STVELPLAN_setCfg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24823.2.6.45 STVELPLAN_setCfgAct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24923.2.6.46 STVELPLAN_setCfgArray . . . . . . . . . . . . . . . . . . . . . . . . . . . 24923.2.6.47 STVELPLAN_setCfgCond . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25023.2.6.48 STVELPLAN_setCfgHaltState . . . . . . . . . . . . . . . . . . . . . . . . . . 25023.2.6.49 STVELPLAN_setCfgState . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25123.2.6.50 STVELPLAN_setCfgTran . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25123.2.6.51 STVELPLAN_setCfgVar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25223.2.6.52 STVELPLAN_setCfgVarCond . . . . . . . . . . . . . . . . . . . . . . . . . . 25223.2.6.53 STVELPLAN_setEnable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25323.2.6.54 STVELPLAN_setReset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25323.2.6.55 STVELPLAN_setUnitProfDone . . . . . . . . . . . . . . . . . . . . . . . . . 25423.2.6.56 STVELPLAN_setVar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254

23.3 SpinTAC™ Position Plan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25523.3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25523.3.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26323.3.2.1 struct ST_PlanError_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26323.3.2.2 struct ST_PosPlan_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26423.3.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 26523.3.3.1 __ST_PLAN_ENUM__ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26523.3.3.2 __ST_PLAN_ERROR__ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26523.3.3.3 ST_POS_PLAN_ACT_DWORDS . . . . . . . . . . . . . . . . . . . . . . . . 26523.3.3.4 ST_POS_PLAN_COND_DWORDS . . . . . . . . . . . . . . . . . . . . . . . 26523.3.3.5 ST_POS_PLAN_STATE_DWORDS . . . . . . . . . . . . . . . . . . . . . . 26523.3.3.6 ST_POS_PLAN_TRAN_DWORDS . . . . . . . . . . . . . . . . . . . . . . . 26523.3.3.7 ST_POS_PLAN_VAR_DWORDS . . . . . . . . . . . . . . . . . . . . . . . . 26523.3.4 Typedef Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26623.3.4.1 ST_POSPLAN_Handle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266

xviiiKinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 19: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

23.3.5 Enumeration Type Documentation . . . . . . . . . . . . . . . . . . . . . . . . . 26623.3.5.1 ST_PlanActOptn_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26623.3.5.2 ST_PlanActTrgr_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26623.3.5.3 ST_PlanComp_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26623.3.5.4 ST_PlanCond_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26723.3.5.5 ST_PlanFsmState_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26723.3.5.6 ST_PlanStatus_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26823.3.5.7 ST_PlanVar_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26823.3.5.8 ST_PosPlan_ErrorCode_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26823.3.5.9 ST_PosPlan_ErrorId_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27023.3.6 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27023.3.6.1 STPOSPLAN_addCfgAct . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27023.3.6.2 STPOSPLAN_addCfgCond . . . . . . . . . . . . . . . . . . . . . . . . . . . 27123.3.6.3 STPOSPLAN_addCfgState . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27123.3.6.4 STPOSPLAN_addCfgTran . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27223.3.6.5 STPOSPLAN_addCfgVar . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27223.3.6.6 STPOSPLAN_addCfgVarCond . . . . . . . . . . . . . . . . . . . . . . . . . 27323.3.6.7 STPOSPLAN_delCfgAct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27323.3.6.8 STPOSPLAN_delCfgCond . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27323.3.6.9 STPOSPLAN_delCfgState . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27423.3.6.10 STPOSPLAN_delCfgTran . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27423.3.6.11 STPOSPLAN_delCfgVar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27423.3.6.12 STPOSPLAN_delCfgVarCond . . . . . . . . . . . . . . . . . . . . . . . . . . 27423.3.6.13 STPOSPLAN_getAccelerationLimit . . . . . . . . . . . . . . . . . . . . . . . 27523.3.6.14 STPOSPLAN_getCfg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27523.3.6.15 STPOSPLAN_getCfgAct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27523.3.6.16 STPOSPLAN_getCfgActNum . . . . . . . . . . . . . . . . . . . . . . . . . . 27623.3.6.17 STPOSPLAN_getCfgCond . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27623.3.6.18 STPOSPLAN_getCfgCondNum . . . . . . . . . . . . . . . . . . . . . . . . . 27723.3.6.19 STPOSPLAN_getCfgError . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27723.3.6.20 STPOSPLAN_getCfgHaltState . . . . . . . . . . . . . . . . . . . . . . . . . . 27723.3.6.21 STPOSPLAN_getCfgState . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27823.3.6.22 STPOSPLAN_getCfgStateNum . . . . . . . . . . . . . . . . . . . . . . . . . 27823.3.6.23 STPOSPLAN_getCfgTran . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27923.3.6.24 STPOSPLAN_getCfgTranNum . . . . . . . . . . . . . . . . . . . . . . . . . 27923.3.6.25 STPOSPLAN_getCfgVar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28023.3.6.26 STPOSPLAN_getCfgVarCond . . . . . . . . . . . . . . . . . . . . . . . . . . 28023.3.6.27 STPOSPLAN_getCfgVarNum . . . . . . . . . . . . . . . . . . . . . . . . . . 28023.3.6.28 STPOSPLAN_getCurrentState . . . . . . . . . . . . . . . . . . . . . . . . . . 28123.3.6.29 STPOSPLAN_getCurrentTimerValue_tick . . . . . . . . . . . . . . . . . . . 28123.3.6.30 STPOSPLAN_getCurrentTransition . . . . . . . . . . . . . . . . . . . . . . . 28123.3.6.31 STPOSPLAN_getDecelerationLimit . . . . . . . . . . . . . . . . . . . . . . . 28223.3.6.32 STPOSPLAN_getEnable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28223.3.6.33 STPOSPLAN_getErrorID . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28223.3.6.34 STPOSPLAN_getFsmState . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283

NXP SemiconductorsKinetis Motor Suite API Reference Manual

xix

Page 20: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

23.3.6.35 STPOSPLAN_getJerkLimit . . . . . . . . . . . . . . . . . . . . . . . . . . . 28323.3.6.36 STPOSPLAN_getPositionStep_mrev . . . . . . . . . . . . . . . . . . . . . . 28323.3.6.37 STPOSPLAN_getReset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28423.3.6.38 STPOSPLAN_getStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28423.3.6.39 STPOSPLAN_getVar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28423.3.6.40 STPOSPLAN_getVelocityLimit . . . . . . . . . . . . . . . . . . . . . . . . . 28523.3.6.41 STPOSPLAN_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28523.3.6.42 STPOSPLAN_reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28523.3.6.43 STPOSPLAN_run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28623.3.6.44 STPOSPLAN_runTick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28623.3.6.45 STPOSPLAN_setCfg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28623.3.6.46 STPOSPLAN_setCfgAct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28623.3.6.47 STPOSPLAN_setCfgArray . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28723.3.6.48 STPOSPLAN_setCfgCond . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28723.3.6.49 STPOSPLAN_setCfgHaltState . . . . . . . . . . . . . . . . . . . . . . . . . . 28823.3.6.50 STPOSPLAN_setCfgState . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28823.3.6.51 STPOSPLAN_setCfgTran . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28923.3.6.52 STPOSPLAN_setCfgVar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29023.3.6.53 STPOSPLAN_setCfgVarCond . . . . . . . . . . . . . . . . . . . . . . . . . . 29023.3.6.54 STPOSPLAN_setEnable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29023.3.6.55 STPOSPLAN_setReset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29123.3.6.56 STPOSPLAN_setUnitProfDone . . . . . . . . . . . . . . . . . . . . . . . . . 29123.3.6.57 STPOSPLAN_setVar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291

Chapter 24Math

24.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293

24.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30024.2.1 struct FLT_butterAccT32bit_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30024.2.2 struct FLT_butterAccT16bit_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30024.2.3 struct FLT_butterAccE32bit_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30024.2.4 struct PID_pidParam32_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30024.2.5 struct PID_pidReg32_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30124.2.6 struct PID_piParam16_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30124.2.7 struct PID_piReg16_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30224.2.8 struct PID_piParam32_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30224.2.9 struct PID_piReg32_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30224.2.10 struct TRF_s3Vector32_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30324.2.11 struct TRF_sVector16_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30324.2.12 struct TRF_sVector32_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30324.2.13 struct TRF_rVector16_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304

xxKinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 21: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

24.2.14 struct TRF_rVector32_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30424.2.15 struct TRF_orient16_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30424.2.16 struct TRF_orient32_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30424.2.17 struct FLT_butterAccT32bit_s . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30524.2.18 struct FLT_butterAccT16bit_s . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30524.2.19 struct FLT_butterAccE32bit_s . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305

24.3 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 30524.3.1 _L32mpyLQL32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30524.3.2 _LQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30524.3.3 _LQ14 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30524.3.4 _LQ15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30524.3.5 _LQ16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30624.3.6 _LQ20 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30624.3.7 _LQ20div . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30624.3.8 _LQ20mpyI32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30624.3.9 _LQ20mpyLQX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30624.3.10 _LQ24 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30624.3.11 _LQ30 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30624.3.12 _LQ30mpyLQX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30624.3.13 _LQ31 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30724.3.14 _LQ_ASL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30724.3.15 _LQ_ASR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30724.3.16 _LQabsFast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30724.3.17 _LQdiv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30724.3.18 _LQmpy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30724.3.19 _LQmpyI32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30824.3.20 _LQmpyInline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30824.3.21 _LQmpyLQX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30824.3.22 _LQmpyMiniSQLQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30824.3.23 _LQmpyMiniSQLQX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30824.3.24 _LQmpyMiniSQLQXInline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30824.3.25 _LQmpySQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30824.3.26 _LQmpySQX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30924.3.27 _LQrecip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30924.3.28 _LQsatFast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30924.3.29 _LQtoSQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30924.3.30 _LQtoSQ15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30924.3.31 _LQZdivLQXY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30924.3.32 _LQZmpyMiniSQLQXY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30924.3.33 _LQZmpyMiniSQLQXYInline . . . . . . . . . . . . . . . . . . . . . . . . . . . 31024.3.34 _LQZmpySQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31024.3.35 _LQZmpySQX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31024.3.36 _SQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31024.3.37 _SQ13 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310

NXP SemiconductorsKinetis Motor Suite API Reference Manual

xxi

Page 22: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

24.3.38 _SQ15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31024.3.39 _SQ15mpySQX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31024.3.40 _SQ15toLQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31124.3.41 _SQ8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31124.3.42 _SQ_ASL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31124.3.43 _SQ_ASR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31124.3.44 _SQabsFast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31124.3.45 _SQdivISQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31124.3.46 _SQmpy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31124.3.47 _SQmpySQX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31224.3.48 _SQsatFast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31224.3.49 _SQtoLQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31224.3.50 FLT_COEFF_EULER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31224.3.51 FLT_COEFF_TUSTIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31224.3.52 FLT_INIT_E_32BIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31324.3.53 FLT_INIT_T_32BIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31324.3.54 FLT_RATIO_EULER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31324.3.55 FLT_RATIO_TUSTIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31424.3.56 GLOBAL_LQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31424.3.57 GLOBAL_SQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31424.3.58 MAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31424.3.59 MAX_LQ_NEG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31524.3.60 MAX_LQ_POS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31524.3.61 MAX_SQ_NEG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31524.3.62 MAX_SQ_POS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31524.3.63 MIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31524.3.64 MIN_LQ_NEG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31524.3.65 MIN_LQ_POS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31524.3.66 MIN_SQ_NEG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31624.3.67 MIN_SQ_POS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31624.3.68 PI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31624.3.69 PID_PI_REG16_INIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31624.3.70 PID_PI_REG32_INIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31624.3.71 PID_PID_REG32_INIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31724.3.72 QM_DIV_TWO_32B_16BRES . . . . . . . . . . . . . . . . . . . . . . . . . . . 31724.3.73 QM_DIV_TWO_32B_32BRES . . . . . . . . . . . . . . . . . . . . . . . . . . . 31724.3.74 QM_mpyInline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31824.3.75 SQRT2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31824.3.76 SQRT3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31824.3.77 TRF_EXT_VECTOR16_DEFAULTS . . . . . . . . . . . . . . . . . . . . . . . 31824.3.78 TRF_EXT_VECTOR32_DEFAULTS . . . . . . . . . . . . . . . . . . . . . . . 31824.3.79 TRF_VECTOR16_DEFAULTS . . . . . . . . . . . . . . . . . . . . . . . . . . . 31824.3.80 TRF_VECTOR32_DEFAULTS . . . . . . . . . . . . . . . . . . . . . . . . . . . 318

24.4 Typedef Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318

xxiiKinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 23: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

24.4.1 _lq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31824.4.2 _lq20 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31924.4.3 _lq24 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31924.4.4 _sq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319

24.5 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31924.5.1 _LQ20exp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31924.5.2 _LQ20log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31924.5.3 _LQ20sqrt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31924.5.4 _LQabs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32024.5.5 _LQatan2PU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32024.5.6 _LQcosPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32024.5.7 _LQexp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32024.5.8 _LQfrac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32124.5.9 _LQint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32124.5.10 _LQlog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32124.5.11 _LQsat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32224.5.12 _LQsincosPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32224.5.13 _LQsinPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32224.5.14 _LQsqrt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32324.5.15 _LQXtoLQY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32324.5.16 _LQXtoSQY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32324.5.17 _LQZdivISQXY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32424.5.18 _LQZdivSQXY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32424.5.19 _LQZmpySQXY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32524.5.20 _SQsat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32524.5.21 _SQXtoLQY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32624.5.22 _SQZdivISQXY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32624.5.23 _SQZmpySQXY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32724.5.24 FLT_coeff_Euler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32724.5.25 FLT_coeff_Tustin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32724.5.26 FLT_hpf1stE_32bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32724.5.27 FLT_hpf1stT_32bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32824.5.28 FLT_lpf1stE_32bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32824.5.29 FLT_lpf1stT_16bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32824.5.30 FLT_lpf1stT_32bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32924.5.31 FLT_ratio_Tustin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32924.5.32 PID_processPI32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32924.5.33 PID_processPID32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32924.5.34 PID_processPIF16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33024.5.35 PID_processPIF32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33024.5.36 QM_div . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33024.5.37 QM_divTwo32bSNum16bRes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33024.5.38 QM_mpy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33124.5.39 qmath_version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331

NXP SemiconductorsKinetis Motor Suite API Reference Manual

xxiii

Page 24: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

24.5.40 TRF_clarkeLarge32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33124.5.41 TRF_iPark32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33224.5.42 TRF_park32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33224.5.43 TRF_park32_16_SQ15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33324.5.44 UTIL_angleWrapAround . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33324.5.45 UTIL_arcUponChord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334

Chapter 25Communication

25.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335

25.2 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 33725.2.1 UART_RX_BUFFER_MASK . . . . . . . . . . . . . . . . . . . . . . . . . . . 33725.2.2 UART_RX_BUFFER_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33725.2.3 UART_TX_BUFFER_MASK . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33725.2.4 UART_TX_BUFFER_SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337

25.3 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33725.3.1 if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33725.3.2 InitUART . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33725.3.3 rda_get_number_processed_messages . . . . . . . . . . . . . . . . . . . . . . . 33825.3.4 rda_get_version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33825.3.5 rda_init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33825.3.6 rda_push_int . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33825.3.7 rda_set_interrupt_freq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33825.3.8 rda_tick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33825.3.9 RDA_UART_ERR_ISR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33925.3.10 RDA_UART_ISR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33925.3.11 uart_rx_byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33925.3.12 uart_rx_data_ready . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33925.3.13 uart_tx_byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34025.3.14 uart_tx_empty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34025.3.15 uart_tx_full . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340

25.4 Variable Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34025.4.1 uart_rx_buf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34025.4.2 uart_rx_head . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34125.4.3 uart_rx_tail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34125.4.4 uart_tx_buf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34125.4.5 uart_tx_head . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34125.4.6 uart_tx_tail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34125.4.7 uartIsrCounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34125.4.8 uartRxCounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341

xxivKinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 25: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

25.4.9 uartRxDroppedCounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34225.4.10 uartRxOverRunCounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34225.4.11 uartTxCounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34225.4.12 uartTxDroppedCounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342

Chapter 26Flash Configuration

26.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343

26.2 Macro Definition Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . 34426.2.1 BACKDOOR_COMPARE_KEY0 . . . . . . . . . . . . . . . . . . . . . . . . . 34426.2.2 BACKDOOR_COMPARE_KEY1 . . . . . . . . . . . . . . . . . . . . . . . . . 34426.2.3 BACKDOOR_COMPARE_KEY2 . . . . . . . . . . . . . . . . . . . . . . . . . 34426.2.4 BACKDOOR_COMPARE_KEY3 . . . . . . . . . . . . . . . . . . . . . . . . . 34426.2.5 BACKDOOR_COMPARE_KEY4 . . . . . . . . . . . . . . . . . . . . . . . . . 34426.2.6 BACKDOOR_COMPARE_KEY5 . . . . . . . . . . . . . . . . . . . . . . . . . 34426.2.7 BACKDOOR_COMPARE_KEY6 . . . . . . . . . . . . . . . . . . . . . . . . . 34426.2.8 BACKDOOR_COMPARE_KEY7 . . . . . . . . . . . . . . . . . . . . . . . . . 34426.2.9 FPROT_15_8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34426.2.10 FPROT_23_16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34426.2.11 FPROT_31_24 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34426.2.12 FPROT_7_0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34426.2.13 FSEC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344

Chapter 27Versions

27.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345

27.2 Data Structure Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34727.2.1 struct ST_Ver_t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347

27.3 Typedef Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34727.3.1 ST_VER_Handle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347

27.4 Enumeration Type Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 34727.4.1 ST_MathType_e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347

27.5 Function Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34727.5.1 direct_encode_16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34727.5.2 direct_encode_32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34827.5.3 GetMotorObserverNonSecureVersion . . . . . . . . . . . . . . . . . . . . . . . . 348

NXP SemiconductorsKinetis Motor Suite API Reference Manual

xxv

Page 26: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Section number Title Page

27.5.4 GetMotorObserverSecureVersion . . . . . . . . . . . . . . . . . . . . . . . . . . 34827.5.5 GetMotorObserverSecureVersionIsCompatible . . . . . . . . . . . . . . . . . . . 34827.5.6 rda_bsp_get_app_version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34927.5.7 rda_mem_address_readable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34927.5.8 rda_mem_address_writable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35027.5.9 ST_getSecureROMIsCompatible . . . . . . . . . . . . . . . . . . . . . . . . . . 35027.5.10 ST_getSecureROMVersion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35127.5.11 ST_getVersionDate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35127.5.12 ST_getVersionMath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35127.5.13 ST_getVersionNumber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35227.5.14 ST_initVersion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352

27.6 Variable Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35227.6.1 __checksum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35227.6.2 buildDate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35227.6.3 buildTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35327.6.4 flashHighAddress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35327.6.5 flashLowAddress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35327.6.6 m_data_2_end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35327.6.7 m_data_start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35327.6.8 m_text_end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35327.6.9 m_text_start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35327.6.10 ramHighAddress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35327.6.11 ramLowAddress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353

Chapter 28Revision history

xxviKinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 27: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 1Kinetis Motor SuiteBased on Kinetis V series microcontrollers (MCUs), Kinetis Motor Suite (KMS) is an integrated solutionof hardware, embedded firmware, and PC software that enables rapid development of applications drivenby three phase motors.

The purpose of this document is to describe the function and API of the embedded firmware componentof KMS, known as Motor Observer, for permanent magnet and brushless DC motors (PMSM/BLDC), sothat Motor Observer can be leveraged and adapted to suit your application's specific operation.

Supporting documentation describes the other elements of KMS:

• The Kinetis V series hardware underlying KMS is explained in the appropriate KV reference ma-nuals.

• Specific pins and peripherals utilized by KMS are described in the KMS User's Guide.• The PC software component of KMS is described in the KMS User's Guide.• For a hands-on introduction to all three elements and the interactions among them, please refer to

the KMS Lab Guide.• For discussion of the embedded firmware underlying the AC induction motor (ACIM) implementa-

tion of KMS, please see the documentation for NXP's ACIM reference design.

1.1 Firmware ArchitectureThe core aim of KMS is to make motor control simple. This is reflected not only in the focus on anintelligent PC-based user interface, but on the design of the PMSM/BLDC embedded firmware providedby KMS.

Modularity

The firmware is written in an easy-to-understand "block and pin" style. Each "block," or software mo-dule, is self-contained and has input, output, and configuration “pins,” which comprise the entirety of theinterface: you do not need full knowledge of the software underlying each module to be able to use thecode effectively.

More precisely, each block contains structures and functions.

The main structures are for:

• Configuration: sets up run-time updateable variables• Output: delivers values to other blocks or to the user• Private: defines memory used internally by the block

The main functions are for:

• Initialization: zeroes out the relevant structure and performing any prerequisites for configuration

NXP SemiconductorsKinetis Motor Suite API Reference Manual

1

Page 28: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Firmware Architecture

• Configuration: calculates values needed by private memory using input values• Running/Updating: performs core functionality of block using input values

(Note that the functions only work on the addresses of the relevant blocks.)

This consistent, modular structure allows you to easily connect, disconnect, and configure blocks in orderto customize code for your specific objectives. It also accelerates debugging, because each block can betested individually.

This modularity also informs the structure of this document: chapters in this document refer to softwareblocks, and each chapter contains an introduction that outlines:

• Functionality,• Inputs & Outputs• Execution• Custom Usage

Control Flow

Maximization of code re-use and ease of debugging are further emphasized by the usage of a single controlflow path with dual interrupt service routines.

Providing a single control path means the code is guaranteed to execute in a comprehensible manner.Similarly, using a Fast Interrupt Service Routine and a Slow Interrupt Service Routine (described below)allows KMS to avoid overruns. The combination of the two means the code is comprehensible and easyto debug when customizing.

Code Partitioning

In order to balance MCU hardware and PC software integration with firmware flexibility, different aspectsof KMS firmware are accessible to different degrees.

• Execute-only locked firmware: This proprietary firmware is locked in execute-only flash memoryand is programmed onto the MCU during production. It resides in the highest section of memoryavailable so as to avoid interference with the normal design flow. Firmware is specific to the partnumber.

• Library: This firmware includes the main motor control and math functions. API functions andpublic variables provide access and control to features in the library.

• Open Source: The full source of the open firmware is provided. These modules include the KinetisSDK, the peripheral interface layer, the connections between the motor control functions, the mainfunction, and interrupts.

A high-level breakdown of how code is partitioned is provided on a module-by-module basis in the remai-ning chapters of this document.

2Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 29: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

1.2 Field Oriented Control Data FlowKMS implements field-oriented, sinusoidal control ("FOC") of three phase permanent magnet or brushlessDC motors (PMSM/BLDC). It provides three different control topologies.

• Sensorless Velocity: A software algorithm calculates the motor electrical angle based on phase cur-rent feedback. The primary mode of operation is variable speed control.

– Sensorless Velocity - Hall Start: A modification of the sensorless velocity project that usesHall-Effect sensors to start the motor before transitioning into sensorless control.

• Sensored Velocity: A physical encoder provides the motor electrical angle. The primary mode ofoperation is variable speed control.

• Sensored Position: A physical encoder provides the motor electrical angle. The primary mode ofoperation is variable position control.

The modular software blocks referenced above that jointly comprise FOC are described pictorially and byfunction in this section. In the block diagrams displayed below, they will indicate which control topologythey belong to.

Block Diagrams

To support a wide variety of motor driven applications and the different stages of application design,many different modes of operation are supported within KMS. The modularity of Motor Observer enablesseamless reconfiguration of blocks to achieve these different modes of operation.

Diagrammatic representations of key operating modes are on the following pages, with block coloringdefined in the figure below.

HARDWAREMOTORCONTROL

HARDWAREABSTRACTION

Figure 1.2.1: Block Diagram Color Key

NXP SemiconductorsKinetis Motor Suite API Reference Manual

3

Page 30: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

• Speed Control: Given any target speed within the operating range of the motor, KMS will act ac-cording to the following block diagrams to attempt to maintain this speed. Note that when usingSensorless Speed Control, the Motor Startup Block Diagram also must be considered.

TRAJ

VEL

SPEE

DCU

RREN

TIP

ARK

SVPW

MFl

ex T

imer

Inve

rter

Mot

or

Shun

t Re

sisto

rsAn

alog

to

Digi

tal

Conv

erte

rFE

EDBA

CKCL

ARKE

PARK

EST

FW

DC B

us S

ense

DC B

us

Spee

d Re

f

Iq R

efId R

ef

V R

ef M

agni

tude

Spee

d Fd

b

Vdq

Ref

V R

ef

Duty

Cyc

les

ADC

Coun

tsIa

bc F

dbI

Fdb

Idq

Fdb

elec

Spee

d Se

tpoi

nt

Figure 1.2.2: Sensorless Velocity Control Block Diagram

4Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 31: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

TRAJ

VEL

SPEE

DCU

RREN

TIP

ARK

SVPW

MFl

ex T

imer

Inve

rter

Mot

or &

En

code

r

Shun

t Re

sisto

rsAn

alog

to

Digi

tal

Conv

erte

rFE

EDBA

CKCL

ARKE

PARK

ENC

FW

DC B

us S

ense

DC B

us

Spee

d Re

f

Iq R

efId R

ef

V R

ef M

agni

tude

Spee

d Fd

b

Vdq

Ref

V R

ef

Duty

Cyc

les

ADC

Coun

tsIa

bc F

dbI

Fdb

Idq

Fdb

elec

Spee

d Se

tpoi

nt

Flex

Tim

er

Enco

der

Phas

esQ

EI

Enco

der

Coun

t

Figure 1.2.3: Sensored Velocity Control Block Diagram

NXP SemiconductorsKinetis Motor Suite API Reference Manual

5

Page 32: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

• Position Control: Given a position setpoint, KMS will act according to the following block diagramsto attempt to maintain this position.

TRAJ

POS

POSI

TIO

NCU

RREN

TIP

ARK

SVPW

MFl

ex T

imer

Inve

rter

Mot

or &

En

code

r

Shun

t Re

sisto

rsAn

alog

to

Digi

tal

Conv

erte

rFE

EDBA

CKCL

ARKE

PARK

ENC

DC B

us S

ense

DC B

us

Pos R

ef

Iq R

ef

Pos F

db

Vdq

Ref

V R

ef

Duty

Cyc

les

ADC

Coun

tsIa

bc F

dbI

Fdb

Idq

Fdb

elec

Posit

ion

Step

Flex

Tim

er

Enco

der

Phas

esQ

EI

Enco

der

Coun

t

Id R

ef0

Figure 1.2.4: Sensored Position Control Block Diagram

6Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 33: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

• Torque Control: Instead of controlling the motor's speed, it may be preferable to control torque inapplications like electric bicycles. This exists as a operation mode within all control topologies.Note that when using Sensorless Torque Control, the Motor Startup Block Diagram also must beconsidered.

CURR

ENT

IPAR

KSV

PWM

Flex

Tim

erIn

vert

erM

otor

Shun

t Re

sisto

rsAn

alog

to

Digi

tal

Conv

erte

rFE

EDBA

CKCL

ARKE

PARK

EST

DC B

us S

ense

DC B

us

Vdq

Ref

V R

ef

Duty

Cyc

les

ADC

Coun

tsIa

bc F

dbI

Fdb

Idq

Fdb

elec

Id S

etpo

int

Iq S

etpo

int

Figure 1.2.5: Sensorless Torque Control Block Diagram

NXP SemiconductorsKinetis Motor Suite API Reference Manual

7

Page 34: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

CURR

ENT

IPAR

KSV

PWM

Flex

Tim

erIn

vert

erM

otor

&

Enco

der

Shun

t Re

sisto

rsAn

alog

to

Digi

tal

Conv

erte

rFE

EDBA

CKCL

ARKE

PARK

DC B

us S

ense

DC B

us

Iq S

etpo

int

Id S

etpo

int

Vdq

Ref

V R

ef

Duty

Cyc

les

ADC

Coun

tsIa

bc F

dbI

Fdb

Idq

Fdb

elec

Flex

Tim

er

Enco

der

Phas

esQ

EI

Enco

der

Coun

t

Figure 1.2.6: Sensored Torque Control Block Diagram

8Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 35: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

• Motion Sequence Control: KMS allows for simple GUI-based creation of motion state machines.This adds an additional block to typical speed or position control operation.

TRAJ

VEL

SPEE

DCU

RREN

TIP

ARK

SVPW

MFl

ex T

imer

Inve

rter

Mot

or

Shun

t Re

sisto

rsAn

alog

to

Digi

tal

Conv

erte

rFE

EDBA

CKCL

ARKE

PARK

EST

FW

DC B

us S

ense

DC B

us

Spee

d Re

f

Iq R

efId R

ef

V R

ef M

agni

tude

Spee

d Fd

b

Vdq

Ref

V R

ef

Duty

Cyc

les

ADC

Coun

tsIa

bc F

dbI

Fdb

Idq

Fdb

elec

PLAN

Spee

d Se

tpoi

nt

Mot

ion

Sequ

ence

Figure 1.2.7: Sensorless Velocity Motion Sequence Control Block Diagram

NXP SemiconductorsKinetis Motor Suite API Reference Manual

9

Page 36: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

TRAJ

VEL

SPEE

DCU

RREN

TIP

ARK

SVPW

MFl

ex T

imer

Inve

rter

Mot

or &

En

code

r

Shun

t Re

sisto

rsAn

alog

to

Digi

tal

Conv

erte

rFE

EDBA

CKCL

ARKE

PARK

ENC

FW

DC B

us S

ense

DC B

us

Spee

d Re

f

Iq R

efId R

ef

V R

ef M

agni

tude

Spee

d Fd

b

Vdq

Ref

V R

ef

Duty

Cyc

les

ADC

Coun

tsIa

bc F

dbI

Fdb

Idq

Fdb

elec

Spee

d Se

tpoi

nt

Flex

Tim

er

Enco

der

Phas

esQ

EI

Enco

der

Coun

t

PLAN

Mot

ion

Sequ

ence

Figure 1.2.8: Sensored Velocity Motion Sequence Control Block Diagram

10Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 37: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

TRAJ

POS

POSI

TIO

NCU

RREN

TIP

ARK

SVPW

MFl

ex T

imer

Inve

rter

Mot

or &

En

code

r

Shun

t Re

sisto

rsAn

alog

to

Digi

tal

Conv

erte

rFE

EDBA

CKCL

ARKE

PARK

ENC

DC B

us S

ense

DC B

us

Pos R

ef

Iq R

ef

Pos F

db

Vdq

Ref

V R

ef

Duty

Cyc

les

ADC

Coun

tsIa

bc F

dbI

Fdb

Idq

Fdb

elec

Posit

ion

Step

Flex

Tim

er

Enco

der

Phas

esQ

EI

Enco

der

Coun

t

PLAN

Mot

ion

Sequ

ence

Id R

ef0

Figure 1.2.9: Sensored Position Motion Sequence Control Block Diagram

NXP SemiconductorsKinetis Motor Suite API Reference Manual

11

Page 38: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

• Startup: Sensorless FOC relies on a back-EMF signal that cannot occur without motor rotation. Toreach sufficient rotational speed to achieve a signal, the motor must operate slightly differently.

STAR

TUP

Flux

Pll L

ocke

d

TRAJ

VEL

CURR

ENT

IPAR

KSV

PWM

Flex

Tim

erIn

vert

erM

otor

Shun

t Re

sisto

rsAn

alog

to

Digi

tal

Conv

erte

rFE

EDBA

CKCL

ARKE

PARK

EST

DC B

us S

ense

DC B

us

Spee

d Re

fId

q Re

f

Vdq

Ref

V R

ef

Duty

Cyc

les

ADC

Coun

tsIa

bc F

dbI

Fdb

Idq

Fdb

elec

Spee

d Se

tpoi

nt

elec

Figure 1.2.10: Motor Startup Block Diagram

12Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 39: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

• Hall Startup: Sensorless FOC has difficulty when starting under large load situation. By usingthe Hall-Effect sensors, the motor can be started in large load situations before transitioning intosensorless FOC control.

ST

AR

TU

P D

ete

rmin

es

wh

en

to

tr

an

siti

on

to

FO

C

SP

EE

D e

sta

bli

she

s S

VP

WM

d

uty

cyc

leH

ALL

pro

vid

es

spe

ed

fe

ed

ba

ck

an

d s

ele

cts

SV

PW

M c

on

fig

ura

tio

n

TRA

JVEL

SPEE

DSV

PW

MFl

ex T

imer

Inve

rter

Mo

tor

&H

all-

effe

ct

Sen

sors

Shu

nt

Res

isto

rs

An

alo

g to

D

igit

al

Co

nve

rter

FEED

BA

CK

CLA

RK

EP

AR

K

DC

Bu

s Se

nse

DC

Bu

s

Spee

d R

efD

uty

Cyc

le

Du

ty C

ycle

s

AD

C

Co

un

tsIa

bc

Fdb

Spee

d

Setp

oin

t

GP

IOQ

EIH

ALL

Iαβ

Fd

b

STA

RTU

P

Pll

Lock

ed

EST

Spee

d F

db

Θel

ec

Hal

l St

ates

Hal

l In

dex

GP

IO V

alu

e

Figure 1.2.11: Hall Startup Block Diagram

NXP SemiconductorsKinetis Motor Suite API Reference Manual

13

Page 40: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

• Alignment: Sensored FOC relies on an encoder in order to provide the motor electrical angle. It isimportant that this encoder signal is aligned with the true electrical angle of the motor.

CURR

ENT

IPAR

KSV

PWM

Flex

Tim

erIn

vert

erM

otor

&

Enco

der

Shun

t Re

sisto

rsAn

alog

to

Digi

tal

Conv

erte

rFE

EDBA

CKCL

ARKE

PARK

DC B

us S

ense

DC B

us

0

Vdq

Ref

V R

ef

Duty

Cyc

les

ADC

Coun

tsIa

bc F

dbI

Fdb

Idq

Fdb

0Fl

ex T

imer

Enco

der

Phas

esQ

EI

Enco

der

Coun

t

Iq R

ef

Id R

ef

USE

R

Figure 1.2.12: Encoder Alignment Block Diagram

14Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 41: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

• Resistance & Inductance Measurement: KMS must energize the motor in a specific manner toidentify the motor's resistance and inductance, which enables valid FOC operation.

IPAR

KSV

PWM

Flex

Tim

erIn

vert

erM

otor

Shun

t Re

sisto

rsAn

alog

to

Digi

tal

Conv

erte

rFE

EDBA

CKCL

ARKE

SCM

DC B

us S

ense

DC B

usV

Ref

Duty

Cyc

les

ADC

Coun

tsIa

bc F

dbI

Fdb0

Idq

Ref

PARK

E

CURR

ENT

Vdq

Ref

Idq

Fdb

Figure 1.2.13: Resistance and Inductance Measurement Block Diagram

NXP SemiconductorsKinetis Motor Suite API Reference Manual

15

Page 42: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

• Flux Measurement: KMS must also assess the flux of the motor with a short test running the motorat a low speed.

TRAJ

VEL

CURR

ENT

IPAR

KSV

PWM

Flex

Tim

erIn

vert

erM

otor

Shun

t Re

sisto

rsAn

alog

to

Digi

tal

Conv

erte

rFE

EDBA

CKCL

ARKE

PARK

STAR

TUP

DC B

us S

ense

DC B

us

Spee

d Re

f

Idq

Ref

Vdq

Ref

V R

ef

Duty

Cyc

les

ADC

Coun

tsIa

bc F

db

I F

db

elec

elec

Spee

d Se

tpoi

nt

EST

Flux

SCM

Figure 1.2.14: Sensorless Velocity Flux Measurement Block Diagram

16Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 43: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

TRAJ

VEL

SPEE

DCU

RREN

TIP

ARK

SVPW

MFl

ex T

imer

Inve

rter

Mot

or &

En

code

r

Shun

t Re

sisto

rsAn

alog

to

Digi

tal

Conv

erte

rFE

EDBA

CKCL

ARKE

PARK

ENC

DC B

us S

ense

DC B

us

Spee

d Re

f

Iq R

efId R

ef

Spee

d Fd

b

Vdq

Ref

V R

ef

Duty

Cyc

les

ADC

Coun

tsIa

bc F

dbI

Fdb

Idq

Fdb

elec

Spee

d Se

tpoi

nt

Flex

Tim

er

Enco

der

Phas

esQ

EI

Enco

der

Coun

t

FLU

XEST

SCM

Flux

V

Ref

I

Fdb0

Figure 1.2.15: Sensored Velocity Flux Measurement Block Diagram

NXP SemiconductorsKinetis Motor Suite API Reference Manual

17

Page 44: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

TRAJ

POS

POSI

TIO

NCU

RREN

TIP

ARK

SVPW

MFl

ex T

imer

Inve

rter

Mot

or &

En

code

r

Shun

t Re

sisto

rsAn

alog

to

Digi

tal

Conv

erte

rFE

EDBA

CKCL

ARKE

PARK

ENC

DC B

us S

ense

DC B

us

Pos R

ef

Iq R

efId R

ef

Pos F

db

Vdq

Ref

V R

ef

Duty

Cyc

les

ADC

Coun

tsIa

bc F

dbI

Fdb

Idq

Fdb

elec

Spee

d Se

tpoi

nt

Flex

Tim

er

Enco

der

Phas

esQ

EI

Enco

der

Coun

t

FLU

XEST

SCM

Flux

V

Ref

I

Fdb0

Spee

d Pr

ofile

Figure 1.2.16: Sensored Position Flux Measurement Block Diagram

18Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 45: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Field Oriented Control Data Flow

• Hall-Effect State Identification: To enable the Sensorless Velocity Hall Start feature, the order of theHall-Effect states must be known. KMS does this in parallel with the Flux Measurement.

Use

s S

TA

RT

UP

to

ro

tate

mo

tor

for

Flu

x Id

en

tifi

cati

on

Ha

ll S

tate

s a

re c

ap

ture

d d

uri

ng

Flu

x Id

en

tifi

cati

on

TRA

JVEL

CU

RR

ENT

IPA

RK

SVP

WM

Flex

Tim

erIn

vert

erM

oto

r &

Hal

l-ef

fect

Se

nso

rs

Shu

nt

Res

isto

rs

An

alo

g to

D

igit

al

Co

nve

rter

FEED

BA

CK

CLA

RK

EP

AR

K

STA

RTU

P

DC

Bu

s Se

nse

DC

Bu

s

Spee

d R

ef

Idq

Ref

Vd

q R

ef

β R

ef

Du

ty C

ycle

s

AD

C

Co

un

tsIa

bc

Fdb

Iαβ

Fd

b

Θel

ec

Θel

ec

Spee

d

Setp

oin

t

EST

Flu

xαβ

SCM

GP

IOQ

EIH

ALL

Hal

l St

ates

GP

IO V

alu

e

Figure 1.2.17: Hall-Effect State Identification Block Diagram

NXP SemiconductorsKinetis Motor Suite API Reference Manual

19

Page 46: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Interrupt Service Routines

Description of Blocks

The software blocks that make up the above diagrams can be described as follows:

• User (USER): Allows user to easily access main motor operating states.• Self Commissioning (SCM): Self commissioning module controls the automatic parameter identifi-

cation process.• Motion Sequence (PLAN): Configures and runs a user-configured motion sequence.• Trajectory - Velocity (TRAJVEL): Ramps speed command from the previous target speed to the

current target speed according to the selected curve type and acceleration and jerk limits.• Trajectory - Position (TRAJPOS): Ramps position command for the position step according to the

selected curve type and speed, acceleration, deceleration, and jerk limits.• Speed Control (SPEED): Outputs torque (Iq) reference according to speed feedback and speed refe-

rence.• Position Control (POSITION): Outputs torque (Iq) reference according to position feedback and

position reference.• Field Weakening (FW): Outputs D-phase current reference based on modulation command and rotor

speed for field weakening operation.• Feedback (FEEDBACK): Generates the three phase currents and DC bus voltage from the ADC

hardware and internal scaling, calibration and offset.• Clarke Transform (CLARKE): Converts three phase current feedback signals to two phase represen-

tation.• Park Transform (PARK): Rotates current feedback from stator reference frame to rotor reference

frame.• Startup (STARTUP): Controls startup sequencing and logic and generates sensorless angle and speed

feedback while running in the startup region.• Estimator (EST): Generates sensorless angle and speed feedback from the phase currents in the

stator reference frame.• Encoder (ENC): Generates position and speed feedback from the motor electrical angle.• Hall (HALL): Generates position and speed feedback from the Hall-Effect sensors.• Current (CURRENT): Two channel (Iq and Id) current regulator which outputs D and Q phase

voltages.• Inverse Park Transform (IPARK): Rotates voltage commands from rotor reference frame to stator

reference frame according to angle feedback.• Space Vector PWM (SVPWM): Generates modulation values for the three phase inverter from the

stator frame voltages.

Detailed descriptions of each make up the bulk of the remainder of this document.

1.3 Interrupt Service RoutinesKMS employs a dual interrupt service routine (ISR) approach. Each ISR is briefly described in this section.

20Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 47: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Interrupt Service Routines

Fast Interrupt

Running a motor requires running calculations at or very close to the PWM frequency. This is due to thevery fast dynamics of the electrical control of a motor. In KMS, this is called the Fast Interrupt ServiceRoutine, or Fast ISR.

During this ISR, the three motor phase currents and sampled (FEEDBACK), the sensorless angle estima-tion is performed (EST) or the electrical angle will be provided by the sensor, the current controllers arerun to update the reference voltage (CURRENT), and the space vector modulator is called to update thethree PWM duty cycles (SVPWM). There are additional time-sensitive software components dealing withfault detection (DSM) and braking (BRAKE) that are called during this ISR.

The specifics of these software modules are individually addressed in this document, and the execution ofkey elements within these blocks is described therein.

The rate at which the Fast ISR operates is configurable in relation to the PWM switching frequency ofthe processor as well as to the operation of the Slow ISR. The PWM frequency of the system can bespecified in absolute terms (in the range 4-80 kHz). The ratio of PWM cycles to Fast ISR cycles can thenbe specified, and in turn, so too can the ratio of Fast ISR cycles to Slow ISR cycles. KMS will provide awarning if the rate of the Fast ISR will consume greater than 80% of the available processor resources.

The defaults for KV3/KV4 are as follows:

• PWM Frequency = 10 kHz• PWM tick per Fast ISR = 1• Fast ISR Frequency = 10 kHz

In other words, the Fast ISR is configured to run at the PWM frequency of 10 kHz.

The defaults for KV1 are as follows:

• PWM Frequency = 10 kHz• PWM tick per Fast ISR = 2• Fast ISR Frequency = 5 kHz

Due to the reduced processing power available on the KV1 device, the Fast ISR runs at half of the PWMfrequency by default.

Slow Interrupt

While very fast dynamic response is critical for controlling a motor electrically, the mechanical responseof a motor is much slower than the electrical response which means that the control loops can be run muchslower. To achieve good control of these less time-sensitive operations, KMS relies on a Slow InterruptService Routine, or Slow ISR.

During this ISR, the feedback speed is estimated (EST) or calculated from the encoder (ENC), the refe-rence speeds are updated (TRAJ), the speed (SPEED) or position (POSITION) is controlled, and the fieldweakening controller is run (FW). There is also some additional software executed to handle the drive(DSM) and user (USER) state machines.

The blocks cited as contributing to the Fast ISR may also have less time critical elements operating in the

NXP SemiconductorsKinetis Motor Suite API Reference Manual

21

Page 48: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Additional Control Modes

Slow ISR. A high-level breakdown of when the code comprising a block is executed is included in eachchapter of this document.

The rate at which the Slow ISR operates is configurable in relation to the Fast ISR, which is configurablein relation to the PWM switching frequency of the processor.

The defaults for KV3/KV4 are as follows:

• Fast ISR Frequency = 10 kHz• Fast ISR per Slow ISR = 10• Slow ISR Frequency = 1 kHz

In other words, the Slow ISR by default is configured to run at 1/10th the speed of both the Fast ISR andthe PWM Frequency, or 1 kHz.

The defaults for KV1 are as follows:

• Fast ISR Frequency = 5 kHz• Fast ISR per Slow ISR = 5• Slow ISR Frequency = 1 kHz

On the KV1, the Slow ISR by default is configured to run at 1/5th the speed of the Fast ISR and 1/10th thespeed of the PWM Frequency.

1.4 Additional Control ModesBeyond speed and position control, KMS can also provide additional types of motor control.

Torque Control

In some applications the motor speed does not need to be controlled. For example, in an eBike application,the human riding the eBike is the speed controller and the throttle is a torque demand signal. KMS doessupport this type of control. Torque control merely constitutes the inner loop of the speed or positioncontrol loops. This type of control can be done either sensored or sensorlessly. Via the KMS PC GUI, thiscontrol mode is accessible in the Sensorless Velocity or Sensored Velocity control topologies.

In the below example plot, torque control used to spin the motor with a fixed torque reference. Whenthe motor was loaded down, the speed (est.output.rotorSpeed) in green reduces since the motor cannotovercome the amount of load using only the allowed current (user.command.statorRefCurrent.q) in red.This condition is represented by the estimated torque signal (est.output.torque) in blue flattening out at aconstant value.

22Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 49: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Additional Control Modes

Figure 1.4.1: Torque Control Example

When the amount of allowed current user.command.statorRefCurrent.q) in red is allowed to increase, themotor uses more current to overcome the load and the estimated torque signal (est.output.torque) in blueincreases. Additionally, the speed (est.output.rotorSpeed) in green increases as well.

Figure 1.4.2: Changing Torque Control Example

Just like in Sensorless Velocity control, startup is critical for torque control. When using Sensorless Torquecontrol via KMS the same startup mechanism is used as Sensorless Velocity control. The below plot isan example of what happens when running startup in torque control. The speed (est.output.rotorSpeed)

NXP SemiconductorsKinetis Motor Suite API Reference Manual

23

Page 50: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Additional Control Modes

in purple rises via the Trajectory block until it reaches the point where the Sensorless Estimator block isready to begin running (this point is called the crossover point and it indicated by the Speed Threshold).Once that point is reached, the Startup block begins blending the current onto the Q-axis and will increaseit until it is aligned with the user reference for torque. This process is shown by the gradual merge ofthe Startup current (startup.output.statorRefCurrent.q) in green to the value in the user reference (user.←↩command.statorRefCurrent.q) in blue. Once the merge process is complete the Startup block indicates thatthe control mode (startup.output.controlMode) shown in red should be 1 which indicates FOC operation.At that point the speed begins increasing very quickly.

Figure 1.4.3: Motor Startup in Torque Control

When using torque control with a sensor, the startup considerations can be ignored.

Voltage Control

For advanced motor control customers, the control of the current flowing through the motor can be bypas-sed. This allows the user to command a voltage to apply across the motor terminals. This can result in thecurrent being very large if the motor is not rotating. It is only recommended for customers who are verycomfortable with motor control topics and understand the risks involved.

When running in voltage control mode, the user is allowed to specify references which are used in placeof the references produced by the Current block. These references are in the units of modulation. Thiscontrol mode will still run the Sensorless Estimator block and can use that for the angle source whenperforming the Inverse Park transform. By default, this control mode does not run the Startup block andtherefore will not rotate, however this behaviour can be modified in the KMS firmware.

24Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 51: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Additional Control Modes

Duty Control

For advanced motor control customers, the control of the current flowing through the motor can be bypas-sed. This allows the user to command a voltage to apply across the motor terminals. This can result in thecurrent being very large if the motor is not rotating. It is only recommended for customers who are verycomfortable with motor control topics and understand the risks involved.

When running in duty control mode, the user is allowed to specify the references which are used in placeof the references produced by the Inverse Park block. These references are in the units of modulation.This control mode will still run the Sensorless Estimator but will not use that for the angle source. Theuser will have the ability to directly control the commanded motor angle by adjusting the reference valuesprovided to the SVPWM block.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

25

Page 52: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Additional Control Modes

26Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 53: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 2User2.1 OverviewEnables easy access for the user to the main operating states.

Functional description

The User block aggregates the main motor operating states capable of being called by the user. Thisis intended to provide an easy, consistent code interface for the user to be able to command a specificoperating state and perform certain common configurations of the desired state.

For example, if you wanted the motor to run in speed control mode at 2000 rpm this is the block wherethose commands would be written. In this example, the User block would be told to operate the drive inSpeed Control mode and it would receive the commanded speed of 2000 rpm that it would provide to thetrajectory generator.

This is the block that the KMS PC GUI operates on in order to command the motor.

The User block is intended to be a multiplexer into the FOC so that only a single interface needs to beaccessed in order to run the motor. The User block is slightly different for the different control modes. Forexample, not every state is available in all control modes. Differences between the control modes will becalled out in this document.

States that can be accessed via the User block include:

• Idle• Fault• Self-commissioning (SCM)• Inertia Estimation (Inertia)• PWM Duty Control• Voltage Control• Current Control (Current)• Speed Control (Speed)• Position Control (Position) [Sensored Position]• Motion Sequence (Plan)• Braking (Brake)• Encoder Alignment (Align) [Sensored Velocity or Sensored Position]

The User block interacts with both the Drive State Machine (DSM) and the Field Oriented Control (FOC).It sends a state command to the DSM to configure the FOC and sends references (speed setpoints, positionsteps, current setpoints, etc) to the FOC depending on the selected state. The User block also containsthe more complicated blocks that exist outside of the normal control flow. Namely: INERTIA, BRAKE,

NXP SemiconductorsKinetis Motor Suite API Reference Manual

27

Page 54: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

SCM, and PLAN. A visual representation of this is shown below.

Figure 2.1.1: USER - DSM - FOC Interaction

Block diagram detail

Figure 2.1.2: User

Configuration, inputs, and outputs

The only required configuration of the User block is for automatically retrying a failed startup for Sen-sorless. For Sensored Velocity and Sensored Position, the User block needs to be configured for encoderalignment.

28Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 55: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

The input to the User block is the requested state of operation and motor control setpoints.

The outputs of the User block are the required drive state to the Drive State Machine and the requestedcommands to the control blocks.

Code security breakdown

The table below describes the partitioning of User block code among open source, library, and protectedexecute-only.

Open Source Library Execute-onlyDefinition of available operatingstates, commands for states; functi-ons for initialization, configuration,updating

N/A N/A

Execution

As the User block aggregates different operating states, it has certain elements that are executed in theFAST ISR and certain elements executed in the SLOW ISR. The time of execution for these elementsis determined by the normal operation of the states they refer to. For example, configuration of the self-commissioning state occurs in the SLOW ISR because that is how the self-commissioning state (SCMblock) typically operates.

The User block also includes two update functions, one for FAST ISR and one for SLOW ISR.

User customization example

The user may prefer to operate in a constant voltage or torque-controlled manner for an application like aneBike, which does not require speed control. This can be achieved by effectively bypassing the Trajectoryand Speed blocks and utilizing the User block to command a constant current. Any unneeded operatingmodes for the end application can be removed from the User block.

Modules• Sensorless Velocity Control

The specific API interface for the User block inside of Sensorless Velocity Control.• Sensored Velocity Control

The specific API interface for the User block inside of Sensored Velocity Control.• Sensored Position Control

The specific API interface for the User block inside of Sensored Position Control.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

29

Page 56: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

2.2 Sensorless Velocity Control

2.2.1 Overview

The specific API interface for the User block inside of Sensorless Velocity Control.

Data Structures

• struct USER_config_t• struct USER_internal_t• struct USER_command_t• struct USER_output_t• struct USER_t

Macros

• #define SCM_CHANGE_TIME_COUNT ((uint16_t)1024)Time interval between motor parameter measurements (in timer counts)

• #define SCM_RS_STEADY_STATE_TIME_COUNT ((uint16_t)2048)Steady-state time interval for stator resistance measurement (in timer counts)

• #define SCM_LS_STEADY_STATE_TIME_COUNT ((uint16_t)1024)Steady-state time interval for stator inductance measurement (in timer counts)

• #define SCM_LS_OFF_TIME_COUNT ((uint16_t)2048)Time interval with zero voltage during stator inductance measurement (in timer counts)

• #define SCM_HI_SCM_THD (0.9)Relative high current threshold for stator inductance measurement.

• #define SCM_LO_SCM_THD (0.1)Relative low current threshold for stator inductance measurement.

• #define SCM_PM_STEADY_STATE_TIME_COUNT ((uint16_t)4096)Steady-state time interval for PM Flux measurement (in timer counts)

Enumerations

• enum USER_state_e {USER_IDLE = 0,USER_FAULT = 1,USER_SCM = 2,USER_INERTIA = 3,USER_RUN_DUTY = 4,USER_RUN_VOLTAGE = 5,USER_RUN_CURRENT = 6,USER_RUN_SPEED = 7,USER_RUN_PLAN = 8,USER_BRAKE = 9 }

USER state-machine states.

30Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 57: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

Functions

• USER_t ∗ USER_init (void ∗pMem, size_t size)Initializes USER module.

• void USER_initStructs (USER_t ∗pUSER, _lq limitAcc, _lq lq20LimitJerk, _lq IqRefMax, _lq Iq←↩RefMin)

Initializes all structs in USER module.• void USER_config (USER_t ∗pUSER, const USER_config_t ∗const config)

Configures the USER module.• void USER_updateSlowTick (USER_t ∗pUSER, DSM_t ∗pDSM, bool trajComplete, DRV_←↩

control_e controlType, _lq rotorSpeed, _lq fieldAngle, _lq trajRefSpeed)Updates the USER module at the Slow ISR.

• FAST void USER_updateFastTick (USER_t ∗pUSER, const FEEDBACK_output_t ∗const pADC,_lq speedOutMax, _lq speedOutMin)

Updates USER module at the Fast ISR.• void USER_selfCommissioningState (USER_t ∗pUSER, DSM_t ∗pDSM, bool scComplete)

Processes USER self-commissioning state.• FAST void USER_setInertiaOutput (USER_t ∗pUSER, _sq output)• void USER_cfgInertia (const INERTIA_config_t ∗const inertiaConfig, _lq sampleTime)

Configures the INERTIA module.• void USER_cfgBrake (const BRAKE_config_t ∗const brakeCfg)

Configures the BRAKE module.• void USER_cfgSCM (const SCM_config_t ∗const scmCfg, void ∗scmData, _sq ratedCurrent, _sq

ratedSpeed, _lq lq16BaseSpeedElecFreq, _lq focSampleTime)Configures the SCM module.

• void USER_resetDRVCommands (USER_t ∗pUSER)Resets drive commands going out of the USER module.

• static bool USER_runStartupRetry (USER_t ∗pUSER, DSM_t ∗pDSM)• static void USER_OnExit (USER_t ∗pUSER)

Cleans up the USER module upon exiting a state.• static void USER_OnEntry (USER_t ∗pUSER, USER_state_e commandedState)

Sets up the USER module upon entering a state.• static void USER_runIdleState (USER_t ∗pUSER)

Runs the Idle USER state.• static USER_state_e USER_runFaultState (USER_t ∗pUSER, DSM_t ∗pDSM)

Runs the Fault USER state.• static USER_state_e USER_runScmState (USER_t ∗pUSER, _lq fieldAngle, _lq trajRefSpeed)

Runs the Self Commissioning Module USER state.• static USER_state_e USER_runInertiaState (USER_t ∗pUSER, DRV_control_e controlType, _lq

rotorSpeed)Runs the Inertia Identification USER state.

• static void USER_runDutyState (USER_t ∗pUSER)Runs the PWM Duty Control USER state.

• static void USER_runVoltageState (USER_t ∗pUSER)Runs the Voltage Control USER state.

• static void USER_runCurrentState (USER_t ∗pUSER)Runs the Current Control USER state.

• static void USER_runSpeedState (USER_t ∗pUSER)Runs the Speed Control USER state.

• static USER_state_e USER_runPlanState (USER_t ∗pUSER, bool trajComplete)Runs the Plan USER state.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

31

Page 58: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

• static void USER_runBrakeStateFastTick (USER_t ∗pUSER, bool brakeEnable, _lq speedOutMax,_lq speedOutMin)

Runs the Braking USER state (Fast ISR)• static void USER_runBrakeStateSlowTick (USER_t ∗pUSER, _lq trajRefSpeed)

Runs the Braking USER state (Slow ISR)• static void USER_onEntryIdle (USER_t ∗pUSER)

Runs code upon entering Idle USER state.• static void USER_onEntryFault (USER_t ∗pUSER)

Runs code upon entering Fault USER state.• static void USER_onEntryScm (USER_t ∗pUSER)

Runs code upon entering Self Commissioning Module USER state.• static void USER_onEntryInertia (USER_t ∗pUSER)

Runs code upon entering Inertia Identification USER state.• static void USER_onEntryDuty (USER_t ∗pUSER)

Runs code upon entering PWM Duty Control USER state.• static void USER_onEntryVoltage (USER_t ∗pUSER)

Runs code upon entering Voltage Control USER state.• static void USER_onEntryCurrent (USER_t ∗pUSER)

Runs code upon entering Current Control USER state.• static void USER_onEntrySpeed (USER_t ∗pUSER)

Runs code upon entering Speed Control USER state.• static void USER_onEntryPlan (USER_t ∗pUSER)

Runs code upon entering Plan USER state.• static void USER_onEntryBrake (USER_t ∗pUSER)

Runs code upon entering Braking USER state.

Variables

• static SCM_t scmSCM block.

• static INERTIA_t inertiaINERTIA block.

• static BRAKE_t brakeBRAKE control block.

• static ST_VELPLAN_Handle pVelPlan• static ST_VelPlan_t VelPlan

2.2.2 Data Structure Documentation

2.2.2.1 struct USER_config_t

Data Fields

32Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 59: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

bool disable←↩FaultsinBrake

Setting this will disable all faults while applying brake

bool FWEnabled Controls if Field Weakening is allowed

uint16_t startupRetry←↩Attempts

Number of startup retries configured

uint16_t startupRetry←↩Delay

Startup retry delay counter incremented at Fast ISR sample rate

2.2.2.2 struct USER_internal_t

Data Fields

uint16_t autoRetry←↩Delay

Auto retry delay counter

uint16_t startupRetry←↩Counter

Startup retry counter

2.2.2.3 struct USER_command_t

Data Fields

_lq dutyA duty cycle to inverter { unit: [percentage], value range: [0,1.0] }

_lq dutyB duty cycle to inverter { unit: [percentage], value range: [0,1.0] }

_lq dutyC duty cycle to inverter { unit: [percentage], value range: [0,1.0] }

bool enableClamp←↩Phases

flag to clamp phases low

bool enableDC←↩Injection

configurable flag to enable DC injection

_lq IqRefMax Sets maximum Iq reference for speed loop { unit: [pu amps] }

_lq IqRefMin Sets minimum Iq reference for speed loop { unit: [pu amps] }

_lq limitAcc Profile generator acceleration limit { unit: [(pu rpm)/s] }

NXP SemiconductorsKinetis Motor Suite API Reference Manual

33

Page 60: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

_lq lq20LimitJerk Profile generator jerk limit { unit: [(pu rpm)/s∧2] }

bool pwmDisable flag to enable/disable PWM output

bool resetFault set to true to reset a fault

bool runTrajectory Configurable value to enable/ disable profile generator

TRF_r←↩Vector16_t

statorRef←↩Current

stator reference current { unit: [pu amps] }

TRF_r←↩Vector32_t

statorRef←↩Voltage

stator reference voltage { unit: [pu volts] }

_lq targetSpeed Target speed (in pu rpm) { unit: [pu rpm] }

2.2.2.4 struct USER_output_t

Data Fields

bool disableFaults Indicates if faults are disabled

USER_←↩command_t

drvCommand USER command references to DRV

DSM_state_e dsmCommand USER command to change DSM state

USER_state_e inState USER the current USER state

USER_state_e prevState USER previous USER state

bool runEstimator USER command to run estimator

2.2.2.5 struct USER_t

Data Fields

USER_←↩command_t

command Set the desired commands

USER_config←↩_t

config Holds the configuration for the USER block

USER_←↩internal_t

internal Internal variables to USER

34Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 61: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

USER_←↩output_t

output Stores the outputs from the USER block

USER_state_e state Set the desired USER state

2.2.3 Macro Definition Documentation

2.2.3.1 #define SCM_CHANGE_TIME_COUNT ((uint16_t)1024)

Time interval between motor parameter measurements (in timer counts)

Referenced by USER_cfgSCM().

2.2.3.2 #define SCM_HI_SCM_THD (0.9)

Relative high current threshold for stator inductance measurement.

Referenced by USER_cfgSCM().

2.2.3.3 #define SCM_LO_SCM_THD (0.1)

Relative low current threshold for stator inductance measurement.

Referenced by USER_cfgSCM().

2.2.3.4 #define SCM_LS_OFF_TIME_COUNT ((uint16_t)2048)

Time interval with zero voltage during stator inductance measurement (in timer counts)

Referenced by USER_cfgSCM().

2.2.3.5 #define SCM_LS_STEADY_STATE_TIME_COUNT ((uint16_t)1024)

Steady-state time interval for stator inductance measurement (in timer counts)

Referenced by USER_cfgSCM().

2.2.3.6 #define SCM_PM_STEADY_STATE_TIME_COUNT ((uint16_t)4096)

Steady-state time interval for PM Flux measurement (in timer counts)

Referenced by USER_cfgSCM().

NXP SemiconductorsKinetis Motor Suite API Reference Manual

35

Page 62: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

2.2.3.7 #define SCM_RS_STEADY_STATE_TIME_COUNT ((uint16_t)2048)

Steady-state time interval for stator resistance measurement (in timer counts)

Referenced by USER_cfgSCM().

2.2.4 Enumeration Type Documentation

2.2.4.1 enum USER_state_e

USER state-machine states.

Enumerator

USER_IDLE 0: USER IDLE stateUSER_FAULT 1: USER FAULT stateUSER_SCM 2: USER self-commissioning stateUSER_INERTIA 3: USER inertia estimation stateUSER_RUN_DUTY 4: DSM run PWM duty control stateUSER_RUN_VOLTAGE 5: DSM run voltage control stateUSER_RUN_CURRENT 6: USER run current control stateUSER_RUN_SPEED 7: USER run speed control stateUSER_RUN_PLAN 8: USER run a motion plan stateUSER_BRAKE 9: USER braking state

2.2.5 Function Documentation

2.2.5.1 void USER_cfgBrake ( const BRAKE_config_t ∗const brakeCfg )

Configures the BRAKE module.

Parameters

brakeCfg - pointer to the BRAKE configuration block

Returns

none

References BRAKE_config().

2.2.5.2 void USER_cfgInertia ( const INERTIA_config_t ∗const inertiaConfig, _lqsampleTime )

Configures the INERTIA module.

36Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 63: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

Parameters

inertiaConfig - pointer to the INERTIA configuration block

sampleTime - time between successive INERTIA calls

Returns

none

References INERTIA_config().

2.2.5.3 void USER_cfgSCM ( const SCM_config_t ∗const scmCfg, void ∗ scmData, _sqratedCurrent, _sq ratedSpeed, _lq lq16BaseSpeedElecFreq, _lq focSampleTime )

Configures the SCM module.

Parameters

scmCfg - pointer to the SCM configuration block

scmData - pointer to the EST's output SCM block

ratedCurrent - motor rated current

ratedSpeed - motor rated speed

lq16Base←↩SpeedElecFreq

- base electrical speed (in rad/sec)

focSampleTime - sample time of Current ISR (in sec)

Returns

none

References _LQ, SCM_CHANGE_TIME_COUNT, SCM_config(), SCM_HI_SCM_THD, SCM_LO_←↩SCM_THD, SCM_LS_OFF_TIME_COUNT, SCM_LS_STEADY_STATE_TIME_COUNT, SCM_P←↩M_STEADY_STATE_TIME_COUNT, and SCM_RS_STEADY_STATE_TIME_COUNT.

2.2.5.4 void USER_config ( USER_t ∗ pUSER, const USER_config_t ∗const config )

Configures the USER module.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

37

Page 64: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

Parameters

pUSER - pointer to the USER block

config - configuration structure for USER block

Returns

none

References USER_t::config.

2.2.5.5 USER_t ∗ USER_init ( void ∗ pMem, size_t size )

Initializes USER module.

Parameters

pMem - pointer to memory where the USER block is stored

size - size of memory where the USER block is stored

Returns

handle - interface to access the USER block

References USER_IDLE.

2.2.5.6 void USER_initStructs ( USER_t ∗ pUSER, _lq limitAcc, _lq lq20LimitJerk, _lqIqRefMax, _lq IqRefMin )

Initializes all structs in USER module.

Parameters

pUSER - pointer to the USER block

limitAcc - initial acceleration limit

lq20LimitJerk - initial jerk limit

IqRefMax - initial maximum Iq reference

38Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 65: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

IqRefMin - initial minimum Iq reference

Returns

none

References BRAKE_init(), USER_t::command, USER_output_t::drvCommand, INERTIA_init(), USE←↩R_output_t::inState, USER_command_t::IqRefMax, USER_command_t::IqRefMin, USER_command←↩_t::limitAcc, USER_command_t::lq20LimitJerk, USER_t::output, SCM_init(), USER_t::state, and US←↩ER_IDLE.

2.2.5.7 static void USER_OnEntry ( USER_t ∗ pUSER, USER_state_e commandedState )[static]

Sets up the USER module upon entering a state.

Parameters

pUSER - pointer to the USER block

commanded←↩State

- the next state commanded

Returns

none

References USER_BRAKE, USER_FAULT, USER_IDLE, USER_INERTIA, USER_onEntryBrake(),USER_onEntryCurrent(), USER_onEntryDuty(), USER_onEntryFault(), USER_onEntryIdle(), USER_←↩onEntryInertia(), USER_onEntryPlan(), USER_onEntryScm(), USER_onEntrySpeed(), USER_onEntry←↩Voltage(), USER_RUN_CURRENT, USER_RUN_DUTY, USER_RUN_PLAN, USER_RUN_SPEED,USER_RUN_VOLTAGE, and USER_SCM.

Referenced by USER_updateSlowTick().

2.2.5.8 static void USER_onEntryBrake ( USER_t ∗ pUSER ) [static]

Runs code upon entering Braking USER state.

Runs code upon entering USER Braking state.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

39

Page 66: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

Parameters

pUSER - pointer to the USER block

Returns

none

References BRAKE_COAST, BRAKE_DC_INJECTION, BRAKE_REGEN, BRAKE_ZERO_VECT←↩OR, BRAKE_config_t::brakingType, BRAKE_output_t::clampPhasesLow, USER_t::command, BRA←↩KE_t::config, USER_output_t::drvCommand, DSM_CURRENT, DSM_IDLE, DSM_MOTION, DSM←↩_PWM_DUTY, USER_output_t::dsmCommand, USER_command_t::enableClampPhases, BRAKE_t←↩::output, USER_t::output, USER_output_t::runEstimator, USER_command_t::runTrajectory, and USE←↩R_command_t::targetSpeed.

Referenced by USER_OnEntry().

2.2.5.9 static void USER_onEntryCurrent ( USER_t ∗ pUSER ) [static]

Runs code upon entering Current Control USER state.

Runs code upon entering USER Current control state.

Parameters

pUSER - pointer to the USER block

Returns

none

References USER_t::command, USER_output_t::drvCommand, DSM_CURRENT, USER_output_t←↩::dsmCommand, USER_command_t::limitAcc, USER_command_t::lq20LimitJerk, USER_t::output, U←↩SER_output_t::runEstimator, USER_command_t::runTrajectory, and USER_command_t::targetSpeed.

Referenced by USER_OnEntry().

2.2.5.10 static void USER_onEntryDuty ( USER_t ∗ pUSER ) [static]

Runs code upon entering PWM Duty Control USER state.

Runs code upon entering USER PWM Duty state.

40Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 67: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

Parameters

pUSER - pointer to the USER block

Returns

none

References DSM_PWM_DUTY, USER_output_t::dsmCommand, USER_t::output, and USER_output←↩_t::runEstimator.

Referenced by USER_OnEntry().

2.2.5.11 static void USER_onEntryFault ( USER_t ∗ pUSER ) [static]

Runs code upon entering Fault USER state.

Runs code upon entering USER FAULT state.

Parameters

pUSER - pointer to the USER block

Returns

none

References USER_t::output, and USER_output_t::runEstimator.

Referenced by USER_OnEntry().

2.2.5.12 static void USER_onEntryIdle ( USER_t ∗ pUSER ) [static]

Runs code upon entering Idle USER state.

Runs code upon entering USER IDLE state.

Parameters

pUSER - pointer to the USER block

Returns

none

References USER_t::output, and USER_output_t::runEstimator.

Referenced by USER_OnEntry().

NXP SemiconductorsKinetis Motor Suite API Reference Manual

41

Page 68: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

2.2.5.13 static void USER_onEntryInertia ( USER_t ∗ pUSER ) [static]

Runs code upon entering Inertia Identification USER state.

Runs code upon entering USER Inertia state.

Parameters

pUSER - pointer to the USER block

Returns

none

References USER_t::command, USER_output_t::drvCommand, DSM_CURRENT, USER_output_t←↩::dsmCommand, INERTIA_reset(), USER_command_t::limitAcc, USER_command_t::lq20LimitJerk,USER_t::output, USER_output_t::runEstimator, and USER_command_t::runTrajectory.

Referenced by USER_OnEntry().

2.2.5.14 static void USER_onEntryPlan ( USER_t ∗ pUSER ) [static]

Runs code upon entering Plan USER state.

Runs code upon entering USER Plan state.

Parameters

pUSER - pointer to the USER block

Returns

none

References USER_output_t::drvCommand, DSM_MOTION, USER_output_t::dsmCommand, USER_←↩t::output, USER_output_t::runEstimator, USER_command_t::runTrajectory, STVELPLAN_setEnable(),and STVELPLAN_setReset().

Referenced by USER_OnEntry().

2.2.5.15 static void USER_onEntryScm ( USER_t ∗ pUSER ) [static]

Runs code upon entering Self Commissioning Module USER state.

Runs code upon entering USER Self Commissioning state.

42Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 69: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

Parameters

pUSER - pointer to the USER block

Returns

none

References USER_t::command, USER_output_t::drvCommand, USER_command_t::limitAcc, USER←↩_command_t::lq20LimitJerk, USER_t::output, USER_output_t::runEstimator, and USER_command_t←↩::runTrajectory.

Referenced by USER_OnEntry().

2.2.5.16 static void USER_onEntrySpeed ( USER_t ∗ pUSER ) [static]

Runs code upon entering Speed Control USER state.

Runs code upon entering USER Speed control state.

Parameters

pUSER - pointer to the USER block

Returns

none

References DSM_MOTION, USER_output_t::dsmCommand, USER_t::output, and USER_output_t←↩::runEstimator.

Referenced by USER_OnEntry().

2.2.5.17 static void USER_onEntryVoltage ( USER_t ∗ pUSER ) [static]

Runs code upon entering Voltage Control USER state.

Runs code upon entering USER Voltage control state.

Parameters

NXP SemiconductorsKinetis Motor Suite API Reference Manual

43

Page 70: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

pUSER - pointer to the USER block

Returns

none

References DSM_VOLTAGE, USER_output_t::dsmCommand, USER_t::output, and USER_output_t←↩::runEstimator.

Referenced by USER_OnEntry().

2.2.5.18 static void USER_OnExit ( USER_t ∗ pUSER ) [static]

Cleans up the USER module upon exiting a state.

Parameters

pUSER - pointer to the USER block

Returns

none

References USER_output_t::inState, SCM_t::output, USER_t::output, SCM_resetOutputs(), SCM_Stop,SCM_output_t::state, STVELPLAN_run(), USER_INERTIA, USER_resetDRVCommands(), USER_←↩RUN_PLAN, and USER_SCM.

Referenced by USER_updateSlowTick().

2.2.5.19 void USER_resetDRVCommands ( USER_t ∗ pUSER )

Resets drive commands going out of the USER module.

Parameters

pUSER - pointer to the USER module

Returns

none

References _LQ, _SQ15, TRF_rVector16_t::d, TRF_rVector32_t::d, USER_output_t::drvCommand,DSM_IDLE, USER_output_t::dsmCommand, USER_command_t::dutyA, USER_command_t::dutyB,

44Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 71: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

USER_command_t::dutyC, USER_command_t::enableClampPhases, USER_command_t::enableDC←↩Injection, USER_t::output, USER_command_t::pwmDisable, TRF_rVector16_t::q, TRF_rVector32_t←↩::q, USER_command_t::runTrajectory, USER_command_t::statorRefCurrent, and USER_command_t←↩::statorRefVoltage.

Referenced by USER_OnExit().

2.2.5.20 static void USER_runBrakeStateFastTick ( USER_t ∗ pUSER, bool brakeEnable,_lq speedOutMax, _lq speedOutMin ) [static]

Runs the Braking USER state (Fast ISR)

Parameters

pUSER - pointer to the USER block

brakeEnable - true if braking is currently active

speedOutMax - speed loop max output

speedOutMin - speed loop min output

Returns

none

References BRAKE_COAST, BRAKE_run(), BRAKE_ZERO_VECTOR, BRAKE_config_t::braking←↩Type, BRAKE_output_t::clampPhasesLow, BRAKE_t::config, USER_t::config, BRAKE_output_t←↩::control, USER_output_t::disableFaults, USER_config_t::disableFaultsinBrake, USER_output_t::drv←↩Command, DSM_IDLE, USER_output_t::dsmCommand, USER_command_t::enableClampPhases, B←↩RAKE_t::output, USER_t::output, and USER_command_t::pwmDisable.

Referenced by USER_updateFastTick().

2.2.5.21 static void USER_runBrakeStateSlowTick ( USER_t ∗ pUSER, _lq trajRefSpeed) [static]

Runs the Braking USER state (Slow ISR)

Runs the Braking state (Slow actions)

Parameters

NXP SemiconductorsKinetis Motor Suite API Reference Manual

45

Page 72: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

pUSER - pointer to the USER block

trajRefSpeed - rotor reference speed as output by the TRAJ block

Returns

none

Parameters

pUSER - pointer to the USER block

trajRefSpeed - current reference speed

Returns

none

References _LQ, _SQ15, BRAKE_COAST, BRAKE_DC_INJECTION, BRAKE_REGEN, BRAK←↩E_ZERO_VECTOR, BRAKE_config_t::brakingType, USER_t::command, BRAKE_t::config, BR←↩AKE_output_t::control, TRF_rVector16_t::d, USER_output_t::drvCommand, DSM_IDLE, USER_←↩output_t::dsmCommand, BRAKE_output_t::enableDCInjection, USER_command_t::enableDCInjection,USER_command_t::IqRefMax, USER_command_t::IqRefMin, USER_command_t::limitAcc, USE←↩R_command_t::lq20LimitJerk, BRAKE_t::output, USER_t::output, TRF_rVector16_t::q, BRAKE_←↩output_t::rotorRefSpeed, BRAKE_output_t::speedOutMax, BRAKE_output_t::speedOutMin, USER_←↩command_t::statorRefCurrent, BRAKE_output_t::statorRefCurrentD, and USER_command_t::target←↩Speed.

Referenced by USER_updateSlowTick().

2.2.5.22 static void USER_runCurrentState ( USER_t ∗ pUSER ) [static]

Runs the Current Control USER state.

Runs the Current control USER state.

Parameters

pUSER - pointer to the USER block

Returns

none

References USER_t::command, USER_output_t::drvCommand, USER_command_t::enableDCInjection,USER_command_t::limitAcc, USER_command_t::lq20LimitJerk, USER_t::output, USER_command_←↩t::statorRefCurrent, and USER_command_t::targetSpeed.

Referenced by USER_updateSlowTick().

46Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 73: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

2.2.5.23 static void USER_runDutyState ( USER_t ∗ pUSER ) [static]

Runs the PWM Duty Control USER state.

Runs the PWM Duty control USER state.

Parameters

pUSER - pointer to the USER block

Returns

none

References USER_t::command, USER_output_t::drvCommand, USER_command_t::dutyA, USER_←↩command_t::dutyB, USER_command_t::dutyC, USER_command_t::enableClampPhases, and USER_←↩t::output.

Referenced by USER_updateSlowTick().

2.2.5.24 static USER_state_e USER_runFaultState ( USER_t ∗ pUSER, DSM_t ∗ pDSM )[static]

Runs the Fault USER state.

Runs the USER IDLE state.

Parameters

pUSER - pointer to the USER block

pDSM - pointer to the DSM block

Returns

USER_state_e The next state of USER user, indication a fault has been cleared

Parameters

pUSER - pointer to the USER block

pDSM - pointer to the DSM block

NXP SemiconductorsKinetis Motor Suite API Reference Manual

47

Page 74: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

Returns

none

References USER_t::command, DSM_IDLE, DSM_resetFaults(), USER_output_t::dsmCommand, U←↩SER_t::internal, USER_t::output, USER_output_t::prevState, USER_command_t::resetFault, USER←↩_internal_t::startupRetryCounter, USER_FAULT, USER_IDLE, USER_RUN_CURRENT, USER_R←↩UN_DUTY, USER_RUN_PLAN, USER_RUN_SPEED, USER_RUN_VOLTAGE, and USER_run←↩StartupRetry().

Referenced by USER_updateSlowTick().

2.2.5.25 static void USER_runIdleState ( USER_t ∗ pUSER ) [static]

Runs the Idle USER state.

Runs the USER IDLE state.

Parameters

pUSER - pointer to the USER block

Returns

none

References DSM_IDLE, USER_output_t::dsmCommand, and USER_t::output.

Referenced by USER_updateSlowTick().

2.2.5.26 static USER_state_e USER_runInertiaState ( USER_t ∗ pUSER, DRV_control_econtrolType, _lq rotorSpeed ) [static]

Runs the Inertia Identification USER state.

Cleans up a USER state upon exiting it.

Parameters

pUSER - pointer to the USER block

controlType - Startup or FOC mode

48Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 75: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

rotorSpeed - Speed feedback

Returns

USER_state_e USER state that INERTIA will run in the next slow tick

Parameters

pUSER - pointer to the USER block

controlType - Startup or FOC mode

rotorSpeed - Speed feedback

Returns

USER_state_e USER state that the SCM will run in the next slow tick

References _SQ15, TRF_rVector16_t::d, USER_output_t::drvCommand, INERTIA_output_t::finished,FOC, INERTIA_run(), INERTIA_output_t::IqRef, INERTIA_t::output, USER_t::output, TRF_←↩rVector16_t::q, USER_command_t::statorRefCurrent, INERTIA_output_t::targetSpeed, USER_←↩command_t::targetSpeed, USER_IDLE, and USER_INERTIA.

Referenced by USER_updateSlowTick().

2.2.5.27 static USER_state_e USER_runPlanState ( USER_t ∗ pUSER, bool trajComplete) [static]

Runs the Plan USER state.

Parameters

pUSER - pointer to the USER block

trajComplete - trajectory block has completed a trajectory

Returns

USER_state_e USER state that PLAN will run in the next slow tick

Parameters

NXP SemiconductorsKinetis Motor Suite API Reference Manual

49

Page 76: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

pUSER - pointer to the USER block

trajStatus - trajectory block status

Returns

none

References USER_t::command, USER_output_t::drvCommand, USER_command_t::IqRefMax, USE←↩R_command_t::IqRefMin, USER_command_t::limitAcc, USER_command_t::lq20LimitJerk, USER_t←↩::output, ST_PLAN_IDLE, STVELPLAN_getAccelerationLimit(), STVELPLAN_getJerkLimit(), ST←↩VELPLAN_getStatus(), STVELPLAN_getVelocitySetpoint(), STVELPLAN_run(), STVELPLAN_run←↩Tick(), STVELPLAN_setUnitProfDone(), USER_command_t::targetSpeed, USER_IDLE, and USER_←↩RUN_PLAN.

Referenced by USER_updateSlowTick().

2.2.5.28 static USER_state_e USER_runScmState ( USER_t ∗ pUSER, _lq fieldAngle,_lq trajRefSpeed ) [static]

Runs the Self Commissioning Module USER state.

Cleans up a USER state upon exiting it.

Parameters

pUSER - pointer to the USER block

trajRefSpeed - Target speed

fieldAngle - field angle

Returns

USER_state_e USER state that the SCM will run in the next slow tick

Parameters

pUSER - pointer to the USER block

fieldAngle - Rotor angle

trajRefSpeed - Target speed

50Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 77: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

Returns

USER_state_e USER state that the SCM will run in the next slow tick

References _LQ, _LQsincosPU(), _SQ15, TRF_orient32_t::cosAngle, TRF_rVector16_t::d, TRF_r←↩Vector32_t::d, USER_output_t::drvCommand, DSM_CURRENT, DSM_MOTION, DSM_VOLTAGE,USER_output_t::dsmCommand, USER_command_t::enableClampPhases, SCM_output_t::enableD←↩CInjection, USER_command_t::enableDCInjection, SCM_output_t::enableLsDecay, SCM_t::output,USER_t::output, TRF_rVector16_t::q, TRF_rVector32_t::q, SCM_output_t::rotorRefCurrent, SCM_←↩output_t::rotorRefSpeed, SCM_Ls, SCM_Pm, SCM_Rs, SCM_Stop, SCM_updateSlowTick(), TRF_←↩orient32_t::sinAngle, SCM_output_t::state, USER_command_t::statorRefCurrent, USER_command_t←↩::statorRefVoltage, USER_command_t::targetSpeed, USER_IDLE, and USER_SCM.

Referenced by USER_updateSlowTick().

2.2.5.29 static void USER_runSpeedState ( USER_t ∗ pUSER ) [static]

Runs the Speed Control USER state.

Parameters

pUSER - pointer to the USER block

Returns

none

References USER_t::command, USER_output_t::drvCommand, USER_command_t::IqRefMax, USE←↩R_command_t::IqRefMin, USER_command_t::limitAcc, USER_command_t::lq20LimitJerk, USER_t←↩::output, USER_command_t::runTrajectory, and USER_command_t::targetSpeed.

Referenced by USER_updateSlowTick().

2.2.5.30 static bool USER_runStartupRetry ( USER_t ∗ pUSER, DSM_t ∗ pDSM )[static]

References DSM_nonClrFaults_t::all, USER_internal_t::autoRetryDelay, DSM_clrFaults_t::bits, DS←↩M_t::clearableFaults, USER_t::config, USER_t::internal, DSM_clrFaults_t::DSM_clrFaultsBits_s::mot←↩StartupFailure, DSM_t::nonClearableFaults, USER_config_t::startupRetryAttempts, USER_internal_t←↩::startupRetryCounter, and USER_config_t::startupRetryDelay.

Referenced by USER_runFaultState().

2.2.5.31 static void USER_runVoltageState ( USER_t ∗ pUSER ) [static]

Runs the Voltage Control USER state.

Runs the Voltage control USER state.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

51

Page 78: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

Parameters

pUSER - pointer to the USER block

Returns

none

References USER_t::command, USER_output_t::drvCommand, USER_t::output, and USER_command←↩_t::statorRefVoltage.

Referenced by USER_updateSlowTick().

2.2.5.32 USER_selfCommissioningState ( USER_t ∗ pUSER, DSM_t ∗ pDSM, boolscComplete )

Processes USER self-commissioning state.

Parameters

pDSM - pointer to the drive module

scComplete - indicates if self commissioning is finished

Returns

none

2.2.5.33 void USER_setInertiaOutput ( USER_t ∗ pUSER, _sq output )

References USER_output_t::drvCommand, INERTIA_setOutput(), USER_t::output, TRF_rVector16_t←↩::q, and USER_command_t::statorRefCurrent.

2.2.5.34 void USER_updateFastTick ( USER_t ∗ pUSER, const FEEDBACK_output_t∗const pADC, _lq speedOutMax, _lq speedOutMin )

Updates USER module at the Fast ISR.

Parameters

52Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 79: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

pUSER - pointer to the USER module

pADC - pointer to the FEEDBACK output

speedOutMax - max Iqref configured in the SPEED module

speedOutMin - min Iqref configured in the SPEED module

Returns

none

References USER_output_t::inState, USER_t::output, SCM_updateFastTick(), USER_BRAKE, USER←↩_runBrakeStateFastTick(), and USER_SCM.

2.2.5.35 void USER_updateSlowTick ( USER_t ∗ pUSER, DSM_t ∗ pDSM, booltrajComplete, DRV_control_e controlType, _lq rotorSpeed, _lq fieldAngle, _lqtrajRefSpeed )

Updates the USER module at the Slow ISR.

Parameters

pUSER - pointer to the USER block

pDSM - pointer to the DSM block

trajComplete - trajectory block has completed a trajectory

controlType - control method used

rotorSpeed - Speed feedback

fieldAngle - field angle

trajRefSpeed - Target speed

Returns

none

References USER_t::command, DSM_FAULT, DSM_internal_t::inStartUpRegion, USER_output_←↩t::inState, USER_t::internal, DSM_t::internal, USER_t::output, USER_output_t::prevState, USER←↩_command_t::resetFault, USER_internal_t::startupRetryCounter, USER_t::state, DSM_t::state, US←↩ER_BRAKE, USER_FAULT, USER_IDLE, USER_INERTIA, USER_OnEntry(), USER_OnExit(),USER_RUN_CURRENT, USER_RUN_DUTY, USER_RUN_PLAN, USER_RUN_SPEED, USER_←↩RUN_VOLTAGE, USER_runBrakeStateSlowTick(), USER_runCurrentState(), USER_runDutyState(),USER_runFaultState(), USER_runIdleState(), USER_runInertiaState(), USER_runPlanState(), USER_←↩runScmState(), USER_runSpeedState(), USER_runVoltageState(), and USER_SCM.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

53

Page 80: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensorless Velocity Control

2.2.6 Variable Documentation

2.2.6.1 brake [static]

BRAKE control block.

2.2.6.2 inertia [static]

INERTIA block.

Referenced by STPOSCTL_setInertia(), and STVELCTL_setInertia().

2.2.6.3 ST_VELPLAN_Handle pVelPlan [static]

2.2.6.4 scm [static]

SCM block.

2.2.6.5 ST_VelPlan_t VelPlan [static]

54Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 81: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensored Velocity Control

2.3 Sensored Velocity ControlThe specific API interface for the User block inside of Sensored Velocity Control.

Differences from Sensorless Velocity

The primary difference between User block in Sensored Velocity control and Sensorless Velocity controlis that the Startup Retry mechanism has been replaced with the Alignment mechanism. The alignmentroutine forces the motor into an alignment state so that the encoder reading can be aligned to a knownmotor position. It does this by injecting D-axis current into the motor at an electrical angle of 0. Whichforces the motor to conform to this known electrical angle. The encoder reading is reset to 0, so that itwill accurately represent the motor's true angle. This is always done the first time that the User block iscommanded to go to a state where it needs to run the complete FOC. This step can be done at any time bysetting a flag to false.

For more specific details about this implementation refer to the user.c and user.h included in the SensoredVelocity reference project.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

55

Page 82: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Sensored Position Control

2.4 Sensored Position ControlThe specific API interface for the User block inside of Sensored Position Control.

Differences from Sensorless Velocity

One of the differences between User block in Sensored Position control and Sensorless Velocity controlis that the Startup Retry mechanism has been replaced with the Alignment mechanism. This alignmentroutine is identical to the one found in the Sensored Velocity reference project. The alignment routineforces the motor into an alignment state so that the encoder reading can be aligned to a known motorposition. It does this by injecting D-axis current into the motor at an electrical angle of 0. Which forcesthe motor to conform to this known electrical angle. The encoder reading is reset to 0, so that it willaccurately represent the motor's true angle. This is always done the first time that the User block iscommanded to go to a state where it needs to run the complete FOC. This step can be done at any time bysetting a flag to false.

The User block included for the Sensored Position reference design also has an expanded set of availablemotion commands so that position steps can be commanded and limits on velocity during a position profilecan be defined.

For more specific details about this implementation refer to the user.c and user.h included in the SensoredPosition reference project.

56Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 83: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 3Self Commissioning3.1 OverviewControls automatic motor parameter identification.

Functional description

The SCM ("self commissioning") block automatically identifies three electrical characteristics of a per-manent magnet or brushless DC motor:

• stator resistance• stator inductance• permanent magnet rotor flux

These key motor characteristics, in combination with the Basic Motor Parameters (rated current, polepairs, etc.) entered by the user, allow KMS to configure the current control loop (CURRENT) and speedand angle estimators (EST) which allow the user to spin the motor.

KMS performs resistance and inductance measurements by applying currents that are configurable aspercentages of rated current to excite the motor. During the resistance measurement, the current is slowlyincreased until it reaches the configured percentage of rated current. Once the desired current is reached,the current feedbacks are sampled and averaged over time and the stator voltage is estimated. Using Ohm’slaw, KMS is able to calculate the resistance. An example of this process is provided below.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

57

Page 84: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Figure 3.1.1: Resistance Measurement Example

In order to perform the inductance measurement, the current is again built up to a configurable level, andthe drive is then switched into clamp low, where all three low side switches are turned on. From this thecurrent decay is measured which when combined with the resistance, can give the inductance. An exampleof this process is provided below.

Figure 3.1.2: Inductance Measurement Example

After the resistance and inductance are calculated, the current controller is configured using pole-zerocancellation methods, and the motor is commanded to spin at an electrical frequency that is configurable

58Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 85: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

as a percentage of the motor’s rated frequency (determined by rated speed and number of pole pairs).While the motor is spinning, the instantaneous flux is calculated using values for average current and thepreviously determined stator inductance value, and instantaneous flux values are averaged to arrive at afinal permanent magnet flux value. An example of the start of this process is provided below.

Figure 3.1.3: Rotor Flux Measurement Example

In certain scenarios, SCM may require DC injection current or all phases clamped low. The SCM blockproduces outputs that will configure these functions within other blocks.

Block diagram detail

Figure 3.1.4: Self Commissioning

NXP SemiconductorsKinetis Motor Suite API Reference Manual

59

Page 86: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Configuration, inputs, and outputs

User configuration of the SCM block is achieved primarily by the specification of current and frequency tobe applied, as a percentage of the motor’s rated values. Additional configuration arguments include ratedmotor characteristics and time intervals for calculating resistance, inductance, and flux.

Outputs of the SCM block include measured values for stator resistance, stator inductance, permanentmagnet flux, and state of SCM operation.

Code security breakdown

The table below describes the partitioning of SCM block code among open source, library, and protectedexecute-only.

Open Source Library Execute-onlyStructures for module and output;functions for initialization, configu-ration, running, and updating

N/A Implementation of functions to me-asure motor parameters automati-cally

Execution

The SCM block is executed in the slow ISR and resides outside of the control flow, as it is typicallyperformed once in the early stage of the design process to get the motor up and running. Once the motorcharacteristics are well known, it is not necessary for this function to run repetitively.

User customization example

After initially identifying the motor's parameters, the Open Source portion of the SCM block can beremoved from the firmware. Since the motor parameters typically only need to be identified during theinitial design phase, they can be stored as the defaults in the reference project.

Data Structures• struct SCM_config_t

Self Commissioning configuration structure. More...• struct SCM_output_t

Self Commissioning output structure. More...• struct SCM_t

SCM module structure. More...

Macros• #define SCM_PRV_SIZE 32

60Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 87: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

Enumerations• enum SCM_state_e {

SCM_Stop = 0,SCM_Rs,SCM_Ls,SCM_Pm }

Self Commissioning state-machine states.

Functions• SCM_t ∗ SCM_init (void ∗pMem, size_t size)

Self commissioning initialization.• void SCM_config (SCM_t ∗handle, const SCM_config_t ∗const config, void ∗scmData, _sq rated←↩

Current, _sq ratedSpeed, _lq lq16BaseSpeedElecFreq, _lq focSampleTime, uint16_t rsSteadyState←↩TimeCount, uint16_t lsSteadyStateTimeCount, uint16_t lsOffTimeCount, uint16_t pmSteadyState←↩TimeCount, uint16_t scmChangeTimeCount, _lq scmHiThd, _lq scmLoThd)

• void SCM_updateSlowTick (SCM_t ∗handle, bool enable, bool closedLoop, const TRF_orient32_t∗const pOrient, _lq refRampOutput)

• void SCM_resetOutputs (SCM_t ∗handle)Resets (zeroes out) the self-commissioning (SCM) module's output signals.

• void SCM_measureStatorInductanceCurrent (SCM_t ∗handle, const FEEDBACK_output_t ∗constpADC)

• static void SCM_updateFastTick (SCM_t ∗handle, const FEEDBACK_output_t ∗const pADC)

3.2 Data Structure Documentation

3.2.1 struct SCM_config_t

Self Commissioning configuration structure.

Data Fields

_lq R_igbt IGBT resistance / DRV_BASE_RESISTANCE { unit: [pu ohms]}

_sq relativeLs←↩Current

Percentage (rel) of rated current applied for stator inductance ID

_sq relativePm←↩FluxFrequency

Percentage (rel) of rated frequency for PM Flux ID

_sq relativeRs←↩Current

Percentage (rel) of rated current applied for stator resistance ID

NXP SemiconductorsKinetis Motor Suite API Reference Manual

61

Page 88: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

SCM_state_e state Measurement the SCM should perform

3.2.2 struct SCM_output_t

Self Commissioning output structure.

Data Fields

bool enableDC←↩Injection

Flag to indicate if SCM needs DC injection

bool enableLsDecay

bool finished true: SCM has finished a commissioning stage

_lq pmFlux Permanent Magnet flux { unit: [pu webers] }

_sq rotorRef←↩Current

Output stator reference current rs & ls calculation (SQ15) { unit:[pu amps] }

_lq rotorRefSpeed Output Rotor ref Speed for pmFlux calculation { unit: [pu rpm] }

SCM_state_e state SCM State

_lq statorInd Stator inductance { unit: [pu henries] }

_lq statorRes Stator resistance { unit: [pu ohms] }

3.2.3 struct SCM_t

SCM module structure.

Data Fields

SCM_config←↩_t

config SCM Configuration structure

SCM_output←↩_t

output SCM output structure

uint32_t prv[SCM_PR←↩V_SIZE]

Private data block

3.3 Macro Definition Documentation

3.3.1 #define SCM_PRV_SIZE 32

62Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 89: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

3.4 Enumeration Type Documentation

3.4.1 enum SCM_state_e

Self Commissioning state-machine states.

Enumerator

SCM_Stop Self Commissioning Stop (Idle) stateSCM_Rs Self Commissioning Stator Resistance stateSCM_Ls Self Commissioning Stator Inductance stateSCM_Pm Self Commissioning PM Flux state

3.5 Function Documentation

3.5.1 void SCM_config ( SCM_t ∗ handle, const SCM_config_t ∗const config, void∗ scmData, _sq ratedCurrent, _sq ratedSpeed, _lq lq16BaseSpeedElecFreq,_lq focSampleTime, uint16_t rsSteadyStateTimeCount, uint16_tlsSteadyStateTimeCount, uint16_t lsOffTimeCount, uint16_tpmSteadyStateTimeCount, uint16_t scmChangeTimeCount, _lq scmHiThd,_lq scmLoThd )

Referenced by USER_cfgSCM().

3.5.2 SCM_init ( void ∗ pMem, size_t size )

Self commissioning initialization.

Parameters

pMem - pointer to memory where the SCM block is stored

size - size of memory where the SCM block is stored

Returns

handle - interface to access the SCM block

Referenced by USER_initStructs().

3.5.3 void SCM_measureStatorInductanceCurrent ( SCM_t ∗ handle, constFEEDBACK_output_t ∗const pADC )

Referenced by SCM_updateFastTick().

NXP SemiconductorsKinetis Motor Suite API Reference Manual

63

Page 90: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

3.5.4 SCM_resetOutputs ( SCM_t ∗ handle )

Resets (zeroes out) the self-commissioning (SCM) module's output signals.

Parameters

handle - interface to access the SCM block

Returns

none

Referenced by USER_OnExit().

3.5.5 static void SCM_updateFastTick ( SCM_t ∗ handle, constFEEDBACK_output_t ∗const pADC ) [inline], [static]

References SCM_t::config, SCM_Ls, SCM_measureStatorInductanceCurrent(), and SCM_config_t::state.

Referenced by USER_updateFastTick().

3.5.6 void SCM_updateSlowTick ( SCM_t ∗ handle, bool enable, bool closedLoop,const TRF_orient32_t ∗const pOrient, _lq refRampOutput )

Referenced by USER_runScmState().

64Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 91: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 4Inertia4.1 OverviewControls automatic system inertia measurement.

Functional description

The Inertia block identifies the mechanical inertia of a motor system. Mechanical inertia consists of themotor shaft and any part of the application that is rigidly coupled to the motor shaft and will rotate withthe shaft. This is contrasted with load, better identified as load torque, which will serve as an externaltorque that must be overcome. An easy example to consider is the washing machine: the drum constitutesinertia whereas the clothes in the drum constitute load. A visual example is provided below.

Figure 4.1.1: Example of What is and isn't Inertia

An estimate of system inertia is required by KMS’ advanced velocity controller, which uses the inertiainput to determine the amount of torque required to accelerate the system and ensure precise motioncontrol.

The inertia can only be measured when the motor is operating in the field oriented control region. Oncethe motor is operating in field oriented control, the torque will be increased at a configurable rate until theconfigured goal speed is reached. It will then decelerate quickly. This motion profile allows for KMS tosample velocity feedback and determine the inertia of the system. The closest block diagram to reference

NXP SemiconductorsKinetis Motor Suite API Reference Manual

65

Page 92: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

for inertia identification is Torque Control with the exception that the torque reference is provided by theInertia block. An example of the inertia estimation process is provided below.

Figure 4.1.2: Example of Inertia Measurement

KMS also provides an estimate of friction via this same profile, but this is purely informational and is notrequired for successful usage of KMS’ advanced velocity controller.

The Inertia block is effectively a simplified wrapper block for the core algorithms of SpinTAC™ VelocityIdentify submodule.

Block diagram detail

Figure 4.1.3: Inertia

66Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 93: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Configuration, inputs, and outputs

User configuration of the Inertia block is achieved primarily by the specification of the speed that themotor should attempt to accelerate to and the time allotted to ramp to this speed. Additional configurationarguments include trajectory (acceleration & jerk) and current (Q-axis current) constraints.

The input to the Inertia block is the velocity feedback from the Estimator block.

The primary outputs of the Inertia block is the instantaneous Iq reference and the estimates of systeminertia and friction.

Code security breakdown

The table below describes the partitioning of Inertia block code among open source, library, and protectedexecute-only.

Open Source Library Execute-onlyStructures for configuring inertiaidentification; set & get functions

N/A Implementation of automatic inertiaidentification algorithm

Execution

The Inertia block is executed in the slow ISR and resides outside of the control flow, as it is typicallyperformed once in the early stage of the design process to get the application running. Once the motorsystem inertia is well known, it is not necessary for this function to run repetitively.

User customization example

After initially identifying the system inertia and friction, the Inertia block can be removed from the firm-ware. Since the system inertia and friction typically only need to be identified during the initial designphase, they can be stored as the defaults in the reference project.

This is particularly true given the insensitivity of KMS’ advanced controller to changes in inertia - de-pending on application, KMS may require only an order of magnitude approximation of inertia to achievegood operation.

Data Structures• struct INERTIA_config_t

Inertia module config structure. More...• struct INERTIA_output_t

Inertia module output structure. More...• struct INERTIA_t• struct INERTIA_Status_e

NXP SemiconductorsKinetis Motor Suite API Reference Manual

67

Page 94: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

Inertia module status enum. More...

Macros• #define INERTIA_PRV_SIZE 40

Enumerations• enum INERTIA_Status_e {

INERTIA_IDLE =0,INERTIA_INIT,INERTIA_BUSY }

Functions• INERTIA_t ∗ INERTIA_init (void ∗pMem, size_t size)

Inertia Estimation initialization.• void INERTIA_config (INERTIA_t ∗handle, const INERTIA_config_t ∗const config, _lq sample←↩

Time)Inertia Estimation configuration.

• void INERTIA_run (INERTIA_t ∗handle, bool enable, bool closedLoopEnabled, _lq rotorSpeed)Inertia Estimation function.

• FAST void INERTIA_setOutput (INERTIA_t ∗handle, _sq output)Inertia Estimation update output.

• void INERTIA_reset (INERTIA_t ∗handle)Inertia module reset.

4.2 Data Structure Documentation

4.2.1 struct INERTIA_config_t

Inertia module config structure.

Data Fields

_lq goalSpeed goal speed setting of the Inertia identification { units: [pu rpm] }

uint16_t lpfTime_tick low pass filter time constant setting for the velocity feedback

_lq outMax output maximum limit configuration { units: [pu amps] }

_lq timeOut_sec maximum time allowed for the inertia estimation process { units:[sec] }

68Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 95: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

_lq torqueRamp←↩Time_sec

ramp time setting for the torque reference { units: [sec] }

4.2.2 struct INERTIA_output_t

Inertia module output structure.

Inertia module nested structure.

Data Fields

uint16_t error error ID

bool finished indicator for whether inertia ID is complete

_lq frictionEst estimated friction in PU Amp-sec/krpm { units: [(pu amps)/(purpm)] }

_lq inertiaEst estimated inertia in PU Amp-sec/krpm { units: [(pu amps)/(purpm)/s] }

_sq IqRef current reference generated by the inertia module { units: [puamps] }

INERTIA_←↩Status_e

status enum indicating the status of the inertia estimation

_lq targetSpeed target speed for successful inertia estimate { units: [pu rpm] }

4.2.3 struct INERTIA_t

Data Fields

INERTIA_←↩config_t

config configuration structure of inertia estimate module

INERTIA_←↩output_t

output output structure of inertia estimate module

uint32_t prv[INERTI←↩A_PRV_SIZE]

4.2.4 struct INERTIA_Status_e

Inertia module status enum.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

69

Page 96: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

4.3 Macro Definition Documentation

4.3.1 #define INERTIA_PRV_SIZE 40

4.4 Enumeration Type Documentation

4.4.1 enum INERTIA_Status_e

Enumerator

INERTIA_IDLE velocity Identify is in idle state, zero outputINERTIA_INIT velocity Identify is in init state, validating configured parametersINERTIA_BUSY velocity Identify is in busy state, identifying system inertia

4.5 Function Documentation

4.5.1 INERTIA_config ( INERTIA_t ∗ handle, const INERTIA_config_t ∗constconfig, _lq sampleTime )

Inertia Estimation configuration.

Parameters

handle - pointer to the INERTIA block

config - pointer to INERTIA_config structure

sampleTime - sample time of the inertia module

Returns

none

Referenced by USER_cfgInertia().

4.5.2 INERTIA_init ( void ∗ pMem, size_t size )

Inertia Estimation initialization.

Parameters

pMem - pointer to memory where the INERTIA block is stored

70Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 97: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

size - size of memory where the INERTIA block is stored

Returns

handle - interface to access the INERTIA block

Referenced by USER_initStructs().

4.5.3 INERTIA_reset ( INERTIA_t ∗ handle )

Inertia module reset.

Parameters

handle - pointer to the INERTIA block

Returns

none

Referenced by USER_onEntryInertia().

4.5.4 INERTIA_run ( INERTIA_t ∗ handle, bool enable, bool closedLoopEnabled,_lq rotorSpeed )

Inertia Estimation function.

Parameters

handle - pointer to the INERTIA block

enable - enables the current loop operation

closedLoop←↩Enabled

- indicates if closed loop control is available

rotorSpeed - rotor feedback speed { units: [pu rpm] }

Returns

none

Referenced by USER_runInertiaState().

4.5.5 INERTIA_setOutput ( INERTIA_t ∗ handle, _sq output )

Inertia Estimation update output.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

71

Page 98: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

handle - pointer to the INERTIA block

output - current reference to update the inertia module (SQ15) { units: [pu amps] }

Returns

none

Referenced by USER_setInertiaOutput().

72Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 99: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 5Brake5.1 OverviewResponsible for halting motor.

Functional description

The Brake block is intended to force the motor to a halt and should be utilized when user wants above allelse to stop the motor. In this respect, the Brake block operates as an emergency stop function: protectionthresholds and normal kinematic constraints may be disregarded in pursuit of the overall objective ofstopping the motor.

The Brake block offers four methods of braking:

• Coast to stop: PWM output ceases and motor slows to a stop without any influence from the system• DC injection: D-axis current is ramped up to a user specified level and the electrical angle is held at

a constant 0 degrees to prevent rotation• Zero vector: Forces low side transistors of inverter on, tying motor phases together (Default braking

type)• Regenerative: Ramps the motor speed to 0 while limiting the available output of the speed controller.

Given proper hardware, harvests energy from the motor ramp-down.

These are in addition to the option of ramping to stop, which simply involves setting a target speed of zero.In this case, the motor will obey motion trajectory limits - it will slow to a stop according to the specifiedacceleration and jerk limits and is therefore like any other speed-to-speed transition.

The Brake block exists outside the normal control flow path but is engaged by the User block.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

73

Page 100: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Block diagram detail

Figure 5.1.1: Brake

Configuration, inputs, and outputs

Configuration of the Brake block involves specifying the desired brake type and applying any relevantlimits for the behavior implied by the chosen brake type. For instance, if DC injection braking is selected,the limit on this applied current and the rate at which the system ramps current to this level should bespecified.

Code security breakdown

The table below describes the partitioning of Brake block code among open source, library, and protectedexecute-only.

Open Source Library Execute-onlyUser configurable elements - typeof braking, constraints on differentbraking types

Initialization & operation givenuser specifications

N/A

Execution

The Brake block operates in the Fast ISR to ensure that any action to stop the motor happens as quickly aspossible.

74Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 101: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

User customization example

The Brake block is configured by default to operate only when explicitly called by the user. However, theuser can easily tie an unwanted system state to an immediate halting of the motor by toggling the booleanthat applies the brake on a system trigger. Additionally a hardware GPIO or switch can be used to triggerthe Brake to be applied.

Data Structures• struct BRAKE_output_t• struct BRAKE_config_t• struct BRAKE_t

Brake module structure. More...

Macros• #define BRAKE_PRV_SIZE 3

Enumerations• enum BRAKE_type_e {

BRAKE_ZERO_VECTOR = 0,BRAKE_REGEN,BRAKE_COAST,BRAKE_DC_INJECTION }

Braking method enumerations.

Functions• BRAKE_t ∗ BRAKE_init (void ∗pMem, size_t size)

Brake initialization.• void BRAKE_config (BRAKE_t ∗handle, const BRAKE_config_t ∗const config)• FAST void BRAKE_run (BRAKE_t ∗handle, bool enable, _lq speedOutMax, _lq speedOutMin)

5.2 Data Structure Documentation

5.2.1 struct BRAKE_output_t

Data Fields

bool clampPhases←↩Low

true: Lower switches of inverter always on (zero state)

NXP SemiconductorsKinetis Motor Suite API Reference Manual

75

Page 102: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

bool control true: braking is currently active

bool enable←↩CurrentLoop

true: current loop needs to be enabled by drive

bool enableDC←↩Injection

true: DC injection needs to be enabled by drive

bool enableRun true: braking feature is enabled

bool enableSpeed←↩Loop

true: speed loop needs to be enabled by drive

_lq rotorRefSpeed Rotor reference speed output of the brake module

_lq speedOutMax Speed maximum Iq reference limit

_lq speedOutMin Speed minimum Iq reference limit

_sq statorRef←↩CurrentD

Current reference for DC injection braking

5.2.2 struct BRAKE_config_t

Data Fields

BRAKE_←↩type_e

brakingType Braking method to be used

_sq dcInjectIdRef DC injection current during DC_INJECTION_BRAKING [pu A]

_sq dcInjectMax←↩Delta

Maximum change of DC injection current during DC_INJECTI←↩ON_BRAKING [pu A]

_lq regenIqRefLim Absolute Braking torque limit during REGEN_BRAKING [puNm]

5.2.3 struct BRAKE_t

Brake module structure.

Data Fields

76Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 103: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

BRAKE_←↩config_t

config Braking configuration structure

BRAKE_←↩output_t

output Braking output structure

uint32_t prv[BRAKE_←↩PRV_SIZE]

Braking private data block

5.3 Macro Definition Documentation

5.3.1 #define BRAKE_PRV_SIZE 3

5.4 Enumeration Type Documentation

5.4.1 enum BRAKE_type_e

Braking method enumerations.

Enumerator

BRAKE_ZERO_VECTOR Zero Vector braking (High sides OFF, Low side ON) (default)BRAKE_REGEN Regenerative (FOC) brakingBRAKE_COAST Coast to stop braking (all PWM's disabled)BRAKE_DC_INJECTION DC Injection braking

5.5 Function Documentation

5.5.1 void BRAKE_config ( BRAKE_t ∗ handle, const BRAKE_config_t ∗constconfig )

Referenced by USER_cfgBrake().

5.5.2 BRAKE_init ( void ∗ pMem, size_t size )

Brake initialization.

Parameters

pMem - pointer to memory where the BRAKE block is stored

NXP SemiconductorsKinetis Motor Suite API Reference Manual

77

Page 104: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

size - size of memory where the BRAKE block is stored

Returns

handle - interface to access the BRAKE block

Referenced by USER_initStructs().

5.5.3 FAST void BRAKE_run ( BRAKE_t ∗ handle, bool enable, _lq speedOutMax,_lq speedOutMin )

Referenced by USER_runBrakeStateFastTick().

78Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 105: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 6Drive State Machine6.1 OverviewDefines motor states and transitions.

Functional description

The Drive State Machine (DSM) block is responsible for ensuring that KMS operates in accordance withits own block diagram. It is also responsible for handling interactions between available motor operatingstates and for defining faults encountered in operation.

The KMS block diagram (Figure 1) specifies the order of operation of different blocks. These blocks haveinternal operations as described elsewhere in this document, but the DSM is responsible for managing thetransition from one block to the next.

The order of operation may deviate from the flow described in the canonical diagram under certain circum-stances. This is where different available operating states and faults come into play. The DSM accountsfor user specification of, for example running in voltage control mode, and appropriately updates controlflow. Faults similarly trigger an alteration in the control flow, with the DSM responsible for properlyhalting normal operation, reporting the fault, and restoring normal operation upon clearing of the fault.

Block diagram detail

Figure 6.1.1: Drive State Machine

NXP SemiconductorsKinetis Motor Suite API Reference Manual

79

Page 106: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Configuration, inputs, and outputs

Configuration of the DSM block largely consists of definition of faults, as the DSM is itself a configu-ration of the manner in which different operating states interact. Inputs to the DSM block are primarilycommands from other blocks that mandate a shift in operating behavior. For example, the User block maycommand the DSM block to initiate a different motor operating mode (switching from Speed Control toVoltage Control). Outputs of the DSM block are typically commands to switch from block to block andstatus of where the system currently resides.

Code security breakdown

The table below describes the partitioning of DSM block code among open source, library, and protectedexecute-only.

Open Source Library Execute-onlyDefinition of motor operating sta-tes & control type, faults, updatingfunctions

N/A N/A

Execution

Because the DSM block is responsible for managing transitions among blocks with different operatingrequirements, it has certain elements that update in the FAST ISR and certain elements that update inthe SLOW ISR. For example, peak overcurrent fault is evaluated in the FAST ISR but overspeed fault isevaluated in the SLOW ISR.

User customization example

The user may want to add an additional block of proprietary code to motor control operation and woulduse the “glue” logic defined in the DSM block to connect this proprietary code to general motor controloperation. An example of such proprietary code might be torque ripple compensation (typical of compres-sor applications) or load imbalance detection (washing machine applications). Since the DSM owns all ofthe fault handling for KMS if there are additional faults that the user wishes to add, they should be addedinto this block.

Data Structures• struct DSM_faultThresholds_t• union DSM_clrFaults_t• struct DSM_clrFaults_t::DSM_clrFaultsBits_s

Drive state-machine clearable bits structure. More...• union DSM_nonClrFaults_t

80Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 107: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

• struct DSM_nonClrFaults_t::DSM_nonClrFaultsBits_sDrive state-machine non-clearable faults bits structure. More...

• struct DSM_internal_t• struct DSM_t• union DSM_clrFaults_u

Drive state-machine clearable faults union. More...• union DSM_nonClrFaults_u

Drive state-machine non-clearable faults union. More...

Macros• #define DSM_PK_CURRENT_FAULT_COUNTER (15U)

Number of successive peak overcurrents before triggering a fault.• #define DSM_RESET_LINE_HOLD_TIME (4U)

Hold time (in us) for the reset line.

Typedefs• typedef unsigned int bitfield_t

Enumerations• enum DRV_control_e {

STARTUP = 0,FOC = 1 }

Enumeration of control options offered.• enum DSM_state_e {

DSM_START = 0,DSM_IDLE,DSM_FAULT,DSM_PWM_DUTY,DSM_VOLTAGE,DSM_CURRENT,DSM_MOTION }

Drive state-machine states.

Functions• DSM_t ∗ DSM_init (void ∗pMem, size_t size)

Initializes DSM module.• void DSM_configFaults (DSM_t ∗pDSM, const DSM_faultThresholds_t ∗const faults)

Updates DSM module at 1ms tick.• void DSM_updateSlowTick (DSM_t ∗pDSM, DSM_state_e newState, const FEEDBACK_output←↩

_t ∗const pADC, DRV_control_e controlType, _lq rotorRefSpeed, _lq rotorSpeed_50Hz, boolspeedLoopEnabled, _lq filtStatorFluxSpVecMag, bool faultsDisabled)

• void FAST DSM_updateAtFastTick (DSM_t ∗pDSM, const FEEDBACK_output_t ∗const pADC,bool faultsDisabled)

Updates DSM module at the Fast tick.• void DSM_resetFaults (DSM_t ∗pDSM)

NXP SemiconductorsKinetis Motor Suite API Reference Manual

81

Page 108: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

Sets the bit to reset faults in the DSM.• void DSMS_Init (void)

Platform Specific Init.• FAST DSM_clrFaults_t DSMS_GetClearableFaults (const DSM_faultThresholds_t ∗const dsm←↩

FaultThresholds)• FAST DSM_nonClrFaults_t DSMS_GetNonClearableFaults (void)

Get Platform Specific Non Clearable Fault bits to OR into DSM module.• void DSMS_ClearableFaultsReset (void)

Clear any active faults (Platform Specific bits)• void DSMS_CalculateTemperature (uint16_t adcTemperatureInput)

Calculates the temperature and passes it to the DSM system.• static void DSM_startState (DSM_t ∗pDSM)

Processes DSM start state.• static void DSM_idleState (DSM_t ∗pDSM, DSM_state_e newState)

Processes DSM idle state.• static void DSM_runTimeMonitor (DSM_t ∗pDSM, DSM_state_e newState, DRV_control_←↩

e controlType, bool speedLoopEnabled, _lq speedError, bool rotorSyncLoss, bool faultsDisabled)• static void DSM_faultState (DSM_t ∗pDSM)

Processes DSM fault state.• static void DSMS_hwFaultReset (void)

Performs the hardware fault reset.• static void InitSPI (void)

void InitSPI(void)

Variables• static mcdrv_spi_drv3ph_init_t g_sM1Driver3phInit

Configuration structure for 3-phase MOSFET predriver.• static mcdrv_spi_drv3ph_t g_sM1Driver3ph

6.2 Data Structure Documentation

6.2.1 struct DSM_faultThresholds_t

Data Fields

bool enableFaults global fault enable

_lq minSyncSpeed Minimum rotor speed to enable loss of sync detection { unit: [purpm] }

_sq overCurrent←↩Peak

Peak over current fault threshold { unit: [pu amps] }

82Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 109: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

_sq overCurrentR←↩MS

RMS over current fault threshold { unit: [pu amps] }

uint16_t overCurrentR←↩MSCounter

RMS over current fault hysteresis setting { unit: [slow isr ticks] }

_lq overSpeed Over Speed fault threshold { unit: [pu rpm] }

_sq overTemp←↩Inverter

Inverter temperature fault threshold { unit: [deg C] }

_sq overTemp←↩Motor

Motor temperature fault threshold { unit: [deg C] }

_lq overVoltage Over voltage fault threshold { unit: [pu volts] }

_lq pmFluxSync←↩ThreshWb

Stator flux / PM flux threshold to trigger loss of sync { unit: [puwebers] }

uint16_t stallCounter Hysteresis setting for the stall fault { unit: [slow isr ticks] }

_lq stallSpeedError Speed error threshold for stall fault { unit: [pu rpm] }

uint16_t startup←↩VoltageTimer

Startup voltage Timer { unit: [slow isr ticks] }

_lq underVoltage Under voltage fault threshold { unit: [pu volts] }

6.2.2 union DSM_clrFaults_t

Data Fields

uint32_t all DSM clearable faults register

structDSM_clr←↩

FaultsBits_s

bits Drive state-machine clearable faults bits

6.2.3 struct DSM_clrFaults_t::DSM_clrFaultsBits_s

Drive state-machine clearable bits structure.

Data Fields

NXP SemiconductorsKinetis Motor Suite API Reference Manual

83

Page 110: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

bitfield_t brkChopper←↩OverCurrent:1

B1.2 DSM brake chopper over-current fault bitfield

bitfield_t commsFault: 1 B3.1 DSM communications (timeout) fault bitfield

bitfield_t dcBusOver←↩Current: 1

B0.7 DSM DC bus over-curent fault bitfield

bitfield_t dcBusOver←↩Voltage: 1

B1.0 DSM DC bus over-voltage fault bitfield

bitfield_t dcBusUnder←↩Voltage: 1

B1.1 DSM DC bus under-voltage fault bitfield

bitfield_t fastIsr←↩Reentered:1

B3.2 DSM fast ISR reentered

bitfield_t hwFault: 1 B0.0 DSM hardware latched fault (peak over-current or DC busover-voltage) bitfield

bitfield_t invOver←↩Temperature:1

B1.4 DSM inverter over-temperature fault bitfield

bitfield_t motImbPhase←↩A: 1

B2.2 DSM motor phase A imbalance fault bitfield

bitfield_t motImbPhase←↩B: 1

B2.3 DSM motor phase B imbalance fault bitfield

bitfield_t motImbPhase←↩C: 1

B2.4 DSM motor phase C imbalance fault bitfield

bitfield_t motLossSync:1

B2.6 DSM motor stall bitfield - Motor stalled

bitfield_t motOpen←↩PhaseA: 1

B1.7 DSM motor open phase A fault bitfield

bitfield_t motOpen←↩PhaseB: 1

B2.0 BDSM motor open phase B fault bitfield

bitfield_t motOpen←↩PhaseC: 1

B2.1 DSM motor open phase C fault bitfield

bitfield_t motOver←↩Speed: 1

B1.5 DSM motor over-speed fault bitfield

84Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 111: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

bitfield_t motOver←↩Temperature:1

B1.6 DSM motor over-temperature fault bitfield

bitfield_t motStall: 1 B2.5 DSM motor stall bitfield - Motor stalled

bitfield_t motStartup←↩Failure: 1

B2.7 DSM motor startup bitfield - Startup failure

bitfield_t pfcOver←↩Current: 1

B1.3 DSM PFC circuit over-current fault bitfield

bitfield_t pkOver←↩CurrentA:1

B0.4 DSM peak (instantaneous) over-current fault on phase A bit-field

bitfield_t pkOver←↩CurrentB:1

B0.5 DSM peak (instantaneous) over-current fault on phase B bit-field

bitfield_t pkOver←↩CurrentC:1

B0.6 DSM peak (instantaneous) over-current fault on phase B bit-field s

bitfield_t preDriverD←↩CBusOver←↩Current:1

B3.5 DSM Pre-Driver Temp Threshold

bitfield_t preDriver←↩LowVoltage←↩Supply:1

B3.4 DSM Pre-Driver Low Voltage Supply

bitfield_t preDriver←↩PhaseError:1

B3.6 DSM Pre-Driver Phase Error

bitfield_t preDriver←↩Temp:1

B3.7 DSM Pre-Driver Temp Threshold

bitfield_t rmsOver←↩CurrentA:1

B0.1 DSM rms (steady-state) over-current fault on phase A bitfield

bitfield_t rmsOver←↩CurrentB:1

B0.2 DSM rms (steady-state) over-current fault on phase B bitfield

NXP SemiconductorsKinetis Motor Suite API Reference Manual

85

Page 112: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

bitfield_t rmsOver←↩CurrentC:1

B0.3 DSM rms (steady-state) over-current fault on phase C bitfield

bitfield_t slowIsr←↩Reentered:1

B3.3 DSM slow ISR reentered

bitfield_t wdReset: 1 B3.0 DSM watchdog reset fault bitfield

6.2.4 union DSM_nonClrFaults_t

Data Fields

uint16_t all DSM non-clearable faults register

structDSM_nonClr←↩

FaultsBits_s

bits Drive state-machine non-clearable faults bits

6.2.5 struct DSM_nonClrFaults_t::DSM_nonClrFaultsBits_s

Drive state-machine non-clearable faults bits structure.

Data Fields

bitfield_t __pad0__: 5 unused bitfields

bitfield_t adcFault: 1 B0.3 DSM ADC offset fault on phase A, B or C bitfield

bitfield_t calibration←↩Fault: 1

B0.2 DSM current sensors calibration fault bitfield

bitfield_t clkFault: 1 B0.7 DSM CPU clock fault bitfield

bitfield_t encoder←↩SensorFault:1

B0.0 DSM encoder sensor fault bitfield

86Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 113: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

bitfield_t flashFault: 1 B0.5 DSM CPU flash memory fault bitfield

bitfield_t hallSensor←↩Fault: 1

B0.1 DSM Hall sensor fault bitfield

bitfield_t isrFault: 1 B1.0 DSM ISR fault bitfield

bitfield_t ramFault: 1 B0.4 DSM CPU RAM memory fault bitfield

bitfield_t regFault: 1 B0.6 DSM CPU register fault bitfield

bitfield_t secureMotor←↩Observer←↩RomIdFault:1

B1.0 DSM MotorObserver Secure ROM Incompatible fault bitfield

bitfield_t secureSpin←↩TACRomId←↩Fault: 1

B1.0 DSM SpinTAC Secure ROM Incompatible fault bitfield

6.2.6 struct DSM_internal_t

Data Fields

bool faults←↩Configured

Bool indicating whether faults are configured

uint16_t focTran←↩Counter

Counter indicating how long system has been in FOC region

bool inStartUp←↩Region

Bool indication of motor operating in startup region

uint16_t peakOver←↩Current←↩CounterA

Counter indicating peak overcurrent fault counter for Phase A

uint16_t peakOver←↩Current←↩CounterB

Counter indicating peak overcurrent fault counter for Phase B

NXP SemiconductorsKinetis Motor Suite API Reference Manual

87

Page 114: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

uint16_t peakOver←↩Current←↩CounterC

Counter indicating peak overcurrent fault counter for Phase C

uint16_t rmsOver←↩Current←↩CounterA

Counter indicating RMS current fault condition for Phase A

uint16_t rmsOver←↩Current←↩CounterB

Counter indicating RMS current fault condition for Phase B

uint16_t rmsOver←↩Current←↩CounterC

Counter indicating RMS current fault condition for Phase C

uint16_t stallDetect←↩Counter

Stall detect counter

uint16_t startup←↩VoltageCounter

Startup Voltage counter

uint16_t syncDetect←↩Counter

Sync loss detection counter

6.2.7 struct DSM_t

Data Fields

DSM_clr←↩Faults_t

clearableFaults DSM clearable faults

DSM_fault←↩Thresholds_t

faultThresholds DSM configured fault thresholds

DSM_←↩internal_t

internal DSM internal counters

DSM_nonClr←↩Faults_t

nonClearable←↩Faults

DSM non-clearable faults

bool resetFault DSM reset fault

DSM_state_e state DSM state

6.2.8 union DSM_clrFaults_u

Drive state-machine clearable faults union.

88Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 115: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Enumeration Type Documentation

6.2.9 union DSM_nonClrFaults_u

Drive state-machine non-clearable faults union.

6.3 Macro Definition Documentation6.3.1 #define DSM_PK_CURRENT_FAULT_COUNTER (15U)

Number of successive peak overcurrents before triggering a fault.

Referenced by DSM_updateAtFastTick().

6.3.2 #define DSM_RESET_LINE_HOLD_TIME (4U)

Hold time (in us) for the reset line.

Referenced by DSMS_hwFaultReset().

6.4 Typedef Documentation6.4.1 typedef unsigned int bitfield_t

6.5 Enumeration Type Documentation6.5.1 enum DRV_control_e

Enumeration of control options offered.

Enumerator

STARTUP Open Loof IF FOCFOC PMSM rotor FOC sensorless speed control

6.5.2 enum DSM_state_e

Drive state-machine states.

Enumerator

DSM_START 0: DSM start stateDSM_IDLE 1: DSM idle stateDSM_FAULT 2: DSM fault stateDSM_PWM_DUTY 3: DSM PWM duty control stateDSM_VOLTAGE 4: DSM voltage control stateDSM_CURRENT 5: DSM current control stateDSM_MOTION 6: DSM motion control state (speed or position control)

NXP SemiconductorsKinetis Motor Suite API Reference Manual

89

Page 116: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

6.6 Function Documentation

6.6.1 void DSM_configFaults ( DSM_t ∗ pDSM, const DSM_faultThresholds_t∗const faults )

Updates DSM module at 1ms tick.

Parameters

pDSM - pointer to the DSM module

faults - pointer to the fault thresholds structure to take values from

Returns

none

References DSM_internal_t::faultsConfigured, DSM_t::faultThresholds, and DSM_t::internal.

6.6.2 static void DSM_faultState ( DSM_t ∗ pDSM ) [static]

Processes DSM fault state.

Parameters

pDSM - pointer to the drive module

Returns

none

References DSM_clrFaults_t::all, DSM_nonClrFaults_t::all, DSM_t::clearableFaults, DSM_IDL←↩E, DSMS_ClearableFaultsReset(), DSM_internal_t::inStartUpRegion, DSM_t::internal, DSM_t::non←↩ClearableFaults, DSM_t::resetFault, and DSM_t::state.

Referenced by DSM_updateSlowTick().

6.6.3 static void DSM_idleState ( DSM_t ∗ pDSM, DSM_state_e newState )[static]

Processes DSM idle state.

90Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 117: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

pDSM - pointer to the drive module

state change command from USER

Returns

none

References DSM_clrFaults_t::all, DSM_nonClrFaults_t::all, DSM_t::clearableFaults, DSM_CURREN←↩T, DSM_FAULT, DSM_MOTION, DSM_PWM_DUTY, DSM_VOLTAGE, DSM_faultThresholds_←↩t::enableFaults, DSM_t::faultThresholds, DSM_internal_t::inStartUpRegion, DSM_t::internal, DSM_t←↩::nonClearableFaults, and DSM_t::state.

Referenced by DSM_updateSlowTick().

6.6.4 DSM_t ∗ DSM_init ( void ∗ pMem, size_t size )

Initializes DSM module.

Parameters

pMem - pointer to memory where the DSM block is stored

size - size of memory where the DSM block is stored

Returns

handle - interface to access the DSM block

References DSM_nonClrFaults_t::bits, DSM_START, DSMS_Init(), DSM_faultThresholds_t::enable←↩Faults, DSM_t::faultThresholds, GetMotorObserverSecureVersionIsCompatible(), DSM_internal_t←↩::inStartUpRegion, DSM_t::internal, DSM_t::nonClearableFaults, DSM_nonClrFaults_t::DSM_non←↩ClrFaultsBits_s::secureMotorObserverRomIdFault, DSM_nonClrFaults_t::DSM_nonClrFaultsBits_s←↩::secureSpinTACRomIdFault, and ST_getSecureROMIsCompatible().

6.6.5 void DSM_resetFaults ( DSM_t ∗ pDSM )

Sets the bit to reset faults in the DSM.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

91

Page 118: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

pDSM - pointer to the DSM module

Returns

none

References DSM_clrFaults_t::all, DSM_t::clearableFaults, and DSM_t::resetFault.

Referenced by USER_runFaultState().

6.6.6 static void DSM_runTimeMonitor ( DSM_t ∗ pDSM, DSM_state_e newState,DRV_control_e controlType, bool speedLoopEnabled, _lq speedError, boolrotorSyncLoss, bool faultsDisabled ) [static]

References _LQabsFast, DSM_clrFaults_t::all, DSM_nonClrFaults_t::all, DSM_clrFaults_t::bits, DS←↩M_t::clearableFaults, DSM_FAULT, DSM_faultThresholds_t::enableFaults, DSM_t::faultThresholds,FOC, DSM_internal_t::focTranCounter, DSM_internal_t::inStartUpRegion, DSM_t::internal, DSM←↩_clrFaults_t::DSM_clrFaultsBits_s::motLossSync, DSM_clrFaults_t::DSM_clrFaultsBits_s::motStall,DSM_clrFaults_t::DSM_clrFaultsBits_s::motStartupFailure, DSM_t::nonClearableFaults, DSM_fault←↩Thresholds_t::stallCounter, DSM_internal_t::stallDetectCounter, DSM_faultThresholds_t::stallSpeed←↩Error, STARTUP, DSM_t::state, and DSM_internal_t::syncDetectCounter.

Referenced by DSM_updateSlowTick().

6.6.7 static void DSM_startState ( DSM_t ∗ pDSM ) [static]

Processes DSM start state.

Parameters

pDSM - pointer to the drive module

Returns

none

References DSM_IDLE, DSM_internal_t::faultsConfigured, DSM_t::faultThresholds, DSM_t::internal,DSM_internal_t::startupVoltageCounter, DSM_faultThresholds_t::startupVoltageTimer, and DSM_t←↩::state.

Referenced by DSM_updateSlowTick().

92Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 119: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

6.6.8 void DSM_updateAtFastTick ( DSM_t ∗ pDSM, const FEEDBACK_output_t∗const pADC, bool faultsDisabled )

Updates DSM module at the Fast tick.

Parameters

pDSM - pointer to the DSM module

pADC - pointer to the FEEDBACK output

faultsDisabled - indicates if faults should be processed

Returns

none

References _SQabsFast, DSM_clrFaults_t::all, DSM_clrFaults_t::bits, DSM_t::clearableFaults, DSM←↩_FAULT, DSM_PK_CURRENT_FAULT_COUNTER, DSM_faultThresholds_t::enableFaults, DSM←↩_t::faultThresholds, DSM_t::internal, FEEDBACK_output_t::Isa, FEEDBACK_output_t::Isb, FEED←↩BACK_output_t::Isc, DSM_faultThresholds_t::overCurrentPeak, DSM_internal_t::peakOverCurrent←↩CounterA, DSM_internal_t::peakOverCurrentCounterB, DSM_internal_t::peakOverCurrentCounterC,DSM_clrFaults_t::DSM_clrFaultsBits_s::pkOverCurrentA, DSM_clrFaults_t::DSM_clrFaultsBits_s←↩::pkOverCurrentB, DSM_clrFaults_t::DSM_clrFaultsBits_s::pkOverCurrentC, and DSM_t::state.

6.6.9 void DSM_updateSlowTick ( DSM_t ∗ pDSM, DSM_state_e newState,const FEEDBACK_output_t ∗const pADC, DRV_control_e controlType,_lq rotorRefSpeed, _lq rotorSpeed_50Hz, bool speedLoopEnabled, _lqfiltStatorFluxSpVecMag, bool faultsDisabled )

References _LQabs(), _LQabsFast, _LQsqrt(), _LQtoSQ, DSM_nonClrFaults_t::DSM_nonClrFaults←↩Bits_s::adcFault, DSM_clrFaults_t::all, DSM_nonClrFaults_t::all, DSM_clrFaults_t::bits, DSM_non←↩ClrFaults_t::bits, DSM_nonClrFaults_t::DSM_nonClrFaultsBits_s::calibrationFault, DSM_t::clearable←↩Faults, DSM_clrFaults_t::DSM_clrFaultsBits_s::dcBusOverVoltage, DSM_clrFaults_t::DSM_clrFaults←↩Bits_s::dcBusUnderVoltage, DSM_CURRENT, DSM_FAULT, DSM_faultState(), DSM_IDLE, DSM←↩_idleState(), DSM_MOTION, DSM_PWM_DUTY, DSM_runTimeMonitor(), DSM_START, DSM_←↩startState(), DSM_VOLTAGE, DSMS_GetClearableFaults(), DSMS_GetNonClearableFaults(), DSM←↩_t::faultThresholds, FEEDBACK_output_t::gainFault, DSM_t::internal, DSM_faultThresholds_t::min←↩SyncSpeed, DSM_clrFaults_t::DSM_clrFaultsBits_s::motOverSpeed, DSM_t::nonClearableFaults, F←↩EEDBACK_output_t::offsetFault, DSM_faultThresholds_t::overCurrentRMS, DSM_faultThresholds_←↩t::overCurrentRMSCounter, DSM_faultThresholds_t::overSpeed, DSM_faultThresholds_t::overVoltage,FEEDBACK_output_t::rmsIsaSquare, FEEDBACK_output_t::rmsIsbSquare, DSM_clrFaults_t::DSM_←↩clrFaultsBits_s::rmsOverCurrentA, DSM_clrFaults_t::DSM_clrFaultsBits_s::rmsOverCurrentB, DSM_←↩clrFaults_t::DSM_clrFaultsBits_s::rmsOverCurrentC, DSM_internal_t::rmsOverCurrentCounterA, DS←↩M_internal_t::rmsOverCurrentCounterB, DSM_internal_t::rmsOverCurrentCounterC, DSM_t::state, D←↩SM_faultThresholds_t::underVoltage, and FEEDBACK_output_t::Vdc_200Hz.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

93

Page 120: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

6.6.10 DSMS_CalculateTemperature ( uint16_t adcTemperatureInput )

Calculates the temperature and passes it to the DSM system.

Parameters

adc←↩Temperature←↩

Input

Raw input from the ADC Converter

Returns

none

6.6.11 void DSMS_ClearableFaultsReset ( void )

Clear any active faults (Platform Specific bits)

Returns

none

References DSMS_hwFaultReset().

Referenced by DSM_faultState().

6.6.12 DSM_clrFaults_t DSMS_GetClearableFaults ( const DSM_faultThresholds←↩_t ∗const dsmFaultThresholds )

References DSM_clrFaults_t::all, mc33937SR0_t::B, DSM_clrFaults_t::bits, DSM_clrFaults_t::DSM←↩_clrFaultsBits_s::dcBusOverCurrent, DSM_clrFaults_t::DSM_clrFaultsBits_s::preDriverDCBusOver←↩Current, DSM_clrFaults_t::DSM_clrFaultsBits_s::preDriverPhaseError, DSM_clrFaults_t::DSM_clr←↩FaultsBits_s::preDriverTemp, mcdrv_spi_drv3ph_t::sSr0, and DSM_clrFaults_t::DSM_clrFaultsBits_s←↩::wdReset.

Referenced by DSM_updateSlowTick().

6.6.13 DSM_nonClrFaults_t DSMS_GetNonClearableFaults ( void )

Get Platform Specific Non Clearable Fault bits to OR into DSM module.

94Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 121: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Returns

DSM_nonClrFaults_t (Platform Specific only)

References DSM_nonClrFaults_t::all.

Referenced by DSM_updateSlowTick().

6.6.14 static void DSMS_hwFaultReset ( void ) [static]

Performs the hardware fault reset.

Returns

none

References DSM_RESET_LINE_HOLD_TIME.

Referenced by DSMS_ClearableFaultsReset().

6.6.15 void DSMS_Init ( void )

Platform Specific Init.

Returns

none

References mc33937ConfigMask_t::B, mcdrv_spi_drv3ph_init_t::bResetPinControl, InitSPI(), mcdrv←↩_spi_drv3ph_init_t::pGpioEnBase, mcdrv_spi_drv3ph_init_t::pGpioIntBase, mcdrv_spi_drv3ph_init←↩_t::pGpioResetBase, mcdrv_spi_drv3ph_init_t::pPortEnBase, mcdrv_spi_drv3ph_init_t::pPortIntBase,mcdrv_spi_drv3ph_init_t::pPortResetBase, mcdrv_spi_drv3ph_init_t::pSpiBase, mcdrv_spi_drv3ph←↩_t::sInterruptEnable, mcdrv_spi_drv3ph_t::ui16Deadtime, mcdrv_spi_drv3ph_init_t::ui32GpioEnPin,mcdrv_spi_drv3ph_init_t::ui32GpioIntPin, mcdrv_spi_drv3ph_init_t::ui32GpioResetPin, and mcdrv_←↩spi_drv3ph_init_t::ui32Pcs.

Referenced by DSM_init().

6.6.16 void InitSPI ( void ) [static]

void InitSPI(void)

• Initialization of the SPI peripheral for motor M1 3-phase MOSFET pre-driver• SPI configuration for MOSFET pre-driver MC33937

NXP SemiconductorsKinetis Motor Suite API Reference Manual

95

Page 122: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Variable Documentation

Parameters

void

Returns

none

• Initialization of the SPI peripheral for motor M1 3-phase MOSFET pre-driver

Parameters

void

Returns

none

Referenced by DSMS_Init().

6.7 Variable Documentation

6.7.1 mcdrv_spi_drv3ph_t g_sM1Driver3ph [static]

6.7.2 g_sM1Driver3phInit [static]

Configuration structure for 3-phase MOSFET predriver.

Structure for 3-phase MOSFET predriver mc driver.

96Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 123: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 7Field Oriented Control7.1 OverviewThe "glue logic" layer between all motor control blocks.

Functional description

The Field Oriented Control (FOC) block or DRV block contains all of the motor control blocks. It descri-bes how to connect the motor control algorithm components in order to realize field oriented control. Dueto the nature of this block it does not conform to the typical interfaces of the other blocks. It is merely alayer that exists in order to contain other blocks. There are three different versions of this block that con-form to the three control topologies offerd by KMS: Sensorless Velocity, Sensored Velocity, and SensoredPosition.

The common components for the three control topologies are described in this part. The implementationof these functions differs for the three control topologies. See the specific drv.c file for details. In additionto containing the interface layer between all of the motor control algorithm components, the DRV blockalso describes how to setup the complete FOC. It does this via the system.h header file. This file isgenerated by KMS so that it can tailor the reference project to the user motor and application. It contains aconst structure called flashSysParamsHeader. Upon power-up this structure is copied into flashSysParamswhich is then used to configure the FOC. When using KMS, the flashSysParams strucutre will be updatedin order to store the temporary drive configuration. It will only be placed into the reference project whenthe system.h header file is updated. The definition for flashSysParams & flashSysParamsHeader will varydepending on the control topology. See the specific sysparams.h header file for details.

Block diagram detail

The block diagrams for this part are described in the Block Diagram portion of part 1.

Code security breakdown

The connections between the various motor control blocks in KMS are provided as open source.

Open Source Library Execute-onlyFunctions to run fast and slow inter-rupt motor control tasks.

N/A N/A

NXP SemiconductorsKinetis Motor Suite API Reference Manual

97

Page 124: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Execution

Due to the nature of motor control algorithms, portions of this block need to run at the Fast ISR andportions need to run at the Slow ISR.

User customization example

The user may need to alter the layout of the FOC to suit their end application needs. For example, the usermay wish to remove the Field Weakening block completely if the application does not require it.

Macros• #define FULL_SCALE_VOLTAGE (36.3)

Actual voltage [V] represented by 1.0 scaled voltage [pu V] This should be set to the DC bus voltage whenthe ADC reads 3.3V.

• #define FULL_SCALE_CURRENT (8.0079)Actual current [A] represented by 1.0 scaled current [pu A] This should be set to the motor phase currentwhen the ADC reads 3.3V.

• #define FULL_SCALE_SPEED_RPM (1.2 ∗ 8000.0)Actual speed [RPM] represented by 1.0 scaled speed [pu RPM] Calculation: 1.2 [Scalar] ∗ Motor Maxi-mum Speed.

• #define FULL_SCALE_SPEED_WE (FULL_SCALE_SPEED_RPM ∗ (2 ∗ 3.1415) / 60 ∗ 2)Actual electrical speed [rad/s] represented by 1.0 scaled electrical speed [pu rad/s] Calculation: FUL←↩L_SCALE_SPEED_RPM [Base Speed in RPM] ∗ (2 ∗ 3.1415) / 60 [Unit Conversion: RPM -> rad/s] ∗Motor Pole Pairs.

• #define FULL_SCALE_RESISTANCE (FULL_SCALE_VOLTAGE / FULL_SCALE_CURRE←↩NT)

Actual resistance [Ohms] represented by 1.0 scaled resistance [pu Ohms].• #define FULL_SCALE_INDUCTANCE (FULL_SCALE_VOLTAGE / (FULL_SCALE_CURR←↩

ENT ∗ FULL_SCALE_SPEED_WE))Actual inductance [Henrys] represented by 1.0 scaled inductance [pu Henrys].

• #define FULL_SCALE_FLUX (FULL_SCALE_VOLTAGE / FULL_SCALE_SPEED_WE)Actual flux [Webers] represented by 1.0 scaled flux [pu Webers].

• #define FULL_SCALE_POWER (1.5 ∗ FULL_SCALE_VOLTAGE ∗ FULL_SCALE_CURRE←↩NT)

Actual power [W] represented by 1.0 scaled power [pu W] Calculation: 1.5 [Scalar] ∗ FULL_SCALE_←↩VOLTAGE [Base Voltage in V] ∗ FULL_SCALE_CURRENT [Base Current in A].

• #define FULL_SCALE_TORQUE (FULL_SCALE_POWER / (FULL_SCALE_SPEED_RPM ∗ (2∗ 3.1415) / 60))

Actual power [Nm] represented by 1.0 scaled power [pu Nm] Calculation: FULL_SCALE_POWER [BasePower in W] / (FULL_SCALE_SPEED_RPM [Base Speed in RPM] ∗ (2 ∗ 3.1415) / 60 [Unit Conversion:RPM -> rad/s])

Functions• void DRV_init (const SystemParams_t ∗const flashSysParams)

Initializes DRV module using the provided SystemParams_t structure.

98Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 125: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

• void DRV_updateSlowTick (void)Updates DRV module at Slow ISR tick.

• FAST void UpdateAtFastTick (const ADC_results_t ∗const adc_results)Updates DRV module at Fast ISR tick.

• bool DRV_motorStall (void)Checks if the motor is potentially stalling.

• _lq DRV_getDcbBusVoltage (void)Gets the DC bus voltage.

• _lq DRV_getDcbBusUnderVoltageThreshold (void)DC Bus Under Voltage Threshold.

• bool DRV_getIsFaultActive (void)Any clearable or non-clearable fault is active.

• void DRV_forceToIdle (void)Helper function to force control state to IDLE.

Variables• static const SystemParams_t flashSysParamsHeader

Default system parameters loaded at startup.

7.2 Macro Definition Documentation

7.2.1 #define FULL_SCALE_CURRENT (8.0079)

Actual current [A] represented by 1.0 scaled current [pu A] This should be set to the motor phase currentwhen the ADC reads 3.3V.

7.2.2 #define FULL_SCALE_FLUX (FULL_SCALE_VOLTAGE /FULL_SCALE_SPEED_WE)

Actual flux [Webers] represented by 1.0 scaled flux [pu Webers].

7.2.3 #define FULL_SCALE_INDUCTANCE (FULL_SCALE_VOLTAGE /(FULL_SCALE_CURRENT ∗ FULL_SCALE_SPEED_WE))

Actual inductance [Henrys] represented by 1.0 scaled inductance [pu Henrys].

7.2.4 #define FULL_SCALE_POWER (1.5 ∗ FULL_SCALE_VOLTAGE ∗FULL_SCALE_CURRENT)

Actual power [W] represented by 1.0 scaled power [pu W] Calculation: 1.5 [Scalar] ∗ FULL_SCALE_←↩VOLTAGE [Base Voltage in V] ∗ FULL_SCALE_CURRENT [Base Current in A].

NXP SemiconductorsKinetis Motor Suite API Reference Manual

99

Page 126: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

7.2.5 #define FULL_SCALE_RESISTANCE (FULL_SCALE_VOLTAGE /FULL_SCALE_CURRENT)

Actual resistance [Ohms] represented by 1.0 scaled resistance [pu Ohms].

7.2.6 #define FULL_SCALE_SPEED_RPM (1.2 ∗ 8000.0)

Actual speed [RPM] represented by 1.0 scaled speed [pu RPM] Calculation: 1.2 [Scalar] ∗ Motor Maxi-mum Speed.

7.2.7 #define FULL_SCALE_SPEED_WE (FULL_SCALE_SPEED_RPM ∗ (2 ∗3.1415) / 60 ∗ 2)

Actual electrical speed [rad/s] represented by 1.0 scaled electrical speed [pu rad/s] Calculation: FULL←↩_SCALE_SPEED_RPM [Base Speed in RPM] ∗ (2 ∗ 3.1415) / 60 [Unit Conversion: RPM -> rad/s] ∗Motor Pole Pairs.

7.2.8 #define FULL_SCALE_TORQUE (FULL_SCALE_POWER /(FULL_SCALE_SPEED_RPM ∗ (2 ∗ 3.1415) / 60))

Actual power [Nm] represented by 1.0 scaled power [pu Nm] Calculation: FULL_SCALE_POWER [BasePower in W] / (FULL_SCALE_SPEED_RPM [Base Speed in RPM] ∗ (2 ∗ 3.1415) / 60 [Unit Conversion:RPM -> rad/s])

7.2.9 #define FULL_SCALE_VOLTAGE (36.3)

Actual voltage [V] represented by 1.0 scaled voltage [pu V] This should be set to the DC bus voltage whenthe ADC reads 3.3V.

Includes Defines for information purposes only. Values are calculated based on KMS inputs. Do notmodify outside of KMS.

7.3 Function Documentation7.3.1 DRV_forceToIdle ( void )

Helper function to force control state to IDLE.

Returns

none

100Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 127: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

7.3.2 DRV_getDcbBusUnderVoltageThreshold ( void )

DC Bus Under Voltage Threshold.

Returns

_lq Under Voltage Threshold Voltage { unit: [pu volts] }

7.3.3 DRV_getDcbBusVoltage ( void )

Gets the DC bus voltage.

Returns

_lq DC Bus Voltage { unit: [pu volts] }

7.3.4 DRV_getIsFaultActive ( void )

Any clearable or non-clearable fault is active.

Returns

bool Fault active { True: Fault Active; False: No Fault Active }

7.3.5 DRV_init ( const SystemParams_t ∗const flashSysParams )

Initializes DRV module using the provided SystemParams_t structure.

Parameters

flashSysParams - Complete collection of FOC configuration parameters

Returns

none

7.3.6 DRV_motorStall ( void )

Checks if the motor is potentially stalling.

Returns

true if stalling, false otherwise

NXP SemiconductorsKinetis Motor Suite API Reference Manual

101

Page 128: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Variable Documentation

7.3.7 DRV_updateSlowTick ( void )

Updates DRV module at Slow ISR tick.

Returns

none

7.3.8 UpdateAtFastTick ( const ADC_results_t ∗const adc_results )

Updates DRV module at Fast ISR tick.

Parameters

adc_results - Pointer to a ADC_results_t containing latest ADC samples.

Returns

none

7.4 Variable Documentation

7.4.1 flashSysParamsHeader [static]

Default system parameters loaded at startup.

Global variables

102Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 129: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 8Trajectory - Velocity8.1 OverviewAutomatically generates real-time motion commands based on desired speed, acceleration, and jerk limits.

Functional description

The Trajectory block is a motion profile generator. That is, it defines motion between different comman-ded speeds under constraints specified by the user. Given a start speed and an end speed, a curve type,and upper limits on acceleration and jerk (the time derivative of acceleration), the Trajectory block willcalculate the optimum speed, acceleration, and jerk references. These reference values are then sent to theSpeed block, which is responsible for ensuring that the motor adheres to these desired values.

Note that there is no distinction made between transitions where the speed increases and transitions wherethe speed decreases - that is, there are not distinct acceleration and deceleration limits. This is because eachtransition is considered independently and is constrained by the specified limits on motion; the directionof the transition does not matter.

The available curve types provided by this Trajectory block are described in the following diagram.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

103

Page 130: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Figure 8.1.1: Available Velocity Curves Types

The key distinction between the available curve types is in the jerk. By smoothing out the jerk, theacceleration and therefore the velocity is also much smoother. This results in less stress on the mechanicalcomponents in end applications.

The Trajectory block is effectively a simplified wrapper block for the core algorithms of SpinTAC™Velocity Move submodule.

104Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 131: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Block diagram detail

Figure 8.1.2: Trajectory Velocity

Configuration, inputs, and outputs

Configuration available to the user involves system level parameters.

Inputs to the Trajectory block are simply the motion limits: desired speed, curve type, acceleration limit,and jerk limit.

Primary outputs of the Trajectory block are the aforementioned reference values for speed, acceleration,and jerk, to be passed to the Speed block. Additional information that may be extracted from the Trajectoryblock includes status and error conditions.

Execution

The Trajectory block is executed in the main control flow in the Slow ISR, as speed loop considerationsdo not require faster updating than that.

Code security breakdown

The table below describes the partitioning of Trajectory block code among open source, library, and pro-tected execute-only.

Open Source Library Execute-only

NXP SemiconductorsKinetis Motor Suite API Reference Manual

105

Page 132: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Abstracted structures for states,curve type, configuration, output;functions for initializing, configu-ring, running, resetting; detailedstructures for proprietary code; set& get functions

N/A Implementation of real-time con-straint based curve optimization

User customization example

The user may choose which curve type to use when transitioning speeds. For simple applications, thetrapezoidal curve will require the least amount of calculations of the three available curve types.

Data Structures

• struct TRAJVEL_config_tTRAJVEL config structure. More...

• struct TRAJVEL_output_tTRAJVEL output structure. More...

• struct TRAJVEL_tTRAJVEL module structure. More...

Macros• #define TRAJVEL_PRV_SIZE 50

Enumerations• enum TRAJVEL_CurveType_e {

TRAJVEL_TRAP = 0,TRAJVEL_SCRV,TRAJVEL_STCRV }

Trajectory curve types.• enum TRAJVEL_Status_e {

TRAJVEL_IDLE = 0,TRAJVEL_INIT,TRAJVEL_CONF,TRAJVEL_BUSY,TRAJVEL_HALT }

TRAJVEL state information.

Functions• TRAJVEL_t ∗ TRAJVEL_init (void ∗pMem, size_t size)

Trajectory generator initialization.• void TRAJVEL_config (TRAJVEL_t ∗handle, const TRAJVEL_config_t ∗const config, _lq20

lq20HaltLimitJerk, _lq sampleTime)

106Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 133: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

• void TRAJVEL_run (TRAJVEL_t ∗handle, bool enable)Runs the Trajectory (TRAJVEL) module.

• void TRAJVEL_reset (TRAJVEL_t ∗handle, _lq speed)Resets the Trajectory (TRAJVEL) module.

8.2 Data Structure Documentation

8.2.1 struct TRAJVEL_config_t

TRAJVEL config structure.

Data Fields

TRAJVEL_←↩CurveType_e

curve Curve Type { TRAJVEL_TRAP: Trap; TRAJVEL_SCRV: s-←↩Curve; TRAJVEL_STCRV: st-Curve }

_lq limitAcc Acceleration Limit { unit: [(pu rpm)/s], value range: [0.001, 120.0]}

_lq lq20LimitJerk Jerk Limit { unit: [(pu rpm)/s∧2], value range: [0.0005, 2000.0] }

_lq startSpeed Velocity start value { unit: [pu rpm], value range: [-1.0, 1.0] }

_lq targetSpeed reference ramp setpoint { unit: [pu rpm], value range: [-1.0, 1.0] }

bool test Profile test bit { false: Not Testing; true: Testing Mode }

8.2.2 struct TRAJVEL_output_t

TRAJVEL output structure.

Data Fields

_lq actualLimitAcc Actual maximum acceleration of the profile { unit: [(pu rpm)/s],value range: (0.0, AccLim] }

uint16_t error Error ID { 0: no error; others: see error code }

_lq lq20Actual←↩LimitJerk

Actual maximum jerk of the profile { unit: [(pu rpm)/s∧2], valuerange: (0.0, JrkLim] }

_lq lq20RefJerk Jerk reference { unit: [(pu rpm)/s∧2] }

uint32_t profileTime_←↩tick

Amount of time profile will take ( unit: [tick], value range: (0,uint32_t max] }

NXP SemiconductorsKinetis Motor Suite API Reference Manual

107

Page 134: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Enumeration Type Documentation

_lq refAcc Acceleration reference { unit: [(pu rpm)/s] }

_lq refSpeed Velocity reference { unit: [pu rpm] }

TRAJVEL_←↩Status_e

status Trajectory generator status { TRAJVEL_IDLE, TRAJVEL_INIT,TRAJVEL_CONF, TRAJVEL_BUSY}

8.2.3 struct TRAJVEL_t

TRAJVEL module structure.

Data Fields

TRAJVEL_←↩config_t

config Trajectory configuration structure

TRAJVEL_←↩output_t

output Trajectory output structure

uint32_t prv[TRAJVE←↩L_PRV_SIZE]

Trajectory private data block

8.3 Macro Definition Documentation

8.3.1 #define TRAJVEL_PRV_SIZE 50

8.4 Enumeration Type Documentation

8.4.1 enum TRAJVEL_CurveType_e

Trajectory curve types.

Enumerator

TRAJVEL_TRAP Trapazoidal curveTRAJVEL_SCRV S-CurveTRAJVEL_STCRV ST-Curve

8.4.2 enum TRAJVEL_Status_e

TRAJVEL state information.

Enumerator

TRAJVEL_IDLE TRAJVEL is in idle state, holding velocity

108Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 135: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

TRAJVEL_INIT TRAJVEL is in init state, validating configured parametersTRAJVEL_CONF TRAJVEL is in conf state, determining the curvesTRAJVEL_BUSY TRAJVEL is in busy state, providing the curvesTRAJVEL_HALT Not used in TRAJVEL

8.5 Function Documentation

8.5.1 void TRAJVEL_config ( TRAJVEL_t ∗ handle, const TRAJVEL_config_t∗const config, _lq20 lq20HaltLimitJerk, _lq sampleTime )

8.5.2 TRAJVEL_init ( void ∗ pMem, size_t size )

Trajectory generator initialization.

Parameters

pMem - pointer to memory where the TRAJVEL block is stored

size - size of memory where the TRAJVEL block is stored

Returns

handle - interface to access the TRAJVEL block

8.5.3 TRAJVEL_reset ( TRAJVEL_t ∗ handle, _lq speed )

Resets the Trajectory (TRAJVEL) module.

Parameters

handle - interface to access the TRAJVEL block

speed - speed to initialize the module with

Returns

none

8.5.4 TRAJVEL_run ( TRAJVEL_t ∗ handle, bool enable )

Runs the Trajectory (TRAJVEL) module.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

109

Page 136: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

handle - interface to access the TRAJVEL block

enable - run the trajectory module

Returns

none

110Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 137: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 9Trajectory - Position9.1 OverviewAutomatically generates real-time motion commands based on desired position step, speed, acceleration,deceleration, and jerk limits.

Functional description

The Trajectory block is a motion profile generator. That is, it defines motion between different commandedpositions under constraints specified by the user. Given a position step, a curve type, and upper limits onspeed, acceleration, deceleration, and jerk (the time derivative of acceleration), the Trajectory block willcalculate the optimum position, speed, acceleration, and jerk references. These reference values are thensent to the Position block, which is responsible for ensuring that the motor adheres to these desired values.

The available curve types provided by this Trajectory block are described in the following diagram.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

111

Page 138: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Figure 9.1.1: Available Position Curves Types

The key distinction between the available curve types is in the jerk. By smoothing out the jerk, theacceleration, velocity and therefore the position is also much smoother. This results in less stress on themechanical components in end applications.

The Trajectory block is effectively a simplified wrapper block for the core algorithms of SpinTAC™Position Move submodule.

112Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 139: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Block diagram detail

Figure 9.1.2: Trajectory Position

Configuration, inputs, and outputs

Configuration available to the user involves system level parameters.

Inputs to the Trajectory block are simply the motion limits: position step, curve type, speed limit, accele-ration limit, deceleration limit, and jerk limit.

Primary outputs of the Trajectory block are the aforementioned reference values for position, speed, acce-leration, and jerk, to be passed to the Position block. Additional information that may be extracted fromthe Trajectory block includes status and error conditions.

Execution

The Trajectory block is executed in the main control flow in the Slow ISR, as position loop considerationsdo not require faster updating than that.

Code security breakdown

The table below describes the partitioning of Trajectory block code among open source, library, and pro-tected execute-only.

Open Source Library Execute-only

NXP SemiconductorsKinetis Motor Suite API Reference Manual

113

Page 140: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Abstracted structures for states,curve type, configuration, output;functions for initializing, configu-ring, running, resetting; detailedstructures for proprietary code; set& get functions

N/A Implementation of real-time con-straint based curve optimization

User customization example

The user may choose which curve type to use when transitioning positions. For simple applications, thetrapezoidal curve will require the least amount of calculations of the three available curve types.

Data Structures

• struct TRAJPOS_config_tTRAJPOS config structure. More...

• struct TRAJPOS_output_tTRAJPOS output structure. More...

• struct TRAJPOS_tTRAJPOS module structure. More...

Macros• #define TRAJPOS_PRV_SIZE 108

Enumerations• enum TRAJPOS_ProfileType_e {

TRAJPOS_MOVE_VEL = 0,TRAJPOS_MOVE_POS }

Trajectory profile types.• enum TRAJPOS_CurveType_e {

TRAJPOS_TRAP = 0,TRAJPOS_SCRV,TRAJPOS_STCRV }

Trajectory curve types.• enum TRAJPOS_Status_e {

TRAJPOS_IDLE = 0,TRAJPOS_INIT,TRAJPOS_CONF,TRAJPOS_BUSY,TRAJPOS_HALT }

Trajectory state information.

Functions• TRAJPOS_t ∗ TRAJPOS_init (void ∗pMem, size_t size)

114Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 141: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

Trajectory generator initialization.• void TRAJPOS_config (TRAJPOS_t ∗handle, const TRAJPOS_config_t ∗const config, _lq halt←↩

LimitAcc, _lq20 lq20HaltLimitJerk, _lq sampleTime)• void TRAJPOS_run (TRAJPOS_t ∗handle, bool enable)

Runs the Trajectory (TRAJPOS) module.• void TRAJPOS_reset (TRAJPOS_t ∗handle, _lq speed, _lq position)

REsets the Trajectory (TRAJPOS) module.

9.2 Data Structure Documentation

9.2.1 struct TRAJPOS_config_t

TRAJPOS config structure.

Data Fields

TRAJPOS_←↩CurveType_e

curve Curve Type { TRAJPOS_TRAP: Trap; TRAJPOS_SCRV: s-←↩Curve; TRAJPOS_STCRV: st-Curve }

_lq limitAcc Acceleration Limit { unit: [(pu rpm)/s], value range: [0.001, 120.0]}

_lq limitDec Deceleration Limit { unit: [(pu rpm)/s], value range: [0.001, 120.0]}

_lq limitVel Velocity Limit { unit: [pu rpm], value range: (0.0, 1.0] }

_lq lq20LimitJerk Jerk Limit { unit: [(pu rpm)/s∧2], value range: [0.0005, 2000.0] }

_lq mrev_TO_pu Conversion between mechanical revolutions and pu speed { valuerange: }

_lq PosStart_mrev Position start value { unit: [mrev], value range: [-10, 10.0] }

_lq PosStepFrac_←↩mrev

Position step in fractional revolutions { unit: [mrev], value range:(-1.0, 1.0) }

int32_t PosStepInt_←↩mrev

Position step in whole revolutions { unit: [mrev], value range←↩: int32_t max }

TRAJPOS_←↩ProfileType_e

profile Type of profile to generate { TRAJPOS_MOVE_VEL: position-controlled velocity; TRAJPOS_MOVE_POS: position }

_lq startSpeed Velocity start value { unit: [pu rpm], value range: [-1.0, 1.0] }

_lq targetSpeed Velocity setpoint { unit: [pu rpm], value range: [-1.0, 1.0] }

NXP SemiconductorsKinetis Motor Suite API Reference Manual

115

Page 142: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

bool test Profile test bit { false: Not Testing; true: Testing Mode }

9.2.2 struct TRAJPOS_output_t

TRAJPOS output structure.

Data Fields

_lq actualLimitAcc Actual maximum acceleration of the profile { unit: [(pu rpm)/s],value range: (0.0, AccLim] }

_lq actualLimitDec Actual maximum deceleration of the profile { unit: [(pu rpm)/s],value range: (0.0, DecLim] }

_lq actualLimitVel Actual maximum velocity of the profile { unit: [pu rpm], valuerange: (0.0, VelLim] }

uint16_t error Error ID { 0: no error; others: see error code }

_lq lq20Actual←↩LimitJerk

Actual maximum jerk of the profile { unit: [(pu rpm)/s∧2], valuerange: (0.0, JrkLim] }

_lq lq20RefJerk Jerk reference { unit: [(pu rpm)/s∧2] }

uint32_t profileTime_←↩mtick

Amount of time profile will take ( unit: [million ticks], valuerange: (0, uint32_t max] }

uint32_t profileTime_←↩tick

Amount of time profile will take ( unit: [tick], value range: (0,uint32_t max] }

_lq refAcc Acceleration reference { unit: [(pu rpm)/s] }

_lq refPos_mrev Position reference { unit: [mrev] }

int32_t refRollOver←↩Counts

Number of rollovers between position windows (i.e. 10 -> -10,increases count; -10 -> 10 decreases count)

_lq refSpeed Velocity reference { unit: [pu rpm] }

TRAJPOS_←↩Status_e

status Trajectory generator status { TRAJPOS_IDLE, TRAJPOS_INIT,TRAJPOS_CONF, TRAJPOS_BUSY}

9.2.3 struct TRAJPOS_t

TRAJPOS module structure.

116Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 143: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Enumeration Type Documentation

Data Fields

TRAJPOS_←↩config_t

config Trajectory configuration structure

TRAJPOS_←↩output_t

output Trajectory output structure

uint32_t prv[TRAJPO←↩S_PRV_SIZE]

Trajectory private data block

9.3 Macro Definition Documentation

9.3.1 #define TRAJPOS_PRV_SIZE 108

9.4 Enumeration Type Documentation

9.4.1 enum TRAJPOS_CurveType_e

Trajectory curve types.

Enumerator

TRAJPOS_TRAP Trapazoidal curveTRAJPOS_SCRV S-CurveTRAJPOS_STCRV ST-Curve

9.4.2 enum TRAJPOS_ProfileType_e

Trajectory profile types.

Enumerator

TRAJPOS_MOVE_VEL velocity-determined position profileTRAJPOS_MOVE_POS position-determined position profile

9.4.3 enum TRAJPOS_Status_e

Trajectory state information.

Enumerator

TRAJPOS_IDLE TRAJPOS is in idle state, holding velocityTRAJPOS_INIT TRAJPOS is in init state, validating configured parameters

NXP SemiconductorsKinetis Motor Suite API Reference Manual

117

Page 144: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

TRAJPOS_CONF TRAJPOS is in conf state, determining the curvesTRAJPOS_BUSY TRAJPOS is in busy state, providing the curvesTRAJPOS_HALT TRAJPOS is in halt state, generating a profile to halt motion

9.5 Function Documentation

9.5.1 void TRAJPOS_config ( TRAJPOS_t ∗ handle, const TRAJPOS_config_t∗const config, _lq haltLimitAcc, _lq20 lq20HaltLimitJerk, _lq sampleTime )

9.5.2 TRAJPOS_init ( void ∗ pMem, size_t size )

Trajectory generator initialization.

Parameters

pMem - pointer to memory where the TRAJPOS block is stored

size - size of memory where the TRAJPOS block is stored

Returns

handle - interface to access the TRAJPOS block

9.5.3 TRAJPOS_reset ( TRAJPOS_t ∗ handle, _lq speed, _lq position )

REsets the Trajectory (TRAJPOS) module.

Parameters

handle - interface to access the TRAJPOS block

speed - speed to initialize the module

speed - position to initialize the module

Returns

none

9.5.4 TRAJPOS_run ( TRAJPOS_t ∗ handle, bool enable )

Runs the Trajectory (TRAJPOS) module.

118Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 145: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

handle - interface to access the TRAJPOS block

enable - run the trajectory module

Returns

none

NXP SemiconductorsKinetis Motor Suite API Reference Manual

119

Page 146: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

120Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 147: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 10Speed Control10.1 OverviewGenerates the torque (Iq) reference based on the real-time motion commands (speed and acceleration) andestimated speed feedback.

Functional description

The Speed block is responsible for controlling motor speed using KMS’ advanced velocity controller.This controller, based on an extended state observer, estimates and actively rejects disturbances to desiredoperation, in real-time. It is configured using two pieces of information: system inertia, provided by theInertia block, and bandwidth, the single parameter to be manually adjusted by the user.

The controller is described at a high level by the equation:

Jv(t) = f (v(t),d(t))+u(t)

In this equation, v(t), u(t), and d(t) are system output (velocity), system input (torque), and externaldisturbance respectively. f is an unknown nonlinear function, and J is the system inertia.

In traditional control design, a proportional-integral (PI) controller would be used to control these dy-namics with the proportional gain and integral gains determined experimentally. The KMS advancedcontroller, however, treats the nonlinear term f as a disturbance that can be estimated and rejected. Thisenables high performance in highly dynamic systems with a simpler tuning scheme, as only bandwidthmust be adjusted to properly calibrate the aggressiveness of disturbance rejection.

The Speed block is effectively a simplified wrapper block for the core algorithms of SpinTAC™ VelocityControl submodule.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

121

Page 148: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Block diagram detail

Figure 10.1.1: Speed

Configuration, inputs, and outputs

The Speed block is primarily configured by system parameters, sample time and motor maximum current,as well as controller tuning parameters, inertia, and bandwidth; inertia is provided by the Inertia block;and bandwidth is entered by the user after empirical assessment.

The inputs to the Speed block are the velocity reference and velocity feedback. Velocity reference isprovided by the Trajectory block, which creates the proper motion profile given start and target speeds.Velocity feedback is provided by the Estimator block.

The main output of the Speed block is the desired value for Q-axis (torque producing) current. Otheroutputs include status indicators for Speed block operation.

Code security breakdown

The table below describes the partitioning of Speed block code among open source, library, and protectedexecute-only.

Open Source Library Execute-onlyStructures for configuring speedloop controller; set & get functions

N/A Implementation of proprietary con-trol algorithm

Execution

The Speed block runs in the main control flow in the Slow ISR.

122Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 149: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

User customization example

While the KMS advanced velocity controller offers high performance with minimal tuning effort, theuser may prefer a traditional proportional-integral controller developed specifically for an application overmultiple development cycles. Such a block, provided that it can take in a speed reference and output atorque reference, could replace the Speed block. For applications that only wish to control the torque ofan application, the Speed block can be removed.

Data Structures• struct SPEED_output_t

SPEED output structure. More...• struct SPEED_config_t

SPEED config structure. More...• struct SPEED_t

SPEED module nested structure. More...

Macros• #define SPEED_PRV_SIZE 40

Enumerations• enum SPEED_status_e {

SPEED_CONTROL_IDLE =0,SPEED_CONTROL_INIT,SPEED_CONTROL_CONF,SPEED_CONTROL_BUSY }

SPEED module status enum.

Functions• SPEED_t ∗ SPEED_init (void ∗pMem, size_t size)

Speed control loop initialization.• void SPEED_config (SPEED_t ∗handle, const SPEED_config_t ∗const config, _lq sampleTime, _sq

maxStatorCurrent, _lq pmFlux)Speed control loop configuration.

• void SPEED_reset (SPEED_t ∗handle)Resets internal states for SPEED block.

• void SPEED_run (SPEED_t ∗handle, bool enable, _lq speedRef, _lq accRef, _lq speedFdb, _sqIdRef)

Speed control loop function (regulates speed)• FAST void SPEED_set (SPEED_t ∗handle, _sq IqFdb, _lq SpeedFdb)

Speed loop set function used to initialize during transition from I-F to FOC.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

123

Page 150: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

10.2 Data Structure Documentation

10.2.1 struct SPEED_output_t

SPEED output structure.

Data Fields

uint16_t errID error id of the speed module

_sq IqRef control output (SQ15) { unit: [pu amps] }

SPEED_←↩status_e

status indicator of the speed module status

_lq24 torqueRef torque reference

10.2.2 struct SPEED_config_t

SPEED config structure.

Data Fields

bool ctlFilterEnable enable low-pass Filter { false: Filter Disabled; true: Filter Enabled}

_lq friction friction coefficient { unit: [(pu amps)/(pu rpm)], value range: posi-tive _lq24 value }

_lq inertia system inertia { unit: [(pu amps)/((pu rpm)/s)], value range: posi-tive _lq24 value }

_lq IqRefComp torque compensation signal { unit: [pu amps], value range: [-1,OutMax], _lq24 format}

_sq IqRefDerate←↩Ratio

torque derating ratio { unit: [-], value range: (0,1), _sq14 format}

_lq IqRefMax control signal upper limit { unit: [pu amps], value range: [-1, 1],_lq24 format}

_lq IqRefMin control signal lower limit { unit: [pu amps], value range: [-1, Out←↩Max], _lq24 format}

124Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 151: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

_lq lq20Bw_radps Controller Bandwidth in _LQ20

10.2.3 struct SPEED_t

SPEED module nested structure.

Data Fields

SPEED_←↩config_t

config speed configuration structure

SPEED_←↩output_t

output speed output structure

uint32_t prv[SPEED_←↩PRV_SIZE]

speed private structure

10.3 Macro Definition Documentation

10.3.1 #define SPEED_PRV_SIZE 40

10.4 Enumeration Type Documentation

10.4.1 enum SPEED_status_e

SPEED module status enum.

Enumerator

SPEED_CONTROL_IDLE speed module in idle stateSPEED_CONTROL_INIT speed module in initialization stateSPEED_CONTROL_CONF speed module in configuration stateSPEED_CONTROL_BUSY speed module in busy state

10.5 Function Documentation

10.5.1 SPEED_config ( SPEED_t ∗ handle, const SPEED_config_t ∗const config,_lq sampleTime, _sq maxStatorCurrent, _lq pmFlux )

Speed control loop configuration.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

125

Page 152: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

handle - pointer to the SPEED block

config - pointer to SPEED_config block

sampleTime - time between successive current loop calls

maxStator←↩Current

- maximum motor current

pmFlux - measured flux of the motor

Returns

none

10.5.2 SPEED_init ( void ∗ pMem, size_t size )

Speed control loop initialization.

Parameters

pMem - pointer to memory where the SPEED block is stored

size - size of memory where the SPEED block is stored

Returns

handle - interface to access the SPEED block

10.5.3 void SPEED_reset ( SPEED_t ∗ handle )

Resets internal states for SPEED block.

Parameters

handle - pointer to the SPEED block

Returns

none

10.5.4 SPEED_run ( SPEED_t ∗ handle, bool enable, _lq speedRef, _lq accRef,_lq speedFdb, _sq IdRef )

Speed control loop function (regulates speed)

126Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 153: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

handle - pointer to the SPEED block

enable - enables the speed loop operation

speedRef - speed reference to the system

accRef - acceleration reference to the system

IdRef - Id current reference

Returns

none

10.5.5 SPEED_set ( SPEED_t ∗ handle, _sq IqFdb, _lq SpeedFdb )

Speed loop set function used to initialize during transition from I-F to FOC.

Parameters

handle - pointer to the SPEED block

IqFdb - Feedback Iq Current

SpeedFdb - Speed Feedback

Returns

none

NXP SemiconductorsKinetis Motor Suite API Reference Manual

127

Page 154: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

128Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 155: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 11Position Control11.1 OverviewGenerates the torque (Iq) reference based on the real-time motion commands (position, speed, and acce-leration) and position feedback.

Functional description

The Position block is responsible for controlling motor position using KMS’ advanced position controller.This controller, based on an extended state observer, estimates and actively rejects disturbances to desiredoperation, in real-time. It is configured using two pieces of information: system inertia, provided by theInertia block, and bandwidth, the single parameter to be manually adjusted by the user. The Position blockencompasses both position control and velocity control and internal contains 2 controllers.

A single instance of the controller is described at a high level by the equation:

Jv(t) = f (v(t),d(t))+u(t)

In this equation, v(t), u(t), and d(t) are system output (velocity), system input (torque), and externaldisturbance respectively. f is an unknown nonlinear function, and J is the system inertia.

In traditional control design, a proportional-integral (PI) controller would be used to control these dy-namics with the proportional gain and integral gains determined experimentally. The KMS advancedcontroller, however, treats the nonlinear term f as a disturbance that can be estimated and rejected. Thisenables high performance in highly dynamic systems with a simpler tuning scheme, as only bandwidthmust be adjusted to properly calibrate the aggressiveness of disturbance rejection.

The Position block is effectively a simplified wrapper block for the core algorithms of SpinTAC™ PositionControl submodule.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

129

Page 156: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Block diagram detail

Figure 11.1.1: Position

Configuration, inputs, and outputs

The Position block is primarily configured by system parameters, sample time and motor maximum cur-rent, as well as controller tuning parameters, inertia, and bandwidth; inertia is provided by the Inertiablock; and bandwidth is entered by the user after empirical assessment.

The inputs to the Position block are the position reference and position feedback. Position reference isprovided by the Trajectory block, which creates the proper motion profile given a position step. Positionfeedback is provided by the Encoder block.

The main output of the Position block is the desired value for Q-axis (torque producing) current. Otheroutputs include status indicators for Position block operation.

Code security breakdown

The table below describes the partitioning of Position block code among open source, library, and pro-tected execute-only.

Open Source Library Execute-onlyStructures for configuring position& speed loop controllers; set & getfunctions

N/A Implementation of proprietary con-trol algorithm

Execution

The Position block runs in the main control flow in the Slow ISR.

130Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 157: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

User customization example

While the KMS advanced position controller offers high performance with minimal tuning effort, theuser may prefer a traditional proportional-integral controller developed specifically for an application overmultiple development cycles. Such a block, provided that it can take in a position reference and output atorque reference, could replace the Position block. For applications that only wish to control the torque ofan application, the Position block can be removed.

Data Structures• struct POSITION_output_t

POSITION output structure. More...• struct POSITION_config_t

POSITION config structure. More...• struct POSITION_t

POSITION module nested structure. More...

Macros• #define POSITION_PRV_SIZE 66

Enumerations• enum POSITION_status_e {

POSITION_CONTROL_IDLE =0,POSITION_CONTROL_INIT,POSITION_CONTROL_CONF,POSITION_CONTROL_BUSY }

POSITION module status enum.

Functions• POSITION_t ∗ POSITION_init (void ∗pMem, size_t size)

Position control loop initialization.• void POSITION_config (POSITION_t ∗handle, const POSITION_config_t ∗const config, _lq

sampleTime, _sq maxStatorCurrent, _lq pmFlux)Position control loop configuration.

• void POSITION_reset (POSITION_t ∗handle)Resets internal states for POSITION block.

• void POSITION_run (POSITION_t ∗handle, bool enable, _lq posRef_mrev, _lq speedRef, _lq acc←↩Ref, _lq posFdb_mrev, _sq IdRef)

11.2 Data Structure Documentation

11.2.1 struct POSITION_output_t

POSITION output structure.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

131

Page 158: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

Data Fields

uint16_t errID error id of the position module

_sq IqRef control output (SQ15) { units: [pu amps] }

_lq24 posErr_mrev instantaneous position error { unit: [MRev] }

POSITION_←↩status_e

status indicator of the position module status

_lq24 torqueRef torque reference

11.2.2 struct POSITION_config_t

POSITION config structure.

Data Fields

bool ctlFilterEnable enable low-pass Filter { false: Filter Disabled; true: Filter Enabled}

_lq friction friction coefficient { unit: [(pu amps)/(pu rpm)], value range: posi-tive _lq24 value}

_lq inertia system inertia { unit: [(pu amps)/((pu rpm)/s)], value range: posi-tive _lq24 value}

_lq IqRefComp torque compensation signal { unit: [pu amps], value range: [-1,OutMax], _lq24 format}

_sq IqRefDerate←↩Ratio

torque derating ratio { unit: [-], value range: (0,1), _sq14 format}

_lq IqRefMax control signal upper limit { unit: [pu amps], value range: [-1, 1],_lq24 format}

_lq IqRefMin control signal lower limit { unit: [pu amps], value range: [-1, Out←↩Max], _lq24 format}

_lq lq20Bw_radps Controller Bandwidth in _LQ20

_lq maximum←↩Speed

maximum speed of the motor { unit: [pu rpm], value range: [-1,1],_lq24 format}

132Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 159: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

_lq mrev_TO_pu Ratio between mechanical revolutions and scaled position units

11.2.3 struct POSITION_t

POSITION module nested structure.

Data Fields

POSITION_←↩config_t

config position configuration structure

POSITION_←↩output_t

output position output structure

uint32_t prv[POSITIO←↩N_PRV_SIZE]

position private structure

11.3 Macro Definition Documentation

11.3.1 #define POSITION_PRV_SIZE 66

11.4 Enumeration Type Documentation

11.4.1 enum POSITION_status_e

POSITION module status enum.

Enumerator

POSITION_CONTROL_IDLE position module in idle statePOSITION_CONTROL_INIT position module in initialization statePOSITION_CONTROL_CONF position module in configuration statePOSITION_CONTROL_BUSY position module in busy state

11.5 Function Documentation

11.5.1 POSITION_config ( POSITION_t ∗ handle, const POSITION_config_t∗const config, _lq sampleTime, _sq maxStatorCurrent, _lq pmFlux )

Position control loop configuration.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

133

Page 160: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

handle - pointer to the POSITION block

config - pointer to POSITION_config block

sampleTime - time between successive position loop calls

maxStator←↩Current

- maximum motor current

pmFlux - measured flux of the motor

Returns

none

11.5.2 POSITION_init ( void ∗ pMem, size_t size )

Position control loop initialization.

Parameters

pMem - pointer to memory where the POSITION block is stored

size - size of memory where the POSITION block is stored

Returns

handle - interface to access the POSITION block

11.5.3 void POSITION_reset ( POSITION_t ∗ handle )

Resets internal states for POSITION block.

Parameters

handle - pointer to the POSITION block

Returns

none

11.5.4 void POSITION_run ( POSITION_t ∗ handle, bool enable, _lq posRef_mrev,_lq speedRef, _lq accRef, _lq posFdb_mrev, _sq IdRef )

134Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 161: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 12Field Weakening12.1 OverviewOutputs D-phase current reference based on controlling modulation command to align with maximummodulation.

Functional description

Field Weakening allows a motor to operate above its rated speed at a cost of torque. This is achieved byapplying a negative D-axis current, which will serve to reduce the flux of the motor allowing operation athigher speeds than the normal back-emf would allow.

KMS applies field weakening when the modulation index exceeds the configured maximum modulation.The default for this value is the linear region limit of 0.9069. A typical proportional-integral controller isused to control the D-axis reference current based on the error between the configured maximum modu-lation and the actual modulation. The output maximum for this controller is forced to 0 so that a positiveD-axis current will not be applied.

By default the FW block is enabled, but it can be dynamically enabled and disabled.

Block diagram detail

Figure 12.1.1: Field Weakening

Configuration, inputs, and outputs

The Field Weakening block is configured primarily by defining the output minimum of the block. Thisinforms the system as to the minimum amount (or maximum negative amount) of current that can be

NXP SemiconductorsKinetis Motor Suite API Reference Manual

135

Page 162: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

applied for field weakening.

Inputs to the block include target speed and the signal of applied stator modulation, which is an output ofthe Estimator block.

The key output is a desired D-axis current value, which is passed to the Current block.

Code security breakdown

The table below describes the partitioning of Field Weakening block code among open source, library, andprotected execute-only.

Open Source Library Execute-onlyFunctions for initializing, configu-ring, running field weakening

Implementation of relevant functi-ons

N/A

Execution

The Field Weakening block operates in the Slow ISR since it helps regulate the motor speed, it is governedby the same mechanical dynamics as the Speed block.

User customization example

Achieving operation well above rated speed is a particular challenge of certain applications like washingmachines. The user may have proprietary algorithms developed over time with his/her specific application,and in this case may prefer to replace the Field Weakening block.

Data Structures• struct FW_output_t• struct FW_config_t• struct FW_t

Macros• #define FW_PRV_SIZE 20

Functions• FW_t ∗ FW_init (void ∗pMem, size_t size)

Field Weakening initialization.• void FW_config (FW_t ∗handle, const FW_config_t ∗const config, _lq sampleTime, _lq lq16fltId←↩

RefCutoffFreqHz)• void FW_resetController (FW_t ∗handle)

Resets the FW controller.

136Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 163: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

• void FW_run (FW_t ∗handle, bool enable, _lq statorRefVoltageMagnitude, _lq rotorTrajSpeed, _lqrotorRefSpeed)

12.2 Data Structure Documentation

12.2.1 struct FW_output_t

Data Fields

_sq IdRef Id reference output from the module (SQ15) { unit: [pu amps] }

12.2.2 struct FW_config_t

Data Fields

_lq max←↩Modulation

Reference modulation for Field Weakening controller { unit←↩: [modulation percent] }

PID_pi←↩Param32_t

pi Field Weakening PI regulator parameters

_lq ratedSpeed Motor Rated speed { unit: [pu rpm] }

12.2.3 struct FW_t

Data Fields

FW_config_t config Field Weakening configuration structure

FW_output_t output Field Weakening output structure

uint32_t prv[FW_PR←↩V_SIZE]

Field Weakening private data block

12.3 Macro Definition Documentation

12.3.1 #define FW_PRV_SIZE 20

NXP SemiconductorsKinetis Motor Suite API Reference Manual

137

Page 164: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

12.4 Function Documentation

12.4.1 void FW_config ( FW_t ∗ handle, const FW_config_t ∗const config, _lqsampleTime, _lq lq16fltIdRefCutoffFreqHz )

12.4.2 FW_init ( void ∗ pMem, size_t size )

Field Weakening initialization.

Parameters

pMem - pointer to memory where the FW block is stored

size - size of memory where the FW block is stored

Returns

handle - interface to access the FW block

12.4.3 FW_resetController ( FW_t ∗ handle )

Resets the FW controller.

Parameters

handle - pointer to the FW block

Returns

none

12.4.4 void FW_run ( FW_t ∗ handle, bool enable, _lq statorRefVoltageMagnitude,_lq rotorTrajSpeed, _lq rotorRefSpeed )

138Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 165: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 13Feedback13.1 OverviewGenerates the three phase currents and DC bus voltage from the ADC hardware and internal scaling,calibration and offset.

Functional description

The Feedback block is responsible for processing the samples from the hardware analog-to-digital conver-ters (ADC) to obtain information about the state of motor and inverter operation. It is also responsible forfiltering this information and thereby passing it to the system in a usable manner. This involves checkingand configuring calibration gains, offsets, and fault status.

The most critical pieces of information are the three phase currents that are transformed to provide theactual values that are compared with desired values in the Current block.

When the SVPWM block indicates that it is running in the overmodulation region, the FEEDBACK blockwill begin to implement current reconstruction, where it will choose which phase current sample to ignorebased on the SVPWM sector.

Block diagram detail

Figure 13.1.1: Feedback

Configuration, inputs, and outputs

There is no configuration required for the Feedback block.

The inputs to the Feedback block are the ADC samples.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

139

Page 166: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

The outputs are the processed feedback signals for phase current and bus voltage.

Code security breakdown

The table below describes the partitioning of Feedback block code among open source, library, and pro-tected execute-only.

Open Source Library Execute-onlyDefinition of feedback states, initi-alization, calibration, configuration,implementation of calibration, ini-tialization, configuration, sampling,filtering

N/A N/A

Execution

The Feedback block runs in the Fast ISR, as accuracy in sampled current values is critical for motorcontrol.

User customization example

The user may want to leverage additional signals from the hardware for his/her application. For instance,Freescale reference hardware does not typically come with a thermocouple, but on custom hardware, ADCchannels can be sampled and combined with the thermocouple to provide temperature sensing capabilities.Motor and inverter temperature can then be used as any other signals in the system. At a minimum onlytwo phase currents are required to be sampled. In this reference design all three phase currents are sampledin order to provide the maximum performance. This block would need to be modified to reconstruct thenon-sampled current.

Modules• Analog to Digital Converter Interface

The Analog to Digital Converter (ADC) Interface describes how the ADC is configured and used.

Data Structures• struct FEEDBACK_internal_t

FEEDBACK internal module structure. More...• struct FEEDBACK_calib_t

FEEDBACK calibration module structure. More...• struct FEEDBACK_t

FEEDBACK module nested structure. More...• struct ADC_results_t

140Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 167: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

ADC results structure to hold raw values after ADC conversion. More...• struct FEEDBACK_gains_t

FEEDBACK calibration gains structure. More...• struct FEEDBACK_output_t

FEEDBACK output structure. More...

Enumerations• enum FEEDBACK_State_e {

FEEDBACK_CALIB = 0,FEEDBACK_RUN,FEEDBACK_FAULT }

States of the FEEDBACK block.

Functions• FEEDBACK_t ∗ FEEDBACK_init (void ∗pMem, size_t size)

Initializes FEEDBACK module.• void FEEDBACK_config (FEEDBACK_t ∗handle, const FEEDBACK_gains_t ∗const gains, _lq

focSampleTime, _lq lq16FltVdc1Hz, _lq lq16FltVdc200Hz, _lq lq16FltVdc1kHz, _lq lq16FltIsrms)• FAST void FEEDBACK_run (FEEDBACK_t ∗handle, SVPWM_state_e svpwmState, SVPWM←↩

_sector_e svpwmSector, const ADC_results_t ∗const adcResults)

13.2 Data Structure Documentation

13.2.1 struct FEEDBACK_internal_t

FEEDBACK internal module structure.

Data Fields

bool halfPWM←↩Decrementer

FLT_butter←↩AccT16bit_t

rmsIsa_halfP←↩WM

RMS Phase a current filter initialization, half the fastloop sampletime

FLT_butter←↩AccT16bit_t

rmsIsb_halfP←↩WM

RMS Phase b current filter initialization, half the fastloop sampletime

FLT_butter←↩AccT16bit_t

rmsIsc_halfP←↩WM

RMS Phase c current filter initialization, half the fastloop sampletime

NXP SemiconductorsKinetis Motor Suite API Reference Manual

141

Page 168: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

FLT_butter←↩AccT16bit_t

Vdc_1kHz VDC filter at 1kHz initialization

FLT_butter←↩AccT16bit_t

Vdc_200Hz VDC filter at 1Hz initialization

13.2.2 struct FEEDBACK_calib_t

FEEDBACK calibration module structure.

Data Fields

FEEDBACK←↩_gains_t

gains calibration gains

uint16_t offsetIa phase A calibration offset

uint16_t offsetIb phase B calibration offset

uint16_t offsetIc phase C calibration offset

_sq offsetVdc DC bus voltage calibration offset

13.2.3 struct FEEDBACK_t

FEEDBACK module nested structure.

Data Fields

FEEDBACK←↩_calib_t

calib calibration structure

FEEDBACK←↩_internal_t

internal internal structure

FEEDBACK←↩_output_t

output output structure

FEEDBACK←↩_State_e

state state enum

13.2.4 struct ADC_results_t

ADC results structure to hold raw values after ADC conversion.

142Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 169: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

Data Fields

uint16_t dcBusVoltage Raw ADC reading to DC Bus Voltage measurement [0 to 4095]

uint16_t phaseACurrent Raw ADC reading to Phase A Current measurement [0 to 4095]

uint16_t phaseBCurrent Raw ADC reading to Phase B Current measurement [0 to 4095]

uint16_t phaseCCurrent Raw ADC reading to Phase C Current measurement [0 to 4095]

13.2.5 struct FEEDBACK_gains_t

FEEDBACK calibration gains structure.

Data Fields

_sq kIa phase A calibration gain (SQ)

_sq kIb phase B calibration gain (SQ)

_sq kIc phase C calibration gain (SQ)

_sq kVdc DC bus voltage calibration gain (SQ)

13.2.6 struct FEEDBACK_output_t

FEEDBACK output structure.

Data Fields

bool gainFault Indicates if a gain fault has occurred

_lq invVdc_1kHz Inverse DC bus voltage 1kHz filter { unit: [pu volts] }

_sq Isa phase A current { unit: [pu amps] }

_sq Isb phase B current { unit: [pu amps] }

_sq Isc phase C current { unit: [pu amps] }

bool offsetFault Indicates if an offset fault has occurred

_lq rmsIsaSquare RMS current on phase A squared

_lq rmsIsbSquare RMS current on phase B squared

NXP SemiconductorsKinetis Motor Suite API Reference Manual

143

Page 170: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

_lq rmsIscSquare RMS current on phase C squared

_lq Vdc DC bus voltage unfiltered { unit: [pu volts] }

_lq Vdc_1kHz DC bus voltage 1kHz filter { unit: [pu volts] }

_lq Vdc_200Hz DC bus voltage 200Hz filter { unit: [pu volts] }

13.3 Enumeration Type Documentation

13.3.1 enum FEEDBACK_State_e

States of the FEEDBACK block.

Enumerator

FEEDBACK_CALIB Do feedback calibrationFEEDBACK_RUN run feedback collectionFEEDBACK_FAULT faulted feedback calibration

13.4 Function Documentation

13.4.1 void FEEDBACK_config ( FEEDBACK_t ∗ handle, constFEEDBACK_gains_t ∗const gains, _lq focSampleTime, _lq lq16FltVdc1Hz,_lq lq16FltVdc200Hz, _lq lq16FltVdc1kHz, _lq lq16FltIsrms )

References _LQtoSQ, FEEDBACK_t::calib, FLT_butterAccT16bit_t::coeff, FLT_coeff_Tustin(), FEE←↩DBACK_calib_t::gains, FEEDBACK_t::internal, FEEDBACK_internal_t::rmsIsa_halfPWM, FEEDB←↩ACK_internal_t::rmsIsb_halfPWM, FEEDBACK_internal_t::rmsIsc_halfPWM, FEEDBACK_internal←↩_t::Vdc_1kHz, and FEEDBACK_internal_t::Vdc_200Hz.

13.4.2 FEEDBACK_init ( void ∗ pMem, size_t size )

Initializes FEEDBACK module.

Parameters

pMem - pointer to memory where the FEEDBACK block is stored

size - size of memory where the FEEDBACK block is stored

Returns

handle - interface to access the FEEDBACK block

References ADCS_enableInt(), ADCS_init(), FEEDBACK_CALIB, and FEEDBACK_t::state.

144Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 171: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

13.4.3 FAST void FEEDBACK_run ( FEEDBACK_t ∗ handle, SVPWM_state_esvpwmState, SVPWM_sector_e svpwmSector, const ADC_results_t ∗constadcResults )

References _LQ, _LQdiv, _LQrecip, _SQmpySQX, _SQtoLQ, FEEDBACK_t::calib, ADC_results_t←↩::dcBusVoltage, FEEDBACK_CALIB, FEEDBACK_RUN, FLT_lpf1stT_16bit(), FEEDBACK_calib_←↩t::gains, GLOBAL_SQ, FEEDBACK_internal_t::halfPWMDecrementer, FEEDBACK_t::internal, FE←↩EDBACK_output_t::invVdc_1kHz, FEEDBACK_output_t::Isa, FEEDBACK_output_t::Isb, FEEDBA←↩CK_output_t::Isc, FEEDBACK_gains_t::kIa, FEEDBACK_gains_t::kIb, FEEDBACK_gains_t::kIc, F←↩EEDBACK_gains_t::kVdc, FEEDBACK_calib_t::offsetIa, FEEDBACK_calib_t::offsetIb, FEEDBAC←↩K_calib_t::offsetIc, FEEDBACK_calib_t::offsetVdc, FEEDBACK_t::output, ADC_results_t::phaseA←↩Current, ADC_results_t::phaseBCurrent, ADC_results_t::phaseCCurrent, FEEDBACK_internal_t::rms←↩Isa_halfPWM, FEEDBACK_output_t::rmsIsaSquare, FEEDBACK_internal_t::rmsIsb_halfPWM, FE←↩EDBACK_output_t::rmsIsbSquare, FEEDBACK_internal_t::rmsIsc_halfPWM, FEEDBACK_output_←↩t::rmsIscSquare, FEEDBACK_t::state, SVPWM_NORM, SVPWM_SECT1, SVPWM_SECT2, SVP←↩WM_SECT3, SVPWM_SECT4, SVPWM_SECT5, SVPWM_SECT6, FEEDBACK_output_t::Vdc, F←↩EEDBACK_internal_t::Vdc_1kHz, FEEDBACK_output_t::Vdc_1kHz, FEEDBACK_internal_t::Vdc_←↩200Hz, and FEEDBACK_output_t::Vdc_200Hz.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

145

Page 172: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Analog to Digital Converter Interface

13.5 Analog to Digital Converter Interface13.5.1 Overview

The Analog to Digital Converter (ADC) Interface describes how the ADC is configured and used.

Functions

• void ADCS_init (void)Initializes ADC module.

• void ADCS_enableInt (void)Enables ADC conversion complete ISR.

• void ADCS_disableInt (void)Disables ADC conversion complete ISR.

• void ADCS_clearIRQ (void)Clears ADC conversion complete ISR.

• FAST void ADCS_readRawADC (ADC_results_t ∗const raw_adc)Reads raw ADC samples for result record.

• void ADCS_getUserSamples (uint16_t adc0Channel, uint16_t adc1Channel, uint16_t adc0HW←↩

Mux, uint16_t adc1HWMux, uint16_t ∗adc0Sample, uint16_t ∗adc1Sample)Configures the ADC to software trigger samples, blocks on conversion, returns results.

• void ADCS_enablePDB (void)Enables the PDB block.

• void ADCS_disablePDB (void)Disables the PDB block.

• void ADCS_clearPDBError (void)Clears PDB trigger errors.

13.5.2 Function Documentation

13.5.2.1 void ADCS_clearIRQ ( void )

Clears ADC conversion complete ISR.

Returns

none

13.5.2.2 void ADCS_clearPDBError ( void )

Clears PDB trigger errors.

13.5.2.3 void ADCS_disableInt ( void )

Disables ADC conversion complete ISR.

146Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 173: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Analog to Digital Converter Interface

Returns

none

13.5.2.4 void ADCS_disablePDB ( void )

Disables the PDB block.

13.5.2.5 void ADCS_enableInt ( void )

Enables ADC conversion complete ISR.

Returns

none

Referenced by FEEDBACK_init().

13.5.2.6 void ADCS_enablePDB ( void )

Enables the PDB block.

13.5.2.7 void ADCS_getUserSamples ( uint16_t adc0Channel, uint16_t adc1Channel,uint16_t adc0HWMux, uint16_t adc1HWMux, uint16_t ∗ adc0Sample, uint16_t ∗adc1Sample )

Configures the ADC to software trigger samples, blocks on conversion, returns results.

Parameters

adc0Channel - Channel to sample on ADC0

adc1Channel - Channel to sample on ADC1

adc0HWMux - Channel to sample on ADC0

adc1HWMux - Channel to sample on ADC1

adc0Sample - ADC0 results (out)

NXP SemiconductorsKinetis Motor Suite API Reference Manual

147

Page 174: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Analog to Digital Converter Interface

adc1Sample - ADC1 results (out)

13.5.2.8 void ADCS_init ( void )

Initializes ADC module.

Returns

none

Referenced by FEEDBACK_init().

13.5.2.9 void ADCS_readRawADC ( ADC_results_t ∗const raw_adc )

Reads raw ADC samples for result record.

Parameters

raw_adc - pointer to the ADC_results data structure

References ADC_results_t::dcBusVoltage, ADC_results_t::phaseACurrent, ADC_results_t::phaseB←↩Current, and ADC_results_t::phaseCCurrent.

148Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 175: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 14Clarke Transform14.1 OverviewConverts three phase current feedback signals (A-B-C frame) to two phase representation (Alpha-Betaframe).

Functional description

Field oriented control of motors requires transformation from three vectors to two perpendicular vectorsin a stationary reference frame to two perpendicular vectors in a rotating reference frame, then the reverseprocess. The Clarke Transform block effects the transition between three vectors in the stationary frame(A-B-C frame) to two vectors in the stationary frame (Alpha-Beta frame).

Figure 14.1.1: Effect of Clarke Transform

This transformation is required in the feedback loop: current is sensed along the motor’s three phases inthe Feedback block, then these three phase current values are mathematically transformed into a set of twocurrent vectors.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

149

Page 176: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Block diagram detail

Figure 14.1.2: Clarke Transform

Configuration, inputs, and outputs

No configuration of the Clarke Transform block is required. The inputs are the sampled motor phasecurrent values as output by the Feedback block. These allow the Clarke Transform block to produce twocurrent vectors in a stationary reference frame to pass to the Park Transform block.

Code security breakdown

The table below describes the partitioning of Clarke block code among open source, library, and protectedexecute-only.

Open Source Library Execute-onlyInitialization and function for run-ning transform as well as output

Implementation of transform N/A

Execution

The Clarke Transform is run in the Fast ISR because the current sensing happening in the Feedback blockoccurs rapidly and these dynamics must be accounted for rapidly in motor control operation.

150Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 177: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

User customization example

While the Clarke Transform is required for field oriented control, the user may wish to utilize differentmathematical method for performing the transform. The underpinnings of this block - the code for trans-formations - may be adapted for this purpose.

Data Structures• struct CLARKE_output_t• struct CLARKE_t

Functions• CLARKE_t ∗ CLARKE_init (void ∗pMem, size_t size)

Clarke transform initialization.• FAST void CLARKE_run (CLARKE_t ∗handle, const FEEDBACK_output_t ∗const input)

14.2 Data Structure Documentation

14.2.1 struct CLARKE_output_t

Data Fields

TRF_s←↩Vector16_t

vector 16 bit stationary vectors

14.2.2 struct CLARKE_t

Data Fields

CLARKE_←↩output_t

output Alpha-Beta stationary vectors

14.3 Function Documentation

14.3.1 CLARKE_init ( void ∗ pMem, size_t size )

Clarke transform initialization.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

151

Page 178: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

pMem - pointer to memory where the CLARKE block is stored

size - size of memory where the CLARKE block is stored

Returns

handle - interface to access the CLARKE block

14.3.2 FAST void CLARKE_run ( CLARKE_t ∗ handle, constFEEDBACK_output_t ∗const input )

152Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 179: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 15Park Transform15.1 OverviewConverts two phase current feedback signals from the stationary frame (Alpha-Beta frame) to the rotatingframe (D-Q frame).

Functional description

Field oriented control of motors requires transformation from three vectors to two perpendicular vectorsin a stationary reference frame to two perpendicular vectors in a rotating reference frame, then the reverseprocess. The Park Transform block effects the transition between two vectors in the stationary frame(Alpha-Beta frame) to two vectors in the rotating frame (D-Q frame).

Figure 15.1.1: Effect of Park Transform

This transformation is required in the feedback loop: after current is sensed along the motor’s three phasesin the Feedback block and converted into two vectors via the Clarke Transform, these two vectors aretransformed into the rotating reference frame using the angular position estimate provided by the Estimatorblock.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

153

Page 180: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Block diagram detail

Figure 15.1.2: Park Transform

Configuration, inputs, and outputs

No configuration of the Park Transform block is required. The inputs are the stationary reference framecurrent vectors and the motor’s angular position as estimated by the Estimator block. These allow the ParkTransform block to produce two current vectors in the rotating (D- and Q-axis) reference frame to pass tothe Current block.

Code security breakdown

The table below describes the partitioning of Park Transform block code among open source, library, andprotected execute-only.

Open Source Library Execute-onlyStructures for output; functions forinitialization and running transfor-mation

Implementation of relevant functi-ons

N/A

Execution

The Park Transform is run in the Fast ISR because the current sensing happening in the feedback loopoccurs rapidly and these dynamics must be accounted for rapidly in motor control operation.

154Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 181: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

User customization example

While the Park Transform is required for field oriented control, the user may wish to utilize differentmathematical method for performing the transform. The underpinnings of this block - the code for trans-formations - may be adapted for this purpose.

Data Structures• struct PARK_output_t

Rotating reference frame 16-bit extended vector type. More...• struct PARK_t

Output of Park function in stationary reference frame. More...

Functions• PARK_t ∗ PARK_init (void ∗pMem, size_t size)

Clarke transform initialization.• FAST void PARK_run (PARK_t ∗handle, const TRF_orient32_t ∗const orient, TRF_sVector16_t∗input)

Park Transformation function.

15.2 Data Structure Documentation15.2.1 struct PARK_output_t

Rotating reference frame 16-bit extended vector type.

Data Fields

TRF_r←↩Vector16_t

vector

15.2.2 struct PARK_t

Output of Park function in stationary reference frame.

Data Fields

PARK_←↩output_t

output

15.3 Function Documentation15.3.1 PARK_init ( void ∗ pMem, size_t size )

Clarke transform initialization.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

155

Page 182: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

pMem - pointer to memory where the PARK block is stored

size - size of memory where the PARK block is stored

Returns

handle - interface to access the PARK block

15.3.2 PARK_run ( PARK_t ∗ handle, const TRF_orient32_t ∗const orient,TRF_sVector16_t ∗ input )

Park Transformation function.

Parameters

handle - pointer to the PARK block

orient - sin and cos of the motor angle

input - stationary reference frame input

Returns

none

156Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 183: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 16Startup16.1 OverviewManages motor operation when near zero speed.

Functional description

The Startup block is responsible for starting the motor from zero speed, where the back-EMF signal isinsufficient to provide knowledge of where the motor is in its rotation and thus insufficient for KMS toestimate the motor electrical angle. The Startup block increases the speed of the motor until it receivesa signal from the Sensorless Estimation block (est.output.sensorlessEnabled in purple), alerting Startupthat it should begin to merge the two motor angles together to provide a seamless transition from open-loop to closed-loop. When the angle merge is complete, Startup sends a signal to the rest of the FOC(startup.output.controlType in blue). An example of this is shown below.

Figure 16.1.1: Startup Example

The Startup block relies on controlling current. Specifically, it involves applying a current on the D-axis, or direct axis, which is aligned with the rotor's magnetic flux. This current implicitly forces therotor to align to a rotating D-axis (startup.output.statorRefCurrent.d in purple), which begins to spin themotor. The amount of current dynamically ramps up as necessary to ensure that the motor can start tospin despite applied load (though dynamic ramp-up may be disabled if a fixed current value is preferred).

NXP SemiconductorsKinetis Motor Suite API Reference Manual

157

Page 184: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Startup determines if the current applied to the D-axis needs to be increased by looking at the motor fluxto determine if the motor is indeed rotating. An example of this is shown in the figure below.

Figure 16.1.2: Startup with Increasing Current

Once the speed reference has crossed the Speed Threshold, the Startup block begins blending (or merging)the angle produced by the Startup block with the angle generated by the Sensorless Estimator block. It willalso blend current along the D-axis (startup.output.statorRefCurrent.d in red) with current on the Q-axis(startup.output.statorRefCurrent.q in green) [quadrature axis, perpendicular to the D-axis, for producingtorque] to avoid abrupt changes in current, as in normal operation current should be applied on the torqueproducing axis. Startup then loads the Q-axis current into the speed controller (speed.output.IqRef inpurple) and switches over from current control to closed loop speed control (startup.output.controlType inblue). This process is shown in the below figure.

158Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 185: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Figure 16.1.3: Startup Current Blend

In addition to starting the motor from zero speed, Startup will also take control of the motor when tran-sitioning from positive speeds to negative speeds and vice versa. An example of this is shown below. Inthis example the control method (startup.output.controlType in blue) is set to open-loop when the speedreference (trajvel.output.refSpeed in red) drops below the Speed Threshold. The control method is setback to closed-loop when the speed reference exceeds the Speed Threshold.

Figure 16.1.4: Startup Current Blend

NXP SemiconductorsKinetis Motor Suite API Reference Manual

159

Page 186: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Block diagram detail

Figure 16.1.5: Startup

Configuration, inputs, and outputs

Configuration of the Startup block primarily involves defining the behavior of dynamic current ramp-up.While defaults are assumed, the user may specify percentages of rated current that will bound the range ofcurrent allowed for dynamic current ramp-up and the speed with which the current will ramp.

Additional inputs include base speed and sample time.

The outputs of the Startup block are reference currents to drive the motor and indicators of ability totransition to closed loop control.

Code security breakdown

The table below describes the partitioning of Startup block code among open source, library, and protectedexecute-only.

Open Source Library Execute-onlyStructures for module and output;functions for initialization, configu-ration, and updating

N/A Implementation of soft start, angleblending, crossover logic, updatingfunctions

Execution

The Startup block is primarily operated in the Fast ISR because the objective is to move the system intoclosed loop control as quickly as possible, and this requires the best possible information. Some Startuproutines execute in the Slow ISR due to the less time-critical nature of those routines.

160Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 187: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

User customization example

Sensorless startup is among the most difficult of challenges in motor control, and wide applicability ofany one solution is not guaranteed. Consequently, the user may have proprietary startup algorithms thathave proven successful over multiple product development cycles. In this case, the user may choose toremove the Startup block entirely in favor of connecting a proprietary startup to KMS’ normal closed loopoperation.

Data Structures• struct STARTUP_config_t• struct STARTUP_output_t• struct STARTUP_t

Macros• #define STARTUP_PRV_SIZE 16

Functions• STARTUP_t ∗ STARTUP_init (void ∗pMem, size_t size)

Startup initialization.• void STARTUP_config (STARTUP_t ∗handle, _lq(∗startup_LQsinPU)(_lq x), const STARTUP_←↩

config_t ∗const config, _lq lq16BaseSpeedElecFreq, _lq focSampleTime, _lq lq16AngDiffCutoff←↩FreqHz)

• void STARTUP_updateSlowTick (STARTUP_t ∗handle, _lq rotorRefSpeed, _lq filtStatorFluxSp←↩VecMag)

• void STARTUP_reset (STARTUP_t ∗handle)Startup reset.

• void STARTUP_setAngle (STARTUP_t ∗handle, _lq angle)Set the angle that STARTUP should begin with.

• void STARTUP_updateFastTick (STARTUP_t ∗handle, _lq angleEst, bool sensorlessEnabled, _lqrotorRefSpeed, _sq currentFdbIq)

16.2 Data Structure Documentation

16.2.1 struct STARTUP_config_t

Data Fields

bool enableSoftStart user configurable variable to enable soft start-up

NXP SemiconductorsKinetis Motor Suite API Reference Manual

161

Page 188: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

_lq minSyncSpeed Minimum speed above which Soft Start works

_lq percentMax maximum percent of rated current for a Soft Start (in real worldpercentage)

_lq percentMin minimum percent of rated current for a Soft Start in real worldpercentage

_lq pmFluxSync←↩ThreshWb

PM Flux in Wb which triggers a stall

_sq ratedCurrent rated motor current (in pu Arms)

_lq risingTime time to rise from percentMin to percentMax during a Soft Start (inseconds)

16.2.2 struct STARTUP_output_t

Data Fields

DRV_control←↩_e

controlType motor control type (startup or FOC)

_lq fieldAngle rotor field angle (in pu radians)

TRF_r←↩Vector16_t

statorRef←↩Current

stator reference dq current (in pu Arms)

16.2.3 struct STARTUP_t

Data Fields

STARTUP_←↩config_t

config Configuration structure for startup module

STARTUP_←↩output_t

output Output structure for startup module

uint32_t prv[STARTU←↩P_PRV_SIZE]

Private variables

16.3 Macro Definition Documentation

16.3.1 #define STARTUP_PRV_SIZE 16

162Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 189: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

16.4 Function Documentation

16.4.1 void STARTUP_config ( STARTUP_t ∗ handle, _lq(∗)(_lq x)startup_LQsinPU, const STARTUP_config_t ∗const config, _lqlq16BaseSpeedElecFreq, _lq focSampleTime, _lq lq16AngDiffCutoffFreqHz)

16.4.2 STARTUP_init ( void ∗ pMem, size_t size )

Startup initialization.

Parameters

pMem - pointer to memory where the STARTUP block is stored

size - size of memory where the STARTUP block is stored

Returns

handle - interface to access the STARTUP block

16.4.3 STARTUP_reset ( STARTUP_t ∗ handle )

Startup reset.

Parameters

handle - pointer to the STARTUP block

Returns

none

16.4.4 STARTUP_setAngle ( STARTUP_t ∗ handle, _lq angle )

Set the angle that STARTUP should begin with.

Parameters

NXP SemiconductorsKinetis Motor Suite API Reference Manual

163

Page 190: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

handle - pointer to the STARTUP block

angle - angle to initialize STARTUP with

Returns

none

16.4.5 void STARTUP_updateFastTick ( STARTUP_t ∗ handle, _lq angleEst, boolsensorlessEnabled, _lq rotorRefSpeed, _sq currentFdbIq )

16.4.6 void STARTUP_updateSlowTick ( STARTUP_t ∗ handle, _lq rotorRefSpeed,_lq filtStatorFluxSpVecMag )

164Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 191: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 17Sensorless Estimator17.1 OverviewGenerates sensorless angle and speed feedback from the phase currents in the stator reference frame. Partof this block runs in the fast ISR and part runs in the slow ISR.

Functional description

The Sensorless Estimator block is primarily responsible for providing an estimate of the motor’s electricalangular position. This estimate allows for properly transforming the voltage references from rotating tostationary reference frame and thereby ensures that maximum torque will be generated by applied voltage.The estimate also allows for the calculation of an estimated speed, which serves as the speed feedback tothe Speed block and thereby allows the velocity controller to assess then compensate for the differencebetween desired and “actual” (estimated) speed.

The angle estimate is achieved by relying on the rotation of the motor to induce back-electromotive force.This form of angle estimation relies on having accurate motor parameters (Stator Resistance, Stator Induc-tance, and Rotor Flux). It is not dependent on knowing the motor's saliency. In order to improve estimationaccuracy KMS also uses device model information (Resistive Loss, Voltage Loss, and Deadtime). Thereis no tuning required for the angle estimation.

The speed estimate is achieved by using the estimated electrical angle. A PLL is used in order to filterthe delta electrical angle used for speed calculation. There is a single tuning parameter to adjust for thespeed estimate, PLL Bandwidth. The initial value for PLL Bandwidth will typically work for a motordisconnected from any load or inertia. If the motor is coupled with a large inertia, the PLL Bandwidthshould be decreased by half. This is because the PLL Bandwidth is related to the system's ability toaccelerate.

The complete Sensorless Estimator block is only required for Sensorless Velocity control. For SensoredVelocity and Sensored Position control a subset of the Sensorless Estimator called Flux Estimator is avai-lable. Its primary objective is to estimate the amount of rotor flux which is used for torque estimation andfor fault detection.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

165

Page 192: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Block diagram detail

Figure 17.1.1: Sensorless

Configuration, inputs, and outputs

The Sensorless Estimator block is configured with the motor and system parameters.

The inputs are the stationary reference currents in the Alpha-Beta (two vector stationary reference frame).Additional current and voltage inputs are also required for data collection and other estimations.

The primary outputs are the electrical angle and speed estimates. There are additional outputs for torqueand power estimates.

Code security breakdown

The table below describes the partitioning of Sensorless Estimator block code among open source, library,and protected execute-only.

Open Source Library Execute-onlyDefinition of outputs such as angle,speed, power; configuration and up-dating functions

N/A Implementation of sensorless ob-server, torque & power estimators

Execution

The main operations of the Sensorless Estimator run in both the Fast ISR and Slow ISR, as the performanceof the system relies substantially on the angular position estimate and the speed feedback estimate.

166Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 193: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

User customization example

Sensorless rotor position detection algorithms are a key area of research and development for any com-pany developing motor control IP. The user may wish to use algorithms developed internally for his/herapplication and may therefore wish to eliminate the Sensorless Estimator.

Another method for customizing the Sensorless Estimator block revolves around other outputs of theblock. Torque and power estimates for example may prove useful for triggering certain application beha-viors.

Modules• Flux Estimator

Generates rotor flux from the phase currents in the stator reference frame. Part of this block runs in thefast ISR and part runs in the slow ISR.

Data Structures• struct EST_config_t

Estimator configuration structure. More...• struct EST_output_t

Estimator output structure. More...• struct EST_t

Estimator structure. More...

Macros• #define EST_PRV_SIZE 91

Functions• EST_t ∗ EST_init (void ∗pMem, size_t size)

Estimator initialization.• void EST_config (EST_t ∗handle, const EST_config_t ∗const config, _lq lq16BaseSpeedElecFreq,

_lq focSampleTime, _lq slowSampleTime, _lq deadTimePerTs, _lq lq16SpeedCutoffFreqHz, _←↩lq lq16PowerCutoffFreqHz, _lq lq16IsdqCutoffFreqHz, _lq lq16FluxCutoffFreqHz, _lq lq16Ang←↩OffsetCutoffFreqHz)

• void EST_reset (EST_t ∗handle)Resets the Estimator module.

• void EST_updateSlowTick (EST_t ∗handle, bool enable, _lq rotorRefSpeed, _lq invVdc, boolenableDCInjection)

• void EST_updateFastTick (EST_t ∗handle, const SVPWM_output_t ∗const pSVPWMOutput, constFEEDBACK_output_t ∗const pADC, TRF_sVector16_t ∗statorCurrentAB, _lq statorRefVoltage←↩Magnitude, TRF_rVector16_t ∗statorCurrentDQ)

• TRF_sVector32_t ∗ EST_getStatorVoltageAB (EST_t ∗handle)Returns the estiamted stator voltages in AB frame.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

167

Page 194: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

17.2 Data Structure Documentation

17.2.1 struct EST_config_t

Estimator configuration structure.

Data Fields

_lq FOCLowSpeed Rotor Speed (pu) threshold for sensorless speed control

PID_pi←↩Param32_t

pll PI parameter structure

_lq pllFiltBwHz Pll P Error filter bandwidth in Hz

_lq pmFlux Permanent magnet flux (pu)

_lq pmFluxDivLsq PM Flux / q-axis Stator inductance

_lq R_igbt IGBT resistance / DRV_BASE_RESISTANCE (pu)

_lq statorDInd d-axis Stator inductance (pu)

_lq statorQInd q-axis Stator inductance (pu)

_lq statorRes Stator resistance (pu)

_lq V_igbt IGBT voltage drop / ADC_BASE_VOLTAGE (pu)

_lq vBasedFlux←↩CoeffA

Flux estimator co-efficient A

_lq vBasedFlux←↩CoeffB

Flux estimator co-efficient B

17.2.2 struct EST_output_t

Estimator output structure.

Data Fields

_lq activePower Active power (pu)

_lq reactivePower Reactive power (pu)

_lq rotorAngle Estimated rotor angle (-1 to +1)

_lq rotorSpeed Estimated rotor speed (pu)

168Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 195: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

_lq rotorSpeed_←↩50Hz

Filtered rotor speed (pu)

void ∗ SCM_data Estimates for the SCM module

bool sensorless←↩Enabled

true: speed sensorless control enabled

_lq statorCurrent←↩Magnitude

Stator Current magnitude (pu)

_lq statorFlux←↩Magnitude

Stator Flux Magnitude (pu)

_lq statorRef←↩Voltage←↩Magnitude

DRV_statorRefVoltageMagnitude

_lq statorVoltage←↩Magnitude

DRV_statorVoltageMagnitude

_lq torque Estimated torque (pu)

17.2.3 struct EST_t

Estimator structure.

Data Fields

EST_config_t config Estimator configuration structure

EST_output_t output Estimator output structure

uint32_t prv[EST_PR←↩V_SIZE]

Estimator private data block

17.3 Macro Definition Documentation

17.3.1 #define EST_PRV_SIZE 91

NXP SemiconductorsKinetis Motor Suite API Reference Manual

169

Page 196: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

17.4 Function Documentation

17.4.1 void EST_config ( EST_t ∗ handle, const EST_config_t ∗const config, _lqlq16BaseSpeedElecFreq, _lq focSampleTime, _lq slowSampleTime, _lqdeadTimePerTs, _lq lq16SpeedCutoffFreqHz, _lq lq16PowerCutoffFreqHz,_lq lq16IsdqCutoffFreqHz, _lq lq16FluxCutoffFreqHz, _lqlq16AngOffsetCutoffFreqHz )

17.4.2 EST_getStatorVoltageAB ( EST_t ∗ handle )

Returns the estiamted stator voltages in AB frame.

Parameters

handle - pointer to the EST block

Returns

pointer to memory where stator voltages are stored in AB frame

17.4.3 EST_init ( void ∗ pMem, size_t size )

Estimator initialization.

Parameters

pMem - pointer to memory where the EST block is stored

size - size of memory where the EST block is stored

Returns

handle - interface to access the EST block

17.4.4 EST_reset ( EST_t ∗ handle )

Resets the Estimator module.

170Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 197: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

handle - pointer to the EST block

Returns

none

17.4.5 void EST_updateFastTick ( EST_t ∗ handle, const SVPWM_output_t∗const pSVPWMOutput, const FEEDBACK_output_t ∗const pADC,TRF_sVector16_t ∗ statorCurrentAB, _lq statorRefVoltageMagnitude,TRF_rVector16_t ∗ statorCurrentDQ )

17.4.6 void EST_updateSlowTick ( EST_t ∗ handle, bool enable, _lqrotorRefSpeed, _lq invVdc, bool enableDCInjection )

NXP SemiconductorsKinetis Motor Suite API Reference Manual

171

Page 198: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Flux Estimator

17.5 Flux Estimator

17.5.1 Overview

Generates rotor flux from the phase currents in the stator reference frame. Part of this block runs in thefast ISR and part runs in the slow ISR.

Functional description

The Flux Estimator block is primarily responsible for providing an estimate of the rotor's flux. Thisestimate is used for fault detection in addition to torque and power estimation.

In order to improve estimation accuracy, KMS uses device model information (Resistive Loss, VoltageLoss, and Deadtime). There is no tuning required for the estimation.

Configuration, inputs, and outputs

The Flux Estimator block is configured with the motor and system parameters.

The inputs are the stationary reference currents in the Alpha-Beta (two vector stationary reference frame).Additional current and voltage inputs are also required for data collection and other estimations.

The primary output is the rotor flux. There are additional outputs for torque and power estimates.

Code security breakdown

The table below describes the partitioning of Flux Estimator block code among open source, library, andprotected execute-only.

Open Source Library Execute-onlyDefinition of outputs such as flux,torque, power; configuration andupdating functions

N/A Implementation of flux estimator,torque & power estimators

Execution

The main operations of the Flux Estimator run in both the Fast ISR and Slow ISR, as the flux estimate israpidly changing and needs to be estimated as quickly as possible.

User customization example

If the rotor flux estimation and associated torque and power estimations are not required in the end appli-cation, this block can be removed.

172Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 199: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Flux Estimator

Data Structures

• struct FLUXEST_config_tEstimator configuration structure. More...

• struct FLUXEST_output_tEstimator output structure. More...

• struct FLUXEST_t

Macros

• #define FLUXEST_PRV_SIZE 61

Functions

• FLUXEST_t ∗ FLUXEST_init (void ∗pMem, size_t size)Estimator initialization.

• void FLUXEST_config (FLUXEST_t ∗handle, const FLUXEST_config_t ∗const config, _lq lq16←↩BaseSpeedElecFreq, _lq focSampleTime, _lq slowSampleTime, _lq deadTimePerTs, _lq lq16←↩PowerCutoffFreqHz, _lq lq16IsdqCutoffFreqHz, _lq lq16FluxCutoffFreqHz)

• void FLUXEST_reset (FLUXEST_t ∗handle)Resets the Estimator module.

• void FLUXEST_updateSlowTick (FLUXEST_t ∗handle, _lq rotorSpeed, bool enableDCInjection)• void FLUXEST_updateFastTick (FLUXEST_t ∗handle, const SVPWM_output_t ∗const pSVP←↩

WMOutput, const FEEDBACK_output_t ∗const pADC, TRF_sVector16_t ∗statorCurrentAB, _lqstatorRefVoltageMagnitude, TRF_rVector16_t ∗statorCurrentDQ)

17.5.2 Data Structure Documentation

17.5.2.1 struct FLUXEST_config_t

Estimator configuration structure.

Data Fields

_lq pmFlux Permanent Magnet flux { unit: [pu webers] }

_lq R_igbt IGBT resistance / DRV_BASE_RESISTANCE { unit: [pu ohms]}

NXP SemiconductorsKinetis Motor Suite API Reference Manual

173

Page 200: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Flux Estimator

_lq statorDInd d-axis Stator inductance { unit: [pu henries] }

_lq statorQInd q-axis Stator inductance { unit: [pu henries] }

_lq statorRes Stator resistance { unit: [pu ohms] }

_lq V_igbt IGBT voltage drop / ADC_BASE_VOLTAGE { unit: [pu volts] }

_lq vBasedFlux←↩CoeffA

Flux estimator co-efficient A

_lq vBasedFlux←↩CoeffB

Flux estimator co-efficient B

17.5.2.2 struct FLUXEST_output_t

Estimator output structure.

Data Fields

_lq activePower Active power { unit: [pu watts] }

_lq reactivePower Reactive power { unit: [pu watts] }

void ∗ SCM_data Estimates for the SCM module

_lq statorCurrent←↩Magnitude

Stator Current magnitude { unit: [pu amps] }

_lq statorFlux←↩Magnitude

Stator Flux Magnitude { unit: [pu webers] }

_lq statorRef←↩Voltage←↩Magnitude

DRV_statorRefVoltageMagnitude

_lq statorVoltage←↩Magnitude

DRV_statorVoltageMagnitude

_lq torque Estimated torque { unit: [pu newton-meters] }

17.5.2.3 struct FLUXEST_t

Data Fields

174Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 201: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Flux Estimator

FLUXEST_←↩config_t

config Estimator configuration structure

FLUXEST_←↩output_t

output Estimator output structure

uint32_t prv[FLUXES←↩T_PRV_SIZE]

Estimator private data block

17.5.3 Macro Definition Documentation

17.5.3.1 #define FLUXEST_PRV_SIZE 61

17.5.4 Function Documentation

17.5.4.1 void FLUXEST_config ( FLUXEST_t ∗ handle, const FLUXEST_config_t ∗constconfig, _lq lq16BaseSpeedElecFreq, _lq focSampleTime, _lq slowSampleTime,_lq deadTimePerTs, _lq lq16PowerCutoffFreqHz, _lq lq16IsdqCutoffFreqHz, _lqlq16FluxCutoffFreqHz )

17.5.4.2 FLUXEST_init ( void ∗ pMem, size_t size )

Estimator initialization.

Parameters

pMem - pointer to memory where the FLUXEST block is stored

size - size of memory where the FLUXEST block is stored

Returns

handle - interface to access the FLUXEST block

17.5.4.3 FLUXEST_reset ( FLUXEST_t ∗ handle )

Resets the Estimator module.

Parameters

NXP SemiconductorsKinetis Motor Suite API Reference Manual

175

Page 202: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Flux Estimator

handle - pointer to the FLUXEST block

Returns

none

17.5.4.4 void FLUXEST_updateFastTick ( FLUXEST_t ∗ handle, constSVPWM_output_t ∗const pSVPWMOutput, const FEEDBACK_output_t ∗constpADC, TRF_sVector16_t ∗ statorCurrentAB, _lq statorRefVoltageMagnitude,TRF_rVector16_t ∗ statorCurrentDQ )

17.5.4.5 void FLUXEST_updateSlowTick ( FLUXEST_t ∗ handle, _lq rotorSpeed, boolenableDCInjection )

176Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 203: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 18Encoder18.1 OverviewProvides sensored angular position and velocity feedback.

Functional description

The Encoder block converts the motor electrical angle into speed a position signals usable by the speedand position control system. The motor electrical angle is generated from the QEI block each iterationof the Fast ISR. The Encoder block uses the delta between the previous electrical angle and the currentelectrical angle in order to perform its speed and position calculations. Since it relies on this delta, it doesnot need to be called at the Fast ISR rate.

The Encoder block is effectively a simplified wrapper block for the core algorithms of SpinTAC™ PositionConvert submodule.

Block diagram detail

Figure 18.1.1: Encoder

Configuration, inputs, and outputs

The Encoder blocks relies on sample time, pole pairs, and the base electrical speed in order to be configuredcorrectly.

The input to the Encoder block is the motor electrical angle which is an output of the QEI block.

The outputs consist of the motor speed and the motor mechanical angle.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

177

Page 204: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Code security breakdown

The table below describes the partitioning of Encoder block code among open source, library, and pro-tected execute-only.

Open Source Library Execute-onlyStructures for configuring encoderand functions for running encodercalculation

Implementation of speed and posi-tion calculation

N/A

Execution

Since the output of the Encoder block is speed and position feedback signals used for motion control, it isexecuted in the Slow ISR.

User customization example

For speed control applications, the Encoder block could be replaced with a similar function that determinesthe motor speed in the correct scaled units. For position control it is not recommended to replace this blocksince the motor mechanical angle output format is aligned with the outputs of the Trajectory block and theinputs of the Position block.

Modules• Quadrature Encoder Interface

The Quadrature Encoder Interface uses the FlexTimer hardware on the MCU to decode the incomingencoder phases into a motor electrical angle. It will also read the Hall-Effect inputs.

Data Structures• struct ENC_output_t

Encoder output structure. More...• struct ENC_t

Encoder structure. More...

Macros• #define ENC_PRV_SIZE 42

Functions• ENC_t ∗ ENC_init (void ∗pMem, size_t size)

Encoder initialization.• void ENC_config (ENC_t ∗handle, _lq sampleTime, uint16_t polePairs, _lq lq16BaseSpeedElec←↩

Freq, _lq lq16SpeedCutoffFreqHz)

178Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 205: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Configure Encoder block.• void ENC_run (ENC_t ∗handle, _lq rotorAngle_erev)

Run Encode calculations.• void ENC_reset (ENC_t ∗handle)

Reset ENC block.

18.2 Data Structure Documentation

18.2.1 struct ENC_output_t

Encoder output structure.

Data Fields

uint16_t errID Error ID { 0: no error; others: see error code }

int32_t rollOverCounts Number of rollovers between position windows (i.e. 10 -> -10,increases count; -10 -> 10 decreases count)

_lq rotorAngle_←↩Mrev

Position { unit: [MRev] }

_lq rotorSpeed Speed unfiltered { unit: [pu rpm] }

_lq rotorSpeed_←↩50Hz

Speed filtered { unit: [pu rpm] }

18.2.2 struct ENC_t

Encoder structure.

Data Fields

ENC_output_t output

uint32_t prv[ENC_PR←↩V_SIZE]

18.3 Macro Definition Documentation

18.3.1 #define ENC_PRV_SIZE 42

18.4 Function Documentation

18.4.1 ENC_config ( ENC_t ∗ handle, _lq sampleTime, uint16_t polePairs, _lqlq16BaseSpeedElecFreq, _lq lq16SpeedCutoffFreqHz )

Configure Encoder block.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

179

Page 206: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

handle - pointer to the ENC block

sampleTime - slow interrupt period { unit: [sec] }

polePairs - number of motor pole pairs

lq16Base←↩SpeedElecFreq

- base electrical speed (in rad/sec)

lq16Speed←↩CutoffFreqHz

- feedback speed filter freq (Q16.16, Hz)

Returns

none

18.4.2 ENC_init ( void ∗ pMem, size_t size )

Encoder initialization.

Parameters

pMem - pointer to memory where the ENC block is stored

size - size of memory where the ENC block is stored

Returns

handle - interface to access the ENC block

18.4.3 ENC_reset ( ENC_t ∗ handle )

Reset ENC block.

Parameters

handle - pointer to the ENC block

18.4.4 ENC_run ( ENC_t ∗ handle, _lq rotorAngle_erev )

Run Encode calculations.

180Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 207: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

handle - pointer to the ENC block

rotorAngle_←↩erev

- feedback electrical angle { unit: [elec angle] }

Returns

none

NXP SemiconductorsKinetis Motor Suite API Reference Manual

181

Page 208: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Quadrature Encoder Interface

18.5 Quadrature Encoder Interface

18.5.1 Overview

The Quadrature Encoder Interface uses the FlexTimer hardware on the MCU to decode the incomingencoder phases into a motor electrical angle. It will also read the Hall-Effect inputs.

Data Structures

• struct QEI_output_tQEI output variables. More...

• struct QEI_internal_tQEI internal variables. More...

• struct QEI_tQEI module. More...

Functions

• QEI_t ∗ QEI_init (void ∗pMem, size_t size)• void QEI_config (QEI_t ∗handle, uint16_t encoderPulses, uint16_t polePairs)

Configures QEI module.• FAST void QEI_updateAtFastTick (QEI_t ∗handle)

Update QEI module at Fast tick.• void QEI_resetEncoderAngle (QEI_t ∗handle)

Resets encoder angle (virtual and real)• void QEIS_init (uint16_t qeiMaxPosCount)

Initializes QEI system.• uint16_t QEIS_readPositionCounter (void)

Reads 16-bit position counter.• void QEIS_writePositionCounter (uint16_t value)

Writes a 16-bit unsigned value into a counter register.• void QEIS_swapTracks (bool swapIt)

Swaps encoder tracks A and B.• void QEIS_initHallInputs (void)

Initializes input pins assigned to Hall effect inputs - See pin_mux.h for pin assignment Do not call thisfunction when using an encoder.

• void QEIS_readHallInputs (HALL_values_t ∗hallReading)Reads input pins assigned to Hall effect inputs - See pin_mux.h for pin assignment.

18.5.2 Data Structure Documentation

18.5.2.1 struct QEI_output_t

QEI output variables.

182Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 209: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Quadrature Encoder Interface

Data Fields

_lq rotorAngle motor angle { unit: [electrical revolutions] }

18.5.2.2 struct QEI_internal_t

QEI internal variables.

Data Fields

_lq angleScalar Scale factor to convert encoder counts into electrical angle

int32_t encoderMax←↩Count

Maximum post-quadrature count on the encoder

uint16_t polePairs Number of motor pole pairs

18.5.2.3 struct QEI_t

QEI module.

Data Fields

QEI_internal←↩_t

internal Internal data structure for QEI module

QEI_output_t output Output structure for QEI module

18.5.3 Function Documentation

18.5.3.1 void QEI_config ( QEI_t ∗ handle, uint16_t encoderPulses, uint16_t polePairs )

Configures QEI module.

Parameters

handle - point to the QEI block

encoderPulses - number of pulses on the encoder

NXP SemiconductorsKinetis Motor Suite API Reference Manual

183

Page 210: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Quadrature Encoder Interface

polePairs - number of motor pole pairs

Returns

none

18.5.3.2 QEI_t∗ QEI_init ( void ∗ pMem, size_t size )

18.5.3.3 void QEI_resetEncoderAngle ( QEI_t ∗ handle )

Resets encoder angle (virtual and real)

Parameters

handle - point to the QEI block

Returns

none

18.5.3.4 void QEI_updateAtFastTick ( QEI_t ∗ handle )

Update QEI module at Fast tick.

Parameters

handle - point to the QEI block

Returns

none

18.5.3.5 void QEIS_init ( uint16_t qeiMaxPosCount )

Initializes QEI system.

184Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 211: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Quadrature Encoder Interface

Parameters

qeiMaxPos←↩Count

- maximum position count [(4 ∗ encoderLines) - 1]

Returns

none

18.5.3.6 void QEIS_initHallInputs ( void )

Initializes input pins assigned to Hall effect inputs - See pin_mux.h for pin assignment Do not call thisfunction when using an encoder.

Initializes input pins assigned to Hall effect inputs - See kms_hw.h for pin assignment Do not call thisfunction when using an encoder.

Returns

none

18.5.3.7 void QEIS_readHallInputs ( HALL_values_t ∗ hallReading )

Reads input pins assigned to Hall effect inputs - See pin_mux.h for pin assignment.

Parameters

hallReading - pointer to memory where Hall Sensor values should be written in order A,B,C

Returns

none

References HALL_values_t::a, HALL_values_t::b, and HALL_values_t::c.

18.5.3.8 uint16_t QEIS_readPositionCounter ( void )

Reads 16-bit position counter.

Returns

16-bit unsigned position value

18.5.3.9 void QEIS_swapTracks ( bool negativeDirection )

Swaps encoder tracks A and B.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

185

Page 212: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Quadrature Encoder Interface

Parameters

swapIt - true to swap tracks, false otherwise

Returns

none

18.5.3.10 void QEIS_writePositionCounter ( uint16_t value )

Writes a 16-bit unsigned value into a counter register.

Writes a 16-bit unsigned value into a Flex Timer counter register. This causes the counter to be initializedto the value in CNTIN register.

Parameters

value - counter value

Returns

none

186Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 213: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 19Hall-Effect Sensor19.1 OverviewProvides angular position and velocity feedback based on estimates from the Hall Effect Sensors.

Functional description

The Hall block converts the Hall-Effect sensors into speed and position signals usable by the startupcontrol system. The individual Hall-Effect sensors are read by the QEI block each iteration of the FastISR. The Hall block uses the number of Fast ISRs between each observed Hall-Effect state change in orderto perform its speed estimation. The position estimation is a combination of the absolute position providedby the change in Hall-Effect state and integration based on the estimated rotor speed.

Since every motor presents a slightly different pattern of Hall-Effect sensors, the Hall block will identifythe correct Hall-Effect sensor pattern during the Flux Identification portion of the Self-Commissioningroutine.

Block diagram detail

Figure 19.1.1: Hall

Configuration, inputs, and outputs

The Hall block relies on sample time, pole pairs, and the base electrical speed in order to be configuredcorrectly.

The input to the Hall block is the Hall-Effect states which is an output of the QEI block.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

187

Page 214: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

The outputs consist of the estimated motor speed, the estimated motor mechanical angle, and the identifiedHall-Effect state and index.

Code security breakdown

The table below describes the partitioning of Hall block code among open source, library, and protectedexecute-only.

Open Source Library Execute-onlyStructures for configuring Hall andfunctions for running Hall calcula-tion

Implementation of speed and posi-tion calculation

N/A

Execution

Since the output of the Hall block is Hall-Effect state and index used for motor control, it is executed inthe Fast ISR.

User customization example

The Hall block could be replaced with a similar block that uses exact timing of the Hall-Effect statechanges in order to get very accurate speed estimation. This would be an advanced use case of the Flex←↩Timer hardware. It is not expected that the vast majority of users would need to alter this block.

Data Structures• struct HALL_output_t• struct HALL_config_t• struct HALL_t

Hall module structure. More...• struct HALL_values_t

Macros• #define HALL_PRV_SIZE 27

Functions• HALL_t ∗ HALL_init (void ∗pMem, size_t size)

Hall Effect Sensor initialization.• void HALL_config (HALL_t ∗handle, const HALL_config_t ∗const config, _lq lq16BaseSpeed←↩

ElecFreq, _lq focSampleTime, uint16_t polePairs, _lq lq16SpeedCutoffFreqHz, _lq lq16SpeedErr←↩TrackCutoffFreqHz)

188Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 215: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

• FAST void HALL_run (HALL_t ∗handle, HALL_values_t ∗hallReading, _lq rotorSpeed, const F←↩EEDBACK_output_t ∗const pADC)

Hall Effect Sensor angle determination function.• void HALL_runIdentify (HALL_t ∗handle, HALL_values_t ∗hallReading, _lq rotorSpeed, _lq

fieldAngle)

19.2 Data Structure Documentation19.2.1 struct HALL_output_t

Data Fields

uint8_t hallIndex Index of the Hall effect sensor reading

uint8_t hallValues Reading of the Hall effect sensors

uint8_t isTracking Is hall controller successfully tracking requested speed

_lq rotorAngle Hall-derived rotor electrical angle (-1 to +1)

_lq rotorSpeed Hall-derived rotor mechanical speed

_lq rotorSpeed_←↩10Hz

Hall-derived rotor mechanical speed filtered to 10Hz

_sq statorFdb←↩Current

Stator feedback current to be used during Trapezoidal control

19.2.2 struct HALL_config_t

Data Fields

uint8_t hall0State First Hall state in electrical rotation

uint8_t hall1State Second Hall state in electrical rotation

uint8_t hall2State Third Hall state in electrical rotation

uint8_t hall3State Fourth Hall state in electrical rotation

uint8_t hall4State Fifth Hall state in electrical rotation

uint8_t hall5State Sixth Hall state in electrical rotation

_lq maxSpeedErr←↩Pct

maximum percent of error of refrence speed to be consideredtracking

19.2.3 struct HALL_t

Hall module structure.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

189

Page 216: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Data Fields

HALL_←↩config_t

config

HALL_←↩output_t

output

uint32_t prv[HALL_P←↩RV_SIZE]

19.2.4 struct HALL_values_t

Data Fields

bool a value for A sensor reading (should be 0 or 1)

bool b value for B sensor reading (should be 0 or 1)

bool c value for C sensor reading (should be 0 or 1)

19.3 Macro Definition Documentation

19.3.1 #define HALL_PRV_SIZE 27

19.4 Function Documentation

19.4.1 void HALL_config ( HALL_t ∗ handle, const HALL_config_t ∗const config,_lq lq16BaseSpeedElecFreq, _lq focSampleTime, uint16_t polePairs, _lqlq16SpeedCutoffFreqHz, _lq lq16SpeedErrTrackCutoffFreqHz )

19.4.2 HALL_init ( void ∗ pMem, size_t size )

Hall Effect Sensor initialization.

Parameters

pMem - pointer to memory where the HALL block is stored

size - size of memory where the HALL block is stored

Returns

handle - interface to access the HALL block

190Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 217: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

19.4.3 HALL_run ( HALL_t ∗ handle, HALL_values_t ∗ hallReading, _lqrotorSpeed, const FEEDBACK_output_t ∗const pADC )

Hall Effect Sensor angle determination function.

Parameters

handle - pointer to the HALL block

hallReading - value for Hall Effect Sensors in order A,B,C

rotorSpeed - actual speed of the motor

pADC - pointer to the FEEDBACK module output

Returns

none

19.4.4 void HALL_runIdentify ( HALL_t ∗ handle, HALL_values_t ∗ hallReading,_lq rotorSpeed, _lq fieldAngle )

NXP SemiconductorsKinetis Motor Suite API Reference Manual

191

Page 218: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

192Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 219: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 20Current20.1 OverviewTwo channel (Iq and Id) current regulator which outputs D and Q phase voltages.

Functional description

The Current block is responsible for taking in a current reference value, comparing it to actual sensedcurrent, then outputting a voltage reference for the D-axis and Q-axis to be used to correct the currenterror and perpetuate the rotating magnetic field that induces rotation in the motor.

This is achieved by means of applying traditional proportional-integral controllers to the direct and qua-drature axes, where feedback current is always provided by the Park Transform block and the origin ofreference current depends on the state of operation. During normal closed loop speed control, the Speedblock provides a current reference. When starting from zero, the Park Transform block still provides feed-back. Finally, at high modulation and speed, the Field Weakening block provides current reference. Ifrunning in torque control mode the current references are provided from the User inputs.

The Current controller gains are automatically tuned during the SCM process based on the motor's ratedelectrical speed, but can be manually updated by changing current loop bandwidth or gains in the userinterface. Increasing the current loop bandwidth causes the system to respond more rapidly to requiredtorque demands and may be desirable for highly dynamic systems (e.g., servo systems) or scenarios whereit is necessary to exceed the rated electrical speed of the motor. The value should be at maximum 10%of the defined PWM frequency. By contrast, reducing the current loop bandwidth diminishes the system'ssusceptibility to torque noise. The current loop must still operate faster than the outer motion controlloop(s) (velocity and/or position), though, so the value should remain on the order of five times the speedloop bandwidth value and ten times the position loop bandwidth value.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

193

Page 220: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Block diagram detail

Figure 20.1.1: Current

Configuration, inputs, and outputs

Configuration of the Current block primarily involves setting the gains for PI controller that compensatesfor error between desired and actual current.

The main inputs are the current references and feedbacks for both D and Q axes.

The outputs are the reference voltages used to adjust the amount of current flowing through the motor.

Code security breakdown

The table below describes the partitioning of Current block code among open source, library, and protectedexecute-only.

Open Source Library Execute-onlyInitialization, configuration, resets,function for performing currentcontrol

Calculation and implementation ofcurrent loop gains

N/A

Execution

The Current block runs in the Fast ISR to perform real-time control action based on rapidly changingcurrent feedback.

194Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 221: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

User customization example

The user may wish to utilize a custom advanced control algorithm (e.g., gain scheduling) specific to his/herapplication. This could be used to replace the PI based controller structure provided that input current errorresults in a voltage reference.

Data Structures• struct CURRENT_output_t• struct CURRENT_config_t• struct CURRENT_t

Current module structure. More...

Macros• #define CURRENT_PRV_SIZE 26

Functions• CURRENT_t ∗ CURRENT_init (void ∗pMem, size_t size)

Current control loop initialization.• void CURRENT_config (CURRENT_t ∗handle, const CURRENT_config_t ∗const config, _lq foc←↩

SampleTime, _lq lq16fltIdqErrorCutoffFrq, _lq voltageGain)Current control loop configuration.

• void CURRENT_resetController (CURRENT_t ∗handle)Resets internal states for CURRENT block.

• void CURRENT_resetFilters (CURRENT_t ∗handle)Resets internal states for filters.

• FAST void CURRENT_run (CURRENT_t ∗handle, _lq Vdc, _lq invVdc, TRF_rVector16_t ∗p←↩RefCurrent, TRF_rVector16_t ∗pFbkCurrent)

• void CURRENT_setIntegrator (CURRENT_t ∗handle, _lq Vdc, const TRF_rVector32_t ∗const p←↩RefVoltage)

20.2 Data Structure Documentation

20.2.1 struct CURRENT_output_t

Data Fields

TRF_r←↩Vector32_t

statorRef←↩VoltageDQ

20.2.2 struct CURRENT_config_t

NXP SemiconductorsKinetis Motor Suite API Reference Manual

195

Page 222: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Data Fields

PID_pi←↩Param16_t

Id

PID_pi←↩Param16_t

Iq

20.2.3 struct CURRENT_t

Current module structure.

Data Fields

CURRENT_←↩config_t

config

CURRENT_←↩output_t

output

uint32_t prv[CURRE←↩NT_PRV_SI←↩ZE]

20.3 Macro Definition Documentation

20.3.1 #define CURRENT_PRV_SIZE 26

20.4 Function Documentation

20.4.1 CURRENT_config ( CURRENT_t ∗ handle, const CURRENT_config_t∗const config, _lq focSampleTime, _lq lq16fltIdqErrorCutoffFrq, _lqvoltageGain )

Current control loop configuration.

Parameters

handle - pointer to the CURRENT block

config - pointer to CURRENT_config block

196Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 223: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

focSampleTime - time between successive current loop calls

lq16fltIdq←↩ErrorCutoffFrq

- current filter cutoff freq (Hz)

voltageGain - gain to scale Vdc

Returns

none

20.4.2 CURRENT_init ( void ∗ pMem, size_t size )

Current control loop initialization.

Parameters

pMem - pointer to memory where the CURRENT block is stored

size - size of memory where the CURRENT block is stored

Returns

handle - interface to access the CURRENT block

20.4.3 void CURRENT_resetController ( CURRENT_t ∗ handle )

Resets internal states for CURRENT block.

Parameters

handle - pointer to the CURRENT block

Returns

none

20.4.4 CURRENT_resetFilters ( CURRENT_t ∗ handle )

Resets internal states for filters.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

197

Page 224: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

handle - pointer to the CURRENT block

Returns

none

20.4.5 FAST void CURRENT_run ( CURRENT_t ∗ handle, _lq Vdc, _lq invVdc,TRF_rVector16_t ∗ pRefCurrent, TRF_rVector16_t ∗ pFbkCurrent )

20.4.6 void CURRENT_setIntegrator ( CURRENT_t ∗ handle, _lq Vdc, constTRF_rVector32_t ∗const pRefVoltage )

198Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 225: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 21Inverse Park Transform21.1 OverviewConverts two phase voltage reference signals from the rotating frame (D-Q frame) to the stationary frame(Alpha-Beta frame).

Functional description

Field oriented control of motors requires transformation from three vectors to two perpendicular vectorsin a stationary reference frame to two perpendicular vectors in a rotating reference frame, then the reverseprocess. The Inverse Park Transform block effects the transition between two vector rotating referenceframe (D-Q frame) to two vector stationary reference frame (Alpha-Beta frame) for the voltage referencesthat need to be provided to the Space Vector PWM module.

Figure 21.1.1: Effect of Inverse Park Transform

NXP SemiconductorsKinetis Motor Suite API Reference Manual

199

Page 226: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Block diagram detail

Figure 21.1.2: Inverse Park Transform

Configuration, inputs, and outputs

No configuration of the Inverse Park Transform block is required.

The inputs are the desired voltages or currents in the rotating frame (D-Q frame) and the angular positionof the rotor as estimated by the Sensorless Estimator block.

The outputs are the same values on the stationary frame (Alpha-Beta frame).

Code security breakdown

The table below describes the partitioning of Inverse Park Transform block code among open source,library, and protected execute-only.

Open Source Library Execute-onlyStructures for output; functions forinitialization and running transfor-mation

Implementation of relevant functi-ons

N/A

Execution

The Inverse Park Transform block is executed in the Fast ISR to ensure real-time adaptation to quicklychanging electrical dynamics.

200Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 227: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

User customization example

While the Inverse Park Transform is required for field oriented control, the user may wish to utilize dif-ferent mathematical method for performing the transform. The underpinnings of this block - the code fortransformations - may be adapted for this purpose.

Data Structures• struct IPARK_output_t

Stationary reference frame (alpha/beta) 32-bit vector type. More...• struct IPARK_t

Output of inverse park function. More...

Functions• IPARK_t ∗ IPARK_init (void ∗pMem, size_t size)

Inverse Park transform initialization.• void IPARK_reset (IPARK_t ∗handle)

Inverse Park transform reset.• FAST void IPARK_run (IPARK_t ∗handle, const TRF_orient32_t ∗const orient, TRF_rVector32_t∗input)

Inverse Park Transformation function.

21.2 Data Structure Documentation

21.2.1 struct IPARK_output_t

Stationary reference frame (alpha/beta) 32-bit vector type.

Magnitude of alpha/beta vectors

Data Fields

_lq magnitude Magnitude of stationary vectors

TRF_s←↩Vector32_t

vector 32 bit stationary vectors

21.2.2 struct IPARK_t

Output of inverse park function.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

201

Page 228: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Data Fields

IPARK_←↩output_t

output

21.3 Function Documentation

21.3.1 IPARK_init ( void ∗ pMem, size_t size )

Inverse Park transform initialization.

Parameters

pMem - pointer to memory where the IPARK block is stored

size - size of memory where the IPARK block is stored

Returns

handle - interface to access the IPARK block

21.3.2 IPARK_reset ( IPARK_t ∗ handle )

Inverse Park transform reset.

Parameters

handle - pointer to the IPARK block

21.3.3 IPARK_run ( IPARK_t ∗ handle, const TRF_orient32_t ∗const orient,TRF_rVector32_t ∗ input )

Inverse Park Transformation function.

Parameters

handle - pointer to the IPARK block

202Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 229: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

orient - sin and cos of motor angle

input - rotational reference frame input

Returns

none

NXP SemiconductorsKinetis Motor Suite API Reference Manual

203

Page 230: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

204Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 231: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 22Space Vector Pulse Width Modulation22.1 OverviewSpace vector PWM block generates modulation values for the three phase inverter from the stator framevoltages.

Functional description

Space vector pulse width modulation, or SVPWM, is a means of sending signals to a three phase inverterto control its switches such that a direct current supply can be transformed into three phase alternatingcurrent. This is a standard implementation of Space Vector Modulation that features the ability to go intoovermodulation region 1. Deadtime insertion is handled by the FlexTimer hardware and not the algorithminside the SVPWM block.

Block diagram detail

Figure 22.1.1: SVPWM

Configuration, inputs, and outputs

The configuration of the SVPWM block primarily consists of defining special characteristics: whetherdead-time compensation is on; whether to enable PWM on only two phases (and thus avoid space vectorentirely); and whether to clamp inverter phases to a specific value.

The primary input to the SVPWM block is the voltage reference vector in the Alpha-Beta frame that comesfrom the Inverse Park Transform block. This reference vector is acted on by the SVPWM block to produce

NXP SemiconductorsKinetis Motor Suite API Reference Manual

205

Page 232: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

relative duty cycles for phases A, B, and C, which will command the switches of the inverter in such away as to persist sinusoidal currents to be applied to the motor.

Additional outputs include status indicators.

Code security breakdown

The table below describes the partitioning of SVPWM block code among open source, library, and pro-tected execute-only.

Open Source Library Execute-onlyStructures and functions definingconfiguration, PWM operation,dead-time, zero vector

PWM implementation based onoperating sector

N/A

Execution

The SVPWM block is executed in the Fast ISR because the proper switching commands for the invertermust be processed as quickly as possible to ensure appropriate driving of current and thus the motor.

User customization example

The user may have a different, preferred strategy of implementing pulse width modulation. This canreplace the SVPWM block.

Modules• Pulse Width Modulation Interface

The Pulse Width Modulation (PWM) Interface describes how the FlexTimer is configured and used.

Data Structures• struct SVPWM_config_t

SVPWM module configuration. More...• struct SVPWM_output_t

SVPWM module output. More...• struct SVPWM_t

SVPWM module nested structure. More...

Macros• #define SVPWM_PRV_SIZE 10

206Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 233: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

Enumerations• enum SVPWM_sector_e {

SVPWM_SECT1 = 1,SVPWM_SECT2 = 2,SVPWM_SECT3 = 3,SVPWM_SECT4 = 4,SVPWM_SECT5 = 5,SVPWM_SECT6 = 6 }

• enum SVPWM_state_e {SVPWM_NORM = 0,SVPWM_OPWM1,SVPWM_OPWM2 }

SVPWM states.

Functions• SVPWM_t ∗ SVPWM_init (void ∗pMem, size_t size)

Initializes SVPWM module.• void SVPWM_config (SVPWM_t ∗handle, const SVPWM_config_t ∗const config, uint32_t pwm←↩

FreqHz, _lq deadTimePerTs, bool isHighSideActiveLow, bool isLowSideActiveLow)• FAST void SVPWM_enable (SVPWM_t ∗handle)

Enables PWM operation.• FAST void SVPWM_disable (SVPWM_t ∗handle)

Disables PWM operation.• FAST void SVPWM_updateFastTick (SVPWM_t ∗handle, TRF_sVector32_t ∗const pStator←↩

Voltage, _lq magnitude)Updates PWM duty cycles - 3 Phase Mode.

• FAST void SVPWM_update2Phase (SVPWM_t ∗handle, uint8_t hallIndex, _lq dutyCycle)• void SVPWM_zeroVector (SVPWM_t ∗handle, bool enableZeroVector)

Outputs zero vector state (0,0,0). Low sides are held ON.

22.2 Data Structure Documentation

22.2.1 struct SVPWM_config_t

SVPWM module configuration.

Data Fields

bool enableClamp←↩Phases

Clamps inverter phases low

22.2.2 struct SVPWM_output_t

SVPWM module output.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

207

Page 234: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Enumeration Type Documentation

Data Fields

_lq drivePwmA Relative duty cycle for phase A

_lq drivePwmB Relative duty cycle for phase B

_lq drivePwmC Relative duty cycle for phase C

bool enable Enable/disable PWM operation

SVPWM_←↩sector_e

sector PWM SVPWM sector

SVPWM_←↩state_e

state PWM state

22.2.3 struct SVPWM_t

SVPWM module nested structure.

Data Fields

SVPWM_←↩config_t

config Configuration structure

SVPWM_←↩output_t

output ouput structure

uint32_t prv[SVPWM←↩_PRV_SIZE]

22.3 Macro Definition Documentation

22.3.1 #define SVPWM_PRV_SIZE 10

22.4 Enumeration Type Documentation

22.4.1 enum SVPWM_sector_e

Enumerator

SVPWM_SECT1 sector 1 (between 0 and 60 degrees)SVPWM_SECT2 sector 2 (between 60 and 120 degrees)SVPWM_SECT3 sector 3 (between 120 and 180 degrees)SVPWM_SECT4 sector 4 (between 180 and 240 degrees)SVPWM_SECT5 sector 5 (between 240 and 300 degrees)SVPWM_SECT6 sector 6 (between 300 and 360 degrees)

208Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 235: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

22.4.2 enum SVPWM_state_e

SVPWM states.

Enumerator

SVPWM_NORM Space Vector PWM (SVPWM)SVPWM_OPWM1 Over-modulation region ISVPWM_OPWM2 Over-modulation region II-III

22.5 Function Documentation22.5.1 void SVPWM_config ( SVPWM_t ∗ handle, const SVPWM_config_t

∗const config, uint32_t pwmFreqHz, _lq deadTimePerTs, boolisHighSideActiveLow, bool isLowSideActiveLow )

22.5.2 SVPWM_disable ( SVPWM_t ∗ handle )

Disables PWM operation.

Parameters

handle - interface to access the SVPWM block

Returns

none

22.5.3 SVPWM_enable ( SVPWM_t ∗ handle )

Enables PWM operation.

Parameters

handle - interface to access the SVPWM block

Returns

none

22.5.4 SVPWM_init ( void ∗ pMem, size_t size )

Initializes SVPWM module.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

209

Page 236: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

pMem - pointer to memory where the SVPWM block is stored

size - size of memory where the SVPWM block is stored

Returns

handle - interface to access the SVPWM block

22.5.5 FAST void SVPWM_update2Phase ( SVPWM_t ∗ handle, uint8_t hallIndex,_lq dutyCycle )

22.5.6 SVPWM_updateFastTick ( SVPWM_t ∗ handle, TRF_sVector32_t ∗constpStatorVoltage, _lq magnitude )

Updates PWM duty cycles - 3 Phase Mode.

Parameters

handle - interface to access the SVPWM block

pStatorVoltage - pointer to the stationary stator voltage vector

magnitude - stator voltage vector magnitude

Returns

none

22.5.7 SVPWM_zeroVector ( SVPWM_t ∗ handle, bool enableZeroVector )

Outputs zero vector state (0,0,0). Low sides are held ON.

Parameters

handle - interface to access the SVPWM block

enableZero←↩Vector

- true / false

Returns

none

210Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 237: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Pulse Width Modulation Interface

22.6 Pulse Width Modulation Interface

22.6.1 Overview

The Pulse Width Modulation (PWM) Interface describes how the FlexTimer is configured and used.

Data Structures

• struct PWMS_duty_tDuty cycles to load into PWM module. More...

Macros

• #define PWM_SYS_MIN_DEADTIME_US (0.25)

Functions

• uint16_t PWMS_init (uint32_t pwmFreqHz, _lq deadTimePerTs, bool isHighSideActiveLow, boolisLowSideActiveLow)

• void PWMS_enable (void)Enables PWM signal buffer.

• void PWMS_disable (void)Disables PWM signal buffer.

• void PWMS_setDuties (const PWMS_duty_t ∗const duties)Sets duties into the PWM module.

22.6.2 Data Structure Documentation

22.6.2.1 struct PWMS_duty_t

Duty cycles to load into PWM module.

Data Fields

uint16_t phaseAhi Duty cycle for Phase A High Side { unit: [PWM ticks] }

uint16_t phaseAlo Duty cycle for Phase A Low Side { unit: [PWM ticks] }

uint16_t phaseBhi Duty cycle for Phase B High Side { unit: [PWM ticks] }

NXP SemiconductorsKinetis Motor Suite API Reference Manual

211

Page 238: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Pulse Width Modulation Interface

uint16_t phaseBlo Duty cycle for Phase B Low Side { unit: [PWM ticks] }

uint16_t phaseChi Duty cycle for Phase C High Side { unit: [PWM ticks] }

uint16_t phaseClo Duty cycle for Phase C Low Side { unit: [PWM ticks] }

22.6.3 Macro Definition Documentation

22.6.3.1 #define PWM_SYS_MIN_DEADTIME_US (0.25)

Referenced by PWMS_init().

22.6.4 Function Documentation

22.6.4.1 void PWMS_disable ( void )

Disables PWM signal buffer.

Returns

none

Parameters

swPeriod - switching period count

Returns

none

22.6.4.2 void PWMS_enable ( void )

Enables PWM signal buffer.

Returns

none

22.6.4.3 uint16_t PWMS_init ( uint32_t pwmFreqHz, _lq deadTimePerTs, boolisHighSideActiveLow, bool isLowSideActiveLow )

References _L32mpyLQL32, _LQ, MAX, and PWM_SYS_MIN_DEADTIME_US.

212Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 239: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Pulse Width Modulation Interface

22.6.4.4 void PWMS_setDuties ( const PWMS_duty_t ∗const duties )

Sets duties into the PWM module.

Parameters

duties - duty cycles to command on the next PWM update

Returns

none

References PWMS_duty_t::phaseAhi, PWMS_duty_t::phaseAlo, PWMS_duty_t::phaseBhi, PWMS_←↩duty_t::phaseBlo, PWMS_duty_t::phaseChi, and PWMS_duty_t::phaseClo.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

213

Page 240: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Pulse Width Modulation Interface

214Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 241: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 23Motion Sequence23.1 OverviewAllows for easy, consistent creation of motion sequences.

Functional description

The Motion Sequence block is the back-end of the Motion Sequence Builder graphical user interface: itis the infrastructure that the code generated by Motion Sequence Builder relies upon to execute a user-specified motion sequence. Since Motion Sequence Builder can create the code that uses this API already,it is not expected that most users will need to understand this API. However there are some run-timeconfiguration features that can prove useful so the complete API is provided for reference.

The building block components of Plans, States, Transitions, Conditions, Variables, and Actions are defi-ned, as are the different options available for each. For instance, each of the comparison relationships thatcan be used to determine whether a Condition has been met are enumerated.

Additionally, the common configuration options for each building block are spelled out - the ability to adda component, gets & sets, etc.

The Motion Sequence block is effectively a simplified wrapper block for the core algorithms of SpinTA←↩C™ Velocity Plan or SpinTAC™ Position Plan submodule.

Block diagram detail

Figure 23.1.1: Motion Sequence

NXP SemiconductorsKinetis Motor Suite API Reference Manual

215

Page 242: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Configuration, inputs, and outputs

Configuration of the Motion Sequence block is effectively represented by State Machine Builder. It invol-ves defining the

• different states of motion,• transitions between speeds,• conditions upon which these transitions occur,• variables that underpin conditions, and• actions to be taken• that comprise the desired motion of a motor-driven application.

Inputs are encapsulated by configuration, and the outputs are a series of trajectory commands sent to beacted upon by the Trajectory block.

Code security breakdown

The table below describes the partitioning of Motion Sequence block code among open source, library,and protected execute-only.

Open Source Library Execute-onlyEnumeration of possible statuses,conditions, comparisons, actions,etc; set & get functions

Implementation of state machineengine

N/A

Execution

As with other blocks revolving largely around motion control, the Motion Sequence block operates in theSlow ISR, as motion control is not as time-sensitive as current control.

User customization example

The Motion Sequence block is a framework and can be customized to virtually any application where aseries of constant speeds or position steps need to be reached based on different conditions of the system.The companion KMS Lab Guide briefly walks through a simplistic example of a ceiling fan.

Modules• SpinTAC™ Velocity Plan

SpinTAC™ Velocity Plan is the code infrastructure for Motion Sequence Builder for velocity control ap-plications.

• SpinTAC™ Position Plan

216Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 243: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

SpinTAC™ Position Plan is the code infrastructure for Motion Sequence Builder for position controlapplications.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

217

Page 244: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

23.2 SpinTAC™ Velocity Plan

23.2.1 Overview

SpinTAC™ Velocity Plan is the code infrastructure for Motion Sequence Builder for velocity controlapplications.

Data Structures

• struct ST_PlanError_tDefines the ST_PlanError_t data. More...

• struct ST_VelPlan_t

Macros

• #define ST_VEL_PLAN_ACT_DWORDS (5)• #define ST_VEL_PLAN_COND_DWORDS (3)• #define ST_VEL_PLAN_VAR_DWORDS (2)• #define ST_VEL_PLAN_TRAN_DWORDS (5)• #define ST_VEL_PLAN_STATE_DWORDS (6)• #define __ST_PLAN_ENUM__• #define __ST_PLAN_ERROR__

Typedefs

• typedef struct _ST_VELPLAN_Handle_ ∗ ST_VELPLAN_Handle

Enumerations

• enum ST_PlanStatus_e {ST_PLAN_IDLE =0,ST_PLAN_INIT,ST_PLAN_BUSY,ST_PLAN_HALT,ST_PLAN_WAIT,ST_PLAN_IDLE =0,ST_PLAN_INIT,ST_PLAN_BUSY,ST_PLAN_HALT,ST_PLAN_WAIT }

• enum ST_PlanCond_e {

218Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 245: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

ST_COND_NC =0,ST_COND_FC,ST_COND_AND,ST_COND_OR,ST_COND_NC =0,ST_COND_FC,ST_COND_AND,ST_COND_OR }

• enum ST_PlanComp_e {ST_COMP_NA =0,ST_COMP_EQ,ST_COMP_NEQ,ST_COMP_GT,ST_COMP_EGT,ST_COMP_LW,ST_COMP_ELW,ST_COMP_In,ST_COMP_EIn,ST_COMP_InE,ST_COMP_EInE,ST_COMP_Out,ST_COMP_EOut,ST_COMP_OutE,ST_COMP_EOutE,ST_COMP_NA =0,ST_COMP_EQ,ST_COMP_NEQ,ST_COMP_GT,ST_COMP_EGT,ST_COMP_LW,ST_COMP_ELW,ST_COMP_In,ST_COMP_EIn,ST_COMP_InE,ST_COMP_EInE,ST_COMP_Out,ST_COMP_EOut,ST_COMP_OutE,ST_COMP_EOutE }

• enum ST_PlanActOptn_e {ST_ACT_EQ =0,ST_ACT_ADD,ST_ACT_EQ =0,ST_ACT_ADD }

• enum ST_PlanActTrgr_e {

NXP SemiconductorsKinetis Motor Suite API Reference Manual

219

Page 246: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

ST_ACT_ENTR =0,ST_ACT_EXIT,ST_ACT_ENTR =0,ST_ACT_EXIT }

• enum ST_PlanFsmState_e {ST_FSM_STATE_STAY =0,ST_FSM_STATE_COND,ST_FSM_STATE_TRAN,ST_FSM_STATE_STAY =0,ST_FSM_STATE_COND,ST_FSM_STATE_TRAN }

• enum ST_PlanVar_e {ST_VAR_INOUT =0,ST_VAR_IN,ST_VAR_OUT,ST_VAR_INOUT =0,ST_VAR_IN,ST_VAR_OUT }

• enum ST_VelPlan_ErrorCode_e {

220Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 247: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

No_ErrorCode = 0,Plan_running = 1,Max_States_exceed = 2,Max_Cond_exceed = 3,Max_Trans_exceed = 4,Max_Act_exceed = 5,Max_Var_exceed = 6,Invalid_Sampletime = 7,Invalid_LoopENB = 11,Invalid_HaltAccLim = 13,Invalid_HaltJrkLim = 14,Invalid_Timer_tick = 15,Invalid_State_index = 16,Invalid_Condition_index = 17,Invalid_Trans_index = 18,Invalid_Action_index = 19,Invalid_Var_index = 20,Invalid_Var_type = 21,Invalid_Value_Comp = 22,Invalid_Operation = 23,Invalid_AndOr = 24,Improper_Var_type = 25,Improper_Val_Comparison = 26,Improper_State_index = 27,Improper_Cond_Idx = 28,Improper_EnterExit = 29,Cannot_delete_Var_Cond = 30,Cannot_delete_Var_Act = 31,PlanCfg_array_Small = 37,Cannot_delete_State_Tran = 38,Cannot_delete_State_Act = 39,Invalid_Var_Compare = 40,Invalid_Var_indexes = 41,Invalid_Cond_Index = 42,Cannot_Delete_Cond_Tran = 43,Cannot_Delete_Cond_Act = 45 }

Enumeration for the Velocity Plan Error Codes.• enum ST_VelPlan_ErrorId_e {

NXP SemiconductorsKinetis Motor Suite API Reference Manual

221

Page 248: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

No_ErrorId = 0,Error_STVELPLAN_addCfgCond = 3000,Error_STVELPLAN_delCfgCond = 3001,Error_STVELPLAN_setCfgCond = 3002,Error_STVELPLAN_getCfgCond = 3003,Error_STVELPLAN_addCfgTran = 3004,Error_STVELPLAN_delCfgTran = 3005,Error_STVELPLAN_setCfgTran = 3006,Error_STVELPLAN_getCfgTran = 3007,Error_STVELPLAN_addCfgAct = 3008,Error_STVELPLAN_delCfgAct = 3009,Error_STVELPLAN_setCfgAct = 3010,Error_STVELPLAN_getCfgAct = 3011,Error_STVELPLAN_addCfgVar = 3012,Error_STVELPLAN_delCfgVar = 3013,Error_STVELPLAN_setCfgVar = 3014,Error_STVELPLAN_getCfgVar = 3015,Error_STVELPLAN_addCfgState = 3016,Error_STVELPLAN_delCfgState = 3017,Error_STVELPLAN_setCfgState = 3018,Error_STVELPLAN_setVar = 3019,Error_STVELPLAN_getVar = 3020,Error_STVELPLAN_setCfg = 3021,Error_STVELPLAN_setCfgHaltState = 3022,Error_STVELPLAN_setCfgArray = 3023,Error_STVELPLAN_addCfgVarCond = 3024,Error_STVELPLAN_delCfgVarCond = 3025,Error_STVELPLAN_setCfgVarCond = 3026,Error_STVELPLAN_getCfgVarCond = 3027,Invalid_STLicense = 4001,Invalid_RomVersion = 4003 }

Enumeration for the Velocity Plan Error Id, indicates the function which caused the error.

Functions

• static _lq24 STVELPLAN_getVelocitySetpoint (ST_VELPLAN_Handle handle)Gets the Velocity Setpoint (VelEnd) for SpinTAC Velocity Plan.

• static _lq24 STVELPLAN_getAccelerationLimit (ST_VELPLAN_Handle handle)Gets the Acceleration Limit (AccLim) for SpinTAC Velocity Plan.

• static _lq20 STVELPLAN_getJerkLimit (ST_VELPLAN_Handle handle)Gets the Jerk Limit (JrkLim) for SpinTAC Velocity Plan.

• static void STVELPLAN_setEnable (ST_VELPLAN_Handle handle, bool enb)Sets the Enable signal (ENB) for SpinTAC Velocity Plan.

• static bool STVELPLAN_getEnable (ST_VELPLAN_Handle handle)Gets the Enable signal (ENB) for SpinTAC Velocity Plan.

222Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 249: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

• static void STVELPLAN_setReset (ST_VELPLAN_Handle handle, bool res)Sets the Reset signal (RES) for SpinTAC Velocity Plan.

• static bool STVELPLAN_getReset (ST_VELPLAN_Handle handle)Gets the Reset signal (RES) for SpinTAC Velocity Plan.

• static ST_PlanStatus_e STVELPLAN_getStatus (ST_VELPLAN_Handle handle)Gets the Status value (STATUS) for SpinTAC Velocity Plan.

• static uint16_t STVELPLAN_getCurrentState (ST_VELPLAN_Handle handle)Gets the Current State (CurState) for SpinTAC Velocity Plan.

• static uint16_t STVELPLAN_getCurrentTransition (ST_VELPLAN_Handle handle)Gets the Current Transition (CurTran) for SpinTAC Velocity Plan.

• static ST_PlanFsmState_e STVELPLAN_getFsmState (ST_VELPLAN_Handle handle)Gets the State Machine State (FsmState) for SpinTAC Velocity Plan.

• static int32_t STVELPLAN_getCurrentTimerValue_tick (ST_VELPLAN_Handle handle)Gets the Current Time Value (Timer_tick) for SpinTAC Velocity Plan.

• static uint16_t STVELPLAN_getCfgError (ST_VELPLAN_Handle handle, uint16_t ∗ERR_idx,uint16_t ∗ERR_code)

Gets the Configuration Error for SpinTAC Velocity Plan.• static uint16_t STVELPLAN_getErrorID (ST_VELPLAN_Handle handle)• void STVELPLAN_getCfgStateNum (ST_VELPLAN_Handle handle, uint16_t ∗StateNum)

Returns the number of configured States in SpinTAC Velocity Plan.• void STVELPLAN_getCfgVarNum (ST_VELPLAN_Handle handle, uint16_t ∗VarNum)

Returns the number of configured Variables in SpinTAC Velocity Plan.• void STVELPLAN_getCfgCondNum (ST_VELPLAN_Handle handle, uint16_t ∗CondNum)

Returns the number of configured Conditions in SpinTAC Velocity Plan.• void STVELPLAN_getCfgTranNum (ST_VELPLAN_Handle handle, uint16_t ∗TranNum)

Returns the number of configured Transitions in SpinTAC Velocity Plan.• void STVELPLAN_getCfgActNum (ST_VELPLAN_Handle handle, uint16_t ∗ActNum)

Returns the number of configured Actions in SpinTAC Velocity Plan.• void STVELPLAN_addCfgCond (ST_VELPLAN_Handle handle, uint16_t VarIdx, ST_Plan←↩

Comp_e Comp, _lq24 Value1, _lq24 Value2)Adds a Condition to the SpinTAC Velocity Plan configuration.

• void STVELPLAN_delCfgCond (ST_VELPLAN_Handle handle, uint16_t CondIdx)Deletes a Condition from the SpinTAC Velocity Plan configuration.

• void STVELPLAN_setCfgCond (ST_VELPLAN_Handle handle, uint16_t CondIdx, uint16_t Var←↩Idx, ST_PlanComp_e Comp, _lq24 Value1, _lq24 Value2)

Modifies a Condition in the SpinTAC Velocity Plan configuration.• void STVELPLAN_getCfgCond (ST_VELPLAN_Handle handle, uint16_t CondIdx, uint16_←↩

t ∗VarIdx, ST_PlanComp_e ∗Comp, _lq24 ∗Value1, _lq24 ∗Value2)Returns a Condition from the SpinTAC Velocity Plan configuration.

• void STVELPLAN_addCfgVarCond (ST_VELPLAN_Handle handle, uint16_t VarIdx1, uint16_tVarIdx2, ST_PlanComp_e Comp)

Adds a Variable Condition to the SpinTAC Velocity Plan configuration.• void STVELPLAN_delCfgVarCond (ST_VELPLAN_Handle handle, uint16_t CondIdx)

Deletes a Variable Condition from the SpinTAC Velocity Plan configuration.• void STVELPLAN_setCfgVarCond (ST_VELPLAN_Handle handle, uint16_t CondIdx, uint16_t

VarIdx1, uint16_t VarIdx2, ST_PlanComp_e Comp)Modifies a Variable Condition to the SpinTAC Velocity Plan configuration.

• void STVELPLAN_getCfgVarCond (ST_VELPLAN_Handle handle, uint16_t CondIdx, uint16_t∗VarIdx1, uint16_t ∗VarIdx2, ST_PlanComp_e ∗Comp)

Returns a Variable Condition from the SpinTAC Velocity Plan configuration.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

223

Page 250: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

• void STVELPLAN_addCfgTran (ST_VELPLAN_Handle handle, uint16_t FromState, uint16_←↩t ToState, ST_PlanCond_e AndOr, uint16_t CondIdx1, uint16_t CondIdx2, _lq24 AccLim, _lq20JrkLim)

Adds a Transition to the SpinTAC Velocity Plan configuration.• void STVELPLAN_delCfgTran (ST_VELPLAN_Handle handle, uint16_t TranIdx)

Deletes a Transition from the SpinTAC Velocity Plan configuration.• void STVELPLAN_setCfgTran (ST_VELPLAN_Handle handle, uint16_t TranIdx, uint16_t From←↩

State, uint16_t ToState, ST_PlanCond_e AndOr, uint16_t CondIdx1, uint16_t CondIdx2, _lq24AccLim, _lq20 JrkLim)

Modifies a Transition in the SpinTAC Velocity Plan configuration.• void STVELPLAN_getCfgTran (ST_VELPLAN_Handle handle, uint16_t TranIdx, uint16_←↩

t ∗FromState, uint16_t ∗ToState, ST_PlanCond_e ∗AndOr, uint16_t ∗CondIdx1, uint16_t ∗Cond←↩Idx2, _lq24 ∗AccLim, _lq20 ∗JrkLim)

Return a Transition from the SpinTAC Velocity Plan configuration.• void STVELPLAN_addCfgAct (ST_VELPLAN_Handle handle, uint16_t State, ST_PlanCond_←↩

e AndOr, uint16_t CondIdx1, uint16_t CondIdx2, uint16_t VarIdx, ST_PlanActOptn_e Opt, _lq24Value, ST_PlanActTrgr_e EnterExit)

Adds an action to the SpinTAC Velocity Plan configuration.• void STVELPLAN_delCfgAct (ST_VELPLAN_Handle handle, uint16_t ActIdx)

Deletes an action from the SpinTAC Velocity Plan configuration.• void STVELPLAN_setCfgAct (ST_VELPLAN_Handle handle, uint16_t ActIdx, uint16_t State,

ST_PlanCond_e AndOr, uint16_t CondIdx1, uint16_t CondIdx2, uint16_t VarIdx, ST_PlanAct←↩Optn_e Opt, _lq24 Value, ST_PlanActTrgr_e EnterExit)

Modifies an action in the SpinTAC Velocity Plan configuration.• void STVELPLAN_getCfgAct (ST_VELPLAN_Handle handle, uint16_t ActIdx, uint16_t ∗State,

ST_PlanCond_e ∗AndOr, uint16_t ∗CondIdx1, uint16_t ∗CondIdx2, uint16_t ∗VarIdx, ST_Plan←↩ActOptn_e ∗Opt, _lq24 ∗Value, ST_PlanActTrgr_e ∗EnterExit)

Returns an action from the SpinTAC Velocity Plan configuration.• void STVELPLAN_addCfgVar (ST_VELPLAN_Handle handle, ST_PlanVar_e Type, _lq24 Value)

Adds a variable to the SpinTAC Velocity Plan configuration.• void STVELPLAN_delCfgVar (ST_VELPLAN_Handle handle, uint16_t VarIdx)

Deletes a Variable from the SpinTAC Velocity Plan configuration.• void STVELPLAN_setCfgVar (ST_VELPLAN_Handle handle, uint16_t VarIdx, ST_PlanVar_←↩

e Type, _lq24 Value)Modifies a variable in the SpinTAC Velocity Plan configuration.

• void STVELPLAN_getCfgVar (ST_VELPLAN_Handle handle, uint16_t VarIdx, ST_PlanVar_←↩e ∗Type, _lq24 ∗Value)

Returns a variable from the SpinTAC Velocity Plan configuration.• void STVELPLAN_setVar (ST_VELPLAN_Handle handle, uint16_t VarIdx, _lq24 Value)

Sets the value of a SpinTAC Velocity Plan variable.• void STVELPLAN_getVar (ST_VELPLAN_Handle handle, uint16_t VarIdx, _lq24 ∗Value)

Gets the value of a SpinTAC Velocity Plan variable.• void STVELPLAN_setUnitProfDone (ST_VELPLAN_Handle handle, bool ProDON)

Sets a flag in SpinTAC Velocity Plan to indicate if the unit profile is complete.• void STVELPLAN_setCfg (ST_VELPLAN_Handle handle, _lq24 T_sec, bool LoopENB)

Configures SpinTAC Velocity Plan.• void STVELPLAN_getCfg (ST_VELPLAN_Handle handle, _lq24 ∗T_sec, bool ∗LoopENB)

Gets the SpinTAC Velocity Plan configuration.• void STVELPLAN_setCfgHaltState (ST_VELPLAN_Handle handle, _lq24 VelEnd, _lq24 Acc←↩

224Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 251: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

Lim, _lq20 JrkLim, int32_t Timer_tick)Configures the SpinTAC Velocity Plan Halt state.

• void STVELPLAN_getCfgHaltState (ST_VELPLAN_Handle handle, _lq24 ∗VelEnd, _lq24∗AccLim, _lq20 ∗JrkLim, int32_t ∗Timer_tick)

Gets the SpinTAC Velocity Plan Halt state configuration.• void STVELPLAN_addCfgState (ST_VELPLAN_Handle handle, _lq24 VelEnd, int32_t Timer_←↩

tick)Adds a State to the SpinTAC Velocity Plan configuration.

• void STVELPLAN_delCfgState (ST_VELPLAN_Handle handle, uint16_t StateIdx)Deletes a state from the SpinTAC Velocity Plan configuration.

• void STVELPLAN_setCfgState (ST_VELPLAN_Handle handle, uint16_t StateIdx, _lq24 VelEnd,int32_t Timer_tick)

Modifies a state in the SpinTAC Velocity Plan configuration.• void STVELPLAN_getCfgState (ST_VELPLAN_Handle handle, uint16_t StateIdx, _lq24 ∗Vel←↩

End, int32_t ∗Timer_tick)Returns a state from the SpinTAC Velocity Plan configuration.

• void STVELPLAN_reset (ST_VELPLAN_Handle handle)Resets the Velocity Plan component.

• ST_VELPLAN_Handle STVELPLAN_init (void ∗pMemory, const size_t numBytes)Initializes the SpinTAC Velocity Plan component.

• void STVELPLAN_run (ST_VELPLAN_Handle handle)• void STVELPLAN_runTick (ST_VELPLAN_Handle handle)

Updates the SpinTAC Velocity Plan Timer.• void STVELPLAN_setCfgArray (ST_VELPLAN_Handle handle, uint32_t ∗cfgArray, const size_t

numBytes, uint16_t MaxActNum, uint16_t MaxCondNum, uint16_t MaxVarNum, uint16_t Max←↩TranNum, uint16_t MaxStateNum)

Prepares SpinTAC Velocity Plan configuration array.• static _lq24 STVELCTL_getOutputMaximum (ST_VELCTL_Handle handle)

Gets the Maximum Output (cfg.OutMax) for SpinTAC Velocity Controller.

23.2.2 Data Structure Documentation

23.2.2.1 struct ST_PlanError_t

Defines the ST_PlanError_t data.

The ST_PlanError_t object contains error debugging information for the Position Plan component

Data Fields

uint16_t ERR_code Function specific condition that caused the error. Function specificcondition that caused the error

NXP SemiconductorsKinetis Motor Suite API Reference Manual

225

Page 252: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

uint16_t ERR_idx Plan component index that caused the error. Plan component indexthat caused the error

23.2.2.2 struct ST_VelPlan_t

Data Fields

_lq24 AccLim Acceleration limit { unit: [(pu rpm)/s], value range: [0.001, 120.0]}

ST_PlanError←↩_t

CfgError Error decoding structure

uint16_t CurState Current state of the state machine

uint16_t CurTran Current transition of the state machine

bool ENB Enable bit { false: disabled; true: enabled }

uint16_t ERR_ID Error ID { 0: no error; others: see error code }

ST_PlanFsm←↩State_e

FsmState State of the state machine

_lq20 JrkLim Jerk Limit { unit: [(pu rpm)/s∧2], value range: [0.0005, 2000.0] }

bool RES Reset bit { false: not reset; true: reset }

uint32_t s0[26]

ST_Plan←↩Status_e

STATUS Plan status { ST_PLAN_IDLE, ST_PLAN_INIT, ST_PLAN_B←↩USY, ST_PLAN_HALT, ST_PLAN_WAIT}

int32_t Timer_tick State Timer { unit: [tick] }

_lq24 VelEnd Velocity setpoint { unit: [pu rpm], value range: [-1.0, 1.0] }

226Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 253: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

23.2.3 Macro Definition Documentation

23.2.3.1 #define __ST_PLAN_ENUM__

23.2.3.2 #define __ST_PLAN_ERROR__

23.2.3.3 #define ST_VEL_PLAN_ACT_DWORDS (5)

23.2.3.4 #define ST_VEL_PLAN_COND_DWORDS (3)

23.2.3.5 #define ST_VEL_PLAN_STATE_DWORDS (6)

23.2.3.6 #define ST_VEL_PLAN_TRAN_DWORDS (5)

23.2.3.7 #define ST_VEL_PLAN_VAR_DWORDS (2)

23.2.4 Typedef Documentation

23.2.4.1 typedef struct _ST_VELPLAN_Handle_∗ ST_VELPLAN_Handle

23.2.5 Enumeration Type Documentation

23.2.5.1 enum ST_PlanActOptn_e

Enumerator

ST_ACT_EQ Action will set the variable equal to a value.ST_ACT_ADD Action will add a value to the variable.ST_ACT_EQ Action will set the variable equal to a valueST_ACT_ADD Action will add a value to the variable

23.2.5.2 enum ST_PlanActTrgr_e

Enumerator

ST_ACT_ENTR Action will be considered when entering the state.ST_ACT_EXIT Action will be considered when exiting the state.ST_ACT_ENTR Action will be considered when entering the stateST_ACT_EXIT Action will be considered when exiting the state

NXP SemiconductorsKinetis Motor Suite API Reference Manual

227

Page 254: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

23.2.5.3 enum ST_PlanComp_e

Enumerator

ST_COMP_NA No comparison.ST_COMP_EQ Compares, VarIdx == Value1 OR VarIdx1 == VarIdx2.ST_COMP_NEQ Compares, VarIdx != Value1 OR VarIdx1 != VarIdx2.ST_COMP_GT Compares, VarIdx > Value1 OR VarIdx1 > VarIdx2.ST_COMP_EGT Compares, VarIdx >= Value1 OR VarIdx1 >= VarIdx2.ST_COMP_LW Compares, VarIdx < Value1 OR VarIdx1 < VarIdx2.ST_COMP_ELW Compares, VarIdx <= Value1 OR VarIdx1 <= VarIdx2.ST_COMP_In Compares, Value1 <= VarIdx <= Value2.ST_COMP_EIn Compares, Value1 < VarIdx <= Value2.ST_COMP_InE Compares, Value1 <= VarIdx < Value2.ST_COMP_EInE Compares, Value1 < VarIdx < Value2.ST_COMP_Out Compares, Value1 >= VarIdx >= Value2.ST_COMP_EOut Compares, Value1 > VarIdx >= Value2.ST_COMP_OutE Compares, Value1 >= VarIdx > Value2.ST_COMP_EOutE Compares, Value1 > VarIdx > Value2.ST_COMP_NA No comparisonST_COMP_EQ Compares, VarIdx == Value1 OR VarIdx1 == VarIdx2ST_COMP_NEQ Compares, VarIdx != Value1 OR VarIdx1 != VarIdx2ST_COMP_GT Compares, VarIdx > Value1 OR VarIdx1 > VarIdx2ST_COMP_EGT Compares, VarIdx >= Value1 OR VarIdx1 >= VarIdx2ST_COMP_LW Compares, VarIdx < Value1 OR VarIdx1 < VarIdx2ST_COMP_ELW Compares, VarIdx <= Value1 OR VarIdx1 <= VarIdx2ST_COMP_In Compares, Value1 <= VarIdx <= Value2ST_COMP_EIn Compares, Value1 < VarIdx <= Value2ST_COMP_InE Compares, Value1 <= VarIdx < Value2ST_COMP_EInE Compares, Value1 < VarIdx < Value2ST_COMP_Out Compares, Value1 >= VarIdx >= Value2ST_COMP_EOut Compares, Value1 > VarIdx >= Value2ST_COMP_OutE Compares, Value1 >= VarIdx > Value2ST_COMP_EOutE Compares, Value1 > VarIdx > Value2

23.2.5.4 enum ST_PlanCond_e

Enumerator

ST_COND_NC Transition/Action with no conditions satisfied.ST_COND_FC Transition/Action with first condition satisfied.ST_COND_AND Transition/Action with both conditions satisfied.ST_COND_OR Transition/Action with either condition satisfied.ST_COND_NC Transition/Action with no conditions satisfiedST_COND_FC Transition/Action with first condition satisfied

228Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 255: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

ST_COND_AND Transition/Action with both conditions satisfiedST_COND_OR Transition/Action with either condition satisfied

23.2.5.5 enum ST_PlanFsmState_e

Enumerator

ST_FSM_STATE_STAY Plan is staying in a state until the timer is up.ST_FSM_STATE_COND Plan is waiting for a transition condition to be true.ST_FSM_STATE_TRAN Plan is in transition with a motion profile.ST_FSM_STATE_STAY Plan is staying in a state until the timer is upST_FSM_STATE_COND Plan is waiting for a transition condition to be trueST_FSM_STATE_TRAN Plan is in transition with a motion profile

23.2.5.6 enum ST_PlanStatus_e

Enumerator

ST_PLAN_IDLE idle state, holding positionST_PLAN_INIT init state, initialize internal statesST_PLAN_BUSY busy state, running state machineST_PLAN_HALT halt state, return to the position reference in idle stateST_PLAN_WAIT wait state, holding the position reference in idle stateST_PLAN_IDLE idle state, holding velocityST_PLAN_INIT init state, initialize internal statesST_PLAN_BUSY busy state, running state machineST_PLAN_HALT halt state, return to the speed reference in idle stateST_PLAN_WAIT wait state, holding the speed reference in idle state

23.2.5.7 enum ST_PlanVar_e

Enumerator

ST_VAR_INOUT Variable type input/output.ST_VAR_IN Variable type input.ST_VAR_OUT Variable type output.ST_VAR_INOUT Variable type input/outputST_VAR_IN Variable type inputST_VAR_OUT Variable type output

NXP SemiconductorsKinetis Motor Suite API Reference Manual

229

Page 256: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

23.2.5.8 enum ST_VelPlan_ErrorCode_e

Enumeration for the Velocity Plan Error Codes.

Enumerator

No_ErrorCode No error codePlan_running Cannot change config while Plan is runningMax_States_exceed Maximum number of States exceededMax_Cond_exceed Maximum number of Conditions exceededMax_Trans_exceed Maximum number of Transitions exceededMax_Act_exceed Maximum number of Actions exceededMax_Var_exceed Maximum number of Variables exceededInvalid_Sampletime Sample Time is out of rangeInvalid_LoopENB Loop Enable is out of rangeInvalid_HaltAccLim Acceleration Limit is out of rangeInvalid_HaltJrkLim Jerk Limit is out of rangeInvalid_Timer_tick State Timer is out of rangeInvalid_State_index State Index is greater than Maximum number of StatesInvalid_Condition_index Condition Index is greater than Maximum number of ConditionsInvalid_Trans_index Transition Index is greater than Maximum number of TransitionsInvalid_Action_index Action Index is greater than Maximum number of ActionsInvalid_Var_index Variable Index is greater than Maximum number of VariablesInvalid_Var_type Variable Type is out of rangeInvalid_Value_Comp Value Comparison is out of rangeInvalid_Operation Action Operation is out of rangeInvalid_AndOr And/Or Selection is out of rangeImproper_Var_type Indicated Variable cannot be used for this operationImproper_Val_Comparison With a multiple value comparison, Value 1 must be < Value 2Improper_State_index Maximum number of States exceeded OR From State cannot be equal to To

StateImproper_Cond_Idx Maximum number of Conditions exceeded OR Condition 1 cannot be equal to

Condition 2Improper_EnterExit Enter/Exit Selection is out of rangeCannot_delete_Var_Cond Variable is used by a ConditionCannot_delete_Var_Act Variable is used by an ActionPlanCfg_array_Small Plan Configuration Array is not large enoughCannot_delete_State_Tran State is used by a TransitionCannot_delete_State_Act State is used by an ActionInvalid_Var_Compare Cannot select range comparisonInvalid_Var_indexes Variable 1 cannot be equal to Variable 2Invalid_Cond_Index Wrong type of Condition specifiedCannot_Delete_Cond_Tran Condition is used by a TransitionCannot_Delete_Cond_Act Condition is used by an Action

230Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 257: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

23.2.5.9 enum ST_VelPlan_ErrorId_e

Enumeration for the Velocity Plan Error Id, indicates the function which caused the error.

Enumerator

No_ErrorId No error idError_STVELPLAN_addCfgCondError_STVELPLAN_delCfgCondError_STVELPLAN_setCfgCondError_STVELPLAN_getCfgCondError_STVELPLAN_addCfgTranError_STVELPLAN_delCfgTranError_STVELPLAN_setCfgTranError_STVELPLAN_getCfgTranError_STVELPLAN_addCfgActError_STVELPLAN_delCfgActError_STVELPLAN_setCfgActError_STVELPLAN_getCfgActError_STVELPLAN_addCfgVarError_STVELPLAN_delCfgVarError_STVELPLAN_setCfgVarError_STVELPLAN_getCfgVarError_STVELPLAN_addCfgStateError_STVELPLAN_delCfgStateError_STVELPLAN_setCfgStateError_STVELPLAN_setVarError_STVELPLAN_getVarError_STVELPLAN_setCfgError_STVELPLAN_setCfgHaltStateError_STVELPLAN_setCfgArrayError_STVELPLAN_addCfgVarCondError_STVELPLAN_delCfgVarCondError_STVELPLAN_setCfgVarCondError_STVELPLAN_getCfgVarCondInvalid_STLicenseInvalid_RomVersion

23.2.6 Function Documentation

23.2.6.1 STVELCTL_getOutputMaximum ( ST_VELCTL_Handle handle ) [inline],[static]

Gets the Maximum Output (cfg.OutMax) for SpinTAC Velocity Controller.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

231

Page 258: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

Runs SpinTAC Velocity Plan calculation.

Gets the Error ID for SpinTAC Velocity Plan.

Parameters

handle - The handle for the SpinTAC Velocity Controller Object

Returns

_lq24 - OutMax Control signal upper limit { unit: [pu amps], value range: [-1.0, 1.0] }

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

Returns

uint16_t - ERR_ID Error ID { 0: no error; others: see error code }

Parameters

handle - The handle for the Velocity Plan structure

Returns

none

References ST_VelCtl_t::cfg, and ST_VelCtlCfg_t::OutMax.

23.2.6.2 STVELPLAN_addCfgAct ( ST_VELPLAN_Handle handle, uint16_t State,ST_PlanCond_e AndOr, uint16_t CondIdx1, uint16_t CondIdx2, uint16_t VarIdx,ST_PlanActOptn_e Opt, _lq24 Value, ST_PlanActTrgr_e EnterExit )

Adds an action to the SpinTAC Velocity Plan configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

232Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 259: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

State - Index of the State the Action happens in

AndOr - Condition option for the Action

CondIdx1 - Index of the first Condition to consider for the Action

CondIdx2 - Index of the second Condition to consider for the Action

VarIdx - Index of the Variable to be acted upon

Opt - Type of Action to perform on the Variable

Value - Value to use in the Action

EnterExit - State event that will trigger the Action

Returns

none

23.2.6.3 STVELPLAN_addCfgCond ( ST_VELPLAN_Handle handle, uint16_t VarIdx,ST_PlanComp_e Comp, _lq24 Value1, _lq24 Value2 )

Adds a Condition to the SpinTAC Velocity Plan configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

VarIdx - Index of the Plan Variable that will be compared

Comp - Type of comparison that will be done

Value1 - First value to use in the comparison

Value2 - Second value to use in the comparison

Returns

none

23.2.6.4 STVELPLAN_addCfgState ( ST_VELPLAN_Handle handle, _lq24 VelEnd,int32_t Timer_tick )

Adds a State to the SpinTAC Velocity Plan configuration.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

233

Page 260: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

VelEnd - Velocity setpoint for State { unit: [pu rpm], value range: [-1.0, 1.0] }

Timer_tick - Minimum time to stay in State { unit: [tick] }

Returns

none

23.2.6.5 STVELPLAN_addCfgTran ( ST_VELPLAN_Handle handle, uint16_t FromState,uint16_t ToState, ST_PlanCond_e AndOr, uint16_t CondIdx1, uint16_tCondIdx2, _lq24 AccLim, _lq20 JrkLim )

Adds a Transition to the SpinTAC Velocity Plan configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

FromState - Index of the from State

ToState - Index of the to State

AndOr - Condition option for the Transition

CondIdx1 - Index of the first Condition to consider for the Transition

CondIdx2 - Index of the second Condition to consider for the Transition

AccLim - Acceleration limit for the Transition { unit: [(pu rpm)/s], value range: [0.001, 120.0]}

JrkLim - Jerk limit for the Transition { unit: [(pu rpm)/s∧2], value range: [0.0005, 2000.0] }

Returns

none

23.2.6.6 STVELPLAN_addCfgVar ( ST_VELPLAN_Handle handle, ST_PlanVar_e Type,_lq24 Value )

Adds a variable to the SpinTAC Velocity Plan configuration.

234Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 261: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

Type - Type of Variable

Value - Initial value of the Variable

Returns

none

23.2.6.7 STVELPLAN_addCfgVarCond ( ST_VELPLAN_Handle handle, uint16_t VarIdx1,uint16_t VarIdx2, ST_PlanComp_e Comp )

Adds a Variable Condition to the SpinTAC Velocity Plan configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

VarIdx1 - Index of the first Plan Variable that will be compared

VarIdx2 - Index of the second Plan Variable that will be compared

Comp - Type of comparison that will be done

Returns

none

23.2.6.8 STVELPLAN_delCfgAct ( ST_VELPLAN_Handle handle, uint16_t ActIdx )

Deletes an action from the SpinTAC Velocity Plan configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

ActIdx - Index of the Action to delete

Returns

none

23.2.6.9 STVELPLAN_delCfgCond ( ST_VELPLAN_Handle handle, uint16_t CondIdx )

Deletes a Condition from the SpinTAC Velocity Plan configuration.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

235

Page 262: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

CondIdx - Index of the Plan Condition to delete

Returns

none

23.2.6.10 STVELPLAN_delCfgState ( ST_VELPLAN_Handle handle, uint16_t StateIdx )

Deletes a state from the SpinTAC Velocity Plan configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

StateIdx - Index of the State to delete

Returns

none

23.2.6.11 STVELPLAN_delCfgTran ( ST_VELPLAN_Handle handle, uint16_t TranIdx )

Deletes a Transition from the SpinTAC Velocity Plan configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

TranIdx - Index of the Transition to delete

Returns

none

23.2.6.12 STVELPLAN_delCfgVar ( ST_VELPLAN_Handle handle, uint16_t VarIdx )

Deletes a Variable from the SpinTAC Velocity Plan configuration.

236Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 263: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

VarIdx - Index of the Variable to delete

Returns

none

23.2.6.13 STVELPLAN_delCfgVarCond ( ST_VELPLAN_Handle handle, uint16_tCondIdx )

Deletes a Variable Condition from the SpinTAC Velocity Plan configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

CondIdx - Index of the Plan Condition to delete

Returns

none

23.2.6.14 STVELPLAN_getAccelerationLimit ( ST_VELPLAN_Handle handle )[inline], [static]

Gets the Acceleration Limit (AccLim) for SpinTAC Velocity Plan.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

Returns

_lq24 - AccLim Acceleration limit { unit: [(pu rpm)/s], value range: [0.001, 120.0] }

References ST_VelPlan_t::AccLim.

Referenced by USER_runPlanState().

23.2.6.15 STVELPLAN_getCfg ( ST_VELPLAN_Handle handle, _lq24 ∗ T_sec, bool ∗LoopENB )

Gets the SpinTAC Velocity Plan configuration.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

237

Page 264: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

Parameters

handle - handle The handle for the SpinTAC Velocity Plan Object

∗T - Sample Time { unit: [sec], value range: (0, 0.01] }

∗LoopENB - Sets if SpinTAC Velocity Plan should continuously run after it reaches the end {false: Do not continuously run Plan; true: Continuously run Plan }

Returns

none

23.2.6.16 STVELPLAN_getCfgAct ( ST_VELPLAN_Handle handle, uint16_t ActIdx,uint16_t ∗ State, ST_PlanCond_e ∗ AndOr, uint16_t ∗ CondIdx1, uint16_t∗ CondIdx2, uint16_t ∗ VarIdx, ST_PlanActOptn_e ∗ Opt, _lq24 ∗ Value,ST_PlanActTrgr_e ∗ EnterExit )

Returns an action from the SpinTAC Velocity Plan configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

ActIdx - Index of the Action to modify

∗State - Index of the State the Action happens in

∗AndOr - Condition option for the Action

∗CondIdx1 - Index of the first Condition to consider for the Action

∗CondIdx2 - Index of the second Condition to consider for the Action

∗VarIdx - Index of the Variable to be acted upon

∗Opt - Type of Action to perform on the Variable

∗Value - Value to use in the Action

∗EnterExit - State event that will trigger the Action

Returns

none

23.2.6.17 STVELPLAN_getCfgActNum ( ST_VELPLAN_Handle handle, uint16_t ∗ActNum )

Returns the number of configured Actions in SpinTAC Velocity Plan.

238Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 265: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

∗ActNum - The number of configured Actions in SpinTAC Velocity Plan

Returns

none

23.2.6.18 STVELPLAN_getCfgCond ( ST_VELPLAN_Handle handle, uint16_t CondIdx,uint16_t ∗ VarIdx, ST_PlanComp_e ∗ Comp, _lq24 ∗ Value1, _lq24 ∗ Value2 )

Returns a Condition from the SpinTAC Velocity Plan configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

CondIdx - Index of the Plan Condition to return

∗VarIdx - Index of the Plan Variable that will be compared

∗Comp - Type of comparison that will be done

∗Value1 - First value to use in the comparison

∗Value2 - Second value to use in the comparison

Returns

none

23.2.6.19 STVELPLAN_getCfgCondNum ( ST_VELPLAN_Handle handle, uint16_t ∗CondNum )

Returns the number of configured Conditions in SpinTAC Velocity Plan.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

NXP SemiconductorsKinetis Motor Suite API Reference Manual

239

Page 266: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

∗CondNum - The number of configured Conditions in SpinTAC Velocity Plan

Returns

none

23.2.6.20 STVELPLAN_getCfgError ( ST_VELPLAN_Handle handle, uint16_t ∗ ERR_idx,uint16_t ∗ ERR_code ) [inline], [static]

Gets the Configuration Error for SpinTAC Velocity Plan.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

∗ERR_idx - Component index where error occurred { 0: no index; others: see error code }

∗ERR_code - Specific configuration error { 0: no additional information; others: see error code }

Returns

uint16_t ERR_ID Error ID { 0: no error; others: see error code }

References ST_VelPlan_t::CfgError, ST_PlanError_t::ERR_code, ST_VelPlan_t::ERR_ID, and ST_←↩PlanError_t::ERR_idx.

23.2.6.21 STVELPLAN_getCfgHaltState ( ST_VELPLAN_Handle handle, _lq24 ∗ VelEnd,_lq24 ∗ AccLim, _lq20 ∗ JrkLim, int32_t ∗ Timer_tick )

Gets the SpinTAC Velocity Plan Halt state configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

∗VelEnd - Velocity setpoint during Halt state { unit: [pu rpm], value range: [-1.0, 1.0] }

∗AccLim - Acceleration limit for Halt state { unit: [(pu rpm)/s], value range: [0.001, 120.0] }

∗JrkLim - Jerk limit for Halt state { unit: [(pu rpm)/s∧2], value range: [0.0005, 2000.0] }

240Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 267: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

∗Timer_tick - Minimum amount of time to stay in Halt state { unit: [tick] }

Returns

none

23.2.6.22 STVELPLAN_getCfgState ( ST_VELPLAN_Handle handle, uint16_t StateIdx,_lq24 ∗ VelEnd, int32_t ∗ Timer_tick )

Returns a state from the SpinTAC Velocity Plan configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

StateIdx - Index of the State to modify

∗VelEnd - Velocity setpoint for State { unit: [pu rpm], value range: [-1.0, 1.0] }

∗Timer_tick - Minimum time to stay in State { unit: [tick] }

Returns

none

23.2.6.23 STVELPLAN_getCfgStateNum ( ST_VELPLAN_Handle handle, uint16_t ∗StateNum )

Returns the number of configured States in SpinTAC Velocity Plan.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

∗StateNum - The number of configured States in SpinTAC Velocity Plan

Returns

none

23.2.6.24 STVELPLAN_getCfgTran ( ST_VELPLAN_Handle handle, uint16_t TranIdx,uint16_t ∗ FromState, uint16_t ∗ ToState, ST_PlanCond_e ∗ AndOr, uint16_t ∗CondIdx1, uint16_t ∗ CondIdx2, _lq24 ∗ AccLim, _lq20 ∗ JrkLim )

Return a Transition from the SpinTAC Velocity Plan configuration.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

241

Page 268: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

TranIdx - Index of the Transition to modify

∗FromState - Index of the from State

∗ToState - Index of the to State

∗AndOr - Condition option for the Transition

∗CondIdx1 - Index of the first Condition to consider for the Transition

∗CondIdx2 - Index of the second Condition to consider for the Transition

∗AccLim - Acceleration limit for the Transition { unit: [(pu rpm)/s], value range: [0.001, 120.0]}

∗JrkLim - Jerk limit for the Transition { unit: [(pu rpm)/s∧2], value range: [0.0005, 2000.0] }

Returns

none

23.2.6.25 STVELPLAN_getCfgTranNum ( ST_VELPLAN_Handle handle, uint16_t ∗TranNum )

Returns the number of configured Transitions in SpinTAC Velocity Plan.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

∗TranNum - The number of configured Transitions in SpinTAC Velocity Plan

Returns

none

23.2.6.26 STVELPLAN_getCfgVar ( ST_VELPLAN_Handle handle, uint16_t VarIdx,ST_PlanVar_e ∗ Type, _lq24 ∗ Value )

Returns a variable from the SpinTAC Velocity Plan configuration.

242Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 269: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

VarIdx - Index of the Variable to return

∗Type - Type of Variable

∗Value - Initial value of the Variable

Returns

none

23.2.6.27 STVELPLAN_getCfgVarCond ( ST_VELPLAN_Handle handle, uint16_tCondIdx, uint16_t ∗ VarIdx1, uint16_t ∗ VarIdx2, ST_PlanComp_e ∗ Comp )

Returns a Variable Condition from the SpinTAC Velocity Plan configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

CondIdx - Index of the Plan Condition to return

∗VarIdx1 - Index of the first Plan Variable that will be compared

∗VarIdx2 - Index of the second Plan Variable that will be compared

∗Comp - Type of comparison that will be done

Returns

none

23.2.6.28 STVELPLAN_getCfgVarNum ( ST_VELPLAN_Handle handle, uint16_t ∗VarNum )

Returns the number of configured Variables in SpinTAC Velocity Plan.

Parameters

NXP SemiconductorsKinetis Motor Suite API Reference Manual

243

Page 270: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

handle - The handle for the SpinTAC Velocity Plan Object

∗VarNum - The number of configured Variables in SpinTAC Velocity Plan

Returns

none

23.2.6.29 STVELPLAN_getCurrentState ( ST_VELPLAN_Handle handle ) [inline],[static]

Gets the Current State (CurState) for SpinTAC Velocity Plan.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

Returns

uint16_t - CurState Current state of the state machine

References ST_VelPlan_t::CurState.

23.2.6.30 STVELPLAN_getCurrentTimerValue_tick ( ST_VELPLAN_Handle handle )[inline], [static]

Gets the Current Time Value (Timer_tick) for SpinTAC Velocity Plan.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

Returns

int32_t - Timer_tick State Timer { unit: [tick] }

References ST_VelPlan_t::Timer_tick.

23.2.6.31 STVELPLAN_getCurrentTransition ( ST_VELPLAN_Handle handle )[inline], [static]

Gets the Current Transition (CurTran) for SpinTAC Velocity Plan.

244Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 271: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

Returns

uint16_t - CurTran Current transition of the state machine

References ST_VelPlan_t::CurTran.

23.2.6.32 STVELPLAN_getEnable ( ST_VELPLAN_Handle handle ) [inline],[static]

Gets the Enable signal (ENB) for SpinTAC Velocity Plan.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

Returns

bool - EN B Enable bit { false: disable; true: enable }

References ST_VelPlan_t::ENB.

23.2.6.33 static uint16_t STVELPLAN_getErrorID ( ST_VELPLAN_Handle handle )[inline], [static]

References ST_VelPlan_t::ERR_ID.

23.2.6.34 STVELPLAN_getFsmState ( ST_VELPLAN_Handle handle ) [inline],[static]

Gets the State Machine State (FsmState) for SpinTAC Velocity Plan.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

Returns

ST_PlanFsmState_e - FsmState Current operation of the state machine

References ST_VelPlan_t::FsmState.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

245

Page 272: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

23.2.6.35 STVELPLAN_getJerkLimit ( ST_VELPLAN_Handle handle ) [inline],[static]

Gets the Jerk Limit (JrkLim) for SpinTAC Velocity Plan.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

Returns

_lq20 - JrkLim Jerk Limit { unit: [(pu rpm)/s∧2], value range: [0.0005, 2000.0] }

References ST_VelPlan_t::JrkLim.

Referenced by USER_runPlanState().

23.2.6.36 STVELPLAN_getReset ( ST_VELPLAN_Handle handle ) [inline],[static]

Gets the Reset signal (RES) for SpinTAC Velocity Plan.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

Returns

bool - RES Reset bit { false: reset; true: not reset }

References ST_VelPlan_t::RES.

23.2.6.37 STVELPLAN_getStatus ( ST_VELPLAN_Handle handle ) [inline],[static]

Gets the Status value (STATUS) for SpinTAC Velocity Plan.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

Returns

ST_PlanStatus_e - STATUS Status { ST_VEL_ID_IDLE, ST_VEL_ID_INIT, ST_VEL_ID_BUSY}

References ST_VelPlan_t::STATUS.

Referenced by USER_runPlanState().

246Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 273: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

23.2.6.38 STVELPLAN_getVar ( ST_VELPLAN_Handle handle, uint16_t VarIdx, _lq24 ∗Value )

Gets the value of a SpinTAC Velocity Plan variable.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

VarIdx - Index of the Variable to get

∗Value - Value to get from the Variable

Returns

none

23.2.6.39 STVELPLAN_getVelocitySetpoint ( ST_VELPLAN_Handle handle )[inline], [static]

Gets the Velocity Setpoint (VelEnd) for SpinTAC Velocity Plan.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

Returns

_lq24 - VelEnd Velocity setpoint { unit: [pu rpm], value range: [-1.0, 1.0] }

References ST_VelPlan_t::VelEnd.

Referenced by USER_runPlanState().

23.2.6.40 STVELPLAN_init ( void ∗ pMemory, const size_t numBytes )

Initializes the SpinTAC Velocity Plan component.

Parameters

∗pMemory - Pointer to the memory for ST_VelPlan_t

NXP SemiconductorsKinetis Motor Suite API Reference Manual

247

Page 274: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

numBytes - The number of bytes in the ST_VelPlan_t

Returns

ST_VELPLAN_Handle - handle The handle for the SpinTAC Velocity Plan Object

23.2.6.41 STVELPLAN_reset ( ST_VELPLAN_Handle handle )

Resets the Velocity Plan component.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

Returns

none

23.2.6.42 void STVELPLAN_run ( ST_VELPLAN_Handle handle )

Referenced by USER_OnExit(), and USER_runPlanState().

23.2.6.43 STVELPLAN_runTick ( ST_VELPLAN_Handle handle )

Updates the SpinTAC Velocity Plan Timer.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

Returns

none

Referenced by USER_runPlanState().

23.2.6.44 STVELPLAN_setCfg ( ST_VELPLAN_Handle handle, _lq24 T_sec, boolLoopENB )

Configures SpinTAC Velocity Plan.

248Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 275: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

T - Sample Time { unit: [sec], value range: (0, 0.01] }

LoopENB - Sets if SpinTAC Velocity Plan should continuously run after it reaches the end {false: Do not continuously run Plan; true: Continuously run Plan }

Returns

none

23.2.6.45 void STVELPLAN_setCfgAct ( ST_VELPLAN_Handle handle, uint16_t ActIdx,uint16_t State, ST_PlanCond_e AndOr, uint16_t CondIdx1, uint16_t CondIdx2,uint16_t VarIdx, ST_PlanActOptn_e Opt, _lq24 Value, ST_PlanActTrgr_eEnterExit )

Modifies an action in the SpinTAC Velocity Plan configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

ActIdx - Index of the Action to modify

State - Index of the State the Action happens in

AndOr - Condition option for the Action

CondIdx1 - Index of the first Condition to consider for the Action

CondIdx2 - Index of the second Condition to consider for the Action

VarIdx - Index of the Variable to be acted upon

Opt - Type of Action to perform on the Variable

Value - Value to use in the Action

EnterExit - State event that will trigger the Action

Returns

none

23.2.6.46 STVELPLAN_setCfgArray ( ST_VELPLAN_Handle handle, uint32_t ∗ cfgArray,const size_t numBytes, uint16_t MaxActNum, uint16_t MaxCondNum, uint16_tMaxVarNum, uint16_t MaxTranNum, uint16_t MaxStateNum )

Prepares SpinTAC Velocity Plan configuration array.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

249

Page 276: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

∗cfgArray - Pointer to the SpinTAC Velocity Plan configuration array

numBytes - The number of bytes in the SpinTAC Velocity Plan configuration array

MaxActNum - Number of Actions

MaxCondNum - Number of Conditions

MaxVarNum - Number of Variables

MaxTranNum - Number of Transitions

MaxStateNum - Number of States

Returns

none

23.2.6.47 STVELPLAN_setCfgCond ( ST_VELPLAN_Handle handle, uint16_t CondIdx,uint16_t VarIdx, ST_PlanComp_e Comp, _lq24 Value1, _lq24 Value2 )

Modifies a Condition in the SpinTAC Velocity Plan configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

CondIdx - Index of the Plan Condition to modify

VarIdx - Index of the Plan Variable that will be compared

Comp - Type of comparison that will be done

Value1 - First value to use in the comparison

Value2 - Second value to use in the comparison

Returns

23.2.6.48 STVELPLAN_setCfgHaltState ( ST_VELPLAN_Handle handle, _lq24 VelEnd,_lq24 AccLim, _lq20 JrkLim, int32_t Timer_tick )

Configures the SpinTAC Velocity Plan Halt state.

250Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 277: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

VelEnd - Velocity setpoint during Halt state { unit: [pu rpm], value range: [-1.0, 1.0] }

AccLim - Acceleration limit for Halt state { unit: [(pu rpm)/s], value range: [0.001, 120.0] }

JrkLim - Jerk limit for Halt state { unit: [(pu rpm)/s∧2], value range: [0.0005, 2000.0] }

Timer_tick - Minimum amount of time to stay in Halt state { unit: [tick] }

Returns

none

23.2.6.49 STVELPLAN_setCfgState ( ST_VELPLAN_Handle handle, uint16_t StateIdx,_lq24 VelEnd, int32_t Timer_tick )

Modifies a state in the SpinTAC Velocity Plan configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

StateIdx - Index of the State to modify

VelEnd - Velocity setpoint for State { unit: [pu rpm], value range: [-1.0, 1.0] }

Timer_tick - Minimum time to stay in State { unit: [tick] }

Returns

none

23.2.6.50 STVELPLAN_setCfgTran ( ST_VELPLAN_Handle handle, uint16_t TranIdx,uint16_t FromState, uint16_t ToState, ST_PlanCond_e AndOr, uint16_tCondIdx1, uint16_t CondIdx2, _lq24 AccLim, _lq20 JrkLim )

Modifies a Transition in the SpinTAC Velocity Plan configuration.

Parameters

NXP SemiconductorsKinetis Motor Suite API Reference Manual

251

Page 278: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

handle - The handle for the SpinTAC Velocity Plan Object

TranIdx - Index of the Transition to modify

FromState - Index of the from State

ToState - Index of the to State

AndOr - Condition option for the Transition

CondIdx1 - Index of the first Condition to consider for the Transition

CondIdx2 - Index of the second Condition to consider for the Transition

AccLim - Acceleration limit for the Transition { unit: [(pu rpm)/s], value range: [0.001, 120.0]}

JrkLim - Jerk limit for the Transition { unit: [(pu rpm)/s∧2], value range: [0.0005, 2000.0] }

Returns

none

23.2.6.51 STVELPLAN_setCfgVar ( ST_VELPLAN_Handle handle, uint16_t VarIdx,ST_PlanVar_e Type, _lq24 Value )

Modifies a variable in the SpinTAC Velocity Plan configuration.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

VarIdx - Index of the Variable to modify

Type - Type of Variable

Value - Initial value of the Variable

Returns

none

23.2.6.52 STVELPLAN_setCfgVarCond ( ST_VELPLAN_Handle handle, uint16_tCondIdx, uint16_t VarIdx1, uint16_t VarIdx2, ST_PlanComp_e Comp )

Modifies a Variable Condition to the SpinTAC Velocity Plan configuration.

252Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 279: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

CondIdx - Index of the Plan Condition to modify

VarIdx1 - Index of the first Plan Variable that will be compared

VarIdx2 - Index of the second Plan Variable that will be compared

Comp - Type of comparison that will be done

Returns

none

23.2.6.53 STVELPLAN_setEnable ( ST_VELPLAN_Handle handle, bool enb )[inline], [static]

Sets the Enable signal (ENB) for SpinTAC Velocity Plan.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

enb - Enable bit { false: disable; true: enable }

Returns

none

References ST_VelPlan_t::ENB.

Referenced by USER_onEntryPlan().

23.2.6.54 STVELPLAN_setReset ( ST_VELPLAN_Handle handle, bool res )[inline], [static]

Sets the Reset signal (RES) for SpinTAC Velocity Plan.

Parameters

NXP SemiconductorsKinetis Motor Suite API Reference Manual

253

Page 280: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Velocity Plan

handle - The handle for the SpinTAC Velocity Plan Object

res - Reset bit { false: reset; true: not reset }

Returns

none

References ST_VelPlan_t::RES.

Referenced by USER_onEntryPlan().

23.2.6.55 STVELPLAN_setUnitProfDone ( ST_VELPLAN_Handle handle, bool ProDON )

Sets a flag in SpinTAC Velocity Plan to indicate if the unit profile is complete.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

ProDON - Indicates if the unit profile is completed

Returns

none

Referenced by USER_runPlanState().

23.2.6.56 STVELPLAN_setVar ( ST_VELPLAN_Handle handle, uint16_t VarIdx, _lq24Value )

Sets the value of a SpinTAC Velocity Plan variable.

Parameters

handle - The handle for the SpinTAC Velocity Plan Object

VarIdx - Index of the Variable to set

Value - Value to set to the Variable

Returns

none

254Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 281: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

23.3 SpinTAC™ Position Plan

23.3.1 Overview

SpinTAC™ Position Plan is the code infrastructure for Motion Sequence Builder for position controlapplications.

Data Structures

• struct ST_PlanError_tDefines the ST_PlanError_t data. More...

• struct ST_PosPlan_tDefines the ST_PosPlan_t data. More...

Macros

• #define ST_POS_PLAN_ACT_DWORDS (5)Defines the amount of memory that needs to be allocated for each component.

• #define ST_POS_PLAN_COND_DWORDS (3)Each configured Condition takes 3 double words of memory.

• #define ST_POS_PLAN_VAR_DWORDS (2)Each configured Variable takes 2 double words of memory.

• #define ST_POS_PLAN_TRAN_DWORDS (7)Each configured Transition takes 7 double words of memory.

• #define ST_POS_PLAN_STATE_DWORDS (7)Each configured State takes 7 double words of memory.

• #define __ST_PLAN_ENUM__• #define __ST_PLAN_ERROR__

Typedefs

• typedef ST_PosPlan_t ∗ ST_POSPLAN_Handle

NXP SemiconductorsKinetis Motor Suite API Reference Manual

255

Page 282: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

Enumerations

• enum ST_PlanStatus_e {ST_PLAN_IDLE =0,ST_PLAN_INIT,ST_PLAN_BUSY,ST_PLAN_HALT,ST_PLAN_WAIT,ST_PLAN_IDLE =0,ST_PLAN_INIT,ST_PLAN_BUSY,ST_PLAN_HALT,ST_PLAN_WAIT }

Enumeration for the Plan Status States.• enum ST_PlanCond_e {

ST_COND_NC =0,ST_COND_FC,ST_COND_AND,ST_COND_OR,ST_COND_NC =0,ST_COND_FC,ST_COND_AND,ST_COND_OR }

Enumeration for the Plan Condition options.• enum ST_PlanComp_e {

256Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 283: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

ST_COMP_NA =0,ST_COMP_EQ,ST_COMP_NEQ,ST_COMP_GT,ST_COMP_EGT,ST_COMP_LW,ST_COMP_ELW,ST_COMP_In,ST_COMP_EIn,ST_COMP_InE,ST_COMP_EInE,ST_COMP_Out,ST_COMP_EOut,ST_COMP_OutE,ST_COMP_EOutE,ST_COMP_NA =0,ST_COMP_EQ,ST_COMP_NEQ,ST_COMP_GT,ST_COMP_EGT,ST_COMP_LW,ST_COMP_ELW,ST_COMP_In,ST_COMP_EIn,ST_COMP_InE,ST_COMP_EInE,ST_COMP_Out,ST_COMP_EOut,ST_COMP_OutE,ST_COMP_EOutE }

Enumeration for the Plan Compare options.• enum ST_PlanActOptn_e {

ST_ACT_EQ =0,ST_ACT_ADD,ST_ACT_EQ =0,ST_ACT_ADD }

Enumeration for the Plan Action Options.• enum ST_PlanActTrgr_e {

ST_ACT_ENTR =0,ST_ACT_EXIT,ST_ACT_ENTR =0,ST_ACT_EXIT }

Enumeration for the Plan Action trigger point types.• enum ST_PlanFsmState_e {

NXP SemiconductorsKinetis Motor Suite API Reference Manual

257

Page 284: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

ST_FSM_STATE_STAY =0,ST_FSM_STATE_COND,ST_FSM_STATE_TRAN,ST_FSM_STATE_STAY =0,ST_FSM_STATE_COND,ST_FSM_STATE_TRAN }

Enumeration for the Plan FSM states.• enum ST_PlanVar_e {

ST_VAR_INOUT =0,ST_VAR_IN,ST_VAR_OUT,ST_VAR_INOUT =0,ST_VAR_IN,ST_VAR_OUT }

Enumeration for the Plan variable types.• enum ST_PosPlan_ErrorCode_e {

258Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 285: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

No_ErrorCode = 0,Plan_running = 1,Max_States_exceed = 2,Max_Cond_exceed = 3,Max_Trans_exceed = 4,Max_Act_exceed = 5,Max_Var_exceed = 6,Invalid_Sampletime = 7,Invalid_LoopENB = 11,Invalid_HaltAccLim = 13,Invalid_HaltJrkLim = 14,Invalid_Timer_tick = 15,Invalid_State_index = 16,Invalid_Condition_index = 17,Invalid_Trans_index = 18,Invalid_Action_index = 19,Invalid_Var_index = 20,Invalid_Var_type = 21,Invalid_Value_Comp = 22,Invalid_Operation = 23,Invalid_AndOr = 24,Improper_Var_type = 25,Improper_Val_Comparison = 26,Improper_State_index = 27,Improper_Cond_Idx = 28,Improper_EnterExit = 29,Cannot_delete_Var_Cond = 30,Cannot_delete_Var_Act = 31,Invalid_HaltVelLim = 32,Invalid_HaltDecLim = 32,Invalid_PosStep = 35,PlanCfg_array_Small = 37,Cannot_delete_State_Tran = 38,Cannot_delete_State_Act = 39,Invalid_Var_Compare = 40,Invalid_Var_indexes = 41,Invalid_Cond_Index = 42,Cannot_Delete_Cond_Tran = 43,Invalid_InitState_Step = 44,Cannot_Delete_Cond_Act = 45 }

Enumeration for the Position Plan Error Codes.• enum ST_PosPlan_ErrorId_e {

NXP SemiconductorsKinetis Motor Suite API Reference Manual

259

Page 286: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

No_ErrorId = 0,Error_STPOSPLAN_addCfgCond = 3000,Error_STPOSPLAN_delCfgCond = 3001,Error_STPOSPLAN_setCfgCond = 3002,Error_STPOSPLAN_getCfgCond = 3003,Error_STPOSPLAN_addCfgTran = 3004,Error_STPOSPLAN_delCfgTran = 3005,Error_STPOSPLAN_setCfgTran = 3006,Error_STPOSPLAN_getCfgTran = 3007,Error_STPOSPLAN_addCfgAct = 3008,Error_STPOSPLAN_delCfgAct = 3009,Error_STPOSPLAN_setCfgAct = 3010,Error_STPOSPLAN_getCfgAct = 3011,Error_STPOSPLAN_addCfgVar = 3012,Error_STPOSPLAN_delCfgVar = 3013,Error_STPOSPLAN_setCfgVar = 3014,Error_STPOSPLAN_getCfgVar = 3015,Error_STPOSPLAN_addCfgState = 3016,Error_STPOSPLAN_delCfgState = 3017,Error_STPOSPLAN_setCfgState = 3018,Error_STPOSPLAN_setVar = 3019,Error_STPOSPLAN_getVar = 3020,Error_STPOSPLAN_setCfg = 3021,Error_STPOSPLAN_setCfgHaltState = 3022,Error_STPOSPLAN_setCfgArray = 3023,Error_STPOSPLAN_addCfgVarCond = 3024,Error_STPOSPLAN_delCfgVarCond = 3025,Error_STPOSPLAN_setCfgVarCond = 3026,Error_STPOSPLAN_getCfgVarCond = 3027,Invalid_STLicense = 4001,Invalid_RomVersion = 4003 }

Enumeration for the Position Plan Error Id, indicates the function which caused the error.

Functions

• static void STPOSPLAN_getPositionStep_mrev (ST_POSPLAN_Handle handle, int32_t ∗pos←↩StepInt_mrev, _lq24 ∗posStepFrac_mrev)

Gets the Position Step (posStepInt_mrev, posStepFrac_mrev) for SpinTAC Position Plan.• static _lq24 STPOSPLAN_getVelocityLimit (ST_POSPLAN_Handle handle)

Gets the Velocity Limit (VelLim) for SpinTAC Position Plan.• static _lq24 STPOSPLAN_getAccelerationLimit (ST_POSPLAN_Handle handle)

Gets the Acceleration Limit (AccLim) for SpinTAC Position Plan.• static _lq24 STPOSPLAN_getDecelerationLimit (ST_POSPLAN_Handle handle)

Gets the Deceleration Limit (DecLim) for SpinTAC Position Plan.• static _lq20 STPOSPLAN_getJerkLimit (ST_POSPLAN_Handle handle)

260Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 287: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

Gets the Jerk Limit (JrkLim) for SpinTAC Position Plan.• static void STPOSPLAN_setEnable (ST_POSPLAN_Handle handle, bool enb)

Sets the Enable signal (ENB) for SpinTAC Position Plan.• static bool STPOSPLAN_getEnable (ST_POSPLAN_Handle handle)

Gets the Enable signal (ENB) for SpinTAC Position Plan.• static void STPOSPLAN_setReset (ST_POSPLAN_Handle handle, bool res)

Sets the Reset signal (RES) for SpinTAC Position Plan.• static bool STPOSPLAN_getReset (ST_POSPLAN_Handle handle)

Gets the Reset signal (RES) for SpinTAC Position Plan.• static ST_PlanStatus_e STPOSPLAN_getStatus (ST_POSPLAN_Handle handle)

Gets the Status value (STATUS) for SpinTAC Position Plan.• static uint16_t STPOSPLAN_getCurrentState (ST_POSPLAN_Handle handle)

Gets the Current State (CurState) for SpinTAC Position Plan.• static uint16_t STPOSPLAN_getCurrentTransition (ST_POSPLAN_Handle handle)

Gets the Current Transition (CurTran) for SpinTAC Position Plan.• static ST_PlanFsmState_e STPOSPLAN_getFsmState (ST_POSPLAN_Handle handle)

Gets the State Machine State (FsmState) for SpinTAC Position Plan.• static int32_t STPOSPLAN_getCurrentTimerValue_tick (ST_POSPLAN_Handle handle)

Gets the Current Time Value (Timer_tick) for SpinTAC Position Plan.• static uint16_t STPOSPLAN_getCfgError (ST_POSPLAN_Handle handle, uint16_t ∗ERR_idx,

uint16_t ∗ERR_code)Gets the Configuration Error for SpinTAC Position Plan.

• static uint16_t STPOSPLAN_getErrorID (ST_POSPLAN_Handle handle)Gets the Error value (ERR_ID) for SpinTAC Position Plan.

• void STPOSPLAN_getCfgStateNum (ST_POSPLAN_Handle handle, uint16_t ∗StateNum)Returns the number of configured States in SpinTAC Position Plan.

• void STPOSPLAN_getCfgVarNum (ST_POSPLAN_Handle handle, uint16_t ∗VarNum)Returns the number of configured Variables in SpinTAC Position Plan.

• void STPOSPLAN_getCfgCondNum (ST_POSPLAN_Handle handle, uint16_t ∗CondNum)Returns the number of configured Conditions in SpinTAC Position Plan.

• void STPOSPLAN_getCfgTranNum (ST_POSPLAN_Handle handle, uint16_t ∗TranNum)Returns the number of configured Transitions in SpinTAC Position Plan.

• void STPOSPLAN_getCfgActNum (ST_POSPLAN_Handle handle, uint16_t ∗ActNum)Returns the number of configured Actions in SpinTAC Position Plan.

• void STPOSPLAN_addCfgCond (ST_POSPLAN_Handle handle, uint16_t VarIdx, ST_Plan←↩Comp_e Comp, _lq24 Value1, _lq24 Value2)

Adds a Condition to the SpinTAC Position Plan configuration.• void STPOSPLAN_delCfgCond (ST_POSPLAN_Handle handle, uint16_t CondIdx)

Deletes a Condition from the SpinTAC Position Plan configuration.• void STPOSPLAN_setCfgCond (ST_POSPLAN_Handle handle, uint16_t CondIdx, uint16_t Var←↩

Idx, ST_PlanComp_e Comp, _lq24 Value1, _lq24 Value2)Modifies a Condition in the SpinTAC Position Plan configuration.

• void STPOSPLAN_getCfgCond (ST_POSPLAN_Handle handle, uint16_t CondIdx, uint16_←↩t ∗VarIdx, ST_PlanComp_e ∗Comp, _lq24 ∗Value1, _lq24 ∗Value2)

Returns a Condition from the SpinTAC Position Plan configuration.• void STPOSPLAN_addCfgVarCond (ST_POSPLAN_Handle handle, uint16_t VarIdx1, uint16_←↩

t VarIdx2, ST_PlanComp_e Comp)Adds a Variable Condition to the SpinTAC Position Plan configuration.

• void STPOSPLAN_delCfgVarCond (ST_POSPLAN_Handle handle, uint16_t CondIdx)Deletes a Variable Condition from the SpinTAC Position Plan configuration.

• void STPOSPLAN_setCfgVarCond (ST_POSPLAN_Handle handle, uint16_t CondIdx, uint16_←↩

NXP SemiconductorsKinetis Motor Suite API Reference Manual

261

Page 288: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

t VarIdx1, uint16_t VarIdx2, ST_PlanComp_e Comp)Modifies a Variable Condition to the SpinTAC Position Plan configuration.

• void STPOSPLAN_getCfgVarCond (ST_POSPLAN_Handle handle, uint16_t CondIdx, uint16_t∗VarIdx1, uint16_t ∗VarIdx2, ST_PlanComp_e ∗Comp)

Returns a Variable Condition from the SpinTAC Position Plan configuration.• void STPOSPLAN_addCfgTran (ST_POSPLAN_Handle handle, uint16_t FromState, uint16_t To←↩

State, ST_PlanCond_e AndOr, uint16_t CondIdx1, uint16_t CondIdx2, _lq24 VelLim, _lq24 Acc←↩Lim, _lq24 DecLim, _lq20 JrkLim)

Adds a Transition to the SpinTAC Position Plan configuration.• void STPOSPLAN_delCfgTran (ST_POSPLAN_Handle handle, uint16_t TranIdx)

Deletes a Transition from the SpinTAC Position Plan configuration.• void STPOSPLAN_setCfgTran (ST_POSPLAN_Handle handle, uint16_t TranIdx, uint16_t From←↩

State, uint16_t ToState, ST_PlanCond_e AndOr, uint16_t CondIdx1, uint16_t CondIdx2, _lq24VelLim, _lq24 AccLim, _lq24 DecLim, _lq20 JrkLim)

Modifies a Transition in the SpinTAC Position Plan configuration.• void STPOSPLAN_getCfgTran (ST_POSPLAN_Handle handle, uint16_t TranIdx, uint16_←↩

t ∗FromState, uint16_t ∗ToState, ST_PlanCond_e ∗AndOr, uint16_t ∗CondIdx1, uint16_t ∗Cond←↩Idx2, _lq24 ∗VelLim, _lq24 ∗AccLim, _lq24 ∗DecLim, _lq20 ∗JrkLim)

Get a Transition from the SpinTAC Position Plan configuration.• void STPOSPLAN_addCfgAct (ST_POSPLAN_Handle handle, uint16_t State, ST_PlanCond_←↩

e AndOr, uint16_t CondIdx1, uint16_t CondIdx2, uint16_t VarIdx, ST_PlanActOptn_e Opt, _lq24Value, ST_PlanActTrgr_e EnterExit)

Adds an action to the SpinTAC Position Plan configuration.• void STPOSPLAN_delCfgAct (ST_POSPLAN_Handle handle, uint16_t ActIdx)

Deletes an action from the SpinTAC Position Plan configuration.• void STPOSPLAN_setCfgAct (ST_POSPLAN_Handle handle, uint16_t ActIdx, uint16_t State, S←↩

T_PlanCond_e AndOr, uint16_t CondIdx1, uint16_t CondIdx2, uint16_t VarIdx, ST_PlanActOptn←↩_e Opt, _lq24 Value, ST_PlanActTrgr_e EnterExit)

Modifies an action in the SpinTAC Position Plan configuration.• void STPOSPLAN_getCfgAct (ST_POSPLAN_Handle handle, uint16_t ActIdx, uint16_t ∗State,

ST_PlanCond_e ∗AndOr, uint16_t ∗CondIdx1, uint16_t ∗CondIdx2, uint16_t ∗VarIdx, ST_Plan←↩ActOptn_e ∗Opt, _lq24 ∗Value, ST_PlanActTrgr_e ∗EnterExit)

Returns an action from the SpinTAC Position Plan configuration.• void STPOSPLAN_addCfgVar (ST_POSPLAN_Handle handle, ST_PlanVar_e Type, _lq24 Value)

Adds a variable to the SpinTAC Position Plan configuration.• void STPOSPLAN_delCfgVar (ST_POSPLAN_Handle handle, uint16_t VarIdx)

Deletes a Variable from the SpinTAC Position Plan configuration.• void STPOSPLAN_setCfgVar (ST_POSPLAN_Handle handle, uint16_t VarIdx, ST_PlanVar_←↩

e Type, _lq24 Value)Modifies a variable in the SpinTAC Position Plan configuration.

• void STPOSPLAN_getCfgVar (ST_POSPLAN_Handle handle, uint16_t VarIdx, ST_PlanVar_←↩e ∗Type, _lq24 ∗Value)

Returns a variable from the SpinTAC Position Plan configuration.• void STPOSPLAN_setVar (ST_POSPLAN_Handle handle, uint16_t VarIdx, _lq24 Value)

Sets the value of a SpinTAC Position Plan variable.• void STPOSPLAN_getVar (ST_POSPLAN_Handle handle, uint16_t VarIdx, _lq24 ∗Value)

Gets the value of a SpinTAC Position Plan variable.• void STPOSPLAN_setUnitProfDone (ST_POSPLAN_Handle handle, bool ProDON)

Sets a flag in SpinTAC Position Plan to indicate if the unit profile is complete.

262Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 289: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

• void STPOSPLAN_setCfg (ST_POSPLAN_Handle handle, _lq24 T_sec, bool LoopENB)Configures SpinTAC Position Plan.

• void STPOSPLAN_getCfg (ST_POSPLAN_Handle handle, _lq24 ∗T_sec, bool ∗LoopENB)Gets the SpinTAC Position Plan configuration.

• void STPOSPLAN_setCfgHaltState (ST_POSPLAN_Handle handle, int32_t PosStepInt_mrev, _←↩lq24 PosStepFrac_mrev, _lq24 VelLim, _lq24 AccLim, _lq20 JrkLim, int32_t Timer_tick)

Configures the SpinTAC Position Plan Halt state.• void STPOSPLAN_getCfgHaltState (ST_POSPLAN_Handle handle, int32_t ∗PosStepInt_mrev, ←↩

_lq24 ∗PosStepFrac_mrev, _lq24 ∗VelLim, _lq24 ∗AccLim, _lq20 ∗JrkLim, int32_t ∗Timer_tick)Gets the SpinTAC Position Plan Halt state.

• void STPOSPLAN_addCfgState (ST_POSPLAN_Handle handle, int32_t PosStepInt_mrev, _lq24PosStep_Fracmrev, int32_t Timer_tick)

Adds a State to the SpinTAC Position Plan configuration.• void STPOSPLAN_delCfgState (ST_POSPLAN_Handle handle, uint16_t StateIdx)

Deletes a state from the SpinTAC Position Plan configuration.• void STPOSPLAN_setCfgState (ST_POSPLAN_Handle handle, uint16_t StateIdx, int32_t Pos←↩

StepInt_mrev, _lq24 PosStepFrac_mrev, int32_t Timer_tick)Modifies a state in the SpinTAC Position Plan configuration.

• void STPOSPLAN_getCfgState (ST_POSPLAN_Handle handle, uint16_t StateIdx, int32_t ∗Pos←↩StepInt_mrev, _lq24 ∗PosStepFrac_mrev, int32_t ∗Timer_tick)

Returns a state from the SpinTAC Position Plan configuration.• void STPOSPLAN_reset (ST_POSPLAN_Handle handle)

Resets the SpinTAC Position Plan component.• ST_POSPLAN_Handle STPOSPLAN_init (void ∗pMemory, const size_t numBytes)

Initializes the SpinTAC Position Plan component.• void STPOSPLAN_run (ST_POSPLAN_Handle handle)

Runs SpinTAC Position Plan calculation.• void STPOSPLAN_runTick (ST_POSPLAN_Handle handle)

Runs SpinTAC Position Plan Timing. Call this only from an ISR.• void STPOSPLAN_setCfgArray (ST_POSPLAN_Handle handle, uint32_t ∗cfgArray, const size_t

numBytes, uint16_t MaxActNum, uint16_t MaxCondNum, uint16_t MaxVarNum, uint16_t Max←↩TranNum, uint16_t MaxStateNum)

Prepares SpinTAC Position Plan data structure.

23.3.2 Data Structure Documentation

23.3.2.1 struct ST_PlanError_t

Defines the ST_PlanError_t data.

The ST_PlanError_t object contains error debugging information for the Position Plan component

Data Fields

NXP SemiconductorsKinetis Motor Suite API Reference Manual

263

Page 290: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

uint16_t ERR_code Function specific condition that caused the error. Function specificcondition that caused the error

uint16_t ERR_idx Plan component index that caused the error. Plan component indexthat caused the error

23.3.2.2 struct ST_PosPlan_t

Defines the ST_PosPlan_t data.

The ST_PosPlan_t object contains all configuration parameters of the Position Plan component

Data Fields

_lq24 AccLim Acceleration limit { unit: [(pu rpm)/s], value range: [0.001, 120.0]}.

ST_PlanError←↩_t

CfgError Error decoding structure.

uint16_t CurState Current state of the state machine.

uint16_t CurTran Current transition of the state machine.

_lq24 DecLim Deceleration limit { unit: [(pu rpm)/s], value range: [0.001, 120.0]}.

bool ENB Enable bit { false: disabled; true: enabled }.

uint16_t ERR_ID Error ID { 0: no error; others: see error code }.

ST_PlanFsm←↩State_e

FsmState State of the state machine.

_lq20 JrkLim Jerk Limit { unit: [(pu rpm)/s∧2], value range: [0.0005, 2000.0] }.

_lq24 PosStepFrac_←↩mrev

Position Step fraction part { unit: [MRev], value range: (-1.0, 1.←↩0)}.

int32_t PosStepInt_←↩mrev

Position Step Integer part { unit: [MRev] }.

bool RES Reset bit { false: not reset; true: reset }.

uint32_t s0[31]

264Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 291: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

ST_Plan←↩Status_e

STATUS Plan status { ST_PLAN_IDLE, ST_PLAN_INIT, ST_PLAN_B←↩USY, ST_PLAN_HALT, ST_PLAN_WAIT}.

int32_t Timer_tick State Timer { unit: [tick] }.

_lq24 VelLim Velocity limit { unit: [pu rpm], value range: (0.0, 1.0] }.

23.3.3 Macro Definition Documentation

23.3.3.1 #define __ST_PLAN_ENUM__

23.3.3.2 #define __ST_PLAN_ERROR__

23.3.3.3 #define ST_POS_PLAN_ACT_DWORDS (5)

Defines the amount of memory that needs to be allocated for each component.

Each configured Action takes 3 double words of memory

23.3.3.4 #define ST_POS_PLAN_COND_DWORDS (3)

Each configured Condition takes 3 double words of memory.

23.3.3.5 #define ST_POS_PLAN_STATE_DWORDS (7)

Each configured State takes 7 double words of memory.

23.3.3.6 #define ST_POS_PLAN_TRAN_DWORDS (7)

Each configured Transition takes 7 double words of memory.

23.3.3.7 #define ST_POS_PLAN_VAR_DWORDS (2)

Each configured Variable takes 2 double words of memory.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

265

Page 292: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

23.3.4 Typedef Documentation

23.3.4.1 typedef ST_PosPlan_t∗ ST_POSPLAN_Handle

23.3.5 Enumeration Type Documentation

23.3.5.1 enum ST_PlanActOptn_e

Enumeration for the Plan Action Options.

Enumerator

ST_ACT_EQ Action will set the variable equal to a value.ST_ACT_ADD Action will add a value to the variable.ST_ACT_EQ Action will set the variable equal to a valueST_ACT_ADD Action will add a value to the variable

23.3.5.2 enum ST_PlanActTrgr_e

Enumeration for the Plan Action trigger point types.

Enumerator

ST_ACT_ENTR Action will be considered when entering the state.ST_ACT_EXIT Action will be considered when exiting the state.ST_ACT_ENTR Action will be considered when entering the stateST_ACT_EXIT Action will be considered when exiting the state

23.3.5.3 enum ST_PlanComp_e

Enumeration for the Plan Compare options.

Enumerator

ST_COMP_NA No comparison.ST_COMP_EQ Compares, VarIdx == Value1 OR VarIdx1 == VarIdx2.ST_COMP_NEQ Compares, VarIdx != Value1 OR VarIdx1 != VarIdx2.ST_COMP_GT Compares, VarIdx > Value1 OR VarIdx1 > VarIdx2.ST_COMP_EGT Compares, VarIdx >= Value1 OR VarIdx1 >= VarIdx2.ST_COMP_LW Compares, VarIdx < Value1 OR VarIdx1 < VarIdx2.ST_COMP_ELW Compares, VarIdx <= Value1 OR VarIdx1 <= VarIdx2.ST_COMP_In Compares, Value1 <= VarIdx <= Value2.ST_COMP_EIn Compares, Value1 < VarIdx <= Value2.

266Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 293: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

ST_COMP_InE Compares, Value1 <= VarIdx < Value2.ST_COMP_EInE Compares, Value1 < VarIdx < Value2.ST_COMP_Out Compares, Value1 >= VarIdx >= Value2.ST_COMP_EOut Compares, Value1 > VarIdx >= Value2.ST_COMP_OutE Compares, Value1 >= VarIdx > Value2.ST_COMP_EOutE Compares, Value1 > VarIdx > Value2.ST_COMP_NA No comparisonST_COMP_EQ Compares, VarIdx == Value1 OR VarIdx1 == VarIdx2ST_COMP_NEQ Compares, VarIdx != Value1 OR VarIdx1 != VarIdx2ST_COMP_GT Compares, VarIdx > Value1 OR VarIdx1 > VarIdx2ST_COMP_EGT Compares, VarIdx >= Value1 OR VarIdx1 >= VarIdx2ST_COMP_LW Compares, VarIdx < Value1 OR VarIdx1 < VarIdx2ST_COMP_ELW Compares, VarIdx <= Value1 OR VarIdx1 <= VarIdx2ST_COMP_In Compares, Value1 <= VarIdx <= Value2ST_COMP_EIn Compares, Value1 < VarIdx <= Value2ST_COMP_InE Compares, Value1 <= VarIdx < Value2ST_COMP_EInE Compares, Value1 < VarIdx < Value2ST_COMP_Out Compares, Value1 >= VarIdx >= Value2ST_COMP_EOut Compares, Value1 > VarIdx >= Value2ST_COMP_OutE Compares, Value1 >= VarIdx > Value2ST_COMP_EOutE Compares, Value1 > VarIdx > Value2

23.3.5.4 enum ST_PlanCond_e

Enumeration for the Plan Condition options.

Enumerator

ST_COND_NC Transition/Action with no conditions satisfied.ST_COND_FC Transition/Action with first condition satisfied.ST_COND_AND Transition/Action with both conditions satisfied.ST_COND_OR Transition/Action with either condition satisfied.ST_COND_NC Transition/Action with no conditions satisfiedST_COND_FC Transition/Action with first condition satisfiedST_COND_AND Transition/Action with both conditions satisfiedST_COND_OR Transition/Action with either condition satisfied

23.3.5.5 enum ST_PlanFsmState_e

Enumeration for the Plan FSM states.

Enumerator

ST_FSM_STATE_STAY Plan is staying in a state until the timer is up.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

267

Page 294: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

ST_FSM_STATE_COND Plan is waiting for a transition condition to be true.ST_FSM_STATE_TRAN Plan is in transition with a motion profile.ST_FSM_STATE_STAY Plan is staying in a state until the timer is upST_FSM_STATE_COND Plan is waiting for a transition condition to be trueST_FSM_STATE_TRAN Plan is in transition with a motion profile

23.3.5.6 enum ST_PlanStatus_e

Enumeration for the Plan Status States.

Enumerator

ST_PLAN_IDLE idle state, holding positionST_PLAN_INIT init state, initialize internal statesST_PLAN_BUSY busy state, running state machineST_PLAN_HALT halt state, return to the position reference in idle stateST_PLAN_WAIT wait state, holding the position reference in idle stateST_PLAN_IDLE idle state, holding velocityST_PLAN_INIT init state, initialize internal statesST_PLAN_BUSY busy state, running state machineST_PLAN_HALT halt state, return to the speed reference in idle stateST_PLAN_WAIT wait state, holding the speed reference in idle state

23.3.5.7 enum ST_PlanVar_e

Enumeration for the Plan variable types.

Enumerator

ST_VAR_INOUT Variable type input/output.ST_VAR_IN Variable type input.ST_VAR_OUT Variable type output.ST_VAR_INOUT Variable type input/outputST_VAR_IN Variable type inputST_VAR_OUT Variable type output

23.3.5.8 enum ST_PosPlan_ErrorCode_e

Enumeration for the Position Plan Error Codes.

Enumerator

No_ErrorCode No error code

268Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 295: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

Plan_running Cannot change config while Plan is runningMax_States_exceed Maximum number of States exceededMax_Cond_exceed Maximum number of Conditions exceededMax_Trans_exceed Maximum number of Transitions exceededMax_Act_exceed Maximum number of Actions exceededMax_Var_exceed Maximum number of Variables exceededInvalid_Sampletime Sample Time is out of rangeInvalid_LoopENB Loop Enable is out of rangeInvalid_HaltAccLim Acceleration Limit is out of rangeInvalid_HaltJrkLim Jerk Limit is out of rangeInvalid_Timer_tick State Timer is out of rangeInvalid_State_index State Index is greater than Maximum number of StatesInvalid_Condition_index Condition Index is greater than Maximum number of ConditionsInvalid_Trans_index Transition Index is greater than Maximum number of TransitionsInvalid_Action_index Action Index is greater than Maximum number of ActionsInvalid_Var_index Variable Index is greater than Maximum number of VariablesInvalid_Var_type Variable Type is out of rangeInvalid_Value_Comp Value Comparison is out of rangeInvalid_Operation Action Operation is out of rangeInvalid_AndOr And/Or Selection is out of rangeImproper_Var_type Indicated Variable cannot be used for this operationImproper_Val_Comparison With a multiple value comparison, Value 1 must be < Value 2Improper_State_index Maximum number of States exceeded OR From State cannot be equal to To

StateImproper_Cond_Idx Maximum number of Conditions exceeded OR Condition 1 cannot be equal to

Condition 2Improper_EnterExit Enter/Exit Selection is out of rangeCannot_delete_Var_Cond Variable is used by a ConditionCannot_delete_Var_Act Variable is used by an ActionInvalid_HaltVelLim Velocity Limit is out of rangeInvalid_HaltDecLim Deceleration Limit is out of rangeInvalid_PosStep Halt Positon Step is out of rangePlanCfg_array_Small Plan Configuration Array is not large enoughCannot_delete_State_Tran State is used by a TransitionCannot_delete_State_Act State is used by an ActionInvalid_Var_Compare Cannot select range comparisonInvalid_Var_indexes Variable 1 cannot be equal to Variable 2Invalid_Cond_Index Wrong type of Condition specifiedCannot_Delete_Cond_Tran Condition is used by a TransitionInvalid_InitState_Step First State must have 0 Position StepCannot_Delete_Cond_Act Condition is used by an Action

NXP SemiconductorsKinetis Motor Suite API Reference Manual

269

Page 296: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

23.3.5.9 enum ST_PosPlan_ErrorId_e

Enumeration for the Position Plan Error Id, indicates the function which caused the error.

Enumerator

No_ErrorId No error idError_STPOSPLAN_addCfgCondError_STPOSPLAN_delCfgCondError_STPOSPLAN_setCfgCondError_STPOSPLAN_getCfgCondError_STPOSPLAN_addCfgTranError_STPOSPLAN_delCfgTranError_STPOSPLAN_setCfgTranError_STPOSPLAN_getCfgTranError_STPOSPLAN_addCfgActError_STPOSPLAN_delCfgActError_STPOSPLAN_setCfgActError_STPOSPLAN_getCfgActError_STPOSPLAN_addCfgVarError_STPOSPLAN_delCfgVarError_STPOSPLAN_setCfgVarError_STPOSPLAN_getCfgVarError_STPOSPLAN_addCfgStateError_STPOSPLAN_delCfgStateError_STPOSPLAN_setCfgStateError_STPOSPLAN_setVarError_STPOSPLAN_getVarError_STPOSPLAN_setCfgError_STPOSPLAN_setCfgHaltStateError_STPOSPLAN_setCfgArrayError_STPOSPLAN_addCfgVarCondError_STPOSPLAN_delCfgVarCondError_STPOSPLAN_setCfgVarCondError_STPOSPLAN_getCfgVarCondInvalid_STLicenseInvalid_RomVersion

23.3.6 Function Documentation

23.3.6.1 void STPOSPLAN_addCfgAct ( ST_POSPLAN_Handle handle, uint16_t State,ST_PlanCond_e AndOr, uint16_t CondIdx1, uint16_t CondIdx2, uint16_t VarIdx,ST_PlanActOptn_e Opt, _lq24 Value, ST_PlanActTrgr_e EnterExit )

Adds an action to the SpinTAC Position Plan configuration.

270Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 297: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

Parameters

in handle The handle for the SpinTAC Position Plan Object

in State Index of the State the Action happens in

in AndOr Condition option for the Action

in CondIdx1 Index of the first Condition to consider for the Action

in CondIdx2 Index of the second Condition to consider for the Action

in VarIdx Index of the Variable to be acted upon

in Opt Type of Action to perform on the Variable

in Value Value to use in the Action

in EnterExit State event that will trigger the Action

23.3.6.2 void STPOSPLAN_addCfgCond ( ST_POSPLAN_Handle handle, uint16_tVarIdx, ST_PlanComp_e Comp, _lq24 Value1, _lq24 Value2 )

Adds a Condition to the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in VarIdx Index of the Plan Variable that will be compared

in Comp Type of comparison that will be done

in Value1 First value to use in the comparison

in Value2 Second value to use in the comparison

23.3.6.3 void STPOSPLAN_addCfgState ( ST_POSPLAN_Handle handle, int32_tPosStepInt_mrev, _lq24 PosStep_Fracmrev, int32_t Timer_tick )

Adds a State to the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

NXP SemiconductorsKinetis Motor Suite API Reference Manual

271

Page 298: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

in PosStepInt_←↩mrev

Position step integer part in State { unit: [MRev], value range: 32 bitinteger (-2∧31, 2∧31) }

in PosStepFrac_←↩mrev

Position step fraction part in State { unit: [MRev], value range: (-1.0,1.0) }

in Timer_tick Minimum time to stay in State { unit: [tick] }

23.3.6.4 void STPOSPLAN_addCfgTran ( ST_POSPLAN_Handle handle, uint16_tFromState, uint16_t ToState, ST_PlanCond_e AndOr, uint16_t CondIdx1,uint16_t CondIdx2, _lq24 VelLim, _lq24 AccLim, _lq24 DecLim, _lq20 JrkLim )

Adds a Transition to the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in FromState Index of the from State

in ToState Index of the to State

in AndOr Condition option for the Transition

in CondIdx1 Index of the first Condition to consider for the Transition

in CondIdx2 Index of the second Condition to consider for the Transition

in VelLim Velocity limit for the Transition { unit: [pu rpm], value range: (0.0, 1.0]}

in AccLim Acceleration limit for the Transition { unit: [(pu rpm)/s], value range:[0.001, 120.0] }

in DecLim Deceleration limit for the Transition { unit: [(pu rpm)/s], value range:[0.001, 120.0] }

in JrkLim Jerk limit for the Transition { unit: [(pu rpm)/s∧2], value range: [0.0005,2000.0] }

23.3.6.5 void STPOSPLAN_addCfgVar ( ST_POSPLAN_Handle handle, ST_PlanVar_eType, _lq24 Value )

Adds a variable to the SpinTAC Position Plan configuration.

272Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 299: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

Parameters

in handle The handle for the SpinTAC Position Plan Object

in Type Type of Variable

in Value Initial value of the Variable

23.3.6.6 void STPOSPLAN_addCfgVarCond ( ST_POSPLAN_Handle handle, uint16_tVarIdx1, uint16_t VarIdx2, ST_PlanComp_e Comp )

Adds a Variable Condition to the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in VarIdx1 Index of the first Plan Variable that will be compared

in VarIdx2 Index of the second Plan Variable that will be compared

in Comp Type of comparison that will be done

23.3.6.7 void STPOSPLAN_delCfgAct ( ST_POSPLAN_Handle handle, uint16_t ActIdx )

Deletes an action from the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in ActIdx Index of the Action to delete

23.3.6.8 void STPOSPLAN_delCfgCond ( ST_POSPLAN_Handle handle, uint16_tCondIdx )

Deletes a Condition from the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

NXP SemiconductorsKinetis Motor Suite API Reference Manual

273

Page 300: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

in CondIdx Index of the Plan Condition to delete

23.3.6.9 void STPOSPLAN_delCfgState ( ST_POSPLAN_Handle handle, uint16_tStateIdx )

Deletes a state from the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in StateIdx Index of the State to delete

23.3.6.10 void STPOSPLAN_delCfgTran ( ST_POSPLAN_Handle handle, uint16_tTranIdx )

Deletes a Transition from the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in TranIdx Index of the Transition to delete

23.3.6.11 void STPOSPLAN_delCfgVar ( ST_POSPLAN_Handle handle, uint16_t VarIdx )

Deletes a Variable from the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in VarIdx Index of the Variable to delete

23.3.6.12 void STPOSPLAN_delCfgVarCond ( ST_POSPLAN_Handle handle, uint16_tCondIdx )

Deletes a Variable Condition from the SpinTAC Position Plan configuration.

274Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 301: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

Parameters

in handle The handle for the SpinTAC Position Plan Object

in CondIdx Index of the Plan Condition to delete

23.3.6.13 static _lq24 STPOSPLAN_getAccelerationLimit ( ST_POSPLAN_Handle handle) [inline], [static]

Gets the Acceleration Limit (AccLim) for SpinTAC Position Plan.

Parameters

in handle The handle for the SpinTAC Position Plan Object

Returns

_lq24 AccLim Acceleration limit { unit: [(pu rpm)/s], value range: (0.0, 120.0] }

References ST_PosPlan_t::AccLim.

23.3.6.14 void STPOSPLAN_getCfg ( ST_POSPLAN_Handle handle, _lq24 ∗ T_sec,bool ∗ LoopENB )

Gets the SpinTAC Position Plan configuration.

Parameters

in handle handle The handle for the SpinTAC Position Plan Object

out ∗T_sec Sample Time { unit: [sec], value range: (0, 0.01] }

out ∗LoopENB Sets if SpinTAC Position Plan should continuously run after it reachesthe end { false: Do not continuously run Plan; true: Continuously runPlan }

23.3.6.15 void STPOSPLAN_getCfgAct ( ST_POSPLAN_Handle handle, uint16_t ActIdx,uint16_t ∗ State, ST_PlanCond_e ∗ AndOr, uint16_t ∗ CondIdx1, uint16_t∗ CondIdx2, uint16_t ∗ VarIdx, ST_PlanActOptn_e ∗ Opt, _lq24 ∗ Value,ST_PlanActTrgr_e ∗ EnterExit )

Returns an action from the SpinTAC Position Plan configuration.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

275

Page 302: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

Parameters

in handle The handle for the SpinTAC Position Plan Object

in ActIdx Index of the Action to return

out ∗State Index of the State the Action happens in

out ∗AndOr Condition option for the Action

out ∗CondIdx1 Index of the first Condition to consider for the Action

out ∗CondIdx2 Index of the second Condition to consider for the Action

out ∗VarIdx Index of the Variable to be acted upon

out ∗Opt Type of Action to perform on the Variable

out ∗Value Value to use in the Action

out ∗EnterExit State event that will trigger the Action

23.3.6.16 void STPOSPLAN_getCfgActNum ( ST_POSPLAN_Handle handle, uint16_t ∗ActNum )

Returns the number of configured Actions in SpinTAC Position Plan.

Parameters

in handle The handle for the SpinTAC Position Plan Object

out ∗ActNum The number of configured Actions in SpinTAC Position Plan

23.3.6.17 void STPOSPLAN_getCfgCond ( ST_POSPLAN_Handle handle, uint16_tCondIdx, uint16_t ∗ VarIdx, ST_PlanComp_e ∗ Comp, _lq24 ∗ Value1, _lq24 ∗Value2 )

Returns a Condition from the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in CondIdx Index of the Plan Condition to return

out ∗VarIdx Index of the Plan Variable that will be compared

276Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 303: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

out ∗Comp Type of comparison that will be done

out ∗Value1 First value to use in the comparison

out ∗Value2 Second value to use in the comparison

23.3.6.18 void STPOSPLAN_getCfgCondNum ( ST_POSPLAN_Handle handle, uint16_t∗ CondNum )

Returns the number of configured Conditions in SpinTAC Position Plan.

Parameters

in handle The handle for the SpinTAC Position Plan Object

out ∗CondNum The number of configured Conditions in SpinTAC Position Plan

23.3.6.19 static uint16_t STPOSPLAN_getCfgError ( ST_POSPLAN_Handle handle,uint16_t ∗ ERR_idx, uint16_t ∗ ERR_code ) [inline], [static]

Gets the Configuration Error for SpinTAC Position Plan.

Parameters

in handle The handle for the SpinTAC Position Plan Object

out ∗ERR_idx Component index where error occurred { 0: no index; others: see errorcode }

out ∗ERR_code Specific configuration error { 0: no additional information; others: seeerror code }

Returns

uint16_t ERR_ID Error ID { 0: no error; others: see error code }

References ST_PosPlan_t::CfgError, ST_PlanError_t::ERR_code, ST_PosPlan_t::ERR_ID, and ST_←↩PlanError_t::ERR_idx.

23.3.6.20 void STPOSPLAN_getCfgHaltState ( ST_POSPLAN_Handle handle, int32_t ∗PosStepInt_mrev, _lq24 ∗ PosStepFrac_mrev, _lq24 ∗ VelLim, _lq24 ∗ AccLim,_lq20 ∗ JrkLim, int32_t ∗ Timer_tick )

Gets the SpinTAC Position Plan Halt state.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

277

Page 304: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

Parameters

in handle The handle for the SpinTAC Position Plan Object

out ∗PosStepInt_←↩mrev

Position step integer part for Halt State { unit: [MRev] }

out ∗PosStepFrac←↩_mrev

Position step fraction part for Halt State { unit: [MRev], value range:(-1.0, 1.0) }

out ∗VelLim Velocity limit during Halt state { unit: [pu rpm], value range: (0, 1] }

out ∗AccLim Acceleration limit for Halt state { unit: [(pu rpm)/s], value range: [0.←↩001, 120.0] }

23.3.6.21 void STPOSPLAN_getCfgState ( ST_POSPLAN_Handle handle, uint16_tStateIdx, int32_t ∗ PosStepInt_mrev, _lq24 ∗ PosStepFrac_mrev, int32_t ∗Timer_tick )

Returns a state from the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in StateIdx Index of the State to modify

out ∗PosStepInt_←↩mrev

Position step integer part in State { unit: [MRev] }

out ∗PosStepFrac←↩_mrev

Position step fraction part in State { unit: [MRev] }

out ∗Timer_tick Minimum time to stay in State { unit: [tick] }

23.3.6.22 void STPOSPLAN_getCfgStateNum ( ST_POSPLAN_Handle handle, uint16_t ∗StateNum )

Returns the number of configured States in SpinTAC Position Plan.

Parameters

278Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 305: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

in handle The handle for the SpinTAC Position Plan Object

out ∗StateNum The number of configured States in SpinTAC Position Plan

23.3.6.23 void STPOSPLAN_getCfgTran ( ST_POSPLAN_Handle handle, uint16_tTranIdx, uint16_t ∗ FromState, uint16_t ∗ ToState, ST_PlanCond_e ∗ AndOr,uint16_t ∗ CondIdx1, uint16_t ∗ CondIdx2, _lq24 ∗ VelLim, _lq24 ∗ AccLim,_lq24 ∗ DecLim, _lq20 ∗ JrkLim )

Get a Transition from the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in TranIdx Index of the Transition to return

out ∗FromState Index of the from State

out ∗ToState Index of the to State

out ∗AndOr Condition option for the Transition

out ∗CondIdx1 Index of the first Condition to consider for the Transition

out ∗CondIdx2 Index of the second Condition to consider for the Transition

out ∗VelLim Velocity limit for the Transition { unit: [pu rpm], value range: (0.0, 1.0]}

out ∗AccLim Acceleration limit for the Transition { unit: [(pu rpm)/s], value range:[0.001, 120.0] }

out ∗DecLim Deceleration limit for the Transition { unit: [(pu rpm)/s], value range:[0.001, 120.0] }

out ∗JrkLim Jerk limit for the Transition { unit: [(pu rpm)/s∧2], value range: [0.0005,2000.0] }

23.3.6.24 void STPOSPLAN_getCfgTranNum ( ST_POSPLAN_Handle handle, uint16_t ∗TranNum )

Returns the number of configured Transitions in SpinTAC Position Plan.

Parameters

NXP SemiconductorsKinetis Motor Suite API Reference Manual

279

Page 306: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

in handle The handle for the SpinTAC Position Plan Object

out ∗TranNum The number of configured Transitions in SpinTAC Position Plan

23.3.6.25 void STPOSPLAN_getCfgVar ( ST_POSPLAN_Handle handle, uint16_t VarIdx,ST_PlanVar_e ∗ Type, _lq24 ∗ Value )

Returns a variable from the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in VarIdx Index of the Variable to return

out ∗Type Type of Variable

out ∗Value Initial value of the Variable

23.3.6.26 void STPOSPLAN_getCfgVarCond ( ST_POSPLAN_Handle handle, uint16_tCondIdx, uint16_t ∗ VarIdx1, uint16_t ∗ VarIdx2, ST_PlanComp_e ∗ Comp )

Returns a Variable Condition from the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in CondIdx Index of the Plan Condition to return

out ∗VarIdx1 Index of the first Plan Variable that will be compared

out ∗VarIdx2 Index of the second Plan Variable that will be compared

out ∗Comp Type of comparison that will be done

23.3.6.27 void STPOSPLAN_getCfgVarNum ( ST_POSPLAN_Handle handle, uint16_t ∗VarNum )

Returns the number of configured Variables in SpinTAC Position Plan.

Parameters

280Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 307: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

in handle The handle for the SpinTAC Position Plan Object

out ∗VarNum The number of configured Variables in SpinTAC Position Plan

23.3.6.28 static uint16_t STPOSPLAN_getCurrentState ( ST_POSPLAN_Handle handle )[inline], [static]

Gets the Current State (CurState) for SpinTAC Position Plan.

Parameters

in handle The handle for the SpinTAC Position Plan Object

Returns

uint16_t CurState Current state of the state machine

References ST_PosPlan_t::CurState.

23.3.6.29 static int32_t STPOSPLAN_getCurrentTimerValue_tick ( ST_POSPLAN_Handlehandle ) [inline], [static]

Gets the Current Time Value (Timer_tick) for SpinTAC Position Plan.

Parameters

in handle The handle for the SpinTAC Position Plan Object

Returns

int32_t Timer State Timer { unit: [tick] }

References ST_PosPlan_t::Timer_tick.

23.3.6.30 static uint16_t STPOSPLAN_getCurrentTransition ( ST_POSPLAN_Handlehandle ) [inline], [static]

Gets the Current Transition (CurTran) for SpinTAC Position Plan.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

281

Page 308: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

Parameters

in handle The handle for the SpinTAC Position Plan Object

Returns

uint16_t CurTran Current transition of the state machine

References ST_PosPlan_t::CurTran.

23.3.6.31 static _lq24 STPOSPLAN_getDecelerationLimit ( ST_POSPLAN_Handle handle) [inline], [static]

Gets the Deceleration Limit (DecLim) for SpinTAC Position Plan.

Parameters

in handle The handle for the SpinTAC Position Plan Object

Returns

_lq24 DecLim Deceleration limit { unit: [(pu rpm)/s], value range: (0.0, 120.0] }

References ST_PosPlan_t::DecLim.

23.3.6.32 static bool STPOSPLAN_getEnable ( ST_POSPLAN_Handle handle )[inline], [static]

Gets the Enable signal (ENB) for SpinTAC Position Plan.

Parameters

in handle The handle for the SpinTAC Position Plan Object

Returns

bool ENB Enable bit { false: disable; true: enable }

References ST_PosPlan_t::ENB.

23.3.6.33 static uint16_t STPOSPLAN_getErrorID ( ST_POSPLAN_Handle handle )[inline], [static]

Gets the Error value (ERR_ID) for SpinTAC Position Plan.

282Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 309: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

Parameters

in handle The handle for the SpinTAC Position Plan Object

Returns

uint16_t ERR_ID Error ID { 0: no error; others: see error code }

References ST_PosPlan_t::ERR_ID.

23.3.6.34 static ST_PlanFsmState_e STPOSPLAN_getFsmState ( ST_POSPLAN_Handlehandle ) [inline], [static]

Gets the State Machine State (FsmState) for SpinTAC Position Plan.

Parameters

in handle The handle for the SpinTAC Position Plan Object

Returns

ST_PlanFsmState_e FsmState Current operation of the state machine

References ST_PosPlan_t::FsmState.

23.3.6.35 static _lq20 STPOSPLAN_getJerkLimit ( ST_POSPLAN_Handle handle )[inline], [static]

Gets the Jerk Limit (JrkLim) for SpinTAC Position Plan.

Parameters

in handle The handle for the SpinTAC Position Plan Object

Returns

_lq20 JrkLim Jerk Limit { unit: [(pu rpm)/s∧2], value range: (0.0, 2000.0] }

References ST_PosPlan_t::JrkLim.

23.3.6.36 static void STPOSPLAN_getPositionStep_mrev ( ST_POSPLAN_Handlehandle, int32_t ∗ posStepInt_mrev, _lq24 ∗ posStepFrac_mrev ) [inline],[static]

Gets the Position Step (posStepInt_mrev, posStepFrac_mrev) for SpinTAC Position Plan.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

283

Page 310: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

Parameters

in handle The handle for the SpinTAC Position Plan Object

out ∗posStepInt_←↩mrev

Position Step integer part value { unit: [MRev], value range: 32-bitinteger }

out ∗posStepFrac←↩_mrev

Position Step fraction part value { unit: [MRev], value range: (-1.0, 1.0)}

References ST_PosPlan_t::PosStepFrac_mrev, and ST_PosPlan_t::PosStepInt_mrev.

23.3.6.37 static bool STPOSPLAN_getReset ( ST_POSPLAN_Handle handle )[inline], [static]

Gets the Reset signal (RES) for SpinTAC Position Plan.

Parameters

in handle The handle for the SpinTAC Position Plan Object

Returns

bool RES Reset bit { false: reset; true: not reset }

References ST_PosPlan_t::RES.

23.3.6.38 static ST_PlanStatus_e STPOSPLAN_getStatus ( ST_POSPLAN_Handlehandle ) [inline], [static]

Gets the Status value (STATUS) for SpinTAC Position Plan.

Parameters

in handle The handle for the SpinTAC Position Plan Object

Returns

ST_PlanStatus_e STATUS Status { ST_VEL_ID_IDLE, ST_VEL_ID_INIT, ST_VEL_ID_BUSY}

References ST_PosPlan_t::STATUS.

23.3.6.39 void STPOSPLAN_getVar ( ST_POSPLAN_Handle handle, uint16_t VarIdx,_lq24 ∗ Value )

Gets the value of a SpinTAC Position Plan variable.

284Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 311: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

Parameters

in handle The handle for the SpinTAC Position Plan Object

in VarIdx Index of the Variable to get

out ∗Value Value to get from the Variable

23.3.6.40 static _lq24 STPOSPLAN_getVelocityLimit ( ST_POSPLAN_Handle handle )[inline], [static]

Gets the Velocity Limit (VelLim) for SpinTAC Position Plan.

Parameters

in handle The handle for the SpinTAC Position Plan Object

Returns

_lq24 VelLim Velocity limit { unit: [pu rpm], value range: [-1.0, 1.0] }

References ST_PosPlan_t::VelLim.

23.3.6.41 ST_POSPLAN_Handle STPOSPLAN_init ( void ∗ pMemory, const size_tnumBytes )

Initializes the SpinTAC Position Plan component.

Parameters

in ∗pMemory Pointer to the memory for ST_PosPlan_t

in numBytes The number of bytes in the ST_PosPlan_t

Returns

ST_POSPLAN_Handle handle The handle for the SpinTAC Position Plan Object

23.3.6.42 void STPOSPLAN_reset ( ST_POSPLAN_Handle handle )

Resets the SpinTAC Position Plan component.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

285

Page 312: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

Parameters

in handle The handle for the SpinTAC Position Plan Object

23.3.6.43 void STPOSPLAN_run ( ST_POSPLAN_Handle handle )

Runs SpinTAC Position Plan calculation.

Parameters

in handle The handle for the Position Plan structure

23.3.6.44 void STPOSPLAN_runTick ( ST_POSPLAN_Handle handle )

Runs SpinTAC Position Plan Timing. Call this only from an ISR.

Parameters

in handle The handle for the Position Plan structure

23.3.6.45 void STPOSPLAN_setCfg ( ST_POSPLAN_Handle handle, _lq24 T_sec, boolLoopENB )

Configures SpinTAC Position Plan.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in T_sec Sample Time { unit: [sec], value range: (0, 0.01] }

in LoopENB Sets if SpinTAC Position Plan should continuously run after it reachesthe end { false: Do not continuously run Plan; true: Continuously runPlan }

23.3.6.46 void STPOSPLAN_setCfgAct ( ST_POSPLAN_Handle handle, uint16_t ActIdx,uint16_t State, ST_PlanCond_e AndOr, uint16_t CondIdx1, uint16_t CondIdx2,uint16_t VarIdx, ST_PlanActOptn_e Opt, _lq24 Value, ST_PlanActTrgr_eEnterExit )

Modifies an action in the SpinTAC Position Plan configuration.

286Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 313: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

Parameters

in handle The handle for the SpinTAC Position Plan Object

in ActIdx Index of the Action to modify

in State Index of the State the Action happens in

in AndOr Condition option for the Action

in CondIdx1 Index of the first Condition to consider for the Action

in CondIdx2 Index of the second Condition to consider for the Action

in VarIdx Index of the Variable to be acted upon

in Opt Type of Action to perform on the Variable

in Value Value to use in the Action

in EnterExit State event that will trigger the Action

23.3.6.47 void STPOSPLAN_setCfgArray ( ST_POSPLAN_Handle handle, uint32_t ∗cfgArray, const size_t numBytes, uint16_t MaxActNum, uint16_t MaxCondNum,uint16_t MaxVarNum, uint16_t MaxTranNum, uint16_t MaxStateNum )

Prepares SpinTAC Position Plan data structure.

Parameters

in handle The handle for the Position Plan structure

in ∗cfgArray Pointer to the SpinTAC Position Plan configuration array

in numBytes The number of bytes in the SpinTAC Position Plan configuration array

in MaxActNum Number of Actions

in MaxCondNum Number of Conditions

in MaxVarNum Number of Variables

in MaxTranNum Number of Transitions

in MaxStateNum Number of States

23.3.6.48 void STPOSPLAN_setCfgCond ( ST_POSPLAN_Handle handle, uint16_tCondIdx, uint16_t VarIdx, ST_PlanComp_e Comp, _lq24 Value1, _lq24 Value2)

Modifies a Condition in the SpinTAC Position Plan configuration.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

287

Page 314: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

Parameters

in handle The handle for the SpinTAC Position Plan Object

in CondIdx Index of the Plan Condition to modify

in VarIdx Index of the Plan Variable that will be compared

in Comp Type of comparison that will be done

in Value1 First value to use in the comparison

in Value2 Second value to use in the comparison

23.3.6.49 void STPOSPLAN_setCfgHaltState ( ST_POSPLAN_Handle handle, int32_tPosStepInt_mrev, _lq24 PosStepFrac_mrev, _lq24 VelLim, _lq24 AccLim,_lq20 JrkLim, int32_t Timer_tick )

Configures the SpinTAC Position Plan Halt state.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in PosStepInt_←↩mrev

Position step integer part for Halt State { unit: [MRev], value range: 32bit integer [-2, 2] }

in PosStepFrac_←↩mrev

Position step fraction part for Halt State { unit: [MRev], value range:(-1.0, 1.0) }

in VelLim Velocity limit during Halt state { unit: [pu rpm], value range: (0, 1] }

in AccLim Acceleration limit for Halt state { unit: [(pu rpm)/s], value range: [0.←↩001, 120.0] }

in JrkLim Jerk limit for Halt state { unit: [(pu rpm)/s∧2], value range: [0.0005,2000.0] }

in Timer_tick Minimum amount of time to stay in Halt state { unit: [tick] }

23.3.6.50 void STPOSPLAN_setCfgState ( ST_POSPLAN_Handle handle, uint16_tStateIdx, int32_t PosStepInt_mrev, _lq24 PosStepFrac_mrev, int32_t Timer_tick)

Modifies a state in the SpinTAC Position Plan configuration.

288Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 315: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

Parameters

in handle The handle for the SpinTAC Position Plan Object

in StateIdx Index of the State to modify

in PosStepInt_←↩mrev

Position step integer part in State { unit: [MRev], value range: 32 bitinteger (-2∧31, 2∧31) }

in PosStepFrac_←↩mrev

Position step fraction part in State { unit: [MRev], value range: (-1.0,1.0) }

in Timer_tick Minimum time to stay in State { unit: [tick] }

23.3.6.51 void STPOSPLAN_setCfgTran ( ST_POSPLAN_Handle handle, uint16_tTranIdx, uint16_t FromState, uint16_t ToState, ST_PlanCond_e AndOr,uint16_t CondIdx1, uint16_t CondIdx2, _lq24 VelLim, _lq24 AccLim, _lq24DecLim, _lq20 JrkLim )

Modifies a Transition in the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in TranIdx Index of the Transition to modify

in FromState Index of the from State

in ToState Index of the to State

in AndOr Condition option for the Transition

in CondIdx1 Index of the first Condition to consider for the Transition

in CondIdx2 Index of the second Condition to consider for the Transition

in VelLim Velocity limit for the Transition { unit: [pu rpm], value range: [-1.0,1.0] }

in AccLim Acceleration limit for the Transition { unit: [(pu rpm)/s], value range:[0.001, 120.0] }

in DecLim Deceleration limit for the Transition { unit: [(pu rpm)/s], value range:[0.001, 120.0] }

NXP SemiconductorsKinetis Motor Suite API Reference Manual

289

Page 316: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

in JrkLim Jerk limit for the Transition { unit: [(pu rpm)/s∧2], value range: [0.0005,2000.0] }

23.3.6.52 void STPOSPLAN_setCfgVar ( ST_POSPLAN_Handle handle, uint16_t VarIdx,ST_PlanVar_e Type, _lq24 Value )

Modifies a variable in the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in VarIdx Index of the Variable to modify

in Type Type of Variable

in Value Initial value of the Variable

23.3.6.53 void STPOSPLAN_setCfgVarCond ( ST_POSPLAN_Handle handle, uint16_tCondIdx, uint16_t VarIdx1, uint16_t VarIdx2, ST_PlanComp_e Comp )

Modifies a Variable Condition to the SpinTAC Position Plan configuration.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in CondIdx Index of the Plan Condition to modify

in VarIdx1 Index of the first Plan Variable that will be compared

in VarIdx2 Index of the second Plan Variable that will be compared

in Comp Type of comparison that will be done

23.3.6.54 static void STPOSPLAN_setEnable ( ST_POSPLAN_Handle handle, bool enb) [inline], [static]

Sets the Enable signal (ENB) for SpinTAC Position Plan.

Parameters

290Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 317: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

in handle The handle for the SpinTAC Position Plan Object

in enb Enable bit { false: disable; true: enable }

References ST_PosPlan_t::ENB.

23.3.6.55 static void STPOSPLAN_setReset ( ST_POSPLAN_Handle handle, bool res )[inline], [static]

Sets the Reset signal (RES) for SpinTAC Position Plan.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in res Reset bit { false: reset; true: not reset }

References ST_PosPlan_t::RES.

23.3.6.56 void STPOSPLAN_setUnitProfDone ( ST_POSPLAN_Handle handle, boolProDON )

Sets a flag in SpinTAC Position Plan to indicate if the unit profile is complete.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in ProDON Indicates if the unit profile is completed

23.3.6.57 void STPOSPLAN_setVar ( ST_POSPLAN_Handle handle, uint16_t VarIdx,_lq24 Value )

Sets the value of a SpinTAC Position Plan variable.

Parameters

in handle The handle for the SpinTAC Position Plan Object

in VarIdx Index of the Variable to set

in Value Value to set to the Variable

NXP SemiconductorsKinetis Motor Suite API Reference Manual

291

Page 318: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

SpinTAC™ Position Plan

292Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 319: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 24Math24.1 OverviewProvides core math functions for application.

Functional description

KMS includes files defining the QMath utilized in all other blocks. KMS utilizes Q24 (lq) numbers inthe vast majority of cases, with Q20 and Q16 otherwise specified. For sq numbers, currents are typicallydefined as Q15 with all others being Q14.

The Math block also includes definitions for various PI(D) controllers, frame transforms, and filters.

Code security breakdown

The table below describes the partitioning of Math block code among open source, library, and protectedexecute-only.

Open Source Library Execute-onlyDifferent available types, conversi-ons, PID options that the customercan use

Implementation of PID N/A

Execution

Execution of Math functions depends on where and how they are utilized.

Data Structures• struct FLT_butterAccT32bit_t• struct FLT_butterAccT16bit_t• struct FLT_butterAccE32bit_t• struct PID_pidParam32_t• struct PID_pidReg32_t• struct PID_piParam16_t• struct PID_piReg16_t• struct PID_piParam32_t• struct PID_piReg32_t• struct TRF_s3Vector32_t• struct TRF_sVector16_t

NXP SemiconductorsKinetis Motor Suite API Reference Manual

293

Page 320: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

• struct TRF_sVector32_t• struct TRF_rVector16_t• struct TRF_rVector32_t• struct TRF_orient16_t• struct TRF_orient32_t• struct FLT_butterAccT32bit_s

First order Butterworth filter accumulator type/structure (32-bit, Tustin) More...• struct FLT_butterAccT16bit_s

First order Butterworth filter accumulator type/structure (16-bit, Tustin) More...• struct FLT_butterAccE32bit_s

First order Butterworth filter accumulator type/structure (32-bit, Euler) More...

Macros• #define FLT_RATIO_TUSTIN(cutOffFreqHz, sampleTime) (PI ∗ ((cutOffFreqHz) ∗ (sample←↩

Time)))Calculates filter ratio of Butterworth filter (Tustin implementation) as Pi ∗ (cut-off frequency) ∗ sampletime.

• #define FLT_COEFF_TUSTIN(cutOffFreqHz, sampleTime) (FLT_RATIO_TUSTIN((cutOff←↩FreqHz), (sampleTime)) / (1.0 + FLT_RATIO_TUSTIN((cutOffFreqHz), (sampleTime))))

Calculates Butterworth filter coefficient (Tustin implementation)• #define FLT_RATIO_EULER(cutOffFreqHz, sampleTime) 2.0 ∗ FLT_RATIO_TUSTIN((cutOff←↩

FreqHz), (sampleTime))Calculates filter ratio of Butterworth filter (Euler implementation) as Pi ∗ (cut-off frequency) ∗ sampletime.

• #define FLT_COEFF_EULER(cutOffFreqHz, sampleTime) FLT_RATIO_EULER((cutOffFreq←↩Hz), (sampleTime))

Calculates Butterworth filter coefficient (Euler implementation)• #define FLT_INIT_T_32BIT(cutOffFreqHz, sampleTime) {_LQ(0.0), _LQ(0.0), _LQ(FLT_COE←↩

FF_TUSTIN((cutOffFreqHz), (sampleTime)))}Initializer macro for low/high-pass filter FLT_butterAccT16bit_t type variables (32-bit, Tustin implemen-tation)

• #define FLT_INIT_E_32BIT(cutOffFreqHz, sampleTime) {_LQ(0.0), _LQ(FLT_COEFF_EULE←↩R((cutOffFreqHz), (sampleTime)))}

Initializer macro for low/high-pass filter FLT_butterAccE32bit_t type variables (32-bit, Euler implemen-tation)

• #define PI (3.1415926535897932384626433832795)• #define SQRT2 (1.4142135623730950488016887242097)

Square root of two value.• #define SQRT3 (1.7320508075688772935274463415059)

Square root of three value.• #define PID_PID_REG32_INIT(pid)

32-bit PID default initializer for the regulation structure• #define PID_PI_REG16_INIT(pi)

16-bit PI default initializer for the regulation structure• #define PID_PI_REG32_INIT(pi)

32-bit PI default initializer for the regulation structure• #define MAX(x, y) (((x) > (y))? (x) : (y))

Finds maximum of two variables x and y.• #define MIN(x, y) (((x) < (y))? (x) : (y))

Finds minimum of two variables x and y.

294Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 321: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

• #define GLOBAL_SQ 14Global SQ format definition (value between 1 and 15)

• #define GLOBAL_LQ 24Global LQ format definition (value between 1 and 31)

• #define MAX_LQ_POS ((_lq)0x7FFFFFFFUL)Maximum positive number in LQ format.

• #define MAX_LQ_NEG ((_lq)0x80000000UL)Maximum negative number in LQ format.

• #define MIN_LQ_POS ((_lq) 1)Minimum positive number in LQ format.

• #define MIN_LQ_NEG ((_lq)-1)Minimum negative number in LQ format.

• #define _LQ31(A) ((_lq)((A) ∗ 2147483648.0L))Converts floating-point number A to LQ31 fixed-point format.

• #define _LQ30(A) ((_lq)((A) ∗ 1073741824.0L))Converts floating-point number A to LQ30 fixed-point format.

• #define _LQ24(A) ((_lq)((A) ∗ 16777216.0L))Converts floating-point number A to LQ24 fixed-point format.

• #define _LQ20(A) ((_lq)((A) ∗ 1048576.0L))Converts floating-point number A to LQ20 fixed-point format.

• #define _LQ16(A) ((_lq)((A) ∗ 65536.0L))Converts floating-point number A to LQ16 fixed-point format.

• #define _LQ15(A) ((_lq)((A) ∗ 32768.0L))Converts floating-point number A to LQ15 fixed-point format.

• #define _LQ14(A) ((_lq)((A) ∗ 16384.0L))Converts floating-point number A to LQ14 fixed-point format.

• #define _LQ(A) ((_lq)((A) ∗ 16777216.0L))Converts floating-point number A to LQ fixed-point format.

• #define MAX_SQ_POS ((_sq)0x7FFFU)Maximum positive number in SQ format.

• #define MAX_SQ_NEG ((_sq)0x8000U)Maximum negative number in SQ format.

• #define MIN_SQ_POS ((_sq) 1)Minimum positive number in SQ format.

• #define MIN_SQ_NEG ((_sq)-1)Minimum negative number in SQ format.

• #define _SQ15(A) ((_sq)((A) ∗ 32768.0))Converts floating-point number A to SQ15 fixed-point format.

• #define _SQ13(A) ((_sq)((A) ∗ 8192.0))Converts floating-point number A to SQ13 fixed-point format.

• #define _SQ8(A) ((_sq)((A) ∗ 256.0))Converts floating-point number A to SQ8 fixed-point format.

• #define _SQ(A) ((_sq)((A) ∗ 16384.0))Converts floating-point number A to SQ fixed-point format.

• #define _LQ_ASR(A, x) /∗lint -save -e649 -e704 -esym(960, 12.7) ∗/ ((_lq)(A) >> (x)) /∗lint -restore ∗/

Arithmetic (signed) shift right of 32-bit integer number.• #define _LQ_ASL(A, x) /∗lint -save -e649 -e703 -esym(960, 12.7) ∗/ ((_lq)(A) << (x)) /∗lint -

restore ∗/Arithmetic (signed) shift left of 32-bit integer number.

• #define _SQ_ASR(A, x) /∗lint -save -e649 -e702 -esym(960, 12.7) ∗/ ((_sq)(A) >> (x)) /∗lint -

NXP SemiconductorsKinetis Motor Suite API Reference Manual

295

Page 322: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

restore ∗/Arithmetic (signed) shift right of 16-bit integer number.

• #define _SQ_ASL(A, x) /∗lint -save -e649 -e701 -esym(960, 12.7) ∗/ ((_sq)(A) << (x)) /∗lint -restore ∗/

Arithmetic (signed) shift left of 16-bit integer number.• #define _SQtoLQ(qx) _SQXtoLQY((qx), GLOBAL_SQ, GLOBAL_LQ)

Converts SQ variable to LQ.• #define _LQtoSQ(lq) _LQXtoSQY((lq), GLOBAL_LQ, GLOBAL_SQ)

Converts LQ variable to SQ.• #define _LQtoSQ15(lq) _LQXtoSQY((lq), GLOBAL_LQ, 15)

Converts LQ variable to SQ15.• #define _SQ15toLQ(sq) _SQXtoLQY((sq), 15, GLOBAL_LQ)

Converts SQ15 variable to LQ.• #define _SQabsFast(x) ((_sq)(((x) < 0) ? (-(x)) : (x)))

Calculates absolute value of number in SQ global format (without checking for overflow)• #define _SQsatFast(x, max, min) (((x) >= (max))? (max) : (((x) <= (min))? (min) : (x)))

Limits the value of number in SQ global format between min and max value (fast macro)• #define _SQmpy(sqx, sqy) _SQZmpySQXY((sqx), GLOBAL_SQ, (sqy), GLOBAL_SQ, GLOB←↩

AL_SQ)Multiplies two numbers in SQ format and gives result in SQ format.

• #define _SQmpySQX(sqx, fx, sqy, fy) _SQZmpySQXY((sqx), (fx), (sqy), (fy), GLOBAL_SQ)Multiplies a number in SQX format with a number in SQY format and gives result in SQ format.

• #define _LQmpySQ(sqx, sqy) _LQZmpySQXY((sqx), GLOBAL_SQ, (sqy), GLOBAL_SQ, GL←↩OBAL_LQ)

Multiplies two numbers in SQ format and gives result in LQ format.• #define _LQZmpySQ(sqx, sqy, fz) _LQZmpySQXY((sqx), GLOBAL_SQ, (sqy), GLOBAL_SQ,

(fz))Multiplies two numbers in SQ format and gives result in LQZ format.

• #define _LQZmpySQX(sqx, fx, sqy, fy, fz) _LQZmpySQXY((sqx), (fx), (sqy), (fy), (fz))Multiplies two numbers in SQX and SQY format and gives result in LQZ format.

• #define _LQmpySQX(sqx, fx, sqy, fy) _LQZmpySQXY((sqx), (fx), (sqy), (fy), GLOBAL_LQ)Multiplies two numbers in SQX and SQY format respectively and gives result in LQ format.

• #define _SQ15mpySQX(sqx, fx, sqy, fy) QM_mpy((_lq)(sqx), (_lq)(sqy), (fx) + (fy) - 15)Multiplies two numbers in SQX and SQY format respectively and gives result in SQ15 format.

• #define QM_DIV_TWO_32B_16BRES(x, y) ((_sq)((x) / (y)))Macro which divides two 32-bit numbers and gives a 16-bit result.

• #define QM_DIV_TWO_32B_32BRES(x, y) ((_lq)((x) / (y)))Macro which divides two 32-bit numbers and gives a 32-bit result.

• #define _SQdivISQ(lqx, sqy) _SQZdivISQXY((lqx), GLOBAL_LQ, (sqy), GLOBAL_SQ, GLO←↩BAL_SQ)

Divides two numbers in LQ and SQ format respectively and gives result in SQ format.• #define _LQabsFast(x) ((_lq)(((x) < 0L) ? (-(x)) : (x)))

Calculates absolute value of number in LQ global format (without checking for overflow)• #define _LQsatFast(x, max, min) (((x) >= (max))? (max) : (((x) <= (min))? (min) : (x)))

Limits the value of number in LQ global format between min and max value (fast macro)• #define _LQmpy(lqx, lqy) QM_mpy((lqx), (lqy), (GLOBAL_LQ))

Multiplies two signed 32-bit numbers in LQ format and returns a signed 32-bit number in LQ format.• #define _LQmpyInline(lqx, lqy) QM_mpy((lqx), (lqy), (GLOBAL_LQ))• #define QM_mpyInline(lqx, lqy, GLOBAL_LQ) QM_mpy((lqx), (lqy), (GLOBAL_LQ))• #define _LQZmpyMiniSQLQXY(sqx, fx, lqy, fy, fz) QM_mpy((_lq)(sqx), (lqy), (((fx) +(fy)) - (fz)))

Multiplies a 16-bit signed number with a 32-bit signed number in SQX and LQY formats and returns a

296Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 323: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

signed 32-bit number in LQZ format.• #define _LQZmpyMiniSQLQXYInline(sqx, fx, lqy, fy, fz) QM_mpy((_lq)(sqx), (lqy), (((fx) +(fy))

- (fz)))• #define _LQmpyMiniSQLQ(sqx, lqy) QM_mpy((_lq)(sqx), (lqy), GLOBAL_SQ + GLOBAL_LQ

- GLOBAL_LQ)Multiplies a 16-bit signed number with a 32-bit signed number in SQ and LQ formats and returns a signed32-bit number in LQ format.

• #define _LQmpyMiniSQLQX(sqx, fx, lqy, fy) QM_mpy((_lq)(sqx), (lqy), ((fx) + (fy)) - GLOBA←↩L_LQ)

Multiplies two signed a 16-bit signed number with a 32-bit signed number in SQX and LQY formats andreturns a signed 32-bit number in LQ format.

• #define _LQmpyMiniSQLQXInline(sqx, fx, lqy, fy) QM_mpy((_lq)(sqx), (lqy), ((fx) + (fy)) - G←↩LOBAL_LQ)

• #define _L32mpyLQL32(l32, lqy) QM_mpy((l32), (lqy), GLOBAL_LQ + 0 - 0)Multiplies two signed 32-bit numbers in LQ and int32 (LQ0) format respectively and returns a signed32-bit number in LQ0 format.

• #define _LQ20mpyI32(lqx, lqy) QM_mpy((lqx), (lqy), 0)Multiplies two signed 32-bit numbers in LQ20 and int32 format respectively and returns a signed 32-bitnumber in LQ20 format.

• #define _LQmpyI32(lqx, lqy) QM_mpy((lqx), (lqy), 0)Multiplies two signed 32-bit numbers in LQ and int32 format respectively and returns a signed 32-bitnumber in LQ format.

• #define _LQmpyLQX(lqx, fx, lqy, fy) QM_mpy((lqx), (lqy), ((fx) + (fy)) - GLOBAL_LQ)Multiplies two signed 32-bit numbers in LQX and LQY format respectively and returns a signed 32-bitnumber in LQ format.

• #define _LQdiv(lqx, lqy) QM_div((lqx), (lqy), GLOBAL_LQ)Divides two signed 32-bit numbers in LQ format and returns a signed 32-bit number in LQ format.

• #define _LQZdivLQXY(lqx, lqy, fz) QM_div((lqx), (lqy), (fz))Divides two signed 32-bit numbers in LQX and LQY format respectively and returns a signed 32-bit num-ber in LQ format LQX and LQY must be of the same format (any Q value) fz MUST be divisible by 4.

• #define _LQ30mpyLQX(lqx, fx, lqy, fy) QM_mpy((lqx), (lqy), ((fx) + (fy)) - 30)Multiplies two numbers in LQX and LQY format respectively and gives result in LQ30 format.

• #define _LQ20mpyLQX(lqx, fx, lqy, fy) QM_mpy((lqx), (lqy), ((fx) + (fy)) - 20)Multiplies two numbers in LQX and LQY format respectively and gives result in LQ20 format.

• #define _LQ20div(lqx, lqy) QM_div((lqx), (lqy), 20 )Divides two numbers in LQX and LQY format respectively and gives result in LQ20 format LQX and LQYmust be of the same format.

• #define _LQrecip(lqX) _LQdiv((_LQ(1.0)), ((lqX) ))• #define TRF_VECTOR16_DEFAULTS {_SQ(0.0), _SQ(0.0)}

16-bit vector initializer• #define TRF_VECTOR32_DEFAULTS {_LQ(0.0), _LQ(0.0)}

32-bit vector initializer• #define TRF_EXT_VECTOR16_DEFAULTS {TRF_VECTOR16_DEFAULTS, TRF_VECTO←↩

R16_DEFAULTS}16-bit extended vector initializer

• #define TRF_EXT_VECTOR32_DEFAULTS {TRF_VECTOR32_DEFAULTS, TRF_VECTO←↩R32_DEFAULTS}

32-bit extended vector initializer

NXP SemiconductorsKinetis Motor Suite API Reference Manual

297

Page 324: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Typedefs• typedef int32_t _lq

LQ type definition.• typedef _lq _lq24• typedef _lq _lq20• typedef int16_t _sq

SQ type definition.

Functions• _lq FLT_ratio_Tustin (_lq lq16cutoffHz, _lq Ts)• _lq FLT_coeff_Tustin (_lq lq16cutoffHz, _lq Ts)• _lq FLT_coeff_Euler (_lq lq16cutoffHz, _lq Ts)• FAST _lq FLT_lpf1stT_32bit (FLT_butterAccT32bit_t ∗pflt, _lq input)

Executes first order low-pass Butterworth filter (32-bit Tustin implementation)• FAST _sq FLT_lpf1stT_16bit (FLT_butterAccT16bit_t ∗pflt, _sq input)

Executes first order low-pass Butterworth filter (16-bit Tustin implementation)• FAST _lq FLT_hpf1stT_32bit (FLT_butterAccT32bit_t ∗pflt, _lq input)

Executes first order high-pass Butterworth filter (32-bit Tustin implementation)• FAST _lq FLT_lpf1stE_32bit (FLT_butterAccE32bit_t ∗pflt, _lq input)

Executes first order low-pass Butterworth filter (32-bit forward Euler implementation)• FAST _lq FLT_hpf1stE_32bit (FLT_butterAccE32bit_t ∗pflt, _lq input)

Executes first order high-pass Butterworth filter (32-bit forward Euler implementation)• void PID_processPID32 (PID_pidReg32_t ∗v)

Processes a 32-bit PID regulator.• void PID_processPI32 (PID_piReg32_t ∗v)

Processes a 32-bit PI regulator.• void PID_processPIF32 (PID_piReg32_t ∗v, _lq flterr)

Processes a 32-bit PIF regulator.• void PID_processPIF16 (PID_piReg16_t ∗v, _sq flterr)• static int32_t _LQint (_lq x)

Returns integer value of LQ number.• static _lq _LQfrac (_lq x)

Returns fractional value of LQ number.• static _lq QM_mpy (_lq x, _lq y, int16_t format)

Multiplies two LQ numbers and returns an LQ number.• static _lq _LQXtoLQY (_lq lqx, int16_t x, int16_t y)

Converts signed 32-bit LQx to signed 32-bit LQy representation.• static _sq _LQXtoSQY (_lq lqx, int16_t x, int16_t y)

Converts signed 32-bit LQx to signed 16-bit SQy representation.• static _lq _SQXtoLQY (_sq qx, int16_t x, int16_t y)

Converts signed 16-bit SQx to signed 32-bit LQy representation.• int16_t QM_divTwo32bSNum16bRes (int32_t numerator, int32_t denominator)

Divides two 32-bit signed integer numbers and returns a 16-bit signed integer number.• _sq _SQsat (_sq x, _sq max, _sq min)

Limits the value of number in SQ global format between min and max value.• static _lq _LQZmpySQXY (_sq sqx, int16_t fx, _sq sqy, int16_t fy, int16_t fz)

Multiplies two signed numbers in SQX and SQY formats and returns result in LQZ format.• static _sq _SQZmpySQXY (_sq sqx, int16_t fx, _sq sqy, int16_t fy, int16_t fz)

Multiplies two signed numbers in SQX and SQY formats and returns result in SQZ format.• static _lq _LQZdivSQXY (_sq sqx, int16_t fx, _sq sqy, int16_t fy, int16_t fz)

298Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 325: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Divides two signed numbers in SQX and SQY format and returns number in LQZ format.• static _sq _SQZdivISQXY (_lq lqx, int16_t fx, _sq sqy, int16_t fy, int16_t fz)

Divides two signed numbers (32 and 16-bit) in LQX and SQY format and gives result in SQZ format.• static _lq _LQZdivISQXY (_lq lqx, int16_t fx, _sq sqy, int16_t fy, int16_t fz)

Divides two signed numbers (32 and 16-bit) in LQX and SQY format and gives result in LQZ format.• _lq QM_div (_lq numerator, _lq denominator, int16_t format)

Divides two LQ numbers and returns an LQX number in a designated X format.• _lq _LQabs (_lq x)• _lq _LQsat (_lq x, _lq max, _lq min)

Limits the value of number in LQ global format between min and max value.• _lq _LQsinPU (_lq angle)

Returns sine of PU angle (-1 to 1, which corresponds to -PI to PI)• _lq _LQcosPU (_lq angle)

Returns cosine of PU angle (-1 to 1, which corresponds to -PI to PI)• _lq _LQsqrt (_lq x)

Square-root function (for input values 0-1)• _lq20 _LQ20sqrt (_lq20 input)

Square-root function (for input values 0-1)• _lq _LQexp (_lq x)

Exponential function (for input values 0-1)• _lq20 _LQ20exp (_lq20 x)

Exponential function (for input values 0-1)• _lq24 _LQlog (_lq24 x)

Log base e function (for input values 0-1)• _lq20 _LQ20log (_lq20 x)

Log base e function (for input values 0-1)• _lq _LQatan2PU (_lq lqy, _lq lqx)

Returns angle of atan(y/x) in PU range (-PI, PI)• void _LQsincosPU (_lq angle, _lq ∗pSin, _lq ∗pCos)

Returns sin and cosine of PU angle (-1 to 1, which corresponds to -PI to PI)• int32_t qmath_version (void)

Returns the version number of the QMath Library.• static void TRF_park32 (const TRF_orient32_t ∗const pOrient, const TRF_sVector32_t ∗const p←↩

VectorAB, TRF_rVector32_t ∗const pVectorDQ)Direct Park transform of a 32-bit alpha-beta vector into a 32-bit d-q vector.

• static void TRF_park32_16_SQ15 (const TRF_orient32_t ∗pOrient, const TRF_sVector16_t ∗p←↩VectorAB, TRF_rVector16_t ∗pVectorDQ)

Direct Park transform of a 16-bit alpha-beta vector into a 16-bit d-q vector (by using 32-bit sine/cosinevalues)

• static void TRF_iPark32 (const TRF_orient32_t ∗pOrient, const TRF_rVector32_t ∗pVectorDQ, T←↩RF_sVector32_t ∗pVectorAB)

Inverse Park transform of a 32-bit d-q vector into a 32-bit alpha-beta vector.• static void TRF_clarkeLarge32 (_lq a, _lq b, _lq c, TRF_sVector32_t ∗pVectorAB)

Direct Clarke transform of a 32-bit a-b-c vector into a 32-bit alpha-beta vector.• static _lq UTIL_angleWrapAround (const _lq inputAngle)

Angle wrap-around function.• static _sq UTIL_arcUponChord (bool enableDCInjection, _lq speedEst, _lq anglexTslowscale, _←↩

lq(∗p_LQsinPU)(_lq x))

NXP SemiconductorsKinetis Motor Suite API Reference Manual

299

Page 326: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

24.2 Data Structure Documentation

24.2.1 struct FLT_butterAccT32bit_t

Data Fields

_lq coeff Butterworth filter coefficient

_lq inputOld Butterworth filter old input sample

_lq outputOld Butterworth filter old output sample

24.2.2 struct FLT_butterAccT16bit_t

Data Fields

_sq coeff Butterworth filter coefficient

_sq inputOld Butterworth filter old input sample

_sq outputOld Butterworth filter old output sample

24.2.3 struct FLT_butterAccE32bit_t

Data Fields

_lq coeff Butterworth filter coefficient

_lq outputOld Butterworth filter old output sample

24.2.4 struct PID_pidParam32_t

Data Fields

bool activeTustin Tustin or Euler implementation

_lq Kd Derivative gain

_lq Ki Integral gain

300Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 327: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

_lq Kp Proportional gain

_lq outMax Maximum output limit

_lq outMin Minimum output limit

24.2.5 struct PID_pidReg32_t

Data Fields

_lq error PID error term

_lq errorOld PID old error term

_lq outPreSat Pre-saturated output

_lq output PID output

PID_pid←↩Param32_t

const ∗

pid Pointer to PID parameters

_lq Ud Derivative term

_lq Ui Integral term

_lq Up Proportional term

_lq upOld Old proportional term

24.2.6 struct PID_piParam16_t

Data Fields

bool activeTustin Tustin or Euler implementation

_sq Kc Anti-windup correction gain (SQ)

_sq Ki Integral gain (SQ)

_sq Kp Proportional gain (UQ)

_sq outMax Maximum output limit (SQ)

NXP SemiconductorsKinetis Motor Suite API Reference Manual

301

Page 328: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

_sq outMin Minimum output limit (SQ)

24.2.7 struct PID_piReg16_t

Data Fields

_sq error PI error term

_sq errorOld PI old error term

_lq feedForward Feed-forward term

_lq outPreSat Pre-saturated output

_lq output PI output

PID_pi←↩Param16_t

const ∗

pi Pointer to PI parameters

_sq satErr Saturated difference

_lq Ui Integral term

_lq Up Proportional term

24.2.8 struct PID_piParam32_t

Data Fields

bool activeTustin Tustin or Euler implementation

_lq Kc Anti-windup correction gain

_lq Ki Integral gain

_lq Kp Proportional gain

_lq outMax Maximum output limit

_lq outMin Minimum output limit

24.2.9 struct PID_piReg32_t

302Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 329: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

Data Fields

_lq error PI error term

_lq errorOld PI old error term

_lq feedForward Feed-forward term

_lq outPreSat Pre-saturated output

_lq output PI output

PID_pi←↩Param32_t

const ∗

pi Pointer to PI parameters

_lq satErr Saturated difference

_lq Ui Integral term

_lq Up Proportional term

24.2.10 struct TRF_s3Vector32_t

Data Fields

_lq a a axis component

_lq b b axis component

_lq c c axis component

24.2.11 struct TRF_sVector16_t

Data Fields

_sq A Alpha axis component

_sq B Beta axis component

24.2.12 struct TRF_sVector32_t

NXP SemiconductorsKinetis Motor Suite API Reference Manual

303

Page 330: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Data Structure Documentation

Data Fields

_lq A Alpha axis component

_lq B Beta axis component

24.2.13 struct TRF_rVector16_t

Data Fields

_sq d D-axis component

_sq q Q-axis component

24.2.14 struct TRF_rVector32_t

Data Fields

_lq d D-axis component

_lq q Q-axis component

24.2.15 struct TRF_orient16_t

Data Fields

_sq cosAngle cosine value of the field angle

_sq sinAngle sine value of the field angle

24.2.16 struct TRF_orient32_t

Data Fields

_lq cosAngle cosine value of the field angle

304Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 331: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

_lq sinAngle sine value of the field angle

24.2.17 struct FLT_butterAccT32bit_s

First order Butterworth filter accumulator type/structure (32-bit, Tustin)

24.2.18 struct FLT_butterAccT16bit_s

First order Butterworth filter accumulator type/structure (16-bit, Tustin)

24.2.19 struct FLT_butterAccE32bit_s

First order Butterworth filter accumulator type/structure (32-bit, Euler)

24.3 Macro Definition Documentation24.3.1 #define _L32mpyLQL32( l32, lqy ) QM_mpy((l32), (lqy), GLOBAL_LQ + 0

- 0)

Multiplies two signed 32-bit numbers in LQ and int32 (LQ0) format respectively and returns a signed32-bit number in LQ0 format.

Referenced by PWMS_init().

24.3.2 #define _LQ( A ) ((_lq)((A) ∗ 16777216.0L))

Converts floating-point number A to LQ fixed-point format.

Referenced by FEEDBACK_run(), PWMS_init(), TRF_clarkeLarge32(), USER_cfgSCM(), USER←↩_resetDRVCommands(), USER_runBrakeStateSlowTick(), USER_runScmState(), UTIL_angleWrap←↩Around(), and UTIL_arcUponChord().

24.3.3 #define _LQ14( A ) ((_lq)((A) ∗ 16384.0L))

Converts floating-point number A to LQ14 fixed-point format.

24.3.4 #define _LQ15( A ) ((_lq)((A) ∗ 32768.0L))

Converts floating-point number A to LQ15 fixed-point format.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

305

Page 332: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

24.3.5 #define _LQ16( A ) ((_lq)((A) ∗ 65536.0L))

Converts floating-point number A to LQ16 fixed-point format.

24.3.6 #define _LQ20( A ) ((_lq)((A) ∗ 1048576.0L))

Converts floating-point number A to LQ20 fixed-point format.

24.3.7 #define _LQ20div( lqx, lqy ) QM_div((lqx), (lqy), 20 )

Divides two numbers in LQX and LQY format respectively and gives result in LQ20 format LQX andLQY must be of the same format.

24.3.8 #define _LQ20mpyI32( lqx, lqy ) QM_mpy((lqx), (lqy), 0)

Multiplies two signed 32-bit numbers in LQ20 and int32 format respectively and returns a signed 32-bitnumber in LQ20 format.

24.3.9 #define _LQ20mpyLQX( lqx, fx, lqy, fy ) QM_mpy((lqx), (lqy), ((fx) + (fy))- 20)

Multiplies two numbers in LQX and LQY format respectively and gives result in LQ20 format.

24.3.10 #define _LQ24( A ) ((_lq)((A) ∗ 16777216.0L))

Converts floating-point number A to LQ24 fixed-point format.

24.3.11 #define _LQ30( A ) ((_lq)((A) ∗ 1073741824.0L))

Converts floating-point number A to LQ30 fixed-point format.

Referenced by TRF_park32_16_SQ15().

24.3.12 #define _LQ30mpyLQX( lqx, fx, lqy, fy ) QM_mpy((lqx), (lqy), ((fx) +(fy)) - 30)

Multiplies two numbers in LQX and LQY format respectively and gives result in LQ30 format.

306Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 333: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

24.3.13 #define _LQ31( A ) ((_lq)((A) ∗ 2147483648.0L))

Converts floating-point number A to LQ31 fixed-point format.

24.3.14 #define _LQ_ASL( A, x ) /∗lint -save -e649 -e703 -esym(960, 12.7) ∗/((_lq)(A) << (x)) /∗lint -restore ∗/

Arithmetic (signed) shift left of 32-bit integer number.

Referenced by _LQXtoLQY(), _LQZdivISQXY(), _LQZdivSQXY(), _LQZmpySQXY(), and _SQXto←↩LQY().

24.3.15 #define _LQ_ASR( A, x ) /∗lint -save -e649 -e704 -esym(960, 12.7) ∗/((_lq)(A) >> (x)) /∗lint -restore ∗/

Arithmetic (signed) shift right of 32-bit integer number.

Referenced by _LQXtoLQY(), _LQZdivISQXY(), _LQZdivSQXY(), _LQZmpySQXY(), and _SQXto←↩LQY().

24.3.16 #define _LQabsFast( x ) ((_lq)(((x) < 0L) ? (-(x)) : (x)))

Calculates absolute value of number in LQ global format (without checking for overflow)

Referenced by DSM_runTimeMonitor(), DSM_updateSlowTick(), and UTIL_arcUponChord().

24.3.17 #define _LQdiv( lqx, lqy ) QM_div((lqx), (lqy), GLOBAL_LQ)

Divides two signed 32-bit numbers in LQ format and returns a signed 32-bit number in LQ format.

Referenced by FEEDBACK_run().

24.3.18 #define _LQmpy( lqx, lqy ) QM_mpy((lqx), (lqy), (GLOBAL_LQ))

Multiplies two signed 32-bit numbers in LQ format and returns a signed 32-bit number in LQ format.

Referenced by TRF_iPark32(), TRF_park32(), and UTIL_arcUponChord().

NXP SemiconductorsKinetis Motor Suite API Reference Manual

307

Page 334: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

24.3.19 #define _LQmpyI32( lqx, lqy ) QM_mpy((lqx), (lqy), 0)

Multiplies two signed 32-bit numbers in LQ and int32 format respectively and returns a signed 32-bitnumber in LQ format.

24.3.20 #define _LQmpyInline( lqx, lqy ) QM_mpy((lqx), (lqy), (GLOBAL_LQ))

Referenced by TRF_clarkeLarge32(), TRF_iPark32(), and TRF_park32().

24.3.21 #define _LQmpyLQX( lqx, fx, lqy, fy ) QM_mpy((lqx), (lqy), ((fx) + (fy)) -GLOBAL_LQ)

Multiplies two signed 32-bit numbers in LQX and LQY format respectively and returns a signed 32-bitnumber in LQ format.

24.3.22 #define _LQmpyMiniSQLQ( sqx, lqy ) QM_mpy((_lq)(sqx), (lqy),GLOBAL_SQ + GLOBAL_LQ - GLOBAL_LQ)

Multiplies a 16-bit signed number with a 32-bit signed number in SQ and LQ formats and returns a signed32-bit number in LQ format.

24.3.23 #define _LQmpyMiniSQLQX( sqx, fx, lqy, fy ) QM_mpy((_lq)(sqx),(lqy), ((fx) + (fy)) - GLOBAL_LQ)

Multiplies two signed a 16-bit signed number with a 32-bit signed number in SQX and LQY formats andreturns a signed 32-bit number in LQ format.

24.3.24 #define _LQmpyMiniSQLQXInline( sqx, fx, lqy, fy ) QM_mpy((_lq)(sqx),(lqy), ((fx) + (fy)) - GLOBAL_LQ)

24.3.25 #define _LQmpySQ( sqx, sqy ) _LQZmpySQXY((sqx), GLOBAL_SQ,(sqy), GLOBAL_SQ, GLOBAL_LQ)

Multiplies two numbers in SQ format and gives result in LQ format.

308Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 335: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

24.3.26 #define _LQmpySQX( sqx, fx, sqy, fy ) _LQZmpySQXY((sqx), (fx),(sqy), (fy), GLOBAL_LQ)

Multiplies two numbers in SQX and SQY format respectively and gives result in LQ format.

24.3.27 #define _LQrecip( lqX ) _LQdiv((_LQ(1.0)), ((lqX) ))

Referenced by FEEDBACK_run().

24.3.28 #define _LQsatFast( x, max, min ) (((x) >= (max))? (max) : (((x) <=(min))? (min) : (x)))

Limits the value of number in LQ global format between min and max value (fast macro)

Referenced by TRF_park32_16_SQ15().

24.3.29 #define _LQtoSQ( lq ) _LQXtoSQY((lq), GLOBAL_LQ, GLOBAL_SQ)

Converts LQ variable to SQ.

Referenced by DSM_updateSlowTick(), FEEDBACK_config(), and UTIL_arcUponChord().

24.3.30 #define _LQtoSQ15( lq ) _LQXtoSQY((lq), GLOBAL_LQ, 15)

Converts LQ variable to SQ15.

24.3.31 #define _LQZdivLQXY( lqx, lqy, fz ) QM_div((lqx), (lqy), (fz))

Divides two signed 32-bit numbers in LQX and LQY format respectively and returns a signed 32-bitnumber in LQ format LQX and LQY must be of the same format (any Q value) fz MUST be divisible by4.

24.3.32 #define _LQZmpyMiniSQLQXY( sqx, fx, lqy, fy, fz) QM_mpy((_lq)(sqx), (lqy), (((fx) +(fy)) - (fz)))

Multiplies a 16-bit signed number with a 32-bit signed number in SQX and LQY formats and returns asigned 32-bit number in LQZ format.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

309

Page 336: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

24.3.33 #define _LQZmpyMiniSQLQXYInline( sqx, fx, lqy, fy, fz) QM_mpy((_lq)(sqx), (lqy), (((fx) +(fy)) - (fz)))

Referenced by TRF_park32_16_SQ15().

24.3.34 #define _LQZmpySQ( sqx, sqy, fz ) _LQZmpySQXY((sqx),GLOBAL_SQ, (sqy), GLOBAL_SQ, (fz))

Multiplies two numbers in SQ format and gives result in LQZ format.

24.3.35 #define _LQZmpySQX( sqx, fx, sqy, fy, fz ) _LQZmpySQXY((sqx),(fx), (sqy), (fy), (fz))

Multiplies two numbers in SQX and SQY format and gives result in LQZ format.

24.3.36 #define _SQ( A ) ((_sq)((A) ∗ 16384.0))

Converts floating-point number A to SQ fixed-point format.

Referenced by UTIL_arcUponChord().

24.3.37 #define _SQ13( A ) ((_sq)((A) ∗ 8192.0))

Converts floating-point number A to SQ13 fixed-point format.

24.3.38 #define _SQ15( A ) ((_sq)((A) ∗ 32768.0))

Converts floating-point number A to SQ15 fixed-point format.

Referenced by USER_resetDRVCommands(), USER_runBrakeStateSlowTick(), USER_runInertia←↩State(), and USER_runScmState().

24.3.39 #define _SQ15mpySQX( sqx, fx, sqy, fy ) QM_mpy((_lq)(sqx),(_lq)(sqy), (fx) + (fy) - 15)

Multiplies two numbers in SQX and SQY format respectively and gives result in SQ15 format.

310Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 337: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

24.3.40 #define _SQ15toLQ( sq ) _SQXtoLQY((sq), 15, GLOBAL_LQ)

Converts SQ15 variable to LQ.

24.3.41 #define _SQ8( A ) ((_sq)((A) ∗ 256.0))

Converts floating-point number A to SQ8 fixed-point format.

24.3.42 #define _SQ_ASL( A, x ) /∗lint -save -e649 -e701 -esym(960, 12.7) ∗/((_sq)(A) << (x)) /∗lint -restore ∗/

Arithmetic (signed) shift left of 16-bit integer number.

Referenced by _SQZdivISQXY().

24.3.43 #define _SQ_ASR( A, x ) /∗lint -save -e649 -e702 -esym(960, 12.7) ∗/((_sq)(A) >> (x)) /∗lint -restore ∗/

Arithmetic (signed) shift right of 16-bit integer number.

Referenced by _SQZdivISQXY().

24.3.44 #define _SQabsFast( x ) ((_sq)(((x) < 0) ? (-(x)) : (x)))

Calculates absolute value of number in SQ global format (without checking for overflow)

Referenced by DSM_updateAtFastTick().

24.3.45 #define _SQdivISQ( lqx, sqy ) _SQZdivISQXY((lqx), GLOBAL_LQ,(sqy), GLOBAL_SQ, GLOBAL_SQ)

Divides two numbers in LQ and SQ format respectively and gives result in SQ format.

Referenced by UTIL_arcUponChord().

24.3.46 #define _SQmpy( sqx, sqy ) _SQZmpySQXY((sqx), GLOBAL_SQ, (sqy),GLOBAL_SQ, GLOBAL_SQ)

Multiplies two numbers in SQ format and gives result in SQ format.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

311

Page 338: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

24.3.47 #define _SQmpySQX( sqx, fx, sqy, fy ) _SQZmpySQXY((sqx), (fx),(sqy), (fy), GLOBAL_SQ)

Multiplies a number in SQX format with a number in SQY format and gives result in SQ format.

Referenced by FEEDBACK_run().

24.3.48 #define _SQsatFast( x, max, min ) (((x) >= (max))? (max) : (((x) <=(min))? (min) : (x)))

Limits the value of number in SQ global format between min and max value (fast macro)

24.3.49 #define _SQtoLQ( qx ) _SQXtoLQY((qx), GLOBAL_SQ, GLOBAL_LQ)

Converts SQ variable to LQ.

Referenced by FEEDBACK_run().

24.3.50 #define FLT_COEFF_EULER( cutOffFreqHz, sampleTime) FLT_RATIO_EULER((cutOffFreqHz), (sampleTime))

Calculates Butterworth filter coefficient (Euler implementation)

Parameters

cutOffFreqHz - cut-off frequency in Hz

sampleTime - sample time in s

24.3.51 #define FLT_COEFF_TUSTIN( cutOffFreqHz, sampleTime) (FLT_RATIO_TUSTIN((cutOffFreqHz), (sampleTime)) / (1.0 +FLT_RATIO_TUSTIN((cutOffFreqHz), (sampleTime))))

Calculates Butterworth filter coefficient (Tustin implementation)

Parameters

312Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 339: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

cutOffFreqHz - cut-off frequency in Hz

sampleTime - sample time in s

24.3.52 #define FLT_INIT_E_32BIT( cutOffFreqHz, sampleTime ) {_LQ(0.0),_LQ(FLT_COEFF_EULER((cutOffFreqHz), (sampleTime)))}

Initializer macro for low/high-pass filter FLT_butterAccE32bit_t type variables (32-bit, Euler implemen-tation)

Parameters

cutOffFreqHz - Butterworth filter cut-off frequency in Hz

sampleTime - sample time in s

24.3.53 #define FLT_INIT_T_32BIT( cutOffFreqHz, sampleTime ) {_LQ(0.0),_LQ(0.0), _LQ(FLT_COEFF_TUSTIN((cutOffFreqHz), (sampleTime)))}

Initializer macro for low/high-pass filter FLT_butterAccT16bit_t type variables (32-bit, Tustin implemen-tation)

Parameters

cutOffFreqHz - Butterworth filter cut-off frequency in Hz

sampleTime - sample time in s

24.3.54 #define FLT_RATIO_EULER( cutOffFreqHz, sampleTime ) 2.0 ∗FLT_RATIO_TUSTIN((cutOffFreqHz), (sampleTime))

Calculates filter ratio of Butterworth filter (Euler implementation) as Pi ∗ (cut-off frequency) ∗ sampletime.

Parameters

cutOffFreqHz - cut-off frequency in Hz

NXP SemiconductorsKinetis Motor Suite API Reference Manual

313

Page 340: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

sampleTime - sample time in s

24.3.55 #define FLT_RATIO_TUSTIN( cutOffFreqHz, sampleTime ) (PI ∗((cutOffFreqHz) ∗ (sampleTime)))

Calculates filter ratio of Butterworth filter (Tustin implementation) as Pi ∗ (cut-off frequency) ∗ sampletime.

Filter coefficients

Parameters

cutOffFreqHz - cut-off frequency in Hz

sampleTime - sample time in s

24.3.56 #define GLOBAL_LQ 24

Global LQ format definition (value between 1 and 31)

Referenced by TRF_park32_16_SQ15().

24.3.57 #define GLOBAL_SQ 14

Global SQ format definition (value between 1 and 15)

Referenced by FEEDBACK_run().

24.3.58 #define MAX( x, y ) (((x) > (y))? (x) : (y))

Finds maximum of two variables x and y.

Parameters

x - variable x

y - variable y

Referenced by PWMS_init().

314Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 341: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

24.3.59 #define MAX_LQ_NEG ((_lq)0x80000000UL)

Maximum negative number in LQ format.

24.3.60 #define MAX_LQ_POS ((_lq)0x7FFFFFFFUL)

Maximum positive number in LQ format.

24.3.61 #define MAX_SQ_NEG ((_sq)0x8000U)

Maximum negative number in SQ format.

Referenced by _LQXtoSQY().

24.3.62 #define MAX_SQ_POS ((_sq)0x7FFFU)

Maximum positive number in SQ format.

Referenced by _LQXtoSQY().

24.3.63 #define MIN( x, y ) (((x) < (y))? (x) : (y))

Finds minimum of two variables x and y.

Parameters

x - variable x

y - variable y

24.3.64 #define MIN_LQ_NEG ((_lq)-1)

Minimum negative number in LQ format.

24.3.65 #define MIN_LQ_POS ((_lq) 1)

Minimum positive number in LQ format.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

315

Page 342: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

24.3.66 #define MIN_SQ_NEG ((_sq)-1)

Minimum negative number in SQ format.

24.3.67 #define MIN_SQ_POS ((_sq) 1)

Minimum positive number in SQ format.

24.3.68 #define PI (3.1415926535897932384626433832795)

Referenced by UTIL_arcUponChord().

24.3.69 #define PID_PI_REG16_INIT( pi )

Value:

{ \&(pi), /**< Address of PI parameters structure */ \_SQ(0.0), /**< PI error term */ \_SQ(0.0), /**< PI old error term */\_LQ(0.0), /**< Proportional term */ \_LQ(0.0), /**< Integral term */ \_LQ(0.0), /**< Feed-forward */ \_LQ(0.0), /**< Pre-saturated output */ \_SQ(0.0), /**< Saturated difference */ \_LQ(0.0) /**< PI output */ \

}

16-bit PI default initializer for the regulation structure

Parameters

pi - 16-bit PI regulation structure

24.3.70 #define PID_PI_REG32_INIT( pi )

Value:

{ \&(pi), /**< Address of PI parameters structure */ \_LQ(0.0), /**< PI error term */ \_LQ(0.0), /**< PI old error term */\_LQ(0.0), /**< Proportional term */ \_LQ(0.0), /**< Integral term */ \_LQ(0.0), /**< Feed-forward */ \_LQ(0.0), /**< Pre-saturated output */ \

316Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 343: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

_LQ(0.0), /**< Saturated difference */ \_LQ(0.0) /**< PI output */ \

}

32-bit PI default initializer for the regulation structure

Parameters

pi - 32-bit PI regulation structure

24.3.71 #define PID_PID_REG32_INIT( pid )

Value:

{ \&(pid), /**< Address of PID parameters structure */ \_LQ(0.0), /**< PID error term */ \_LQ(0.0), /**< PID old error term */ \_LQ(0.0), /**< Proportional term */ \_LQ(0.0), /**< Old proportional term */ \_LQ(0.0), /**< Integral term */ \_LQ(0.0), /**< Derivative term */ \_LQ(0.0), /**< Pre-saturated output */ \_LQ(0.0) /**< PID output */ \

}

32-bit PID default initializer for the regulation structure

Parameters

pid - 32-bit PID regulation structure

24.3.72 #define QM_DIV_TWO_32B_16BRES( x, y ) ((_sq)((x) / (y)))

Macro which divides two 32-bit numbers and gives a 16-bit result.

Referenced by _SQZdivISQXY().

24.3.73 #define QM_DIV_TWO_32B_32BRES( x, y ) ((_lq)((x) / (y)))

Macro which divides two 32-bit numbers and gives a 32-bit result.

Referenced by _LQZdivISQXY(), and _LQZdivSQXY().

NXP SemiconductorsKinetis Motor Suite API Reference Manual

317

Page 344: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Typedef Documentation

24.3.74 #define QM_mpyInline( lqx, lqy, GLOBAL_LQ ) QM_mpy((lqx), (lqy),(GLOBAL_LQ))

24.3.75 #define SQRT2 (1.4142135623730950488016887242097)

Square root of two value.

24.3.76 #define SQRT3 (1.7320508075688772935274463415059)

Square root of three value.

Referenced by TRF_clarkeLarge32().

24.3.77 #define TRF_EXT_VECTOR16_DEFAULTS {TRF_VECTOR16_DEFAULT←↩S, TRF_VECTOR16_DEFAULTS}

16-bit extended vector initializer

24.3.78 #define TRF_EXT_VECTOR32_DEFAULTS {TRF_VECTOR32_DEFAULT←↩S, TRF_VECTOR32_DEFAULTS}

32-bit extended vector initializer

24.3.79 #define TRF_VECTOR16_DEFAULTS {_SQ(0.0), _SQ(0.0)}

16-bit vector initializer

24.3.80 #define TRF_VECTOR32_DEFAULTS {_LQ(0.0), _LQ(0.0)}

32-bit vector initializer

24.4 Typedef Documentation

24.4.1 _lq

LQ type definition.

318Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 345: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

24.4.2 typedef _lq _lq20

24.4.3 typedef _lq _lq24

24.4.4 _sq

SQ type definition.

24.5 Function Documentation

24.5.1 _lq _LQ20exp ( _lq20 x )

Exponential function (for input values 0-1)

Parameters

x - Exponential argument (LQ20 format)

Returns

Exponential value (LQ20 format)

24.5.2 _lq _LQ20log ( _lq20 x )

Log base e function (for input values 0-1)

Parameters

x - Log argument (LQ20 format)

Returns

Log base e value (LQ20 format)

24.5.3 _lq20 _LQ20sqrt ( _lq20 x )

Square-root function (for input values 0-1)

NXP SemiconductorsKinetis Motor Suite API Reference Manual

319

Page 346: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

x - square-root argument (LQ20 format)

Returns

Square-root value (LQ20 format)

24.5.4 _lq _LQabs ( _lq x )

Referenced by DSM_updateSlowTick().

24.5.5 _lq _LQatan2PU ( _lq lqy, _lq lqx )

Returns angle of atan(y/x) in PU range (-PI, PI)

Parameters

lqy numerator argument (LQ format)

lqx denominator argument (LQ format)

Returns

PU angle (LQ format)

24.5.6 _lq _LQcosPU ( _lq angle )

Returns cosine of PU angle (-1 to 1, which corresponds to -PI to PI)

Parameters

angle - PU angle (LQ format)

Returns

Cosine value (LQ format)

24.5.7 _lq _LQexp ( _lq x )

Exponential function (for input values 0-1)

320Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 347: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

x - Exponential argument (LQ format)

Returns

Exponential value (LQ format)

24.5.8 _lq _LQfrac ( _lq x ) [inline], [static]

Returns fractional value of LQ number.

Parameters

x - LQ number to return fractional portion of

Returns

fractional portion of LQ number x

24.5.9 _lq _LQint ( _lq x ) [inline], [static]

Returns integer value of LQ number.

Parameters

x - LQ number to return integer portion of

Returns

integer portion of LQ number x

24.5.10 _lq _LQlog ( _lq24 x )

Log base e function (for input values 0-1)

NXP SemiconductorsKinetis Motor Suite API Reference Manual

321

Page 348: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

x - Log argument (LQ format)

Returns

Log base e value (LQ format)

24.5.11 _lq _LQsat ( _lq x, _lq max, _lq min )

Limits the value of number in LQ global format between min and max value.

Parameters

x - number in LQ global format

max - upper limit

min - lower limit

Returns

Limited value

24.5.12 void _LQsincosPU ( _lq angle, _lq ∗ pSin, _lq ∗ pCos )

Returns sin and cosine of PU angle (-1 to 1, which corresponds to -PI to PI)

Parameters

angle - PU angle (LQ format)

∗pSin - pointer to variable receiving sine value

∗pCos - pointer to variable receiving cosine value

Returns

void

Referenced by USER_runScmState().

24.5.13 _lq _LQsinPU ( _lq angle )

Returns sine of PU angle (-1 to 1, which corresponds to -PI to PI)

322Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 349: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

angle - PU angle (LQ format)

Returns

Sine value (LQ format)

24.5.14 _lq _LQsqrt ( _lq x )

Square-root function (for input values 0-1)

Parameters

x - square-root argument (LQ format)

Returns

Square-root value (LQ format)

Referenced by DSM_updateSlowTick().

24.5.15 _lq _LQXtoLQY ( _lq lqx, int16_t x, int16_t y ) [inline], [static]

Converts signed 32-bit LQx to signed 32-bit LQy representation.

Parameters

lqx - LQx format number to convert

x - input significance (1 <= x <= 31)

y - output significance (1 <= y <= 31)

Returns

LQy representation of LQx

References _LQ_ASL, and _LQ_ASR.

Referenced by _LQXtoSQY().

24.5.16 _sq _LQXtoSQY ( _lq lqx, int16_t x, int16_t y ) [inline], [static]

Converts signed 32-bit LQx to signed 16-bit SQy representation.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

323

Page 350: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

lqx - LQx format number to convert

x - input significance (1 <= x <= 31)

y - output significance (0 <= y <= 15)

Returns

SQy representation of LQx

References _LQXtoLQY(), MAX_SQ_NEG, and MAX_SQ_POS.

Referenced by TRF_park32_16_SQ15().

24.5.17 _lq _LQZdivISQXY ( _lq lqx, int16_t fx, _sq sqy, int16_t fy, int16_t fz )[inline], [static]

Divides two signed numbers (32 and 16-bit) in LQX and SQY format and gives result in LQZ format.

Parameters

lqx - signed number in LQX format

fx - format of lqx number

sqy- signed number in SQY format

fy - format of sqy number

fz - format of the result

Returns

number in LQZ format

References _LQ_ASL, _LQ_ASR, and QM_DIV_TWO_32B_32BRES.

24.5.18 _lq _LQZdivSQXY ( _sq sqx, int16_t fx, _sq sqy, int16_t fy, int16_t fz )[inline], [static]

Divides two signed numbers in SQX and SQY format and returns number in LQZ format.

324Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 351: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

sqx - signed number in SQX format

fx - format of sqx number

sqy - signed number in SQY format

fy - format of sqy number

fz - format of the result

Returns

number in LQZ format

References _LQ_ASL, _LQ_ASR, and QM_DIV_TWO_32B_32BRES.

24.5.19 _lq _LQZmpySQXY ( _sq sqx, int16_t fx, _sq sqy, int16_t fy, int16_t fz )[inline], [static]

Multiplies two signed numbers in SQX and SQY formats and returns result in LQZ format.

Parameters

sqx - signed number in SQX format

fx - format of sqx number

sqy - signed number in SQY format

fy - format of sqy number

fz - format of the result

Returns

number in LQZ format

References _LQ_ASL, and _LQ_ASR.

Referenced by _SQZmpySQXY().

24.5.20 _sq _SQsat ( _sq x, _sq max, _sq min )

Limits the value of number in SQ global format between min and max value.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

325

Page 352: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

x - number in SQ global format

max - upper limit

min - lower limit

Returns

Limited value

24.5.21 _lq _SQXtoLQY ( _sq qx, int16_t x, int16_t y ) [inline], [static]

Converts signed 16-bit SQx to signed 32-bit LQy representation.

Parameters

qx - SQx number to convert

x - input significance (0 <= x <= 15)

y - output significance (1 <= y <= 31)

Returns

LQy representation of SQx

References _LQ_ASL, and _LQ_ASR.

24.5.22 _sq _SQZdivISQXY ( _lq lqx, int16_t fx, _sq sqy, int16_t fy, int16_t fz )[inline], [static]

Divides two signed numbers (32 and 16-bit) in LQX and SQY format and gives result in SQZ format.

Parameters

lqx - signed number in LQX format

fx - format of lqx number

326Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 353: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

sqy- signed number in SQY format

fy - format of sqy number

fz - format of the result

Returns

number in SQZ format

References _SQ_ASL, _SQ_ASR, and QM_DIV_TWO_32B_16BRES.

24.5.23 _sq _SQZmpySQXY ( _sq sqx, int16_t fx, _sq sqy, int16_t fy, int16_t fz )[inline], [static]

Multiplies two signed numbers in SQX and SQY formats and returns result in SQZ format.

Parameters

sqx - number in SQX format

fx - format of sqx number

sqy - number in SQY format

fy - format of sqy number

fz - format of the result (SQZ)

Returns

number in SQZ format

References _LQZmpySQXY().

24.5.24 _lq FLT_coeff_Euler ( _lq lq16cutoffHz, _lq Ts )

24.5.25 _lq FLT_coeff_Tustin ( _lq lq16cutoffHz, _lq Ts )

Referenced by FEEDBACK_config().

24.5.26 _lq FLT_hpf1stE_32bit ( FLT_butterAccE32bit_t ∗ pflt, _lq input )

Executes first order high-pass Butterworth filter (32-bit forward Euler implementation)

NXP SemiconductorsKinetis Motor Suite API Reference Manual

327

Page 354: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

∗pflt - pointer to the Butterworth coefficients

input - input variables

Returns

filtered variable H(s) = s / (s + wc)

24.5.27 _lq FLT_hpf1stT_32bit ( FLT_butterAccT32bit_t ∗ pflt, _lq input )

Executes first order high-pass Butterworth filter (32-bit Tustin implementation)

Parameters

∗pflt - pointer to the Butterworth coefficients

input - input variable

Returns

filtered variable

24.5.28 _lq FLT_lpf1stE_32bit ( FLT_butterAccE32bit_t ∗ pflt, _lq input )

Executes first order low-pass Butterworth filter (32-bit forward Euler implementation)

Parameters

∗pflt - pointer to the Butterworth coefficients

input - input variables

Returns

filtered variable H(s) = wc / (s + wc)

24.5.29 _lq FLT_lpf1stT_16bit ( FLT_butterAccT16bit_t ∗ pflt, _sq input )

Executes first order low-pass Butterworth filter (16-bit Tustin implementation)

328Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 355: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

∗pflt - pointer to the Butterworth coefficients

input - input variables

Returns

filtered variable

Referenced by FEEDBACK_run().

24.5.30 _lq FLT_lpf1stT_32bit ( FLT_butterAccT32bit_t ∗ pflt, _lq input )

Executes first order low-pass Butterworth filter (32-bit Tustin implementation)

Parameters

∗pflt - pointer to the Butterworth coefficients

input - input variables

Returns

filtered variable

24.5.31 _lq FLT_ratio_Tustin ( _lq lq16cutoffHz, _lq Ts )

24.5.32 PID_processPI32 ( PID_piReg32_t ∗ v )

Processes a 32-bit PI regulator.

Parameters

v - pointer to a PI 32-bit regulator structure

Returns

none

24.5.33 PID_processPID32 ( PID_pidReg32_t ∗ v )

Processes a 32-bit PID regulator.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

329

Page 356: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

v - pointer to a PID 32-bit regulator structure

Returns

none

24.5.34 void PID_processPIF16 ( PID_piReg16_t ∗ v, _sq flterr )

24.5.35 PID_processPIF32 ( PID_piReg32_t ∗ v, _lq flterr )

Processes a 32-bit PIF regulator.

Parameters

v - pointer to a PI 32-bit regulator structure

flterr - filtered error

Returns

none

24.5.36 _lq QM_div ( _lq numerator, _lq denominator, int16_t format )

Divides two LQ numbers and returns an LQX number in a designated X format.

Parameters

numerator - dividend (_lq)

denominator - divisor (_lq)

format - desired result format (int16_t)

Returns

Result/quotient (_lq)

24.5.37 int16_t QM_divTwo32bSNum16bRes ( int32_t numerator, int32_tdenominator )

Divides two 32-bit signed integer numbers and returns a 16-bit signed integer number.

330Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 357: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

numerator - dividend (int32_t)

denominator - divisor (int32_t)

Returns

Result/quotient (int16_t)

24.5.38 _lq QM_mpy ( _lq x, _lq y, int16_t format ) [inline], [static]

Multiplies two LQ numbers and returns an LQ number.

Parameters

x - multiplicator x (_lq)

y - multiplicator y (_lq)

format - difference between the sum of two input formats and the output format (int16_t)

Returns

Result/product (_lq)

24.5.39 int32_t qmath_version ( void )

Returns the version number of the QMath Library.

Returns

Version number for QMath Library

Referenced by rda_bsp_get_app_version().

24.5.40 void TRF_clarkeLarge32 ( _lq a, _lq b, _lq c, TRF_sVector32_t ∗pVectorAB ) [inline], [static]

Direct Clarke transform of a 32-bit a-b-c vector into a 32-bit alpha-beta vector.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

331

Page 358: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

a - phase A variable

b - phase B variable

c - phase C variable

pVectorAB - pointer to an alpha-beta reference frame vector

Returns

none

References _LQ, _LQmpyInline, TRF_sVector32_t::A, TRF_sVector32_t::B, and SQRT3.

24.5.41 void TRF_iPark32 ( const TRF_orient32_t ∗ pOrient, constTRF_rVector32_t ∗ pVectorDQ, TRF_sVector32_t ∗ pVectorAB )[inline], [static]

Inverse Park transform of a 32-bit d-q vector into a 32-bit alpha-beta vector.

Parameters

pOrient - pointer to the reference frame orientation variable

pVectorDQ - pointer to a d-q reference frame vector

pVectorAB - pointer to an alpha-beta reference frame vector

Returns

none

References _LQmpy, _LQmpyInline, TRF_sVector32_t::A, TRF_sVector32_t::B, TRF_orient32_t::cos←↩Angle, TRF_rVector32_t::d, TRF_rVector32_t::q, and TRF_orient32_t::sinAngle.

24.5.42 void TRF_park32 ( const TRF_orient32_t ∗const pOrient, constTRF_sVector32_t ∗const pVectorAB, TRF_rVector32_t ∗const pVectorDQ) [inline], [static]

Direct Park transform of a 32-bit alpha-beta vector into a 32-bit d-q vector.

332Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 359: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

pOrient - pointer to the reference frame orientation variable

pVectorAB - pointer to an alpha-beta frame vector

pVectorDQ - pointer to a d-q frame vector

Returns

none

References _LQmpy, _LQmpyInline, TRF_sVector32_t::A, TRF_sVector32_t::B, TRF_orient32_t::cos←↩Angle, TRF_rVector32_t::d, TRF_rVector32_t::q, and TRF_orient32_t::sinAngle.

24.5.43 void TRF_park32_16_SQ15 ( const TRF_orient32_t ∗ pOrient, constTRF_sVector16_t ∗ pVectorAB, TRF_rVector16_t ∗ pVectorDQ )[inline], [static]

Direct Park transform of a 16-bit alpha-beta vector into a 16-bit d-q vector (by using 32-bit sine/cosinevalues)

Parameters

pOrient - pointer to the reference frame orientation variable

pVectorAB - pointer to an alpha-beta frame vector

pVectorDQ - pointer to a d-q frame vector

Returns

none

References _LQ30, _LQsatFast, _LQXtoSQY(), _LQZmpyMiniSQLQXYInline, TRF_sVector16_t::A,TRF_sVector16_t::B, TRF_orient32_t::cosAngle, TRF_rVector16_t::d, GLOBAL_LQ, TRF_rVector16←↩_t::q, and TRF_orient32_t::sinAngle.

24.5.44 UTIL_angleWrapAround ( const _lq inputAngle ) [inline], [static]

Angle wrap-around function.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

333

Page 360: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

inputAngle - input angle

Returns

Wrapped angle

References _LQ.

Referenced by UTIL_arcUponChord().

24.5.45 static _sq UTIL_arcUponChord ( bool enableDCInjection, _lq speedEst,_lq anglexTslowscale, _lq(∗)(_lq x) p_LQsinPU ) [inline], [static]

References _LQ, _LQabsFast, _LQmpy, _LQtoSQ, _SQ, _SQdivISQ, PI, and UTIL_angleWrapAround().

334Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 361: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 25Communication25.1 OverviewProvides communication between target MCU and PC GUI.

Functional description

KMS relies on a serial communication protocol including an agent embedded on chip to transfer data fromthe chip to the PC-based user interface. This embedded agent comprises the Communication block.

Code security breakdown

The table below describes the partitioning of Communication block code among open source, library, andprotected execute-only.

Open Source Library Execute-onlyFunctions for initializing, receiving,transmitting

N/A N/A

Execution

For real-time debugging purposes, the Communication block operates at the Fast ISR frequency.

User customization example

If the user advances toward production and no longer requires the KMS graphical user interface for motorcontrol configuration or debugging purposes, the user may choose to remove the Communication block.This will save memory and execution cycles.

Macros• #define UART_RX_BUFFER_SIZE (64U)

UART receive buffer size (in Bytes)• #define UART_TX_BUFFER_SIZE (256U)

UART transmit buffer size (in Bytes)• #define UART_RX_BUFFER_MASK (UART_RX_BUFFER_SIZE - 1U)

NXP SemiconductorsKinetis Motor Suite API Reference Manual

335

Page 362: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

UART Receive buffer mask.• #define UART_TX_BUFFER_MASK (UART_TX_BUFFER_SIZE - 1U)

UART Transmit buffer mask.

Functions• void rda_init (uint8_t ∗push_buffer, uint32_t push_buffer_len, uint16_t freqHz)• void rda_tick (void)

RDA runtime function.• FAST void rda_push_int (void)

Perform push data collection.• uint32_t rda_get_version (void)• void rda_set_interrupt_freq (uint16_t freqHz)• uint16_t rda_get_number_processed_messages (void)

Counts wraps at uint16_t max.• uint8_t uart_rx_byte (void)

Receives a character from UART.• bool uart_rx_data_ready (void)

Checks for data that is waiting in UART.• void uart_tx_byte (uint8_t data)

Transmits a character over UART.• bool uart_tx_full (void)

Checks if transmit buffer is full.• static bool uart_tx_empty (void)

Checks if transmit buffer is empty.• void InitUART (void)

Initilization for UART.• void RDA_UART_ERR_ISR (void)

ISR for UART ORIE.• void RDA_UART_ISR (void)

Single ISR for UART.• if ((UART_GetStatusFlags(KMS_UART)&kUART_TxDataRegEmptyFlag) > 0)

Variables• static uint32_t uartRxCounts = 0UL

UART receive interrupt count (Diagnostics)• static uint32_t uartTxCounts = 0UL

UART transmit interrupt count (Diagnostics)• static uint32_t uartRxDroppedCounts = 0UL• static uint32_t uartTxDroppedCounts = 0UL• static uint32_t uartRxOverRunCounts = 0UL

Number of Rx FIFO Overrun Errors reset by Error ISR Handler (Diagnostics)• static uint32_t uartIsrCounts = 0UL

Number of (Tx Empty / Rx Full) ISR (Diagnostics)• static uint8_t uart_rx_buf [UART_RX_BUFFER_SIZE]

UART software receive buffer (head-tail ring buffer)• static uint8_t uart_tx_buf [UART_TX_BUFFER_SIZE]

UART software transmit buffer (head-tail ring buffer)• static volatile uint32_t uart_rx_head = 0U

UART receive buffer head variable.• static volatile uint32_t uart_rx_tail = 0U

336Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 363: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

UART receive buffer tail variable.• static volatile uint32_t uart_tx_head = 0U

UART transmit buffer head variable.• static volatile uint32_t uart_tx_tail = 0U

UART transmit buffer tail variable.

25.2 Macro Definition Documentation25.2.1 #define UART_RX_BUFFER_MASK (UART_RX_BUFFER_SIZE - 1U)

UART Receive buffer mask.

Referenced by RDA_UART_ISR(), and uart_rx_byte().

25.2.2 #define UART_RX_BUFFER_SIZE (64U)

UART receive buffer size (in Bytes)

25.2.3 #define UART_TX_BUFFER_MASK (UART_TX_BUFFER_SIZE - 1U)

UART Transmit buffer mask.

Referenced by if(), uart_tx_byte(), and uart_tx_full().

25.2.4 #define UART_TX_BUFFER_SIZE (256U)

UART transmit buffer size (in Bytes)

25.3 Function Documentation25.3.1 if ( (UART_GetStatusFlags(KMS_UART)&kUART_TxDataRegEmptyFlag) , 0

)

References uart_tx_buf, UART_TX_BUFFER_MASK, uart_tx_empty(), uart_tx_head, uart_tx_tail, anduartTxCounts.

25.3.2 void InitUART ( void )

Initilization for UART.

Returns

none

NXP SemiconductorsKinetis Motor Suite API Reference Manual

337

Page 364: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

25.3.3 void rda_get_number_processed_messages ( void )

Counts wraps at uint16_t max.

Returns

Total Number of RDA Requests Processed

25.3.4 void rda_get_version ( void )

Returns

revision id

Referenced by rda_bsp_get_app_version().

25.3.5 void rda_init ( uint8_t ∗ push_buffer, uint32_t push_buffer_len, uint16_tfreqHz )

25.3.6 void rda_push_int ( void )

Perform push data collection.

Returns

none

25.3.7 void rda_set_interrupt_freq ( uint16_t freqHz )

25.3.8 void rda_tick ( void )

RDA runtime function.

Returns

none

338Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 365: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

25.3.9 void RDA_UART_ERR_ISR ( void )

ISR for UART ORIE.

Returns

none

References uartRxOverRunCounts.

25.3.10 void RDA_UART_ISR ( void )

Single ISR for UART.

Returns

none

References uart_rx_buf, UART_RX_BUFFER_MASK, uart_rx_head, uart_rx_tail, uart_tx_tail, uartIsr←↩Counts, uartRxCounts, and uartRxDroppedCounts.

25.3.11 uint8_t uart_rx_byte ( void )

Receives a character from UART.

Returns

Received character

References uart_rx_buf, UART_RX_BUFFER_MASK, uart_rx_data_ready(), and uart_rx_tail.

25.3.12 bool uart_rx_data_ready ( void )

Checks for data that is waiting in UART.

Returns

TRUE if data is present, FALSE if it is nottrue if data is present, false if it is not

References uart_rx_head, and uart_rx_tail.

Referenced by uart_rx_byte().

NXP SemiconductorsKinetis Motor Suite API Reference Manual

339

Page 366: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Variable Documentation

25.3.13 void uart_tx_byte ( uint8_t data )

Transmits a character over UART.

Parameters

data - charcter to be transmitted

Returns

none

References uart_tx_buf, UART_TX_BUFFER_MASK, uart_tx_head, uart_tx_tail, and uartTxDropped←↩Counts.

25.3.14 static bool uart_tx_empty ( void ) [static]

Checks if transmit buffer is empty.

Returns

true if transmit buffer is empty, false if not

References uart_tx_head, and uart_tx_tail.

Referenced by if().

25.3.15 bool uart_tx_full ( void )

Checks if transmit buffer is full.

Returns

TRUE if transmit buffer is full, FALSE if nottrue if transmit buffer is full, false if not

References UART_TX_BUFFER_MASK, uart_tx_head, and uart_tx_tail.

25.4 Variable Documentation

25.4.1 uart_rx_buf [static]

UART software receive buffer (head-tail ring buffer)

Referenced by RDA_UART_ISR(), and uart_rx_byte().

340Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 367: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Variable Documentation

25.4.2 uart_rx_head = 0U [static]

UART receive buffer head variable.

Referenced by RDA_UART_ISR(), and uart_rx_data_ready().

25.4.3 uart_rx_tail = 0U [static]

UART receive buffer tail variable.

Referenced by RDA_UART_ISR(), uart_rx_byte(), and uart_rx_data_ready().

25.4.4 uart_tx_buf [static]

UART software transmit buffer (head-tail ring buffer)

Referenced by if(), and uart_tx_byte().

25.4.5 uart_tx_head = 0U [static]

UART transmit buffer head variable.

Referenced by if(), uart_tx_byte(), uart_tx_empty(), and uart_tx_full().

25.4.6 uart_tx_tail = 0U [static]

UART transmit buffer tail variable.

Referenced by if(), RDA_UART_ISR(), uart_tx_byte(), uart_tx_empty(), and uart_tx_full().

25.4.7 uartIsrCounts = 0UL [static]

Number of (Tx Empty / Rx Full) ISR (Diagnostics)

Referenced by RDA_UART_ISR().

25.4.8 uartRxCounts = 0UL [static]

UART receive interrupt count (Diagnostics)

Referenced by RDA_UART_ISR().

NXP SemiconductorsKinetis Motor Suite API Reference Manual

341

Page 368: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Variable Documentation

25.4.9 uint32_t uartRxDroppedCounts = 0UL [static]

Referenced by RDA_UART_ISR().

25.4.10 uartRxOverRunCounts = 0UL [static]

Number of Rx FIFO Overrun Errors reset by Error ISR Handler (Diagnostics)

Referenced by RDA_UART_ERR_ISR().

25.4.11 uartTxCounts = 0UL [static]

UART transmit interrupt count (Diagnostics)

Referenced by if().

25.4.12 uint32_t uartTxDroppedCounts = 0UL [static]

Referenced by uart_tx_byte().

342Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 369: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 26Flash Configuration26.1 OverviewProvides a suggested flash configuration to use mass erase disable functionality.

Functional description

The KV series microcontrollers supported by KMS have a feature called mass erase disable. This isdesigned to prevent the user from erasing the Execute-only library that is factory programmed by NXPonto the microcontroller. For additional details about this functionality see the appropriate KV referencemanuals.

It is important that if you choose to use this functionality, that your toolchain supports this feature of themicrocontroller.

Code security breakdown

The table below describes the partitioning of Flash Configuration block code among open source, library,and protected execute-only.

Open Source Library Execute-onlySuggested flash configuration N/A N/A

Execution

As this software is used to build the flash configuration, it is only used at link-time.

User customization example

The user will likely modify this software to support any required changes in their flash configuration.

Macros• #define BACKDOOR_COMPARE_KEY0 (0xFF)• #define BACKDOOR_COMPARE_KEY1 (0xFF)• #define BACKDOOR_COMPARE_KEY2 (0xFF)• #define BACKDOOR_COMPARE_KEY3 (0xFF)

NXP SemiconductorsKinetis Motor Suite API Reference Manual

343

Page 370: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Macro Definition Documentation

• #define BACKDOOR_COMPARE_KEY4 (0xFF)• #define BACKDOOR_COMPARE_KEY5 (0xFF)• #define BACKDOOR_COMPARE_KEY6 (0xFF)• #define BACKDOOR_COMPARE_KEY7 (0xFF)• #define FPROT_31_24 (0xFF) /∗ No blocks are protected∗/• #define FPROT_23_16 (0xFF) /∗ No blocks are protected∗/• #define FPROT_15_8 (0xFF) /∗ No blocks are protected∗/• #define FPROT_7_0 (0xFF) /∗ No blocks are protected∗/• #define FSEC (0xFE) /∗ KEYEN = 11b MEEN ==11b FSSLAC = 11b FSEC = 10b ∗/

26.2 Macro Definition Documentation

26.2.1 #define BACKDOOR_COMPARE_KEY0 (0xFF)

26.2.2 #define BACKDOOR_COMPARE_KEY1 (0xFF)

26.2.3 #define BACKDOOR_COMPARE_KEY2 (0xFF)

26.2.4 #define BACKDOOR_COMPARE_KEY3 (0xFF)

26.2.5 #define BACKDOOR_COMPARE_KEY4 (0xFF)

26.2.6 #define BACKDOOR_COMPARE_KEY5 (0xFF)

26.2.7 #define BACKDOOR_COMPARE_KEY6 (0xFF)

26.2.8 #define BACKDOOR_COMPARE_KEY7 (0xFF)

26.2.9 #define FPROT_15_8 (0xFF) /∗ No blocks are protected∗/

26.2.10 #define FPROT_23_16 (0xFF) /∗ No blocks are protected∗/

26.2.11 #define FPROT_31_24 (0xFF) /∗ No blocks are protected∗/

26.2.12 #define FPROT_7_0 (0xFF) /∗ No blocks are protected∗/

26.2.13 #define FSEC (0xFE) /∗ KEYEN = 11b MEEN ==11b FSSLAC = 11b FSEC =10b ∗/

344Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 371: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 27Versions27.1 OverviewProvides version information about the subcomponents of the firmware.

Functional description

KMS firmware is updated on a regular basis. The Version block allows for tracking of KMS subcompo-nents to allow for accelerated troubleshooting and debugging.

Code security breakdown

The table below describes the partitioning of Version block code among open source, library, and protectedexecute-only.

Open Source Library Execute-onlyFunctions for determining versionsof math and other subcomponentsas well as dates

N/A N/A

Execution

As this operation is not time-critical, the Version block operates in the Slow ISR.

User customization example

The user will likely consider this code primarily for reporting any bugs to Freescale and to determinealignment of multiple instances of KMS.

Data Structures• struct ST_Ver_t

Typedefs• typedef ST_Ver_t ∗ ST_VER_Handle

Handle to the ST_Ver_t structure.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

345

Page 372: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Overview

Enumerations• enum ST_MathType_e {

FIXED_POINT_16b = 0,FIXED_POINT_32b,FLOAT_POINT_32b }

Defines the math implementations available for the SpinTAC Library.

Functions• uint32_t GetMotorObserverSecureVersion (void)• uint32_t GetMotorObserverNonSecureVersion (void)• bool GetMotorObserverSecureVersionIsCompatible (void)• static void ST_getVersionNumber (ST_VER_Handle handle, uint16_t ∗major, uint16_t ∗minor,

uint16_t ∗revision)Gets the Version Number (Major, Minor, Revision) for SpinTAC Version.

• static int32_t ST_getVersionMath (ST_VER_Handle handle)Gets the Version Math Implementation (FixedPt) for SpinTAC Version.

• static int32_t ST_getVersionDate (ST_VER_Handle handle)Gets the Version Date (Date) for SpinTAC Version.

• static int32_t ST_getSecureROMVersion (ST_VER_Handle handle)Gets the ROM Version Number (SecureROM) for SpinTAC Version.

• ST_VER_Handle ST_initVersion (void ∗pMemory, const size_t numBytes)Initializes the SpinTAC Version object.

• bool ST_getSecureROMIsCompatible (void)Initializes the SpinTAC Version object.

• static void direct_encode_16 (uint8_t ∗pData, uint16_t value)Splits 16-bit data into 2 bytes (Big Endian)

• static void direct_encode_32 (uint8_t ∗pData, uint32_t value)Splits 32-bit data into 4 bytes (Little Endian)

• uint16_t rda_bsp_get_app_version (uint8_t ∗dst, uint16_t buffSize)Give a platform specific version stream to RDA for Read Identity Response.

• bool rda_mem_address_writable (uint32_t address)Platform specific writable address check. Agent with NACK write requests to address if this functionreturns false.

• bool rda_mem_address_readable (uint32_t address)Platform specific readable address check. Agent with NACK read requests to address if this functionreturns false.

Variables• static const char buildDate [ ] = __DATE__• static const char buildTime [] = __TIME__• const uint32_t __checksum• uint32_t m_data_start• uint32_t ramLowAddress = (uint32_t)(&m_data_start)• uint32_t m_data_2_end• uint32_t ramHighAddress = (uint32_t)(&m_data_2_end)• uint32_t m_text_start• uint32_t flashLowAddress = (uint32_t)(&m_text_start)• uint32_t m_text_end• uint32_t flashHighAddress = (uint32_t)(&m_text_end)

346Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 373: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

27.2 Data Structure Documentation

27.2.1 struct ST_Ver_t

Data Fields

int32_t Date Date the library was compiled { format: YYYYMMDD }

uint_least8_t Label[10] Version label

uint16_t Major Major revision number

ST_Math←↩Type_e

MathType Math implementation type

uint16_t Minor Minor revision number

uint16_t Revision Revision number

uint32_t SecureROM Secure ROM Version Number

27.3 Typedef Documentation

27.3.1 ST_VER_Handle

Handle to the ST_Ver_t structure.

27.4 Enumeration Type Documentation

27.4.1 enum ST_MathType_e

Defines the math implementations available for the SpinTAC Library.

Enumerator

FIXED_POINT_16b Fixed point 16 bit implementationFIXED_POINT_32b Fixed point 32 bit implementationFLOAT_POINT_32b Floating point 32 bit implementation

27.5 Function Documentation

27.5.1 void direct_encode_16 ( uint8_t ∗ pData, uint16_t value ) [static]

Splits 16-bit data into 2 bytes (Big Endian)

NXP SemiconductorsKinetis Motor Suite API Reference Manual

347

Page 374: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

pData - pointer to byte data

value - value

Returns

none

Referenced by rda_bsp_get_app_version().

27.5.2 void direct_encode_32 ( uint8_t ∗ pData, uint32_t value ) [static]

Splits 32-bit data into 4 bytes (Little Endian)

Parameters

pData - pointer to byte data

value - value

Returns

none

Referenced by rda_bsp_get_app_version().

27.5.3 uint32_t GetMotorObserverNonSecureVersion ( void )

Referenced by rda_bsp_get_app_version().

27.5.4 uint32_t GetMotorObserverSecureVersion ( void )

Referenced by rda_bsp_get_app_version().

27.5.5 bool GetMotorObserverSecureVersionIsCompatible ( void )

Referenced by DSM_init().

348Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 375: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

27.5.6 uint16_t rda_bsp_get_app_version ( uint8_t ∗ dst, uint16_t buffSize )

Give a platform specific version stream to RDA for Read Identity Response.

Gets the version of the libraries.

Parameters

dst - pointer to buffer to populate

buffSize - length dst buffer

Returns

number of uint8_t(char) written.

Parameters

dst - pointer to byte data

value - value

Returns

number of bytes in this stream

References __checksum, buildDate, buildTime, ST_Ver_t::Date, direct_encode_16(), direct_encode_←↩32(), GetMotorObserverNonSecureVersion(), GetMotorObserverSecureVersion(), ST_Ver_t::Label, ST←↩_Ver_t::Major, ST_Ver_t::MathType, ST_Ver_t::Minor, qmath_version(), rda_get_version(), ST_Ver_t←↩::Revision, ST_Ver_t::SecureROM, and ST_initVersion().

27.5.7 bool rda_mem_address_readable ( uint32_t address )

Platform specific readable address check. Agent with NACK read requests to address if this functionreturns false.

Gets if memory address is readable.

Parameters

address - address of read

Returns

true if safe to dereference otherwise false.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

349

Page 376: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

Parameters

address to attempt write

Returns

true if the memory is readable

References ramLowAddress.

27.5.8 bool rda_mem_address_writable ( uint32_t address )

Platform specific writable address check. Agent with NACK write requests to address if this functionreturns false.

Gets if memory address is writable.

Parameters

address - address of write

Returns

true if safe to write otherwise false.

Parameters

address to attempt write

Returns

true if the memory is writable

References ramLowAddress.

27.5.9 ST_getSecureROMIsCompatible ( void )

Initializes the SpinTAC Version object.

Returns

True if ROM and PUBLIC Libs are compatible

Referenced by DSM_init().

350Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 377: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Function Documentation

27.5.10 ST_getSecureROMVersion ( ST_VER_Handle handle ) [inline],[static]

Gets the ROM Version Number (SecureROM) for SpinTAC Version.

Parameters

handle - The handle for the SpinTAC Version Object

Returns

int32_t SecureROM Secure ROM Version Number

References ST_Ver_t::SecureROM.

27.5.11 ST_getVersionDate ( ST_VER_Handle handle ) [inline], [static]

Gets the Version Date (Date) for SpinTAC Version.

Parameters

handle - The handle for the SpinTAC Version Object

Returns

int32_t Date Date the library was compiled { format: YYYYMMDD }

References ST_Ver_t::Date.

27.5.12 ST_getVersionMath ( ST_VER_Handle handle ) [inline], [static]

Gets the Version Math Implementation (FixedPt) for SpinTAC Version.

Parameters

handle - The handle for the SpinTAC Version Object

Returns

ST_MathType_e MathType Math implementation used in library

References ST_Ver_t::MathType.

NXP SemiconductorsKinetis Motor Suite API Reference Manual

351

Page 378: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Variable Documentation

27.5.13 ST_getVersionNumber ( ST_VER_Handle handle, uint16_t ∗ major,uint16_t ∗ minor, uint16_t ∗ revision ) [inline], [static]

Gets the Version Number (Major, Minor, Revision) for SpinTAC Version.

Parameters

∗major - Major version number

∗minor - Minor version number

∗revision - Revision version number

Returns

none

References ST_Ver_t::Major, ST_Ver_t::Minor, and ST_Ver_t::Revision.

27.5.14 ST_initVersion ( void ∗ pMemory, const size_t numBytes )

Initializes the SpinTAC Version object.

Parameters

∗pMemory Pointer to the memory for ST_Ver_t

numBytes The number of bytes in the ST_Ver_t

Returns

ST_VER_Handle handle The handle for the SpinTAC Version Object

Referenced by rda_bsp_get_app_version().

27.6 Variable Documentation

27.6.1 const uint32_t __checksum

Referenced by rda_bsp_get_app_version().

27.6.2 const char buildDate[ ] = __DATE__ [static]

Referenced by rda_bsp_get_app_version().

352Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 379: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Variable Documentation

27.6.3 const char buildTime[ ] = __TIME__ [static]

Referenced by rda_bsp_get_app_version().

27.6.4 uint32_t flashHighAddress = (uint32_t)(&m_text_end)

27.6.5 uint32_t flashLowAddress = (uint32_t)(&m_text_start)

27.6.6 uint32_t m_data_2_end

27.6.7 uint32_t m_data_start

27.6.8 uint32_t m_text_end

27.6.9 uint32_t m_text_start

27.6.10 uint32_t ramHighAddress = (uint32_t)(&m_data_2_end)

27.6.11 uint32_t ramLowAddress = (uint32_t)(&m_data_start)

Referenced by rda_mem_address_readable(), and rda_mem_address_writable().

NXP SemiconductorsKinetis Motor Suite API Reference Manual

353

Page 380: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Variable Documentation

354Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 381: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

Chapter 28Revision historyDescribes the revisions of this document.

Table: Revision history

Rev. number Date Substantive change(s)3 11/2017 -Updated KMS 1.1.0 to KMS 1.←↩

2.0. Primary change is support ofKV4x MCUs, ACIM (KV3x & K←↩V4x Only), and MCUXpresso.-Added chapters describing FluxEstimator and Hall Estimator.

2 03/2017 -Updated KMS 1.0.1 to KMS 1.1.0.Primary change is support of KV1xMCUs.-Added chapter describing FlashConfiguration.

1 08/2016 -Updated KMS 1.0.0 to KMS 1.0.1

0 02/2016 -Initial release

NXP SemiconductorsKinetis Motor Suite API Reference Manual

355

Page 382: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

356Kinetis Motor Suite API Reference Manual

NXP Semiconductors

Page 383: Kinetis Motor Suite API Reference Manual - NXP … · Kinetis Motor Suite API Reference Manual Kinetis Motor Suite v1.2.0 Document Number: KMSRM Rev. 3 Nov 2017

How to Reach Us:

Home Page:nxp.com/kinetismotorsuite

Web Support:nxp.com/support

Information in this document is provided solely to enable system andsoftware implementers to use NXP products. There are no express orimplied copyright licenses granted hereunder to design or fabricate anyintegrated circuits based on the information in this document. NXPreserves the right to make changes without further notice to anyproducts herein.

NXP makes no warranty, representation, or guarantee regarding thesuitability of its products for any particular purpose, nor does NXPassume any liability arising out of the application or use of any productor circuit, and specifically disclaims any and all liability, including withoutlimitation consequential or incidental damages. “Typical” parametersthat may be provided in NXP data sheets and/or specifications can anddo vary in different applications, and actual performance may vary overtime. All operating parameters, including “typicals,” must be validated foreach customer application by customer’s technical experts. NXP doesnot convey any license under its patent rights nor the rights of others.NXP sells products pursuant to standard terms and conditions of sale,which can be found at the following address:nxp.com/SalesTermsandConditions.

NXP, the NXP logo, Freescale, the Freescale logo, and Kinetis aretrademarks of NXP B.V. All other product or service names are theproperty of their respective owners. Arm and Cortex are the registeredtrademarks of Arm Limited. Arm is a registered trademark of ArmLimited (or its subsidiaries) in the EU or elsewhere. SpinTAC is atrademark of LineStream Technologies, Inc. All rights reserved.

© 2017 NXP B.V.

Document Number: KMSRM

Rev. 3

11/2017