Automotive Math and Motor Control Library Set for KEAx devices User's Guide Document Number: KEAXMCLUG Rev. 7 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 2 NXP Semiconductors Contents Section number Title Page Chapter 1 Revision History Chapter 2 2.1 ATTACHMENT A - NXP Automotive Software License Agreement v1.3................................................................ 67 Chapter 3 Introduction 3.1 Architecture Overview..................................................................................................................................................77 3.2 General Information......................................................................................................................................................78 3.3 Multiple Implementation Support.................................................................................................................................79 3.3.1 Global Configuration Option......................................................................................................................... 79 3.3.2 Additional Parameter Option......................................................................................................................... 80 3.3.3 API Postfix Option.........................................................................................................................................81 3.4 Supported Compilers.................................................................................................................................................... 81 3.5 Matlab Integration.........................................................................................................................................................82 3.6 Installation.....................................................................................................................................................................83 3.7 Library File Structure....................................................................................................................................................86 3.8 Integration Assumption.................................................................................................................................................88 3.9 Library Integration into a Green Hills Multi Development Environment.................................................................... 88 3.10 Library Integration into a Freescale CodeWarrior Eclipse IDE................................................................................... 92 3.11 Library Testing..............................................................................................................................................................95 3.12 3.11.1 AMMCLIB Testing based on the MATLAB Simulink Toolbox.................................................................. 97 3.11.2 AMMCLIB target-in-loop Testing based on the SFIO Toolbox................................................................... 98 Functions Precision.......................................................................................................................................................99 Chapter 4 4.1 Function Index.............................................................................................................................................................. 103 Chapter 5 API References 5.1 Function GDFLIB_FilterFIRInit_F32.......................................................................................................................... 111 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 3 Section number 5.2 5.3 5.4 5.5 Title Page 5.1.1 Declaration..................................................................................................................................................... 111 5.1.2 Arguments...................................................................................................................................................... 111 5.1.3 Return.............................................................................................................................................................111 5.1.4 Description..................................................................................................................................................... 112 5.1.5 Re-entrancy.................................................................................................................................................... 112 5.1.6 Code Example................................................................................................................................................ 112 Function GDFLIB_FilterFIR_F32................................................................................................................................114 5.2.1 Declaration..................................................................................................................................................... 114 5.2.2 Arguments...................................................................................................................................................... 114 5.2.3 Return.............................................................................................................................................................114 5.2.4 Description..................................................................................................................................................... 115 5.2.5 Re-entrancy.................................................................................................................................................... 116 5.2.6 Code Example................................................................................................................................................ 116 Function GDFLIB_FilterFIRInit_F16.......................................................................................................................... 118 5.3.1 Declaration..................................................................................................................................................... 118 5.3.2 Arguments...................................................................................................................................................... 118 5.3.3 Return.............................................................................................................................................................118 5.3.4 Description..................................................................................................................................................... 118 5.3.5 Re-entrancy.................................................................................................................................................... 119 5.3.6 Code Example................................................................................................................................................ 119 Function GDFLIB_FilterFIR_F16................................................................................................................................120 5.4.1 Declaration..................................................................................................................................................... 121 5.4.2 Arguments...................................................................................................................................................... 121 5.4.3 Return.............................................................................................................................................................121 5.4.4 Description..................................................................................................................................................... 121 5.4.5 Re-entrancy.................................................................................................................................................... 122 5.4.6 Code Example................................................................................................................................................ 123 Function GDFLIB_FilterIIR1Init_F32......................................................................................................................... 124 5.5.1 Declaration..................................................................................................................................................... 124 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 4 NXP Semiconductors Section number 5.6 5.7 5.8 5.9 Title Page 5.5.2 Arguments...................................................................................................................................................... 124 5.5.3 Return.............................................................................................................................................................124 5.5.4 Description..................................................................................................................................................... 125 5.5.5 Re-entrancy.................................................................................................................................................... 125 5.5.6 Code Example................................................................................................................................................ 125 Function GDFLIB_FilterIIR1_F32...............................................................................................................................125 5.6.1 Declaration..................................................................................................................................................... 125 5.6.2 Arguments...................................................................................................................................................... 126 5.6.3 Return.............................................................................................................................................................126 5.6.4 Description..................................................................................................................................................... 126 5.6.5 Re-entrancy.................................................................................................................................................... 128 5.6.6 Code Example................................................................................................................................................ 128 Function GDFLIB_FilterIIR1Init_F16......................................................................................................................... 129 5.7.1 Declaration..................................................................................................................................................... 129 5.7.2 Arguments...................................................................................................................................................... 129 5.7.3 Return.............................................................................................................................................................129 5.7.4 Description..................................................................................................................................................... 129 5.7.5 Re-entrancy.................................................................................................................................................... 130 5.7.6 Code Example................................................................................................................................................ 130 Function GDFLIB_FilterIIR1_F16...............................................................................................................................130 5.8.1 Declaration..................................................................................................................................................... 130 5.8.2 Arguments...................................................................................................................................................... 131 5.8.3 Return.............................................................................................................................................................131 5.8.4 Description..................................................................................................................................................... 131 5.8.5 Re-entrancy.................................................................................................................................................... 133 5.8.6 Code Example................................................................................................................................................ 133 Function GDFLIB_FilterIIR2Init_F32......................................................................................................................... 134 5.9.1 Declaration..................................................................................................................................................... 134 5.9.2 Arguments...................................................................................................................................................... 134 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 5 Section number 5.10 5.11 5.12 5.13 Title Page 5.9.3 Return.............................................................................................................................................................134 5.9.4 Description..................................................................................................................................................... 134 5.9.5 Re-entrancy.................................................................................................................................................... 135 5.9.6 Code Example................................................................................................................................................ 135 Function GDFLIB_FilterIIR2_F32...............................................................................................................................135 5.10.1 Declaration..................................................................................................................................................... 135 5.10.2 Arguments...................................................................................................................................................... 136 5.10.3 Return.............................................................................................................................................................136 5.10.4 Description..................................................................................................................................................... 136 5.10.5 Re-entrancy.................................................................................................................................................... 138 5.10.6 Code Example................................................................................................................................................ 138 Function GDFLIB_FilterIIR2Init_F16......................................................................................................................... 139 5.11.1 Declaration..................................................................................................................................................... 139 5.11.2 Arguments...................................................................................................................................................... 139 5.11.3 Return.............................................................................................................................................................140 5.11.4 Description..................................................................................................................................................... 140 5.11.5 Re-entrancy.................................................................................................................................................... 140 5.11.6 Code Example................................................................................................................................................ 140 Function GDFLIB_FilterIIR2_F16...............................................................................................................................141 5.12.1 Declaration..................................................................................................................................................... 141 5.12.2 Arguments...................................................................................................................................................... 141 5.12.3 Return.............................................................................................................................................................141 5.12.4 Description..................................................................................................................................................... 141 5.12.5 Re-entrancy.................................................................................................................................................... 144 5.12.6 Code Example................................................................................................................................................ 144 Function GDFLIB_FilterMAInit_F32.......................................................................................................................... 144 5.13.1 Declaration..................................................................................................................................................... 145 5.13.2 Arguments...................................................................................................................................................... 145 5.13.3 Return.............................................................................................................................................................145 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 6 NXP Semiconductors Section number 5.14 5.15 5.16 5.17 Title Page 5.13.4 Description..................................................................................................................................................... 145 5.13.5 Re-entrancy.................................................................................................................................................... 145 5.13.6 Code Example................................................................................................................................................ 145 Function GDFLIB_FilterMA_F32............................................................................................................................... 146 5.14.1 Declaration..................................................................................................................................................... 146 5.14.2 Arguments...................................................................................................................................................... 146 5.14.3 Return.............................................................................................................................................................146 5.14.4 Description..................................................................................................................................................... 147 5.14.5 Re-entrancy.................................................................................................................................................... 148 5.14.6 Code Example................................................................................................................................................ 148 Function GDFLIB_FilterMAInit_F16.......................................................................................................................... 148 5.15.1 Declaration..................................................................................................................................................... 148 5.15.2 Arguments...................................................................................................................................................... 148 5.15.3 Return.............................................................................................................................................................149 5.15.4 Description..................................................................................................................................................... 149 5.15.5 Re-entrancy.................................................................................................................................................... 149 5.15.6 Code Example................................................................................................................................................ 149 Function GDFLIB_FilterMA_F16............................................................................................................................... 150 5.16.1 Declaration..................................................................................................................................................... 150 5.16.2 Arguments...................................................................................................................................................... 150 5.16.3 Return.............................................................................................................................................................150 5.16.4 Description..................................................................................................................................................... 150 5.16.5 Re-entrancy.................................................................................................................................................... 151 5.16.6 Code Example................................................................................................................................................ 152 Function GFLIB_Acos_F32......................................................................................................................................... 152 5.17.1 Declaration..................................................................................................................................................... 152 5.17.2 Arguments...................................................................................................................................................... 152 5.17.3 Return.............................................................................................................................................................153 5.17.4 Description..................................................................................................................................................... 153 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 7 Section number 5.18 5.19 5.20 5.21 Title Page 5.17.5 Re-entrancy.................................................................................................................................................... 156 5.17.6 Code Example................................................................................................................................................ 156 Function GFLIB_Acos_F16......................................................................................................................................... 157 5.18.1 Declaration..................................................................................................................................................... 157 5.18.2 Arguments...................................................................................................................................................... 157 5.18.3 Return.............................................................................................................................................................157 5.18.4 Description..................................................................................................................................................... 157 5.18.5 Re-entrancy.................................................................................................................................................... 161 5.18.6 Code Example................................................................................................................................................ 161 Function GFLIB_Asin_F32.......................................................................................................................................... 161 5.19.1 Declaration..................................................................................................................................................... 161 5.19.2 Arguments...................................................................................................................................................... 161 5.19.3 Return.............................................................................................................................................................162 5.19.4 Description..................................................................................................................................................... 162 5.19.5 Re-entrancy.................................................................................................................................................... 166 5.19.6 Code Example................................................................................................................................................ 166 Function GFLIB_Asin_F16.......................................................................................................................................... 166 5.20.1 Declaration..................................................................................................................................................... 166 5.20.2 Arguments...................................................................................................................................................... 167 5.20.3 Return.............................................................................................................................................................167 5.20.4 Description..................................................................................................................................................... 167 5.20.5 Re-entrancy.................................................................................................................................................... 171 5.20.6 Code Example................................................................................................................................................ 171 Function GFLIB_Atan_F32..........................................................................................................................................171 5.21.1 Declaration..................................................................................................................................................... 171 5.21.2 Arguments...................................................................................................................................................... 171 5.21.3 Return.............................................................................................................................................................172 5.21.4 Description..................................................................................................................................................... 172 5.21.5 Re-entrancy.................................................................................................................................................... 175 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 8 NXP Semiconductors Section number 5.21.6 5.22 5.23 5.24 5.25 Title Page Code Example................................................................................................................................................ 175 Function GFLIB_Atan_F16..........................................................................................................................................176 5.22.1 Declaration..................................................................................................................................................... 176 5.22.2 Arguments...................................................................................................................................................... 176 5.22.3 Return.............................................................................................................................................................176 5.22.4 Description..................................................................................................................................................... 176 5.22.5 Re-entrancy.................................................................................................................................................... 179 5.22.6 Code Example................................................................................................................................................ 179 Function GFLIB_AtanYX_F32.................................................................................................................................... 180 5.23.1 Declaration..................................................................................................................................................... 180 5.23.2 Arguments...................................................................................................................................................... 180 5.23.3 Return.............................................................................................................................................................180 5.23.4 Description..................................................................................................................................................... 180 5.23.5 Re-entrancy.................................................................................................................................................... 181 5.23.6 Code Example................................................................................................................................................ 181 Function GFLIB_AtanYX_F16.................................................................................................................................... 182 5.24.1 Declaration..................................................................................................................................................... 182 5.24.2 Arguments...................................................................................................................................................... 182 5.24.3 Return.............................................................................................................................................................182 5.24.4 Description..................................................................................................................................................... 182 5.24.5 Re-entrancy.................................................................................................................................................... 183 5.24.6 Code Example................................................................................................................................................ 183 Function GFLIB_AtanYXShifted_F32........................................................................................................................ 184 5.25.1 Declaration..................................................................................................................................................... 184 5.25.2 Arguments...................................................................................................................................................... 184 5.25.3 Return.............................................................................................................................................................185 5.25.4 Description..................................................................................................................................................... 185 5.25.5 Re-entrancy.................................................................................................................................................... 189 5.25.6 Code Example................................................................................................................................................ 189 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 9 Section number 5.26 5.27 5.28 5.29 5.30 Title Page Function GFLIB_AtanYXShifted_F16........................................................................................................................ 190 5.26.1 Declaration..................................................................................................................................................... 190 5.26.2 Arguments...................................................................................................................................................... 190 5.26.3 Return.............................................................................................................................................................190 5.26.4 Description..................................................................................................................................................... 190 5.26.5 Re-entrancy.................................................................................................................................................... 194 5.26.6 Code Example................................................................................................................................................ 194 Function GFLIB_ControllerPIp_F32........................................................................................................................... 195 5.27.1 Declaration..................................................................................................................................................... 195 5.27.2 Arguments...................................................................................................................................................... 196 5.27.3 Return.............................................................................................................................................................196 5.27.4 Description..................................................................................................................................................... 196 5.27.5 Re-entrancy.................................................................................................................................................... 199 5.27.6 Code Example................................................................................................................................................ 199 Function GFLIB_ControllerPIp_F16........................................................................................................................... 200 5.28.1 Declaration..................................................................................................................................................... 200 5.28.2 Arguments...................................................................................................................................................... 200 5.28.3 Return.............................................................................................................................................................200 5.28.4 Description..................................................................................................................................................... 201 5.28.5 Re-entrancy.................................................................................................................................................... 204 5.28.6 Code Example................................................................................................................................................ 204 Function GFLIB_ControllerPIpAW_F32.....................................................................................................................204 5.29.1 Declaration..................................................................................................................................................... 205 5.29.2 Arguments...................................................................................................................................................... 205 5.29.3 Return.............................................................................................................................................................205 5.29.4 Description..................................................................................................................................................... 205 5.29.5 Re-entrancy.................................................................................................................................................... 209 5.29.6 Code Example................................................................................................................................................ 209 Function GFLIB_ControllerPIpAW_F16.....................................................................................................................210 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 10 NXP Semiconductors Section number 5.31 5.32 5.33 5.34 Title Page 5.30.1 Declaration..................................................................................................................................................... 210 5.30.2 Arguments...................................................................................................................................................... 210 5.30.3 Return.............................................................................................................................................................210 5.30.4 Description..................................................................................................................................................... 211 5.30.5 Re-entrancy.................................................................................................................................................... 214 5.30.6 Code Example................................................................................................................................................ 214 Function GFLIB_ControllerPIr_F32............................................................................................................................ 215 5.31.1 Declaration..................................................................................................................................................... 215 5.31.2 Arguments...................................................................................................................................................... 215 5.31.3 Return.............................................................................................................................................................216 5.31.4 Description..................................................................................................................................................... 216 5.31.5 Re-entrancy.................................................................................................................................................... 219 5.31.6 Code Example................................................................................................................................................ 219 Function GFLIB_ControllerPIr_F16............................................................................................................................ 220 5.32.1 Declaration..................................................................................................................................................... 220 5.32.2 Arguments...................................................................................................................................................... 220 5.32.3 Return.............................................................................................................................................................220 5.32.4 Description..................................................................................................................................................... 220 5.32.5 Re-entrancy.................................................................................................................................................... 223 5.32.6 Code Example................................................................................................................................................ 224 Function GFLIB_ControllerPIrAW_F32......................................................................................................................224 5.33.1 Declaration..................................................................................................................................................... 224 5.33.2 Arguments...................................................................................................................................................... 224 5.33.3 Return.............................................................................................................................................................225 5.33.4 Description..................................................................................................................................................... 225 5.33.5 Re-entrancy.................................................................................................................................................... 229 5.33.6 Code Example................................................................................................................................................ 229 Function GFLIB_ControllerPIrAW_F16......................................................................................................................229 5.34.1 Declaration..................................................................................................................................................... 230 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 11 Section number 5.35 5.36 5.37 5.38 Title Page 5.34.2 Arguments...................................................................................................................................................... 230 5.34.3 Return.............................................................................................................................................................230 5.34.4 Description..................................................................................................................................................... 230 5.34.5 Re-entrancy.................................................................................................................................................... 234 5.34.6 Code Example................................................................................................................................................ 234 Function GFLIB_Cos_F32........................................................................................................................................... 235 5.35.1 Declaration..................................................................................................................................................... 235 5.35.2 Arguments...................................................................................................................................................... 235 5.35.3 Return.............................................................................................................................................................235 5.35.4 Description..................................................................................................................................................... 235 5.35.5 Re-entrancy.................................................................................................................................................... 239 5.35.6 Code Example................................................................................................................................................ 239 Function GFLIB_Cos_F16........................................................................................................................................... 240 5.36.1 Declaration..................................................................................................................................................... 240 5.36.2 Arguments...................................................................................................................................................... 240 5.36.3 Return.............................................................................................................................................................240 5.36.4 Description..................................................................................................................................................... 240 5.36.5 Re-entrancy.................................................................................................................................................... 244 5.36.6 Code Example................................................................................................................................................ 244 Function GFLIB_Hyst_F32.......................................................................................................................................... 244 5.37.1 Declaration..................................................................................................................................................... 244 5.37.2 Arguments...................................................................................................................................................... 244 5.37.3 Return.............................................................................................................................................................245 5.37.4 Description..................................................................................................................................................... 245 5.37.5 Re-entrancy.................................................................................................................................................... 246 5.37.6 Code Example................................................................................................................................................ 246 Function GFLIB_Hyst_F16.......................................................................................................................................... 247 5.38.1 Declaration..................................................................................................................................................... 247 5.38.2 Arguments...................................................................................................................................................... 247 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 12 NXP Semiconductors Section number 5.39 5.40 5.41 5.42 Title Page 5.38.3 Return.............................................................................................................................................................247 5.38.4 Description..................................................................................................................................................... 248 5.38.5 Re-entrancy.................................................................................................................................................... 249 5.38.6 Code Example................................................................................................................................................ 249 Function GFLIB_IntegratorTR_F32.............................................................................................................................250 5.39.1 Declaration..................................................................................................................................................... 250 5.39.2 Arguments...................................................................................................................................................... 250 5.39.3 Return.............................................................................................................................................................250 5.39.4 Description..................................................................................................................................................... 250 5.39.5 Re-entrancy.................................................................................................................................................... 252 5.39.6 Code Example................................................................................................................................................ 252 Function GFLIB_IntegratorTR_F16.............................................................................................................................253 5.40.1 Declaration..................................................................................................................................................... 253 5.40.2 Arguments...................................................................................................................................................... 253 5.40.3 Return.............................................................................................................................................................253 5.40.4 Description..................................................................................................................................................... 254 5.40.5 Re-entrancy.................................................................................................................................................... 255 5.40.6 Code Example................................................................................................................................................ 256 Function GFLIB_Limit_F32.........................................................................................................................................256 5.41.1 Declaration..................................................................................................................................................... 256 5.41.2 Arguments...................................................................................................................................................... 257 5.41.3 Return.............................................................................................................................................................257 5.41.4 Description..................................................................................................................................................... 257 5.41.5 Re-entrancy.................................................................................................................................................... 257 5.41.6 Code Example................................................................................................................................................ 257 Function GFLIB_Limit_F16.........................................................................................................................................258 5.42.1 Declaration..................................................................................................................................................... 258 5.42.2 Arguments...................................................................................................................................................... 258 5.42.3 Return.............................................................................................................................................................259 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 13 Section number 5.43 5.44 5.45 5.46 Title Page 5.42.4 Description..................................................................................................................................................... 259 5.42.5 Re-entrancy.................................................................................................................................................... 259 5.42.6 Code Example................................................................................................................................................ 259 Function GFLIB_LowerLimit_F32.............................................................................................................................. 260 5.43.1 Declaration..................................................................................................................................................... 260 5.43.2 Arguments...................................................................................................................................................... 260 5.43.3 Return.............................................................................................................................................................260 5.43.4 Description..................................................................................................................................................... 260 5.43.5 Re-entrancy.................................................................................................................................................... 261 5.43.6 Code Example................................................................................................................................................ 261 Function GFLIB_LowerLimit_F16.............................................................................................................................. 261 5.44.1 Declaration..................................................................................................................................................... 261 5.44.2 Arguments...................................................................................................................................................... 262 5.44.3 Return.............................................................................................................................................................262 5.44.4 Description..................................................................................................................................................... 262 5.44.5 Re-entrancy.................................................................................................................................................... 262 5.44.6 Code Example................................................................................................................................................ 262 Function GFLIB_Lut1D_F32....................................................................................................................................... 263 5.45.1 Declaration..................................................................................................................................................... 263 5.45.2 Arguments...................................................................................................................................................... 263 5.45.3 Return.............................................................................................................................................................264 5.45.4 Description..................................................................................................................................................... 264 5.45.5 Re-entrancy.................................................................................................................................................... 267 5.45.6 Code Example................................................................................................................................................ 267 Function GFLIB_Lut1D_F16....................................................................................................................................... 268 5.46.1 Declaration..................................................................................................................................................... 268 5.46.2 Arguments...................................................................................................................................................... 269 5.46.3 Return.............................................................................................................................................................269 5.46.4 Description..................................................................................................................................................... 269 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 14 NXP Semiconductors Section number 5.47 5.48 5.49 5.50 Title Page 5.46.5 Re-entrancy.................................................................................................................................................... 272 5.46.6 Code Example................................................................................................................................................ 273 Function GFLIB_Lut2D_F32....................................................................................................................................... 274 5.47.1 Declaration..................................................................................................................................................... 274 5.47.2 Arguments...................................................................................................................................................... 274 5.47.3 Return.............................................................................................................................................................274 5.47.4 Description..................................................................................................................................................... 274 5.47.5 Re-entrancy.................................................................................................................................................... 280 5.47.6 Code Example................................................................................................................................................ 280 Function GFLIB_Lut2D_F16....................................................................................................................................... 281 5.48.1 Declaration..................................................................................................................................................... 281 5.48.2 Arguments...................................................................................................................................................... 281 5.48.3 Return.............................................................................................................................................................282 5.48.4 Description..................................................................................................................................................... 282 5.48.5 Re-entrancy.................................................................................................................................................... 287 5.48.6 Code Example................................................................................................................................................ 287 Function GFLIB_Ramp_F32........................................................................................................................................ 289 5.49.1 Declaration..................................................................................................................................................... 289 5.49.2 Arguments...................................................................................................................................................... 289 5.49.3 Return.............................................................................................................................................................289 5.49.4 Description..................................................................................................................................................... 289 5.49.5 Re-entrancy.................................................................................................................................................... 290 5.49.6 Code Example................................................................................................................................................ 290 Function GFLIB_Ramp_F16........................................................................................................................................ 291 5.50.1 Declaration..................................................................................................................................................... 291 5.50.2 Arguments...................................................................................................................................................... 291 5.50.3 Return.............................................................................................................................................................291 5.50.4 Description..................................................................................................................................................... 291 5.50.5 Re-entrancy.................................................................................................................................................... 292 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 15 Section number 5.50.6 5.51 5.52 5.53 5.54 Title Page Code Example................................................................................................................................................ 292 Function GFLIB_Sign_F32.......................................................................................................................................... 293 5.51.1 Declaration..................................................................................................................................................... 293 5.51.2 Arguments...................................................................................................................................................... 293 5.51.3 Return.............................................................................................................................................................294 5.51.4 Description..................................................................................................................................................... 294 5.51.5 Re-entrancy.................................................................................................................................................... 294 5.51.6 Code Example................................................................................................................................................ 294 Function GFLIB_Sign_F16.......................................................................................................................................... 295 5.52.1 Declaration..................................................................................................................................................... 295 5.52.2 Arguments...................................................................................................................................................... 295 5.52.3 Return.............................................................................................................................................................295 5.52.4 Description..................................................................................................................................................... 295 5.52.5 Re-entrancy.................................................................................................................................................... 296 5.52.6 Code Example................................................................................................................................................ 296 Function GFLIB_Sin_F32............................................................................................................................................ 297 5.53.1 Declaration..................................................................................................................................................... 297 5.53.2 Arguments...................................................................................................................................................... 297 5.53.3 Return.............................................................................................................................................................297 5.53.4 Description..................................................................................................................................................... 297 5.53.5 Re-entrancy.................................................................................................................................................... 301 5.53.6 Code Example................................................................................................................................................ 301 Function GFLIB_Sin_F16............................................................................................................................................ 301 5.54.1 Declaration..................................................................................................................................................... 301 5.54.2 Arguments...................................................................................................................................................... 301 5.54.3 Return.............................................................................................................................................................302 5.54.4 Description..................................................................................................................................................... 302 5.54.5 Re-entrancy.................................................................................................................................................... 305 5.54.6 Code Example................................................................................................................................................ 305 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 16 NXP Semiconductors Section number 5.55 5.56 5.57 5.58 5.59 Title Page Function GFLIB_SinCos_F32...................................................................................................................................... 306 5.55.1 Declaration..................................................................................................................................................... 306 5.55.2 Arguments...................................................................................................................................................... 306 5.55.3 Return.............................................................................................................................................................306 5.55.4 Description..................................................................................................................................................... 306 5.55.5 Re-entrancy.................................................................................................................................................... 311 5.55.6 Code Example................................................................................................................................................ 311 Function GFLIB_SinCos_F16...................................................................................................................................... 311 5.56.1 Declaration..................................................................................................................................................... 311 5.56.2 Arguments...................................................................................................................................................... 312 5.56.3 Return.............................................................................................................................................................312 5.56.4 Description..................................................................................................................................................... 312 5.56.5 Re-entrancy.................................................................................................................................................... 316 5.56.6 Code Example................................................................................................................................................ 316 Function GFLIB_Sqrt_F32...........................................................................................................................................317 5.57.1 Declaration..................................................................................................................................................... 317 5.57.2 Arguments...................................................................................................................................................... 317 5.57.3 Return.............................................................................................................................................................317 5.57.4 Description..................................................................................................................................................... 317 5.57.5 Re-entrancy.................................................................................................................................................... 318 5.57.6 Code Example................................................................................................................................................ 318 Function GFLIB_Sqrt_F16...........................................................................................................................................319 5.58.1 Declaration..................................................................................................................................................... 319 5.58.2 Arguments...................................................................................................................................................... 319 5.58.3 Return.............................................................................................................................................................319 5.58.4 Description..................................................................................................................................................... 320 5.58.5 Re-entrancy.................................................................................................................................................... 320 5.58.6 Code Example................................................................................................................................................ 320 Function GFLIB_Tan_F32........................................................................................................................................... 321 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 17 Section number 5.60 5.61 5.62 5.63 Title Page 5.59.1 Declaration..................................................................................................................................................... 321 5.59.2 Arguments...................................................................................................................................................... 321 5.59.3 Return.............................................................................................................................................................321 5.59.4 Description..................................................................................................................................................... 322 5.59.5 Re-entrancy.................................................................................................................................................... 325 5.59.6 Code Example................................................................................................................................................ 325 Function GFLIB_Tan_F16........................................................................................................................................... 326 5.60.1 Declaration..................................................................................................................................................... 326 5.60.2 Arguments...................................................................................................................................................... 326 5.60.3 Return.............................................................................................................................................................326 5.60.4 Description..................................................................................................................................................... 326 5.60.5 Re-entrancy.................................................................................................................................................... 330 5.60.6 Code Example................................................................................................................................................ 330 Function GFLIB_UpperLimit_F32...............................................................................................................................330 5.61.1 Declaration..................................................................................................................................................... 330 5.61.2 Arguments...................................................................................................................................................... 331 5.61.3 Return.............................................................................................................................................................331 5.61.4 Description..................................................................................................................................................... 331 5.61.5 Re-entrancy.................................................................................................................................................... 331 5.61.6 Code Example................................................................................................................................................ 331 Function GFLIB_UpperLimit_F16...............................................................................................................................332 5.62.1 Declaration..................................................................................................................................................... 332 5.62.2 Arguments...................................................................................................................................................... 332 5.62.3 Return.............................................................................................................................................................332 5.62.4 Description..................................................................................................................................................... 333 5.62.5 Re-entrancy.................................................................................................................................................... 333 5.62.6 Code Example................................................................................................................................................ 333 Function GFLIB_VectorLimit_F32..............................................................................................................................334 5.63.1 Declaration..................................................................................................................................................... 334 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 18 NXP Semiconductors Section number 5.64 5.65 5.66 5.67 Title Page 5.63.2 Arguments...................................................................................................................................................... 334 5.63.3 Return.............................................................................................................................................................334 5.63.4 Description..................................................................................................................................................... 334 5.63.5 Re-entrancy.................................................................................................................................................... 336 5.63.6 Code Example................................................................................................................................................ 337 Function GFLIB_VectorLimit_F16..............................................................................................................................337 5.64.1 Declaration..................................................................................................................................................... 337 5.64.2 Arguments...................................................................................................................................................... 338 5.64.3 Return.............................................................................................................................................................338 5.64.4 Description..................................................................................................................................................... 338 5.64.5 Re-entrancy.................................................................................................................................................... 340 5.64.6 Code Example................................................................................................................................................ 340 Function GMCLIB_Clark_F32.....................................................................................................................................340 5.65.1 Declaration..................................................................................................................................................... 340 5.65.2 Arguments...................................................................................................................................................... 341 5.65.3 Return.............................................................................................................................................................341 5.65.4 Description..................................................................................................................................................... 341 5.65.5 Re-entrancy.................................................................................................................................................... 342 5.65.6 Code Example................................................................................................................................................ 342 Function GMCLIB_Clark_F16.....................................................................................................................................342 5.66.1 Declaration..................................................................................................................................................... 342 5.66.2 Arguments...................................................................................................................................................... 342 5.66.3 Return.............................................................................................................................................................343 5.66.4 Description..................................................................................................................................................... 343 5.66.5 Re-entrancy.................................................................................................................................................... 344 5.66.6 Code Example................................................................................................................................................ 344 Function GMCLIB_ClarkInv_F32............................................................................................................................... 344 5.67.1 Declaration..................................................................................................................................................... 344 5.67.2 Arguments...................................................................................................................................................... 344 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 19 Section number 5.68 5.69 5.70 5.71 Title Page 5.67.3 Return.............................................................................................................................................................345 5.67.4 Description..................................................................................................................................................... 345 5.67.5 Re-entrancy.................................................................................................................................................... 346 5.67.6 Code Example................................................................................................................................................ 346 Function GMCLIB_ClarkInv_F16............................................................................................................................... 346 5.68.1 Declaration..................................................................................................................................................... 346 5.68.2 Arguments...................................................................................................................................................... 347 5.68.3 Return.............................................................................................................................................................347 5.68.4 Description..................................................................................................................................................... 347 5.68.5 Re-entrancy.................................................................................................................................................... 348 5.68.6 Code Example................................................................................................................................................ 348 Function GMCLIB_DecouplingPMSM_F32............................................................................................................... 348 5.69.1 Declaration..................................................................................................................................................... 349 5.69.2 Arguments...................................................................................................................................................... 349 5.69.3 Return.............................................................................................................................................................349 5.69.4 Description..................................................................................................................................................... 349 5.69.5 Re-entrancy.................................................................................................................................................... 353 5.69.6 Code Example................................................................................................................................................ 353 Function GMCLIB_DecouplingPMSM_F16............................................................................................................... 354 5.70.1 Declaration..................................................................................................................................................... 354 5.70.2 Arguments...................................................................................................................................................... 354 5.70.3 Return.............................................................................................................................................................355 5.70.4 Description..................................................................................................................................................... 355 5.70.5 Re-entrancy.................................................................................................................................................... 359 5.70.6 Code Example................................................................................................................................................ 359 Function GMCLIB_ElimDcBusRip_F32..................................................................................................................... 360 5.71.1 Declaration..................................................................................................................................................... 360 5.71.2 Arguments...................................................................................................................................................... 360 5.71.3 Return.............................................................................................................................................................360 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 20 NXP Semiconductors Section number 5.72 5.73 5.74 5.75 Title Page 5.71.4 Description..................................................................................................................................................... 360 5.71.5 Re-entrancy.................................................................................................................................................... 363 5.71.6 Code Example................................................................................................................................................ 363 Function GMCLIB_ElimDcBusRip_F16..................................................................................................................... 364 5.72.1 Declaration..................................................................................................................................................... 364 5.72.2 Arguments...................................................................................................................................................... 364 5.72.3 Return.............................................................................................................................................................364 5.72.4 Description..................................................................................................................................................... 364 5.72.5 Re-entrancy.................................................................................................................................................... 366 5.72.6 Code Example................................................................................................................................................ 366 Function GMCLIB_Park_F32...................................................................................................................................... 367 5.73.1 Declaration..................................................................................................................................................... 367 5.73.2 Arguments...................................................................................................................................................... 368 5.73.3 Return.............................................................................................................................................................368 5.73.4 Description..................................................................................................................................................... 368 5.73.5 Re-entrancy.................................................................................................................................................... 369 5.73.6 Code Example................................................................................................................................................ 369 Function GMCLIB_Park_F16...................................................................................................................................... 369 5.74.1 Declaration..................................................................................................................................................... 370 5.74.2 Arguments...................................................................................................................................................... 370 5.74.3 Return.............................................................................................................................................................370 5.74.4 Description..................................................................................................................................................... 370 5.74.5 Re-entrancy.................................................................................................................................................... 371 5.74.6 Code Example................................................................................................................................................ 371 Function GMCLIB_ParkInv_F32.................................................................................................................................372 5.75.1 Declaration..................................................................................................................................................... 372 5.75.2 Arguments...................................................................................................................................................... 372 5.75.3 Return.............................................................................................................................................................372 5.75.4 Description..................................................................................................................................................... 372 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 21 Section number 5.76 5.77 5.78 5.79 Title Page 5.75.5 Re-entrancy.................................................................................................................................................... 373 5.75.6 Code Example................................................................................................................................................ 373 Function GMCLIB_ParkInv_F16.................................................................................................................................374 5.76.1 Declaration..................................................................................................................................................... 374 5.76.2 Arguments...................................................................................................................................................... 374 5.76.3 Return.............................................................................................................................................................374 5.76.4 Description..................................................................................................................................................... 374 5.76.5 Re-entrancy.................................................................................................................................................... 375 5.76.6 Code Example................................................................................................................................................ 375 Function GMCLIB_SvmStd_F32.................................................................................................................................376 5.77.1 Declaration..................................................................................................................................................... 376 5.77.2 Arguments...................................................................................................................................................... 376 5.77.3 Return.............................................................................................................................................................376 5.77.4 Description..................................................................................................................................................... 376 5.77.5 Re-entrancy.................................................................................................................................................... 389 5.77.6 Code Example................................................................................................................................................ 389 Function GMCLIB_SvmStd_F16.................................................................................................................................390 5.78.1 Declaration..................................................................................................................................................... 390 5.78.2 Arguments...................................................................................................................................................... 390 5.78.3 Return.............................................................................................................................................................391 5.78.4 Description..................................................................................................................................................... 391 5.78.5 Re-entrancy.................................................................................................................................................... 403 5.78.6 Code Example................................................................................................................................................ 403 Function MLIB_Abs_F32.............................................................................................................................................404 5.79.1 Declaration..................................................................................................................................................... 404 5.79.2 Arguments...................................................................................................................................................... 404 5.79.3 Return.............................................................................................................................................................404 5.79.4 Description..................................................................................................................................................... 405 5.79.5 Re-entrancy.................................................................................................................................................... 405 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 22 NXP Semiconductors Section number 5.79.6 5.80 5.81 5.82 5.83 Title Page Code Example................................................................................................................................................ 405 Function MLIB_Abs_F16.............................................................................................................................................406 5.80.1 Declaration..................................................................................................................................................... 406 5.80.2 Arguments...................................................................................................................................................... 406 5.80.3 Return.............................................................................................................................................................406 5.80.4 Description..................................................................................................................................................... 406 5.80.5 Re-entrancy.................................................................................................................................................... 407 5.80.6 Code Example................................................................................................................................................ 407 Function MLIB_AbsSat_F32....................................................................................................................................... 407 5.81.1 Declaration..................................................................................................................................................... 407 5.81.2 Arguments...................................................................................................................................................... 407 5.81.3 Return.............................................................................................................................................................408 5.81.4 Description..................................................................................................................................................... 408 5.81.5 Re-entrancy.................................................................................................................................................... 408 5.81.6 Code Example................................................................................................................................................ 408 Function MLIB_AbsSat_F16....................................................................................................................................... 409 5.82.1 Declaration..................................................................................................................................................... 409 5.82.2 Arguments...................................................................................................................................................... 409 5.82.3 Return.............................................................................................................................................................409 5.82.4 Description..................................................................................................................................................... 410 5.82.5 Re-entrancy.................................................................................................................................................... 410 5.82.6 Code Example................................................................................................................................................ 410 Function MLIB_Add_F32............................................................................................................................................ 411 5.83.1 Declaration..................................................................................................................................................... 411 5.83.2 Arguments...................................................................................................................................................... 411 5.83.3 Return.............................................................................................................................................................411 5.83.4 Description..................................................................................................................................................... 411 5.83.5 Re-entrancy:................................................................................................................................................... 412 5.83.6 Code Example:............................................................................................................................................... 412 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 23 Section number 5.84 5.85 5.86 5.87 5.88 Title Page Function MLIB_Add_F16............................................................................................................................................ 412 5.84.1 Declaration..................................................................................................................................................... 412 5.84.2 Arguments...................................................................................................................................................... 412 5.84.3 Return.............................................................................................................................................................413 5.84.4 Description..................................................................................................................................................... 413 5.84.5 Re-entrancy.................................................................................................................................................... 413 5.84.6 Code Example................................................................................................................................................ 413 Function MLIB_AddSat_F32....................................................................................................................................... 414 5.85.1 Declaration..................................................................................................................................................... 414 5.85.2 Arguments...................................................................................................................................................... 414 5.85.3 Return.............................................................................................................................................................414 5.85.4 Description..................................................................................................................................................... 414 5.85.5 Re-entrancy.................................................................................................................................................... 415 5.85.6 Code Example................................................................................................................................................ 415 Function MLIB_AddSat_F16....................................................................................................................................... 416 5.86.1 Declaration..................................................................................................................................................... 416 5.86.2 Arguments...................................................................................................................................................... 416 5.86.3 Return.............................................................................................................................................................416 5.86.4 Description..................................................................................................................................................... 416 5.86.5 Re-entrancy.................................................................................................................................................... 417 5.86.6 Code Example................................................................................................................................................ 417 Function MLIB_Convert_F32F16................................................................................................................................ 417 5.87.1 Declaration..................................................................................................................................................... 417 5.87.2 Arguments...................................................................................................................................................... 418 5.87.3 Return.............................................................................................................................................................418 5.87.4 Description..................................................................................................................................................... 418 5.87.5 Re-entrancy.................................................................................................................................................... 419 5.87.6 Code Example................................................................................................................................................ 419 Function MLIB_Convert_F16F32................................................................................................................................ 419 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 24 NXP Semiconductors Section number 5.89 5.90 5.91 5.92 Title Page 5.88.1 Declaration..................................................................................................................................................... 419 5.88.2 Arguments...................................................................................................................................................... 419 5.88.3 Return.............................................................................................................................................................420 5.88.4 Description..................................................................................................................................................... 420 5.88.5 Re-entrancy.................................................................................................................................................... 420 5.88.6 Code Example................................................................................................................................................ 421 Function MLIB_ConvertPU_F32F16...........................................................................................................................421 5.89.1 Declaration..................................................................................................................................................... 421 5.89.2 Arguments...................................................................................................................................................... 421 5.89.3 Return.............................................................................................................................................................421 5.89.4 Description..................................................................................................................................................... 422 5.89.5 Re-entrancy.................................................................................................................................................... 422 5.89.6 Code Example................................................................................................................................................ 422 Function MLIB_ConvertPU_F16F32...........................................................................................................................423 5.90.1 Declaration..................................................................................................................................................... 423 5.90.2 Arguments...................................................................................................................................................... 423 5.90.3 Return.............................................................................................................................................................423 5.90.4 Description..................................................................................................................................................... 423 5.90.5 Re-entrancy.................................................................................................................................................... 424 5.90.6 Code Example................................................................................................................................................ 424 Function MLIB_Div_F32............................................................................................................................................. 424 5.91.1 Declaration..................................................................................................................................................... 424 5.91.2 Arguments...................................................................................................................................................... 424 5.91.3 Return.............................................................................................................................................................424 5.91.4 Description..................................................................................................................................................... 425 5.91.5 Re-entrancy.................................................................................................................................................... 425 5.91.6 Code Example................................................................................................................................................ 425 Function MLIB_Div_F16............................................................................................................................................. 426 5.92.1 Declaration..................................................................................................................................................... 426 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 25 Section number 5.93 5.94 5.95 5.96 Title Page 5.92.2 Arguments...................................................................................................................................................... 426 5.92.3 Return.............................................................................................................................................................426 5.92.4 Description..................................................................................................................................................... 426 5.92.5 Re-entrancy.................................................................................................................................................... 427 5.92.6 Code Example................................................................................................................................................ 427 Function MLIB_DivSat_F32........................................................................................................................................ 428 5.93.1 Declaration..................................................................................................................................................... 428 5.93.2 Arguments...................................................................................................................................................... 428 5.93.3 Return.............................................................................................................................................................428 5.93.4 Description..................................................................................................................................................... 428 5.93.5 Re-entrancy.................................................................................................................................................... 429 5.93.6 Code Example................................................................................................................................................ 429 Function MLIB_DivSat_F16........................................................................................................................................ 429 5.94.1 Declaration..................................................................................................................................................... 430 5.94.2 Arguments...................................................................................................................................................... 430 5.94.3 Return.............................................................................................................................................................430 5.94.4 Description..................................................................................................................................................... 430 5.94.5 Re-entrancy.................................................................................................................................................... 430 5.94.6 Code Example................................................................................................................................................ 431 Function MLIB_Mac_F32............................................................................................................................................ 431 5.95.1 Declaration..................................................................................................................................................... 431 5.95.2 Arguments...................................................................................................................................................... 431 5.95.3 Return.............................................................................................................................................................432 5.95.4 Description..................................................................................................................................................... 432 5.95.5 Re-entrancy.................................................................................................................................................... 432 5.95.6 Code Example................................................................................................................................................ 432 Function MLIB_Mac_F32F16F16............................................................................................................................... 433 5.96.1 Declaration..................................................................................................................................................... 433 5.96.2 Arguments...................................................................................................................................................... 433 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 26 NXP Semiconductors Section number 5.97 5.98 5.99 Title Page 5.96.3 Return.............................................................................................................................................................434 5.96.4 Description..................................................................................................................................................... 434 5.96.5 Re-entrancy.................................................................................................................................................... 434 5.96.6 Code Example................................................................................................................................................ 434 Function MLIB_Mac_F16............................................................................................................................................ 435 5.97.1 Declaration..................................................................................................................................................... 435 5.97.2 Arguments...................................................................................................................................................... 435 5.97.3 Return.............................................................................................................................................................435 5.97.4 Description..................................................................................................................................................... 436 5.97.5 Re-entrancy.................................................................................................................................................... 436 5.97.6 Code Example................................................................................................................................................ 436 Function MLIB_MacSat_F32.......................................................................................................................................437 5.98.1 Declaration..................................................................................................................................................... 437 5.98.2 Arguments...................................................................................................................................................... 437 5.98.3 Return.............................................................................................................................................................437 5.98.4 Description..................................................................................................................................................... 437 5.98.5 Re-entrancy.................................................................................................................................................... 438 5.98.6 Code Example................................................................................................................................................ 438 Function MLIB_MacSat_F32F16F16.......................................................................................................................... 439 5.99.1 Declaration..................................................................................................................................................... 439 5.99.2 Arguments...................................................................................................................................................... 439 5.99.3 Return.............................................................................................................................................................439 5.99.4 Description..................................................................................................................................................... 439 5.99.5 Re-entrancy.................................................................................................................................................... 440 5.99.6 Code Example................................................................................................................................................ 440 5.100 Function MLIB_MacSat_F16.......................................................................................................................................441 5.100.1 Declaration..................................................................................................................................................... 441 5.100.2 Arguments...................................................................................................................................................... 441 5.100.3 Return.............................................................................................................................................................441 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 27 Section number Title Page 5.100.4 Description..................................................................................................................................................... 441 5.100.5 Re-entrancy.................................................................................................................................................... 442 5.100.6 Code Example................................................................................................................................................ 442 5.101 Function MLIB_Mnac_F32.......................................................................................................................................... 443 5.101.1 Declaration..................................................................................................................................................... 443 5.101.2 Arguments...................................................................................................................................................... 443 5.101.3 Return.............................................................................................................................................................443 5.101.4 Description..................................................................................................................................................... 443 5.101.5 Re-entrancy.................................................................................................................................................... 444 5.101.6 Code Example................................................................................................................................................ 444 5.102 Function MLIB_Mnac_F32F16F16............................................................................................................................. 444 5.102.1 Declaration..................................................................................................................................................... 444 5.102.2 Arguments...................................................................................................................................................... 445 5.102.3 Return.............................................................................................................................................................445 5.102.4 Description..................................................................................................................................................... 445 5.102.5 Re-entrancy.................................................................................................................................................... 446 5.102.6 Code Example................................................................................................................................................ 446 5.103 Function MLIB_Mnac_F16.......................................................................................................................................... 446 5.103.1 Declaration..................................................................................................................................................... 446 5.103.2 Arguments...................................................................................................................................................... 446 5.103.3 Return.............................................................................................................................................................447 5.103.4 Description..................................................................................................................................................... 447 5.103.5 Re-entrancy.................................................................................................................................................... 447 5.103.6 Code Example................................................................................................................................................ 447 5.104 Function MLIB_Msu_F32............................................................................................................................................ 448 5.104.1 Declaration..................................................................................................................................................... 448 5.104.2 Arguments...................................................................................................................................................... 448 5.104.3 Return.............................................................................................................................................................449 5.104.4 Description..................................................................................................................................................... 449 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 28 NXP Semiconductors Section number Title Page 5.104.5 Re-entrancy.................................................................................................................................................... 449 5.104.6 Code Example................................................................................................................................................ 449 5.105 Function MLIB_Msu_F32F16F16............................................................................................................................... 450 5.105.1 Declaration..................................................................................................................................................... 450 5.105.2 Arguments...................................................................................................................................................... 450 5.105.3 Return.............................................................................................................................................................450 5.105.4 Description..................................................................................................................................................... 451 5.105.5 Re-entrancy.................................................................................................................................................... 451 5.105.6 Code Example................................................................................................................................................ 451 5.106 Function MLIB_Msu_F16............................................................................................................................................ 452 5.106.1 Declaration..................................................................................................................................................... 452 5.106.2 Arguments...................................................................................................................................................... 452 5.106.3 Return.............................................................................................................................................................452 5.106.4 Description..................................................................................................................................................... 452 5.106.5 Re-entrancy.................................................................................................................................................... 453 5.106.6 Code Example................................................................................................................................................ 453 5.107 Function MLIB_Mul_F32............................................................................................................................................ 454 5.107.1 Declaration..................................................................................................................................................... 454 5.107.2 Arguments...................................................................................................................................................... 454 5.107.3 Return.............................................................................................................................................................454 5.107.4 Description..................................................................................................................................................... 454 5.107.5 Re-entrancy.................................................................................................................................................... 455 5.107.6 Code Example................................................................................................................................................ 455 5.108 Function MLIB_Mul_F32F16F16................................................................................................................................ 455 5.108.1 Declaration..................................................................................................................................................... 455 5.108.2 Arguments...................................................................................................................................................... 455 5.108.3 Return.............................................................................................................................................................456 5.108.4 Description..................................................................................................................................................... 456 5.108.5 Re-entrancy.................................................................................................................................................... 456 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 29 Section number Title Page 5.108.6 Code Example................................................................................................................................................ 456 5.109 Function MLIB_Mul_F16............................................................................................................................................ 457 5.109.1 Declaration..................................................................................................................................................... 457 5.109.2 Arguments...................................................................................................................................................... 457 5.109.3 Return.............................................................................................................................................................457 5.109.4 Description..................................................................................................................................................... 457 5.109.5 Re-entrancy.................................................................................................................................................... 458 5.109.6 Code Example................................................................................................................................................ 458 5.110 Function MLIB_MulSat_F32....................................................................................................................................... 459 5.110.1 Declaration..................................................................................................................................................... 459 5.110.2 Arguments...................................................................................................................................................... 459 5.110.3 Return.............................................................................................................................................................459 5.110.4 Description..................................................................................................................................................... 459 5.110.5 Re-entrancy.................................................................................................................................................... 460 5.110.6 Code Example................................................................................................................................................ 460 5.111 Function MLIB_MulSat_F32F16F16...........................................................................................................................460 5.111.1 Declaration..................................................................................................................................................... 460 5.111.2 Arguments...................................................................................................................................................... 461 5.111.3 Return.............................................................................................................................................................461 5.111.4 Description..................................................................................................................................................... 461 5.111.5 Re-entrancy.................................................................................................................................................... 461 5.111.6 Code Example................................................................................................................................................ 462 5.112 Function MLIB_MulSat_F16....................................................................................................................................... 462 5.112.1 Declaration..................................................................................................................................................... 462 5.112.2 Arguments...................................................................................................................................................... 462 5.112.3 Return.............................................................................................................................................................462 5.112.4 Description..................................................................................................................................................... 463 5.112.5 Re-entrancy.................................................................................................................................................... 463 5.112.6 Code Example................................................................................................................................................ 463 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 30 NXP Semiconductors Section number Title Page 5.113 Function MLIB_Neg_F32............................................................................................................................................ 464 5.113.1 Declaration..................................................................................................................................................... 464 5.113.2 Arguments...................................................................................................................................................... 464 5.113.3 Return.............................................................................................................................................................464 5.113.4 Description..................................................................................................................................................... 464 5.113.5 Re-entrancy.................................................................................................................................................... 465 5.113.6 Code Example................................................................................................................................................ 465 5.114 Function MLIB_Neg_F16............................................................................................................................................ 465 5.114.1 Declaration..................................................................................................................................................... 465 5.114.2 Arguments...................................................................................................................................................... 466 5.114.3 Return.............................................................................................................................................................466 5.114.4 Description..................................................................................................................................................... 466 5.114.5 Re-entrancy.................................................................................................................................................... 466 5.114.6 Code Example................................................................................................................................................ 466 5.115 Function MLIB_NegSat_F32....................................................................................................................................... 467 5.115.1 Declaration..................................................................................................................................................... 467 5.115.2 Arguments...................................................................................................................................................... 467 5.115.3 Return.............................................................................................................................................................467 5.115.4 Description..................................................................................................................................................... 468 5.115.5 Re-entrancy.................................................................................................................................................... 468 5.115.6 Code Example................................................................................................................................................ 468 5.116 Function MLIB_NegSat_F16....................................................................................................................................... 469 5.116.1 Declaration..................................................................................................................................................... 469 5.116.2 Arguments...................................................................................................................................................... 469 5.116.3 Return.............................................................................................................................................................469 5.116.4 Description..................................................................................................................................................... 469 5.116.5 Re-entrancy.................................................................................................................................................... 470 5.116.6 Code Example................................................................................................................................................ 470 5.117 Function MLIB_Norm_F32..........................................................................................................................................470 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 31 Section number Title Page 5.117.1 Declaration..................................................................................................................................................... 470 5.117.2 Arguments...................................................................................................................................................... 471 5.117.3 Return.............................................................................................................................................................471 5.117.4 Description..................................................................................................................................................... 471 5.117.5 Re-entrancy.................................................................................................................................................... 471 5.117.6 Code Example................................................................................................................................................ 471 5.118 Function MLIB_Norm_F16..........................................................................................................................................472 5.118.1 Declaration..................................................................................................................................................... 472 5.118.2 Arguments...................................................................................................................................................... 472 5.118.3 Return.............................................................................................................................................................472 5.118.4 Description..................................................................................................................................................... 472 5.118.5 Re-entrancy.................................................................................................................................................... 472 5.118.6 Code Example................................................................................................................................................ 473 5.119 Function MLIB_RndSat_F16F32................................................................................................................................. 473 5.119.1 Declaration..................................................................................................................................................... 473 5.119.2 Arguments...................................................................................................................................................... 473 5.119.3 Return.............................................................................................................................................................474 5.119.4 Description..................................................................................................................................................... 474 5.119.5 Re-entrancy.................................................................................................................................................... 474 5.119.6 Code Example................................................................................................................................................ 474 5.120 Function MLIB_Round_F32........................................................................................................................................ 474 5.120.1 Declaration..................................................................................................................................................... 474 5.120.2 Arguments...................................................................................................................................................... 474 5.120.3 Return.............................................................................................................................................................475 5.120.4 Description..................................................................................................................................................... 475 5.120.5 Re-entrancy.................................................................................................................................................... 475 5.120.6 Code Example................................................................................................................................................ 475 5.121 Function MLIB_Round_F16........................................................................................................................................ 476 5.121.1 Declaration..................................................................................................................................................... 476 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 32 NXP Semiconductors Section number Title Page 5.121.2 Arguments...................................................................................................................................................... 476 5.121.3 Return.............................................................................................................................................................477 5.121.4 Description..................................................................................................................................................... 477 5.121.5 Re-entrancy.................................................................................................................................................... 477 5.121.6 Code Example................................................................................................................................................ 477 5.122 Function MLIB_ShBi_F32........................................................................................................................................... 478 5.122.1 Declaration..................................................................................................................................................... 478 5.122.2 Arguments...................................................................................................................................................... 478 5.122.3 Return.............................................................................................................................................................478 5.122.4 Description..................................................................................................................................................... 479 5.122.5 Re-entrancy.................................................................................................................................................... 479 5.122.6 Code Example................................................................................................................................................ 479 5.123 Function MLIB_ShBi_F16........................................................................................................................................... 479 5.123.1 Declaration..................................................................................................................................................... 480 5.123.2 Arguments...................................................................................................................................................... 480 5.123.3 Return.............................................................................................................................................................480 5.123.4 Description..................................................................................................................................................... 480 5.123.5 Re-entrancy.................................................................................................................................................... 480 5.123.6 Code Example................................................................................................................................................ 481 5.124 Function MLIB_ShBiSat_F32...................................................................................................................................... 481 5.124.1 Declaration..................................................................................................................................................... 481 5.124.2 Arguments...................................................................................................................................................... 481 5.124.3 Return.............................................................................................................................................................482 5.124.4 Description..................................................................................................................................................... 482 5.124.5 Re-entrancy.................................................................................................................................................... 482 5.124.6 Code Example................................................................................................................................................ 482 5.125 Function MLIB_ShBiSat_F16...................................................................................................................................... 483 5.125.1 Declaration..................................................................................................................................................... 483 5.125.2 Arguments...................................................................................................................................................... 483 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 33 Section number Title Page 5.125.3 Return.............................................................................................................................................................483 5.125.4 Description..................................................................................................................................................... 483 5.125.5 Re-entrancy.................................................................................................................................................... 484 5.125.6 Code Example................................................................................................................................................ 484 5.126 Function MLIB_ShL_F32............................................................................................................................................ 484 5.126.1 Declaration..................................................................................................................................................... 484 5.126.2 Arguments...................................................................................................................................................... 484 5.126.3 Return.............................................................................................................................................................485 5.126.4 Description..................................................................................................................................................... 485 5.126.5 Re-entrancy.................................................................................................................................................... 485 5.126.6 Code Example................................................................................................................................................ 485 5.127 Function MLIB_ShL_F16............................................................................................................................................ 486 5.127.1 Declaration..................................................................................................................................................... 486 5.127.2 Arguments...................................................................................................................................................... 486 5.127.3 Return.............................................................................................................................................................486 5.127.4 Description..................................................................................................................................................... 486 5.127.5 Re-entrancy.................................................................................................................................................... 487 5.127.6 Code Example................................................................................................................................................ 487 5.128 Function MLIB_ShLSat_F32....................................................................................................................................... 487 5.128.1 Declaration..................................................................................................................................................... 487 5.128.2 Arguments...................................................................................................................................................... 488 5.128.3 Return.............................................................................................................................................................488 5.128.4 Description..................................................................................................................................................... 488 5.128.5 Re-entrancy.................................................................................................................................................... 488 5.128.6 Code Example................................................................................................................................................ 488 5.129 Function MLIB_ShLSat_F16....................................................................................................................................... 489 5.129.1 Declaration..................................................................................................................................................... 489 5.129.2 Arguments...................................................................................................................................................... 489 5.129.3 Return.............................................................................................................................................................489 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 34 NXP Semiconductors Section number Title Page 5.129.4 Description..................................................................................................................................................... 490 5.129.5 Re-entrancy.................................................................................................................................................... 490 5.129.6 Code Example................................................................................................................................................ 490 5.130 Function MLIB_ShR_F32............................................................................................................................................ 491 5.130.1 Declaration..................................................................................................................................................... 491 5.130.2 Arguments...................................................................................................................................................... 491 5.130.3 Return.............................................................................................................................................................491 5.130.4 Description..................................................................................................................................................... 491 5.130.5 Re-entrancy.................................................................................................................................................... 491 5.130.6 Code Example................................................................................................................................................ 492 5.131 Function MLIB_ShR_F16............................................................................................................................................ 492 5.131.1 Declaration..................................................................................................................................................... 492 5.131.2 Arguments...................................................................................................................................................... 492 5.131.3 Return.............................................................................................................................................................493 5.131.4 Description..................................................................................................................................................... 493 5.131.5 Re-entrancy.................................................................................................................................................... 493 5.131.6 Code Example................................................................................................................................................ 493 5.132 Function MLIB_Sub_F32.............................................................................................................................................494 5.132.1 Declaration..................................................................................................................................................... 494 5.132.2 Arguments...................................................................................................................................................... 494 5.132.3 Return.............................................................................................................................................................494 5.132.4 Description..................................................................................................................................................... 494 5.132.5 Re-entrancy.................................................................................................................................................... 495 5.132.6 Code Example................................................................................................................................................ 495 5.133 Function MLIB_Sub_F16.............................................................................................................................................496 5.133.1 Declaration..................................................................................................................................................... 496 5.133.2 Arguments...................................................................................................................................................... 496 5.133.3 Return.............................................................................................................................................................496 5.133.4 Description..................................................................................................................................................... 496 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 35 Section number Title Page 5.133.5 Re-entrancy.................................................................................................................................................... 497 5.133.6 Code Example................................................................................................................................................ 497 5.134 Function MLIB_SubSat_F32........................................................................................................................................497 5.134.1 Declaration..................................................................................................................................................... 497 5.134.2 Arguments...................................................................................................................................................... 497 5.134.3 Return.............................................................................................................................................................498 5.134.4 Description..................................................................................................................................................... 498 5.134.5 Re-entrancy.................................................................................................................................................... 498 5.134.6 Code Example................................................................................................................................................ 498 5.135 Function MLIB_SubSat_F16........................................................................................................................................499 5.135.1 Declaration..................................................................................................................................................... 499 5.135.2 Arguments...................................................................................................................................................... 499 5.135.3 Return.............................................................................................................................................................499 5.135.4 Description..................................................................................................................................................... 500 5.135.5 Re-entrancy.................................................................................................................................................... 500 5.135.6 Code Example................................................................................................................................................ 500 5.136 Function MLIB_VMac_F32......................................................................................................................................... 501 5.136.1 Declaration..................................................................................................................................................... 501 5.136.2 Arguments...................................................................................................................................................... 501 5.136.3 Return.............................................................................................................................................................501 5.136.4 Description..................................................................................................................................................... 501 5.136.5 Re-entrancy.................................................................................................................................................... 502 5.136.6 Code Example................................................................................................................................................ 502 5.137 Function MLIB_VMac_F32F16F16.............................................................................................................................503 5.137.1 Declaration..................................................................................................................................................... 503 5.137.2 Arguments...................................................................................................................................................... 503 5.137.3 Return.............................................................................................................................................................503 5.137.4 Description..................................................................................................................................................... 503 5.137.5 Re-entrancy.................................................................................................................................................... 504 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 36 NXP Semiconductors Section number Title Page 5.137.6 Code Example................................................................................................................................................ 504 5.138 Function MLIB_VMac_F16......................................................................................................................................... 504 5.138.1 Declaration..................................................................................................................................................... 504 5.138.2 Arguments...................................................................................................................................................... 505 5.138.3 Return.............................................................................................................................................................505 5.138.4 Description..................................................................................................................................................... 505 5.138.5 Re-entrancy.................................................................................................................................................... 505 5.138.6 Code Example................................................................................................................................................ 506 5.139 Function SWLIBS_GetVersion.................................................................................................................................... 506 5.139.1 Declaration..................................................................................................................................................... 506 5.139.2 Return.............................................................................................................................................................506 5.139.3 Description..................................................................................................................................................... 507 5.139.4 Reentrancy..................................................................................................................................................... 507 Chapter 6 6.1 Typedefs Index..............................................................................................................................................................509 Chapter 7 Compound Data Types 7.1 7.2 7.3 7.4 GDFLIB_FILTER_IIR1_COEFF_T_F16.................................................................................................................... 513 7.1.1 Description..................................................................................................................................................... 513 7.1.2 Compound Type Members.............................................................................................................................513 GDFLIB_FILTER_IIR1_COEFF_T_F32.................................................................................................................... 514 7.2.1 Description..................................................................................................................................................... 514 7.2.2 Compound Type Members.............................................................................................................................514 GDFLIB_FILTER_IIR1_T_F16...................................................................................................................................514 7.3.1 Description..................................................................................................................................................... 514 7.3.2 Compound Type Members.............................................................................................................................515 GDFLIB_FILTER_IIR1_T_F32...................................................................................................................................515 7.4.1 Description..................................................................................................................................................... 515 7.4.2 Compound Type Members.............................................................................................................................515 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 37 Section number 7.5 7.6 7.7 7.8 7.9 7.10 7.11 7.12 7.13 7.14 Title Page GDFLIB_FILTER_IIR2_COEFF_T_F16.................................................................................................................... 515 7.5.1 Description..................................................................................................................................................... 516 7.5.2 Compound Type Members.............................................................................................................................516 GDFLIB_FILTER_IIR2_COEFF_T_F32.................................................................................................................... 516 7.6.1 Description..................................................................................................................................................... 516 7.6.2 Compound Type Members.............................................................................................................................516 GDFLIB_FILTER_IIR2_T_F16...................................................................................................................................517 7.7.1 Description..................................................................................................................................................... 517 7.7.2 Compound Type Members.............................................................................................................................517 GDFLIB_FILTER_IIR2_T_F32...................................................................................................................................517 7.8.1 Description..................................................................................................................................................... 518 7.8.2 Compound Type Members.............................................................................................................................518 GDFLIB_FILTER_MA_T_F16................................................................................................................................... 518 7.9.1 Description..................................................................................................................................................... 518 7.9.2 Compound Type Members.............................................................................................................................518 GDFLIB_FILTER_MA_T_F32................................................................................................................................... 518 7.10.1 Description..................................................................................................................................................... 519 7.10.2 Compound Type Members.............................................................................................................................519 GDFLIB_FILTERFIR_PARAM_T_F16..................................................................................................................... 519 7.11.1 Description..................................................................................................................................................... 519 7.11.2 Compound Type Members.............................................................................................................................519 GDFLIB_FILTERFIR_PARAM_T_F32..................................................................................................................... 519 7.12.1 Description..................................................................................................................................................... 520 7.12.2 Compound Type Members.............................................................................................................................520 GDFLIB_FILTERFIR_STATE_T_F16....................................................................................................................... 520 7.13.1 Description..................................................................................................................................................... 520 7.13.2 Compound Type Members.............................................................................................................................520 GDFLIB_FILTERFIR_STATE_T_F32....................................................................................................................... 520 7.14.1 Description..................................................................................................................................................... 521 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 38 NXP Semiconductors Section number 7.14.2 7.15 7.16 7.17 7.18 7.19 7.20 7.21 7.22 7.23 7.24 Title Page Compound Type Members.............................................................................................................................521 GFLIB_ACOS_T_F16..................................................................................................................................................521 7.15.1 Description..................................................................................................................................................... 521 7.15.2 Compound Type Members.............................................................................................................................521 GFLIB_ACOS_T_F32..................................................................................................................................................521 7.16.1 Description..................................................................................................................................................... 522 7.16.2 Compound Type Members.............................................................................................................................522 GFLIB_ACOS_TAYLOR_COEF_T_F16................................................................................................................... 522 7.17.1 Description..................................................................................................................................................... 522 7.17.2 Compound Type Members.............................................................................................................................522 GFLIB_ACOS_TAYLOR_COEF_T_F32................................................................................................................... 522 7.18.1 Description..................................................................................................................................................... 523 7.18.2 Compound Type Members.............................................................................................................................523 GFLIB_ASIN_T_F16................................................................................................................................................... 523 7.19.1 Description..................................................................................................................................................... 523 7.19.2 Compound Type Members.............................................................................................................................523 GFLIB_ASIN_T_F32................................................................................................................................................... 523 7.20.1 Description..................................................................................................................................................... 524 7.20.2 Compound Type Members.............................................................................................................................524 GFLIB_ASIN_TAYLOR_COEF_T_F16.....................................................................................................................524 7.21.1 Description..................................................................................................................................................... 524 7.21.2 Compound Type Members.............................................................................................................................524 GFLIB_ASIN_TAYLOR_COEF_T_F32.....................................................................................................................524 7.22.1 Description..................................................................................................................................................... 524 7.22.2 Compound Type Members.............................................................................................................................525 GFLIB_ATAN_T_F16................................................................................................................................................. 525 7.23.1 Description..................................................................................................................................................... 525 7.23.2 Compound Type Members.............................................................................................................................525 GFLIB_ATAN_T_F32................................................................................................................................................. 525 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 39 Section number 7.25 7.26 7.27 7.28 7.29 7.30 7.31 7.32 7.33 Title Page 7.24.1 Description..................................................................................................................................................... 525 7.24.2 Compound Type Members.............................................................................................................................526 GFLIB_ATAN_TAYLOR_COEF_T_F16...................................................................................................................526 7.25.1 Description..................................................................................................................................................... 526 7.25.2 Compound Type Members.............................................................................................................................526 GFLIB_ATAN_TAYLOR_COEF_T_F32...................................................................................................................526 7.26.1 Description..................................................................................................................................................... 526 7.26.2 Compound Type Members.............................................................................................................................527 GFLIB_ATANYXSHIFTED_T_F16........................................................................................................................... 527 7.27.1 Description..................................................................................................................................................... 527 7.27.2 Compound Type Members.............................................................................................................................527 GFLIB_ATANYXSHIFTED_T_F32........................................................................................................................... 527 7.28.1 Description..................................................................................................................................................... 528 7.28.2 Compound Type Members.............................................................................................................................528 GFLIB_CONTROLLER_PI_P_T_F16........................................................................................................................ 528 7.29.1 Description..................................................................................................................................................... 528 7.29.2 Compound Type Members.............................................................................................................................528 GFLIB_CONTROLLER_PI_P_T_F32........................................................................................................................ 529 7.30.1 Description..................................................................................................................................................... 529 7.30.2 Compound Type Members.............................................................................................................................529 GFLIB_CONTROLLER_PI_R_T_F16........................................................................................................................529 7.31.1 Description..................................................................................................................................................... 529 7.31.2 Compound Type Members.............................................................................................................................529 GFLIB_CONTROLLER_PI_R_T_F32........................................................................................................................530 7.32.1 Description..................................................................................................................................................... 530 7.32.2 Compound Type Members.............................................................................................................................530 GFLIB_CONTROLLER_PIAW_P_T_F16................................................................................................................. 531 7.33.1 Description..................................................................................................................................................... 531 7.33.2 Compound Type Members.............................................................................................................................531 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 40 NXP Semiconductors Section number 7.34 7.35 7.36 7.37 7.38 7.39 7.40 7.41 7.42 7.43 Title Page GFLIB_CONTROLLER_PIAW_P_T_F32................................................................................................................. 531 7.34.1 Description..................................................................................................................................................... 531 7.34.2 Compound Type Members.............................................................................................................................532 GFLIB_CONTROLLER_PIAW_R_T_F16................................................................................................................. 532 7.35.1 Description..................................................................................................................................................... 532 7.35.2 Compound Type Members.............................................................................................................................532 GFLIB_CONTROLLER_PIAW_R_T_F32................................................................................................................. 533 7.36.1 Description..................................................................................................................................................... 533 7.36.2 Compound Type Members.............................................................................................................................533 GFLIB_COS_T_F16.................................................................................................................................................... 534 7.37.1 Description..................................................................................................................................................... 534 7.37.2 Compound Type Members.............................................................................................................................534 GFLIB_COS_T_F32.................................................................................................................................................... 534 7.38.1 Description..................................................................................................................................................... 534 7.38.2 Compound Type Members.............................................................................................................................534 GFLIB_HYST_T_F16..................................................................................................................................................535 7.39.1 Description..................................................................................................................................................... 535 7.39.2 Compound Type Members.............................................................................................................................535 GFLIB_HYST_T_F32..................................................................................................................................................535 7.40.1 Description..................................................................................................................................................... 535 7.40.2 Compound Type Members.............................................................................................................................536 GFLIB_INTEGRATOR_TR_T_F16............................................................................................................................536 7.41.1 Description..................................................................................................................................................... 536 7.41.2 Compound Type Members.............................................................................................................................536 GFLIB_INTEGRATOR_TR_T_F32............................................................................................................................536 7.42.1 Description..................................................................................................................................................... 537 7.42.2 Compound Type Members.............................................................................................................................537 GFLIB_LIMIT_T_F16................................................................................................................................................. 537 7.43.1 Description..................................................................................................................................................... 537 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 41 Section number 7.43.2 7.44 7.45 7.46 7.47 7.48 7.49 7.50 7.51 7.52 7.53 Title Page Compound Type Members.............................................................................................................................537 GFLIB_LIMIT_T_F32................................................................................................................................................. 537 7.44.1 Description..................................................................................................................................................... 538 7.44.2 Compound Type Members.............................................................................................................................538 GFLIB_LOWERLIMIT_T_F16................................................................................................................................... 538 7.45.1 Description..................................................................................................................................................... 538 7.45.2 Compound Type Members.............................................................................................................................538 GFLIB_LOWERLIMIT_T_F32................................................................................................................................... 538 7.46.1 Description..................................................................................................................................................... 538 7.46.2 Compound Type Members.............................................................................................................................539 GFLIB_LUT1D_T_F16................................................................................................................................................539 7.47.1 Description..................................................................................................................................................... 539 7.47.2 Compound Type Members.............................................................................................................................539 GFLIB_LUT1D_T_F32................................................................................................................................................539 7.48.1 Description..................................................................................................................................................... 539 7.48.2 Compound Type Members.............................................................................................................................539 GFLIB_LUT2D_T_F16................................................................................................................................................540 7.49.1 Description..................................................................................................................................................... 540 7.49.2 Compound Type Members.............................................................................................................................540 GFLIB_LUT2D_T_F32................................................................................................................................................540 7.50.1 Description..................................................................................................................................................... 540 7.50.2 Compound Type Members.............................................................................................................................541 GFLIB_RAMP_T_F16................................................................................................................................................. 541 7.51.1 Description..................................................................................................................................................... 541 7.51.2 Compound Type Members.............................................................................................................................541 GFLIB_RAMP_T_F32................................................................................................................................................. 541 7.52.1 Description..................................................................................................................................................... 541 7.52.2 Compound Type Members.............................................................................................................................542 GFLIB_SIN_T_F16......................................................................................................................................................542 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 42 NXP Semiconductors Section number 7.54 7.55 7.56 7.57 7.58 7.59 7.60 7.61 7.62 Title Page 7.53.1 Description..................................................................................................................................................... 542 7.53.2 Compound Type Members.............................................................................................................................542 GFLIB_SIN_T_F32......................................................................................................................................................542 7.54.1 Description..................................................................................................................................................... 542 7.54.2 Compound Type Members.............................................................................................................................543 GFLIB_SINCOS_T_F16.............................................................................................................................................. 543 7.55.1 Description..................................................................................................................................................... 543 7.55.2 Compound Type Members.............................................................................................................................543 GFLIB_SINCOS_T_F32.............................................................................................................................................. 543 7.56.1 Description..................................................................................................................................................... 543 7.56.2 Compound Type Members.............................................................................................................................544 GFLIB_TAN_T_F16.................................................................................................................................................... 544 7.57.1 Description..................................................................................................................................................... 544 7.57.2 Compound Type Members.............................................................................................................................544 GFLIB_TAN_T_F32.................................................................................................................................................... 544 7.58.1 Description..................................................................................................................................................... 544 7.58.2 Compound Type Members.............................................................................................................................545 GFLIB_TAN_TAYLOR_COEF_T_F16......................................................................................................................545 7.59.1 Description..................................................................................................................................................... 545 7.59.2 Compound Type Members.............................................................................................................................545 GFLIB_TAN_TAYLOR_COEF_T_F32......................................................................................................................545 7.60.1 Description..................................................................................................................................................... 546 7.60.2 Compound Type Members.............................................................................................................................546 GFLIB_UPPERLIMIT_T_F16.....................................................................................................................................546 7.61.1 Description..................................................................................................................................................... 546 7.61.2 Compound Type Members.............................................................................................................................546 GFLIB_UPPERLIMIT_T_F32.....................................................................................................................................546 7.62.1 Description..................................................................................................................................................... 546 7.62.2 Compound Type Members.............................................................................................................................547 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 43 Section number 7.63 7.64 7.65 7.66 7.67 7.68 7.69 7.70 7.71 7.72 Title Page GFLIB_VECTORLIMIT_T_F16................................................................................................................................. 547 7.63.1 Description..................................................................................................................................................... 547 7.63.2 Compound Type Members.............................................................................................................................547 GFLIB_VECTORLIMIT_T_F32................................................................................................................................. 547 7.64.1 Description..................................................................................................................................................... 547 7.64.2 Compound Type Members.............................................................................................................................548 GMCLIB_DECOUPLINGPMSM_T_F16................................................................................................................... 548 7.65.1 Description..................................................................................................................................................... 548 7.65.2 Compound Type Members.............................................................................................................................548 GMCLIB_DECOUPLINGPMSM_T_F32................................................................................................................... 548 7.66.1 Description..................................................................................................................................................... 548 7.66.2 Compound Type Members.............................................................................................................................548 GMCLIB_ELIMDCBUSRIP_T_F16........................................................................................................................... 549 7.67.1 Description..................................................................................................................................................... 549 7.67.2 Compound Type Members.............................................................................................................................549 GMCLIB_ELIMDCBUSRIP_T_F32........................................................................................................................... 549 7.68.1 Description..................................................................................................................................................... 549 7.68.2 Compound Type Members.............................................................................................................................550 SWLIBS_2Syst_F16.....................................................................................................................................................550 7.69.1 Description..................................................................................................................................................... 550 7.69.2 Compound Type Members.............................................................................................................................550 SWLIBS_2Syst_F32.....................................................................................................................................................550 7.70.1 Description..................................................................................................................................................... 550 7.70.2 Compound Type Members.............................................................................................................................550 SWLIBS_3Syst_F16.....................................................................................................................................................551 7.71.1 Description..................................................................................................................................................... 551 7.71.2 Compound Type Members.............................................................................................................................551 SWLIBS_3Syst_F32.....................................................................................................................................................551 7.72.1 Description..................................................................................................................................................... 551 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 44 NXP Semiconductors Section number 7.72.2 7.73 Title Page Compound Type Members.............................................................................................................................551 SWLIBS_VERSION_T................................................................................................................................................ 552 7.73.1 Description..................................................................................................................................................... 552 7.73.2 Compound Type Members.............................................................................................................................552 Chapter 8 8.1 Macro Definitions......................................................................................................................................................... 553 8.1.1 Macro Definitions Overview......................................................................................................................... 553 Chapter 9 Macro References 9.1 9.2 9.3 9.4 9.5 9.6 9.7 Define GDFLIB_FilterFIRInit......................................................................................................................................561 9.1.1 Macro Definition............................................................................................................................................561 9.1.2 Description..................................................................................................................................................... 561 Define GDFLIB_FilterFIR........................................................................................................................................... 561 9.2.1 Macro Definition............................................................................................................................................561 9.2.2 Description..................................................................................................................................................... 561 Define GDFLIB_FilterIIR1Init.....................................................................................................................................562 9.3.1 Macro Definition............................................................................................................................................562 9.3.2 Description..................................................................................................................................................... 562 Define GDFLIB_FilterIIR1.......................................................................................................................................... 562 9.4.1 Macro Definition............................................................................................................................................562 9.4.2 Description..................................................................................................................................................... 562 Define GDFLIB_FILTER_IIR1_DEFAULT_F32.......................................................................................................562 9.5.1 Macro Definition............................................................................................................................................562 9.5.2 Description..................................................................................................................................................... 563 Define GDFLIB_FILTER_IIR1_DEFAULT_F16.......................................................................................................563 9.6.1 Macro Definition............................................................................................................................................563 9.6.2 Description..................................................................................................................................................... 563 Define GDFLIB_FilterIIR2Init.....................................................................................................................................563 9.7.1 Macro Definition............................................................................................................................................563 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 45 Section number 9.7.2 9.8 9.9 9.10 9.11 9.12 9.13 9.14 9.15 9.16 9.17 Title Page Description..................................................................................................................................................... 563 Define GDFLIB_FilterIIR2.......................................................................................................................................... 564 9.8.1 Macro Definition............................................................................................................................................564 9.8.2 Description..................................................................................................................................................... 564 Define GDFLIB_FILTER_IIR2_DEFAULT_F32.......................................................................................................564 9.9.1 Macro Definition............................................................................................................................................564 9.9.2 Description..................................................................................................................................................... 564 Define GDFLIB_FILTER_IIR2_DEFAULT_F16.......................................................................................................564 9.10.1 Macro Definition............................................................................................................................................564 9.10.2 Description..................................................................................................................................................... 565 Define GDFLIB_FilterMAInit......................................................................................................................................565 9.11.1 Macro Definition............................................................................................................................................565 9.11.2 Description..................................................................................................................................................... 565 Define GDFLIB_FilterMA........................................................................................................................................... 565 9.12.1 Macro Definition............................................................................................................................................565 9.12.2 Description..................................................................................................................................................... 565 Define GDFLIB_FILTER_MA_DEFAULT_F32........................................................................................................565 9.13.1 Macro Definition............................................................................................................................................565 9.13.2 Description..................................................................................................................................................... 566 Define GDFLIB_FILTER_MA_DEFAULT_F16........................................................................................................566 9.14.1 Macro Definition............................................................................................................................................566 9.14.2 Description..................................................................................................................................................... 566 Define GFLIB_Acos.....................................................................................................................................................566 9.15.1 Macro Definition............................................................................................................................................566 9.15.2 Description..................................................................................................................................................... 566 Define GFLIB_ACOS_DEFAULT_F32...................................................................................................................... 566 9.16.1 Macro Definition............................................................................................................................................567 9.16.2 Description..................................................................................................................................................... 567 Define GFLIB_ACOS_DEFAULT_F16...................................................................................................................... 567 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 46 NXP Semiconductors Section number 9.18 9.19 9.20 9.21 9.22 9.23 9.24 9.25 9.26 Title Page 9.17.1 Macro Definition............................................................................................................................................567 9.17.2 Description..................................................................................................................................................... 567 Define GFLIB_Asin......................................................................................................................................................567 9.18.1 Macro Definition............................................................................................................................................567 9.18.2 Description..................................................................................................................................................... 567 Define GFLIB_ASIN_DEFAULT_F32....................................................................................................................... 568 9.19.1 Macro Definition............................................................................................................................................568 9.19.2 Description..................................................................................................................................................... 568 Define GFLIB_ASIN_DEFAULT_F16....................................................................................................................... 568 9.20.1 Macro Definition............................................................................................................................................568 9.20.2 Description..................................................................................................................................................... 568 Define GFLIB_Atan..................................................................................................................................................... 568 9.21.1 Macro Definition............................................................................................................................................568 9.21.2 Description..................................................................................................................................................... 569 Define GFLIB_ATAN_DEFAULT_F32......................................................................................................................569 9.22.1 Macro Definition............................................................................................................................................569 9.22.2 Description..................................................................................................................................................... 569 Define GFLIB_ATAN_DEFAULT_F16......................................................................................................................569 9.23.1 Macro Definition............................................................................................................................................569 9.23.2 Description..................................................................................................................................................... 569 Define GFLIB_AtanYX................................................................................................................................................569 9.24.1 Macro Definition............................................................................................................................................570 9.24.2 Description..................................................................................................................................................... 570 Define GFLIB_AtanYXShifted.................................................................................................................................... 570 9.25.1 Macro Definition............................................................................................................................................570 9.25.2 Description..................................................................................................................................................... 570 Define GFLIB_ControllerPIp....................................................................................................................................... 570 9.26.1 Macro Definition............................................................................................................................................570 9.26.2 Description..................................................................................................................................................... 570 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 47 Section number 9.27 9.28 9.29 9.30 9.31 9.32 9.33 9.34 9.35 9.36 Title Page Define GFLIB_CONTROLLER_PI_P_DEFAULT_F32............................................................................................ 571 9.27.1 Macro Definition............................................................................................................................................571 9.27.2 Description..................................................................................................................................................... 571 Define GFLIB_CONTROLLER_PI_P_DEFAULT_F16............................................................................................ 571 9.28.1 Macro Definition............................................................................................................................................571 9.28.2 Description..................................................................................................................................................... 571 Define GFLIB_ControllerPIpAW................................................................................................................................ 571 9.29.1 Macro Definition............................................................................................................................................572 9.29.2 Description..................................................................................................................................................... 572 Define GFLIB_CONTROLLER_PIAW_P_DEFAULT_F32......................................................................................572 9.30.1 Macro Definition............................................................................................................................................572 9.30.2 Description..................................................................................................................................................... 572 Define GFLIB_CONTROLLER_PIAW_P_DEFAULT_F16......................................................................................572 9.31.1 Macro Definition............................................................................................................................................572 9.31.2 Description..................................................................................................................................................... 572 Define GFLIB_ControllerPIr........................................................................................................................................573 9.32.1 Macro Definition............................................................................................................................................573 9.32.2 Description..................................................................................................................................................... 573 Define GFLIB_CONTROLLER_PI_R_DEFAULT_F32............................................................................................ 573 9.33.1 Macro Definition............................................................................................................................................573 9.33.2 Description..................................................................................................................................................... 573 Define GFLIB_CONTROLLER_PI_R_DEFAULT_F16............................................................................................ 573 9.34.1 Macro Definition............................................................................................................................................574 9.34.2 Description..................................................................................................................................................... 574 Define GFLIB_ControllerPIrAW................................................................................................................................. 574 9.35.1 Macro Definition............................................................................................................................................574 9.35.2 Description..................................................................................................................................................... 574 Define GFLIB_CONTROLLER_PIAW_R_DEFAULT_F32..................................................................................... 574 9.36.1 Macro Definition............................................................................................................................................574 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 48 NXP Semiconductors Section number 9.36.2 9.37 9.38 9.39 9.40 9.41 9.42 9.43 9.44 9.45 9.46 Title Page Description..................................................................................................................................................... 574 Define GFLIB_CONTROLLER_PIAW_R_DEFAULT_F16..................................................................................... 575 9.37.1 Macro Definition............................................................................................................................................575 9.37.2 Description..................................................................................................................................................... 575 Define GFLIB_Cos.......................................................................................................................................................575 9.38.1 Macro Definition............................................................................................................................................575 9.38.2 Description..................................................................................................................................................... 575 Define GFLIB_COS_DEFAULT_F32.........................................................................................................................575 9.39.1 Macro Definition............................................................................................................................................575 9.39.2 Description..................................................................................................................................................... 576 Define GFLIB_COS_DEFAULT_F16.........................................................................................................................576 9.40.1 Macro Definition............................................................................................................................................576 9.40.2 Description..................................................................................................................................................... 576 Define GFLIB_Hyst......................................................................................................................................................576 9.41.1 Macro Definition............................................................................................................................................576 9.41.2 Description..................................................................................................................................................... 576 Define GFLIB_HYST_DEFAULT_F32...................................................................................................................... 576 9.42.1 Macro Definition............................................................................................................................................577 9.42.2 Description..................................................................................................................................................... 577 Define GFLIB_HYST_DEFAULT_F16...................................................................................................................... 577 9.43.1 Macro Definition............................................................................................................................................577 9.43.2 Description..................................................................................................................................................... 577 Define GFLIB_IntegratorTR........................................................................................................................................ 577 9.44.1 Macro Definition............................................................................................................................................577 9.44.2 Description..................................................................................................................................................... 577 Define GFLIB_INTEGRATOR_TR_DEFAULT_F32................................................................................................ 578 9.45.1 Macro Definition............................................................................................................................................578 9.45.2 Description..................................................................................................................................................... 578 Define GFLIB_INTEGRATOR_TR_DEFAULT_F16................................................................................................ 578 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 49 Section number 9.47 9.48 9.49 9.50 9.51 9.52 9.53 9.54 9.55 Title Page 9.46.1 Macro Definition............................................................................................................................................578 9.46.2 Description..................................................................................................................................................... 578 Define GFLIB_Limit.................................................................................................................................................... 578 9.47.1 Macro Definition............................................................................................................................................578 9.47.2 Description..................................................................................................................................................... 579 Define GFLIB_LIMIT_DEFAULT_F32......................................................................................................................579 9.48.1 Macro Definition............................................................................................................................................579 9.48.2 Description..................................................................................................................................................... 579 Define GFLIB_LIMIT_DEFAULT_F16......................................................................................................................579 9.49.1 Macro Definition............................................................................................................................................579 9.49.2 Description..................................................................................................................................................... 579 Define GFLIB_LowerLimit..........................................................................................................................................579 9.50.1 Macro Definition............................................................................................................................................580 9.50.2 Description..................................................................................................................................................... 580 Define GFLIB_LOWERLIMIT_DEFAULT_F32....................................................................................................... 580 9.51.1 Macro Definition............................................................................................................................................580 9.51.2 Description..................................................................................................................................................... 580 Define GFLIB_LOWERLIMIT_DEFAULT_F16....................................................................................................... 580 9.52.1 Macro Definition............................................................................................................................................580 9.52.2 Description..................................................................................................................................................... 580 Define GFLIB_Lut1D...................................................................................................................................................581 9.53.1 Macro Definition............................................................................................................................................581 9.53.2 Description..................................................................................................................................................... 581 Define GFLIB_LUT1D_DEFAULT_F32.................................................................................................................... 581 9.54.1 Macro Definition............................................................................................................................................581 9.54.2 Description..................................................................................................................................................... 581 Define GFLIB_LUT1D_DEFAULT_F16.................................................................................................................... 581 9.55.1 Macro Definition............................................................................................................................................581 9.55.2 Description..................................................................................................................................................... 582 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 50 NXP Semiconductors Section number 9.56 9.57 9.58 9.59 9.60 9.61 9.62 9.63 9.64 9.65 Title Page Define GFLIB_Lut2D...................................................................................................................................................582 9.56.1 Macro Definition............................................................................................................................................582 9.56.2 Description..................................................................................................................................................... 582 Define GFLIB_LUT2D_DEFAULT_F32.................................................................................................................... 582 9.57.1 Macro Definition............................................................................................................................................582 9.57.2 Description..................................................................................................................................................... 582 Define GFLIB_LUT2D_DEFAULT_F16.................................................................................................................... 582 9.58.1 Macro Definition............................................................................................................................................583 9.58.2 Description..................................................................................................................................................... 583 Define GFLIB_Ramp....................................................................................................................................................583 9.59.1 Macro Definition............................................................................................................................................583 9.59.2 Description..................................................................................................................................................... 583 Define GFLIB_RAMP_DEFAULT_F32..................................................................................................................... 583 9.60.1 Macro Definition............................................................................................................................................583 9.60.2 Description..................................................................................................................................................... 583 Define GFLIB_RAMP_DEFAULT_F16..................................................................................................................... 584 9.61.1 Macro Definition............................................................................................................................................584 9.61.2 Description..................................................................................................................................................... 584 Define GFLIB_Sign......................................................................................................................................................584 9.62.1 Macro Definition............................................................................................................................................584 9.62.2 Description..................................................................................................................................................... 584 Define GFLIB_Sin........................................................................................................................................................584 9.63.1 Macro Definition............................................................................................................................................584 9.63.2 Description..................................................................................................................................................... 585 Define GFLIB_SIN_DEFAULT_F32.......................................................................................................................... 585 9.64.1 Macro Definition............................................................................................................................................585 9.64.2 Description..................................................................................................................................................... 585 Define GFLIB_SIN_DEFAULT_F16.......................................................................................................................... 585 9.65.1 Macro Definition............................................................................................................................................585 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 51 Section number 9.65.2 9.66 9.67 9.68 9.69 9.70 9.71 9.72 9.73 9.74 9.75 Title Page Description..................................................................................................................................................... 585 Define GFLIB_SinCos..................................................................................................................................................585 9.66.1 Macro Definition............................................................................................................................................586 9.66.2 Description..................................................................................................................................................... 586 Define GFLIB_SINCOS_DEFAULT_F32.................................................................................................................. 586 9.67.1 Macro Definition............................................................................................................................................586 9.67.2 Description..................................................................................................................................................... 586 Define GFLIB_SINCOS_DEFAULT_F16.................................................................................................................. 586 9.68.1 Macro Definition............................................................................................................................................586 9.68.2 Description..................................................................................................................................................... 586 Define GFLIB_Sqrt...................................................................................................................................................... 587 9.69.1 Macro Definition............................................................................................................................................587 9.69.2 Description..................................................................................................................................................... 587 Define GFLIB_Tan.......................................................................................................................................................587 9.70.1 Macro Definition............................................................................................................................................587 9.70.2 Description..................................................................................................................................................... 587 Define GFLIB_TAN_DEFAULT_F32........................................................................................................................ 587 9.71.1 Macro Definition............................................................................................................................................587 9.71.2 Description..................................................................................................................................................... 588 Define GFLIB_TAN_DEFAULT_F16........................................................................................................................ 588 9.72.1 Macro Definition............................................................................................................................................588 9.72.2 Description..................................................................................................................................................... 588 Define GFLIB_UpperLimit.......................................................................................................................................... 588 9.73.1 Macro Definition............................................................................................................................................588 9.73.2 Description..................................................................................................................................................... 588 Define GFLIB_UPPERLIMIT_DEFAULT_F32......................................................................................................... 588 9.74.1 Macro Definition............................................................................................................................................589 9.74.2 Description..................................................................................................................................................... 589 Define GFLIB_UPPERLIMIT_DEFAULT_F16......................................................................................................... 589 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 52 NXP Semiconductors Section number 9.76 9.77 9.78 9.79 9.80 9.81 9.82 9.83 9.84 Title Page 9.75.1 Macro Definition............................................................................................................................................589 9.75.2 Description..................................................................................................................................................... 589 Define GFLIB_VectorLimit......................................................................................................................................... 589 9.76.1 Macro Definition............................................................................................................................................589 9.76.2 Description..................................................................................................................................................... 589 Define GFLIB_VECTORLIMIT_DEFAULT_F32......................................................................................................590 9.77.1 Macro Definition............................................................................................................................................590 9.77.2 Description..................................................................................................................................................... 590 Define GFLIB_VECTORLIMIT_DEFAULT_F16......................................................................................................590 9.78.1 Macro Definition............................................................................................................................................590 9.78.2 Description..................................................................................................................................................... 590 Define GMCLIB_Clark................................................................................................................................................ 590 9.79.1 Macro Definition............................................................................................................................................590 9.79.2 Description..................................................................................................................................................... 591 Define GMCLIB_ClarkInv...........................................................................................................................................591 9.80.1 Macro Definition............................................................................................................................................591 9.80.2 Description..................................................................................................................................................... 591 Define GMCLIB_DecouplingPMSM...........................................................................................................................591 9.81.1 Macro Definition............................................................................................................................................591 9.81.2 Description..................................................................................................................................................... 591 Define GMCLIB_DECOUPLINGPMSM_DEFAULT_F32........................................................................................592 9.82.1 Macro Definition............................................................................................................................................592 9.82.2 Description..................................................................................................................................................... 592 Define GMCLIB_DECOUPLINGPMSM_DEFAULT_F16........................................................................................592 9.83.1 Macro Definition............................................................................................................................................592 9.83.2 Description..................................................................................................................................................... 592 Define GMCLIB_ELIMDCBUSRIP_FLT_DNMAX..................................................................................................592 9.84.1 Macro Definition............................................................................................................................................592 9.84.2 Description..................................................................................................................................................... 592 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 53 Section number 9.85 9.86 9.87 9.88 9.89 9.90 9.91 9.92 9.93 9.94 Title Page Define GMCLIB_ElimDcBusRip.................................................................................................................................593 9.85.1 Macro Definition............................................................................................................................................593 9.85.2 Description..................................................................................................................................................... 593 Define GMCLIB_ELIMDCBUSRIP_DEFAULT_F32............................................................................................... 593 9.86.1 Macro Definition............................................................................................................................................593 9.86.2 Description..................................................................................................................................................... 593 Define GMCLIB_ELIMDCBUSRIP_DEFAULT_F16............................................................................................... 593 9.87.1 Macro Definition............................................................................................................................................593 9.87.2 Description..................................................................................................................................................... 594 Define GMCLIB_Park..................................................................................................................................................594 9.88.1 Macro Definition............................................................................................................................................594 9.88.2 Description..................................................................................................................................................... 594 Define GMCLIB_ParkInv............................................................................................................................................ 594 9.89.1 Macro Definition............................................................................................................................................594 9.89.2 Description..................................................................................................................................................... 594 Define GMCLIB_SvmStd............................................................................................................................................ 594 9.90.1 Macro Definition............................................................................................................................................595 9.90.2 Description..................................................................................................................................................... 595 Define MLIB_Abs........................................................................................................................................................ 595 9.91.1 Macro Definition............................................................................................................................................595 9.91.2 Description..................................................................................................................................................... 595 Define MLIB_AbsSat................................................................................................................................................... 595 9.92.1 Macro Definition............................................................................................................................................595 9.92.2 Description..................................................................................................................................................... 595 Define MLIB_Add........................................................................................................................................................596 9.93.1 Macro Definition............................................................................................................................................596 9.93.2 Description..................................................................................................................................................... 596 Define MLIB_AddSat...................................................................................................................................................596 9.94.1 Macro Definition............................................................................................................................................596 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 54 NXP Semiconductors Section number 9.94.2 9.95 9.96 9.97 9.98 9.99 Title Page Description..................................................................................................................................................... 596 Define MLIB_Convert..................................................................................................................................................596 9.95.1 Macro Definition............................................................................................................................................596 9.95.2 Description..................................................................................................................................................... 597 Define MLIB_ConvertPU.............................................................................................................................................597 9.96.1 Macro Definition............................................................................................................................................597 9.96.2 Description..................................................................................................................................................... 597 Define MLIB_Div.........................................................................................................................................................597 9.97.1 Macro Definition............................................................................................................................................597 9.97.2 Description..................................................................................................................................................... 597 Define MLIB_DivSat....................................................................................................................................................597 9.98.1 Macro Definition............................................................................................................................................598 9.98.2 Description..................................................................................................................................................... 598 Define MLIB_Mac........................................................................................................................................................598 9.99.1 Macro Definition............................................................................................................................................598 9.99.2 Description..................................................................................................................................................... 598 9.100 Define MLIB_MacSat.................................................................................................................................................. 598 9.100.1 Macro Definition............................................................................................................................................598 9.100.2 Description..................................................................................................................................................... 598 9.101 Define MLIB_Mnac......................................................................................................................................................599 9.101.1 Macro Definition............................................................................................................................................599 9.101.2 Description..................................................................................................................................................... 599 9.102 Define MLIB_Msu........................................................................................................................................................599 9.102.1 Macro Definition............................................................................................................................................599 9.102.2 Description..................................................................................................................................................... 599 9.103 Define MLIB_Mul........................................................................................................................................................ 599 9.103.1 Macro Definition............................................................................................................................................599 9.103.2 Description..................................................................................................................................................... 600 9.104 Define MLIB_MulSat...................................................................................................................................................600 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 55 Section number Title Page 9.104.1 Macro Definition............................................................................................................................................600 9.104.2 Description..................................................................................................................................................... 600 9.105 Define MLIB_Neg........................................................................................................................................................ 600 9.105.1 Macro Definition............................................................................................................................................600 9.105.2 Description..................................................................................................................................................... 600 9.106 Define MLIB_NegSat...................................................................................................................................................600 9.106.1 Macro Definition............................................................................................................................................601 9.106.2 Description..................................................................................................................................................... 601 9.107 Define MLIB_Norm..................................................................................................................................................... 601 9.107.1 Macro Definition............................................................................................................................................601 9.107.2 Description..................................................................................................................................................... 601 9.108 Define MLIB_Round.................................................................................................................................................... 601 9.108.1 Macro Definition............................................................................................................................................601 9.108.2 Description..................................................................................................................................................... 601 9.109 Define MLIB_ShBi.......................................................................................................................................................602 9.109.1 Macro Definition............................................................................................................................................602 9.109.2 Description..................................................................................................................................................... 602 9.110 Define MLIB_ShBiSat..................................................................................................................................................602 9.110.1 Macro Definition............................................................................................................................................602 9.110.2 Description..................................................................................................................................................... 602 9.111 Define MLIB_ShL........................................................................................................................................................ 602 9.111.1 Macro Definition............................................................................................................................................603 9.111.2 Description..................................................................................................................................................... 603 9.112 Define MLIB_ShLSat...................................................................................................................................................603 9.112.1 Macro Definition............................................................................................................................................603 9.112.2 Description..................................................................................................................................................... 603 9.113 Define MLIB_ShR........................................................................................................................................................603 9.113.1 Macro Definition............................................................................................................................................603 9.113.2 Description..................................................................................................................................................... 603 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 56 NXP Semiconductors Section number Title Page 9.114 Define MLIB_Sub........................................................................................................................................................ 604 9.114.1 Macro Definition............................................................................................................................................604 9.114.2 Description..................................................................................................................................................... 604 9.115 Define MLIB_SubSat................................................................................................................................................... 604 9.115.1 Macro Definition............................................................................................................................................604 9.115.2 Description..................................................................................................................................................... 604 9.116 Define MLIB_VMac.....................................................................................................................................................604 9.116.1 Macro Definition............................................................................................................................................604 9.116.2 Description..................................................................................................................................................... 604 9.117 Define SWLIBS_VERSION.........................................................................................................................................605 9.117.1 Macro Definition............................................................................................................................................605 9.117.2 Description..................................................................................................................................................... 605 9.118 Define SWLIBS_STD_ON...........................................................................................................................................605 9.118.1 Macro Definition............................................................................................................................................605 9.118.2 Description..................................................................................................................................................... 605 9.119 Define SWLIBS_STD_OFF......................................................................................................................................... 605 9.119.1 Macro Definition............................................................................................................................................605 9.119.2 Description..................................................................................................................................................... 605 9.120 Define F32.................................................................................................................................................................... 606 9.120.1 Macro Definition............................................................................................................................................606 9.120.2 Description..................................................................................................................................................... 606 9.121 Define F16.................................................................................................................................................................... 606 9.121.1 Macro Definition............................................................................................................................................606 9.121.2 Description..................................................................................................................................................... 606 9.122 Define FLT....................................................................................................................................................................606 9.122.1 Macro Definition............................................................................................................................................606 9.122.2 Description..................................................................................................................................................... 606 9.123 Define SWLIBS_DEFAULT_IMPLEMENTATION_F32..........................................................................................607 9.123.1 Macro Definition............................................................................................................................................607 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 57 Section number Title Page 9.123.2 Description..................................................................................................................................................... 607 9.124 Define SWLIBS_DEFAULT_IMPLEMENTATION_F16..........................................................................................607 9.124.1 Macro Definition............................................................................................................................................607 9.124.2 Description..................................................................................................................................................... 607 9.125 Define SWLIBS_DEFAULT_IMPLEMENTATION_FLT.........................................................................................607 9.125.1 Macro Definition............................................................................................................................................607 9.125.2 Description..................................................................................................................................................... 607 9.126 Define SWLIBS_SUPPORT_F32................................................................................................................................ 608 9.126.1 Macro Definition............................................................................................................................................608 9.126.2 Description..................................................................................................................................................... 608 9.127 Define SWLIBS_SUPPORT_F16................................................................................................................................ 608 9.127.1 Macro Definition............................................................................................................................................608 9.127.2 Description..................................................................................................................................................... 608 9.128 Define SWLIBS_SUPPORT_FLT............................................................................................................................... 608 9.128.1 Macro Definition............................................................................................................................................608 9.128.2 Description..................................................................................................................................................... 609 9.129 Define SWLIBS_SUPPORTED_IMPLEMENTATION............................................................................................. 609 9.129.1 Macro Definition............................................................................................................................................609 9.129.2 Description..................................................................................................................................................... 609 9.130 Define SWLIBS_DEFAULT_IMPLEMENTATION.................................................................................................. 609 9.130.1 Macro Definition............................................................................................................................................609 9.130.2 Description..................................................................................................................................................... 609 9.131 Define SFRACT_MIN..................................................................................................................................................610 9.131.1 Macro Definition............................................................................................................................................610 9.131.2 Description..................................................................................................................................................... 610 9.132 Define SFRACT_MAX................................................................................................................................................ 610 9.132.1 Macro Definition............................................................................................................................................610 9.132.2 Description..................................................................................................................................................... 610 9.133 Define FRACT_MIN.................................................................................................................................................... 610 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 58 NXP Semiconductors Section number Title Page 9.133.1 Macro Definition............................................................................................................................................610 9.133.2 Description..................................................................................................................................................... 611 9.134 Define FRACT_MAX.................................................................................................................................................. 611 9.134.1 Macro Definition............................................................................................................................................611 9.134.2 Description..................................................................................................................................................... 611 9.135 Define FRAC32_0_5.................................................................................................................................................... 611 9.135.1 Macro Definition............................................................................................................................................611 9.135.2 Description..................................................................................................................................................... 611 9.136 Define FRAC16_0_5.................................................................................................................................................... 612 9.136.1 Macro Definition............................................................................................................................................612 9.136.2 Description..................................................................................................................................................... 612 9.137 Define FRAC32_0_25.................................................................................................................................................. 612 9.137.1 Macro Definition............................................................................................................................................612 9.137.2 Description..................................................................................................................................................... 612 9.138 Define FRAC16_0_25.................................................................................................................................................. 612 9.138.1 Macro Definition............................................................................................................................................612 9.138.2 Description..................................................................................................................................................... 612 9.139 Define UINT16_MAX..................................................................................................................................................613 9.139.1 Macro Definition............................................................................................................................................613 9.139.2 Description..................................................................................................................................................... 613 9.140 Define INT16_MAX.....................................................................................................................................................613 9.140.1 Macro Definition............................................................................................................................................613 9.140.2 Description..................................................................................................................................................... 613 9.141 Define INT16_MIN...................................................................................................................................................... 613 9.141.1 Macro Definition............................................................................................................................................614 9.141.2 Description..................................................................................................................................................... 614 9.142 Define UINT32_MAX..................................................................................................................................................614 9.142.1 Macro Definition............................................................................................................................................614 9.142.2 Description..................................................................................................................................................... 614 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 59 Section number Title Page 9.143 Define INT32_MAX.....................................................................................................................................................614 9.143.1 Macro Definition............................................................................................................................................614 9.143.2 Description..................................................................................................................................................... 614 9.144 Define INT32_MIN...................................................................................................................................................... 615 9.144.1 Macro Definition............................................................................................................................................615 9.144.2 Description..................................................................................................................................................... 615 9.145 Define INT16TOINT32................................................................................................................................................ 615 9.145.1 Macro Definition............................................................................................................................................615 9.145.2 Description..................................................................................................................................................... 615 9.146 Define INT32TOINT16................................................................................................................................................ 615 9.146.1 Macro Definition............................................................................................................................................616 9.146.2 Description..................................................................................................................................................... 616 9.147 Define INT32TOINT64................................................................................................................................................ 616 9.147.1 Macro Definition............................................................................................................................................616 9.147.2 Description..................................................................................................................................................... 616 9.148 Define INT64TOINT32................................................................................................................................................ 616 9.148.1 Macro Definition............................................................................................................................................616 9.148.2 Description..................................................................................................................................................... 616 9.149 Define F16TOINT16.................................................................................................................................................... 617 9.149.1 Macro Definition............................................................................................................................................617 9.149.2 Description..................................................................................................................................................... 617 9.150 Define F32TOINT16.................................................................................................................................................... 617 9.150.1 Macro Definition............................................................................................................................................617 9.150.2 Description..................................................................................................................................................... 617 9.151 Define F64TOINT16.................................................................................................................................................... 617 9.151.1 Macro Definition............................................................................................................................................617 9.151.2 Description..................................................................................................................................................... 618 9.152 Define F16TOINT32.................................................................................................................................................... 618 9.152.1 Macro Definition............................................................................................................................................618 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 60 NXP Semiconductors Section number Title Page 9.152.2 Description..................................................................................................................................................... 618 9.153 Define F32TOINT32.................................................................................................................................................... 618 9.153.1 Macro Definition............................................................................................................................................618 9.153.2 Description..................................................................................................................................................... 618 9.154 Define F64TOINT32.................................................................................................................................................... 618 9.154.1 Macro Definition............................................................................................................................................619 9.154.2 Description..................................................................................................................................................... 619 9.155 Define F16TOINT64.................................................................................................................................................... 619 9.155.1 Macro Definition............................................................................................................................................619 9.155.2 Description..................................................................................................................................................... 619 9.156 Define F32TOINT64.................................................................................................................................................... 619 9.156.1 Macro Definition............................................................................................................................................619 9.156.2 Description..................................................................................................................................................... 619 9.157 Define F64TOINT64.................................................................................................................................................... 620 9.157.1 Macro Definition............................................................................................................................................620 9.157.2 Description..................................................................................................................................................... 620 9.158 Define INT16TOF16.................................................................................................................................................... 620 9.158.1 Macro Definition............................................................................................................................................620 9.158.2 Description..................................................................................................................................................... 620 9.159 Define INT16TOF32.................................................................................................................................................... 620 9.159.1 Macro Definition............................................................................................................................................620 9.159.2 Description..................................................................................................................................................... 621 9.160 Define INT32TOF16.................................................................................................................................................... 621 9.160.1 Macro Definition............................................................................................................................................621 9.160.2 Description..................................................................................................................................................... 621 9.161 Define INT32TOF32.................................................................................................................................................... 621 9.161.1 Macro Definition............................................................................................................................................621 9.161.2 Description..................................................................................................................................................... 621 9.162 Define INT64TOF16.................................................................................................................................................... 622 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 61 Section number Title Page 9.162.1 Macro Definition............................................................................................................................................622 9.162.2 Description..................................................................................................................................................... 622 9.163 Define INT64TOF32.................................................................................................................................................... 622 9.163.1 Macro Definition............................................................................................................................................622 9.163.2 Description..................................................................................................................................................... 622 9.164 Define F16_1_DIVBY_SQRT3....................................................................................................................................622 9.164.1 Macro Definition............................................................................................................................................622 9.164.2 Description..................................................................................................................................................... 623 9.165 Define F32_1_DIVBY_SQRT3....................................................................................................................................623 9.165.1 Macro Definition............................................................................................................................................623 9.165.2 Description..................................................................................................................................................... 623 9.166 Define F16_SQRT3_DIVBY_2....................................................................................................................................623 9.166.1 Macro Definition............................................................................................................................................623 9.166.2 Description..................................................................................................................................................... 623 9.167 Define F32_SQRT3_DIVBY_2....................................................................................................................................623 9.167.1 Macro Definition............................................................................................................................................624 9.167.2 Description..................................................................................................................................................... 624 9.168 Define F16_SQRT2_DIVBY_2....................................................................................................................................624 9.168.1 Macro Definition............................................................................................................................................624 9.168.2 Description..................................................................................................................................................... 624 9.169 Define F32_SQRT2_DIVBY_2....................................................................................................................................624 9.169.1 Macro Definition............................................................................................................................................624 9.169.2 Description..................................................................................................................................................... 624 9.170 Define FRAC16............................................................................................................................................................ 625 9.170.1 Macro Definition............................................................................................................................................625 9.170.2 Description..................................................................................................................................................... 625 9.171 Define FRAC32............................................................................................................................................................ 625 9.171.1 Macro Definition............................................................................................................................................625 9.171.2 Description..................................................................................................................................................... 625 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 62 NXP Semiconductors Section number Title Page 9.172 Define NULL................................................................................................................................................................ 625 9.172.1 Macro Definition............................................................................................................................................626 9.172.2 Description..................................................................................................................................................... 626 9.173 Define FALSE.............................................................................................................................................................. 626 9.173.1 Macro Definition............................................................................................................................................626 9.173.2 Description..................................................................................................................................................... 626 9.174 Define TRUE................................................................................................................................................................ 626 9.174.1 Macro Definition............................................................................................................................................626 9.174.2 Description..................................................................................................................................................... 626 9.175 Define SWLIBS_2Syst................................................................................................................................................. 627 9.175.1 Macro Definition............................................................................................................................................627 9.175.2 Description..................................................................................................................................................... 627 9.176 Define SWLIBS_2Syst................................................................................................................................................. 627 9.176.1 Macro Definition............................................................................................................................................627 9.176.2 Description..................................................................................................................................................... 627 9.177 Define SWLIBS_2Syst................................................................................................................................................. 627 9.177.1 Macro Definition............................................................................................................................................628 9.177.2 Description..................................................................................................................................................... 628 9.178 Define SWLIBS_3Syst................................................................................................................................................. 628 9.178.1 Macro Definition............................................................................................................................................628 9.178.2 Description..................................................................................................................................................... 628 9.179 Define SWLIBS_3Syst................................................................................................................................................. 628 9.179.1 Macro Definition............................................................................................................................................629 9.179.2 Description..................................................................................................................................................... 629 9.180 Define SWLIBS_3Syst................................................................................................................................................. 628 9.180.1 Macro Definition............................................................................................................................................629 9.180.2 Description..................................................................................................................................................... 629 9.181 Define SWLIBS_VERSION_DEFAULT.................................................................................................................... 630 9.181.1 Macro Definition............................................................................................................................................630 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 63 Section number Title Page 9.181.2 Description..................................................................................................................................................... 630 9.182 Define SWLIBS_MCID_SIZE..................................................................................................................................... 630 9.182.1 Macro Definition............................................................................................................................................630 9.182.2 Description..................................................................................................................................................... 630 9.183 Define SWLIBS_MCVERSION_SIZE........................................................................................................................ 630 9.183.1 Macro Definition............................................................................................................................................630 9.183.2 Description..................................................................................................................................................... 630 9.184 Define SWLIBS_MCIMPLEMENTATION_SIZE......................................................................................................631 9.184.1 Macro Definition............................................................................................................................................631 9.184.2 Description..................................................................................................................................................... 631 9.185 Define SWLIBS_ID......................................................................................................................................................631 9.185.1 Macro Definition............................................................................................................................................631 9.185.2 Description..................................................................................................................................................... 631 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 64 NXP Semiconductors Chapter 1 Revision History Revision Date Table 1-1. Revision History Author Description 1.0 31/08/2014 Petr Zelinka Initial version. 2.0 31/03/2015 Jiri Kuhn The Matlab revision, used for testing, changed to Matlab 2014a. 3.0 31/07/2015 Petr Fajmon All compilers versions were increased. Number of the significant digits of the calculated IIR1/IIR2 coefficients in the MATLAB examples for GDFLIB_IIR1/GDFLIB_IIR2 functions was increased. 4.0 30/09/2015 Jiri Kuhn Adding the chapters describing the GFLIB_SinCos function. 5.0 31/12/2015 Petr Fajmon The Service Release v1.1.3. The GreenHills compiler version was increased to the latest v2015.1.4. 6.0 31/03/2016 Jiri Kuhn Change from Freescale to NXP entity, Service release 1.1.4. 7.0 30/06/2016 Petr Fajmon The Service Release v1.1.5. Added new MLIB_RndSat_F16F32 function. Added chapter about possible exceptions. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 65 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 66 NXP Semiconductors Chapter 2 2.1 ATTACHMENT A - NXP Automotive Software License Agreement v1.3 IMPORTANT. Read the following NXP Software License Agreement ("Agreement") completely. By selecting the "I Accept" button at the end of this page, you indicate that you accept the terms of this Agreement. You may then install the software. NXP SOFTWARE LICENSE AGREEMENT This is a legal agreement between you (either as an individual or as an authorized representative of your employer) and Freescale Semiconductor, Inc., a 100% affiliated company of NXP Semiconductors N.V., which will be renamed in due course, on behalf of itself and its Affiliates ("NXP"). "Affiliate" means any corporation, partnership, limited liability company or other entity, which directly or indirectly controls, is controlled by, or is under common control with, NXP Semiconductors N.V. It concerns your rights to use this file and any accompanying written materials (the "Software"). In consideration for NXP allowing you to access the Software, you are agreeing to be bound by the terms of this Agreement. If you do not agree to all of the terms of this Agreement, do not download the Software. If you change your mind later, stop using the Software and delete all copies of the Software in your possession or control. Any copies of the Software that you have already distributed, where permitted, and do not destroy will continue to be governed by this Agreement. Your prior use will also continue to be governed by this Agreement. For the avoidance of doubt, any third party software indicated in the Quotation Document as being provided is not Software licensed under this Agreement and is governed solely by the terms and conditions of the third party licensor. In addition, the parties acknowledge that the Software may contain Open Source Software components. For the avoidance of doubt, all Open Source Software components are governed solely by the applicable Open Source Software licenses. LICENSE GRANT: Your rights to use this Software vary depending upon the type of license model you ordered from NXP. The type of license will be set forth in the NXP Quotation document which formed the basis of your order or, with respect to evaluation Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 67 ATTACHMENT A - NXP Automotive Software License Agreement v1.3 licenses, in the correspondence with NXP confirming your request for a copy of the Software for evaluation. If you do not remember this information, you may contact the party from whom you obtained the Software or NXP at www.NXP.com. Definitions: For purposes of this Agreement the following terms are defined as set forth below: "Authorized System" means the Authorized System set forth in the Quotation Documents or, if none is specified, Licensee's ECU product containing a NXP processor or other semiconductor product supplied directly or indirectly from NXP. "Confidential Information" means any information disclosed by NXP to the Licensee and, if disclosed in writing or in some other tangible form, that is marked at the time of disclosure as being "Confidential" or "Proprietary" or with words of similar import; provided, that Software provided in source code format will be deemed Confidential Information whether or not identified as such in writing or otherwise. Confidential Information does not include any information that: (a) is, or becomes, publicly known through no wrongful act on the Licensee's part; (b) is already known to the Licensee, or becomes lawfully known to the Licensee without restriction on disclosure; or (c) is independently developed by the Licensee. "Customer Product Line" means the customer product line specified in the Quotation Document. "Customer Target Project" means the one customer Target Project for one automotive vehicle manufacturer specified in the Quotation Document. "Limited Derivative Works" means Licensee may make derivative works only to the extent the copyrighted material provided by NXP is not modified. For the avoidance of doubt, Licensee explicitly has the right to: 1) add source code to source code provided by NXP without modification to the original source code; 2) compile any source code into object code, or 3) integrate the NXP source code into its ECU without modifying the original source code. "Quotation Document" means the NXP or NXP authorized reseller document offering the goods and/or services which formed the basis of your order and which is incorporated herein by this reference. "DISM Package" is a commercial offering bundling a Development License with software support and maintenance services as described in detail in the Quotation document. "NXP Target Product" means the NXP processor or other semiconductor product set forth in the Quotation Document. "NXP Target Product Family" means the NXP processor family or other semiconductor product family set forth in the Quotation Document. "Open Source Software" means any software that is subject to terms that, as a condition of use, copying, modification or redistribution, require such software and/or derivative works thereof to be disclosed or distributed in source code form, to be licensed for the purpose of making derivative works, or to be redistributed free of charge, including without limitation software distributed under the GNU General Public License or GNU Lesser/Library and General Public License, Apache or BSD. I. Non-Production License Models: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 68 NXP Semiconductors Chapter 2 a. Evaluation License: NXP grants to you, free of charge, a personal, non-transferable, non-exclusive, revocable, royalty-free, license to use the Software for ninety (90) consecutive days from the date of your acceptance as indicated by clicking the "I accept" button below, internally, solely for the purpose of performing evaluation and testing of the Software, solely for automotive use, and solely on a NXP Target Product. This license does not include the right to reproduce, distribute, sell, lease, sublicense or transfer all or any part of the Software, or to use the Software on non-NXP integrated circuit devices, or to use the Software for any production purposes whatsoever. NXP reserves all rights not expressly granted in this Agreement. If you violate any of the terms or restrictions of this Agreement, NXP may immediately terminate this Agreement, and require that you stop using and delete all copies of the Software in your possession or control. b. Development License as part of the DISM Package: Subject to payment of the fees set forth in the Quotation Document, NXP grants to you a personal, non-transferable, non-exclusive, revocable, license for 12 months beginning on the date of your registration or, if you are renewing, the anniversary date of your registration or prior renewal as indicated by clicking the "I accept" button below, unless a different license term is specified in the Quotation Document ("Term"), (1) to use the Software on one Target Product Family for execution on a maximum of 500 sample Authorized Systems, (2) to reproduce the Software, (3) to prepare Limited Derivative Works of the Licensed Software (4) to distribute the Software and Limited Derivative Works thereof to automotive customers in object code only, (5) to sublicense to automotive customers the right to use the distributed Software in object code only as included within the Authorized System solely for purposes of testing the Authorized System during the Term, and (6) to disclose one copy of the Software and Limited Derivative Works thereof in source code to direct automotive customers solely for internal evaluation and testing or archiving (and not for further use, reproduction, modification or redistribution) only where such disclosure is necessary in order to achieve the purpose of the license because the automotive customer requires disclosure of source code in conjunction with the testing or purchase of an Authorized System incorporating a NXP Target Product, and where the direct automotive customer has executed written agreements obligating itself to observe the limitations set out in this subsection (6) and to protect such Confidential Information on terms at least as strict as those contained in this Agreement. NXP reserves all rights not expressly granted in this Agreement. You must prohibit your sublicensees from translating, reverse engineering, decompiling, or disassembling the Software except to the extent applicable law specifically prohibits such restriction. If you violate any of the terms or restrictions of this Agreement, NXP may immediately terminate this Agreement, and require that you stop using and delete all copies of the Software in your possession or control. You are solely responsible for systems you design using the Software. II. Production License Models: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 69 ATTACHMENT A - NXP Automotive Software License Agreement v1.3 a. Project License: Subject to payment of the fees set forth in the Quotation Document, exclusively in conjunction with Licensee's development and sale of an Authorized System, NXP grants to you the non-exclusive, non-transferable right (1) to use the Software in the Customer Target Project on the Target Product, (2) to reproduce the Software, (3) to prepare or have prepared through multiple layers of subcontractors Limited Derivative Works of the Software, (4) to distribute the Software and Limited Derivative Works thereof in object code only as part of an Authorized System, (5) to sublicense to others the right to use the distributed Software in object code only as included within the Authorized System, and (6) to disclose one copy of the Software and Limited Derivative Works thereof in source code to direct automotive customers solely for internal evaluation and testing or archiving (and not for further use, reproduction, modification or redistribution) only where such disclosure is necessary in order to achieve the purpose of the license because the automotive customer requires disclosure of source code in conjunction with the testing or purchase of an Authorized System incorporating a NXP Target Product, and where the direct automotive customer has executed written agreements obligating itself to observe the limitations set out in this subsection (6) and to protect such Confidential Information on terms at least as strict as those contained in this Agreement. Licensee will remain liable for such subcontractor's adherence to the terms of this Agreement and for any and all acts and omissions of such subcontractors with respect to this Agreement. Notwithstanding limitation on damages in this Agreement, Licensee will indemnify, defend, and hold harmless NXP against any and all claims, costs, damages, liabilities, judgments and attorneys' fees resulting from or arising out of any breach by the sublicensee, or resulting from or arising out of any action by the sublicensee inconsistent with this Agreement. You must prohibit your sublicensees from translating, reverse engineering, decompiling, or disassembling the Software except to the extent applicable law specifically prohibits such restriction. If you violate any of the terms or restrictions of this Agreement, NXP may immediately terminate this Agreement, and require that you stop using and delete all copies of the Software in your possession or control. b. Product Line License: Subject to payment of the fees set forth in the Quotation Document, exclusively in conjunction with Licensee's development and sale of an Authorized System, NXP grants to you, the non-exclusive, non-transferable right (1) to use the Software in one Target Product Family in one Customer Product Line, (2) to reproduce the Software, (3) to prepare or have prepared through multiple layers of subcontractors Limited Derivative Works of the Software, (4) to distribute the Software and Limited Derivative Works thereof in object code only as part of an Authorized System, (5) to sublicense to others the right to use the distributed Software in object code only as included within the Authorized System and (6) to disclose one copy of the Software and Limited Derivative Works thereof in source code to direct automotive customers solely for internal evaluation and testing or archiving (and not for further use, reproduction, modification or redistribution) only where such disclosure is necessary in Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 70 NXP Semiconductors Chapter 2 order to achieve the purpose of the license because the automotive customer requires disclosure of source code in conjunction with the testing or purchase of an Authorized System incorporating a NXP Target Product, and where the direct automotive customer has executed written agreements obligating itself to observe the limitations set out in this subsection (6) and to protect such Confidential Information on terms at least as strict as those contained in this Agreement. Licensee will remain liable for such subcontractor's adherence to the terms of this Agreement and for any and all acts and omissions of such subcontractors with respect to this Agreement. Notwithstanding limitation on damages in this Agreement, Licensee will indemnify, defend, and hold harmless NXP against any and all claims, costs, damages, liabilities, judgments and attorneys' fees resulting from or arising out of any breach by the sublicensee, or resulting from or arising out of any action by the sublicensee inconsistent with this Agreement. You must prohibit your sublicensees from translating, reverse engineering, decompiling, or disassembling the Software except to the extent applicable law specifically prohibits such restriction. If you violate any of the terms or restrictions of this Agreement, NXP may immediately terminate this Agreement, and require that you stop using and delete all copies of the Software in your possession or control. c. Family Multi-Project License: Subject to payment of the fees set forth in the Quotation Document, exclusively in conjunction with Licensee's development and sale of an Authorized System, NXP grants to you, the non-exclusive, non-transferable right (1) to use the Software in one Target Product Family, (2) to reproduce the Software, (3) to prepare or have prepared through multiple layers of subcontractors Limited Derivative Works of the Software, (4) to distribute the Software and Limited Derivative Works thereof in object code only as part of an Authorized System, (5) to sublicense to others the right to use the distributed Software in object code only as included within the Authorized System and (6) to disclose one copy of the Software and Limited Derivative Works thereof in source code to direct automotive customers solely for internal evaluation and testing or archiving (and not for further use, reproduction, modification or redistribution) only where such disclosure is necessary in order to achieve the purpose of the license because the automotive customer requires disclosure of source code in conjunction with the testing or purchase of an Authorized System incorporating a NXP Target Product, and where the direct automotive customer has executed written agreements obligating itself to observe the limitations set out in this subsection (6) and to protect such Confidential Information on terms at least as strict as those contained in this Agreement. Licensee will remain liable for such subcontractor's adherence to the terms of this Agreement and for any and all acts and omissions of such subcontractors with respect to this Agreement. Notwithstanding limitation on damages in this Agreement, Licensee will indemnify, defend, and hold harmless NXP against any and all claims, costs, damages, liabilities, judgments and attorneys' fees resulting from or arising out of any breach by the sublicensee, or resulting from or arising out of any action by the sublicensee inconsistent with this Agreement. You must prohibit your sublicensees from Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 71 ATTACHMENT A - NXP Automotive Software License Agreement v1.3 translating, reverse engineering, decompiling, or disassembling the Software except to the extent applicable law specifically prohibits such restriction. If you violate any of the terms or restrictions of this Agreement, NXP may immediately terminate this Agreement, and require that you stop using and delete all copies of the Software in your possession or control. d. Volume License: Subject to payment of the fees set forth in the Quotation Document., exclusively in conjunction with Licensee's development and sale of a Authorized System, NXP grants to you, the non-exclusive, non-transferable right (1) to use the Software in one Target Product Family on a maximum of the number of Authorized Systems set forth in the Quotation Document, (2) to reproduce the Software, (3) to prepare or have prepared through multiple layers of subcontractors Limited Derivative Works of the Software, (4) to distribute the Software and Limited Derivative Works thereof in object code only as part of an Authorized System, (5) to sublicense to others the right to use the distributed Software in object code only as included within the Authorized System and (6) to disclose one copy of the Software and Limited Derivative Works thereof in source code to direct automotive customers solely for internal evaluation and testing or archiving (and not for further use, reproduction, modification or redistribution) only where such disclosure is necessary in order to achieve the purpose of the license because the automotive customer requires disclosure of source code in conjunction with the testing or purchase of an Authorized System incorporating a NXP Target Product, and where the direct automotive customer has executed written agreements obligating itself to observe the limitations set out in this subsection (6) and to protect such Confidential Information on terms at least as strict as those contained in this Agreement. Licensee will remain liable for such subcontractor's adherence to the terms of this Agreement and for any and all acts and omissions of such subcontractors with respect to this Agreement. Notwithstanding limitation on damages in this Agreement, Licensee will indemnify, defend, and hold harmless NXP against any and all claims, costs, damages, liabilities, judgments and attorneys' fees resulting from or arising out of any breach by the sublicensee, or resulting from or arising out of any action by the sublicensee inconsistent with this Agreement. You must prohibit your sublicensees from translating, reverse engineering, decompiling, or disassembling the Software except to the extent applicable law specifically prohibits such restriction. If you violate any of the terms or restrictions of this Agreement, NXP may immediately terminate this Agreement, and require that you stop using and delete all copies of the Software in your possession or control. COPYRIGHT. The Software is licensed to you, not sold. NXP owns the Software, and United States copyright laws and international treaty provisions protect the Software. Therefore, you must treat the Software like any other copyrighted material (e.g. a book or musical recording). You may not use or copy the Software for any other purpose than what is described in this Agreement. Except as expressly provided herein, NXP does not grant to you any express or implied rights under any NXP or third party patents, Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 72 NXP Semiconductors Chapter 2 copyrights, trademarks, or trade secrets. Additionally, you must reproduce and apply any copyright or other proprietary rights notices included on or embedded in the Software to any copies or derivative works made thereof, in whole or in part, if any. SUPPORT. Except as otherwise agreed by the parties under separate agreement or as specified in the Quotation Document as part of the DISM Package, NXP is NOT obligated to provide any support, upgrades or new releases of the Software. If you wish, you may contact NXP and report problems and provide suggestions regarding the Software. NXP has no obligation whatsoever to respond in any way to such a problem report or suggestion. NXP may make changes to the Software at any time, without any obligation to notify or provide updated versions of the Software to you. NO WARRANTY. TO THE MAXIMUM EXTENT PERMITTED BY LAW, NXP EXPRESSLY DISCLAIMS ANY WARRANTY FOR THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. YOU ASSUME THE ENTIRE RISK ARISING OUT OF THE USE OR PERFORMANCE OF THE SOFTWARE, OR ANY SYSTEMS YOU DESIGN USING THE SOFTWARE (IF ANY). NOTHING IN THIS AGREEMENT MAY BE CONSTRUED AS A WARRANTY OR REPRESENTATION BY NXP THAT THE SOFTWARE OR ANY DERIVATIVE WORK DEVELOPED WITH OR INCORPORATING THE SOFTWARE WILL BE FREE FROM INFRINGEMENT OF THE INTELLECTUAL PROPERTY RIGHTS OF THIRD PARTIES. INDEMNITY. You agree to fully defend and indemnify NXP from any and all claims, liabilities, and costs (including reasonable attorney's fees) related to (1) your use (including your sublicensee's use, if permitted) of the Software or (2) your violation of the terms and conditions of this Agreement. LIMITATION OF LIABILITY. IN NO EVENT WILL NXP BE LIABLE, WHETHER IN CONTRACT, TORT, OR OTHERWISE, FOR ANY INCIDENTAL, SPECIAL, INDIRECT, CONSEQUENTIAL OR PUNITIVE DAMAGES, INCLUDING, BUT NOT LIMITED TO, DAMAGES FOR ANY LOSS OF USE, LOSS OF TIME, INCONVENIENCE, COMMERCIAL LOSS, OR LOST PROFITS, SAVINGS, OR REVENUES TO THE FULL EXTENT SUCH MAY BE DISCLAIMED BY LAW. COMPLIANCE WITH LAWS; EXPORT RESTRICTIONS. You must use the Software in accordance with all applicable U.S. laws, regulations and statutes. You agree that neither you nor your licensees (if any) intend to or will, directly or indirectly, export or transmit the Software to any country in violation of U.S. export restrictions. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 73 ATTACHMENT A - NXP Automotive Software License Agreement v1.3 GOVERNMENT USE. Use of the Software and any corresponding documentation, if any, is provided with RESTRICTED RIGHTS. Use, duplication or disclosure by the Government is subject to restrictions as set forth in subparagraph (c)(1)(ii) of The Rights in Technical Data and Computer Software clause at DFARS 252.227-7013 or subparagraphs (c)(l) and (2) of the Commercial Computer Software--Restricted Rights at 48 CFR 52.227-19, as applicable. Manufacturer is NXP Semiconductor, Inc., 6501 William Cannon Drive West, Austin, TX, 78735. HIGH RISK ACTIVITIES. You acknowledge that the Software is not fault tolerant and is not designed, manufactured or intended by NXP for incorporation into products intended for use or resale in on-line control equipment in hazardous, dangerous to life or potentially life-threatening environments requiring fail-safe performance, such as in the operation of nuclear facilities, aircraft navigation or communication systems, air traffic control, direct life support machines or weapons systems, in which the failure of products could lead directly to death, personal injury or severe physical or environmental damage ("High Risk Activities"). You specifically represent and warrant that you will not use the Software or any derivative work of the Software for High Risk Activities. CHOICE OF LAW; VENUE; LIMITATIONS. You agree that the statutes and laws of the United States and the State of Texas, USA, without regard to conflicts of laws principles, will apply to all matters relating to this Agreement or the Software, and you agree that any litigation will be subject to the exclusive jurisdiction of the state or federal courts in Texas, USA. You agree that regardless of any statute or law to the contrary, any claim or cause of action arising out of or related to this Agreement or the Software must be filed within one (1) year after such claim or cause of action arose or be forever barred. PRODUCT LABELING. You are not authorized to use any NXP trademarks, brand names, or logos. ENTIRE AGREEMENT. This Agreement constitutes the entire agreement between you and NXP regarding the subject matter of this Agreement, and supersedes all prior communications, negotiations, understandings, agreements or representations, either written or oral, if any. This Agreement may only be amended in written form, executed by you and NXP. SEVERABILITY. If any provision of this Agreement is held for any reason to be invalid or unenforceable, then the remaining provisions of this Agreement will be unimpaired and, unless a modification or replacement of the invalid or unenforceable provision is further held to deprive you or NXP of a material benefit, in which case the Agreement will immediately terminate, the invalid or unenforceable provision will be replaced with a provision that is valid and enforceable and that comes closest to the intention underlying the invalid or unenforceable provision. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 74 NXP Semiconductors Chapter 2 NO WAIVER. The waiver by NXP of any breach of any provision of this Agreement will not operate or be construed as a waiver of any other or a subsequent breach of the same or a different provision. CONFIDENTIAL INFORMATION. The Licensee agrees to retain the Confidential Information in confidence perpetually, with respect to Software in source code form (human readable), or for a period of 3 years from the date of receipt of the Confidential Information, with respect to all other Confidential Information. During this period the Licensee may not disclose NXP's Confidential Information to any third party except where such disclosure is necessary in order to achieve the purpose of the license because the automotive customer requires disclosure in conjunction with the testing or purchase of an Authorized System and who have executed written agreements obligating them to protect such Confidential Information. During this period Licensee will also limit dissemination of the Confidential Information to its employees or contractors who have a need to know of the Confidential Information and who have executed written agreements obligating them to protect such Confidential Information, and may not use the NXP's Confidential Information for any purpose or in any manner not authorized by this Agreement. The Licensee further agrees to use the same degree of care, but no less than a reasonable degree of care, with NXP's Confidential Information as it would with its own confidential information. The Licensee may disclose Confidential Information as required by a court or under operation of law or order provided that the Licensee notifies NXP of such requirement prior to disclosure, that the Licensee discloses only that information required, and that the Licensee allows NXP the opportunity to object to such court or other legal body requiring such disclosure. ASSIGNMENT. Neither party may assign this Agreement, by operation of law or otherwise, in whole or in part, or any of its rights, interests, duties or obligations, without the prior written approval of the other party. However, NXP may assign this Agreement, in whole or in part, or any of its rights, interests, duties or obligations, (i) to a subsidiary, parent, or Affiliate or (ii) in connection with a corporate reorganization, acquisition, merger, or sale of all or substantially all of the assets of a division or business unit, provided the acquiring or surviving entity agrees to be bound by this agreement. In addition, NXP reserves the right to supply and invoice through any Affiliate at its discretion. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 75 ATTACHMENT A - NXP Automotive Software License Agreement v1.3 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 76 NXP Semiconductors Chapter 3 Introduction The aim of this document is to describe the Automotive Math and Motor Control Library Set for KEAx devices. It describes the components of the library, its behavior and interaction, the API and steps needed to integrate the library into the customer project. 3.1 Architecture Overview The Automotive Math and Motor Control Library Set for KEAx devices consists of several sub-libraries, functionally connected as depicted in Figure 3-1. Figure 3-1. AMMCLIB components structure Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 77 General Information The Automotive Math and Motor Control Library Set for KEAx devices sub-libraries are as follows: • Mathematical Function Library (MLIB) - comprising basic mathematical operations such as addition, multiplication, etc. • General Function Library (GFLIB) - comprising basic trigonometric and general math functions such as sine, cosine, tan, hysteresis, limit, etc. • General Digital Filters Library (GDFLIB) - comprising digital IIR and FIR filters designed to be used in a motor control application • General Motor Control Library (GMCLIB) - comprising standard algorithms used for motor control such as Clarke/Park transformations, Space Vector Modulation, etc. As can be seen in Figure 3-1, the Automotive Math and Motor Control Library Set for KEAx devices libraries form the layer architecture where all upper libraries utilize the functions from MLIB library. This concept is a key factor for mathematical operations abstractions allowing to support the highly target-optimized variants. 3.2 General Information The Automotive Math and Motor Control Library Set for KEAx devices was developed to support these major implementations: • Fixed-point 32-bit fractional • Fixed-point 16-bit fractional With exception of those functions where the mathematical principle limits the input or output values, these values are considered to be in the following limits: • Fixed-point 32-bit fractional: <-1; 1-2-31> in Q1.31 format and with minimum positive normalized value 2-31. • Fixed-point 16-bit fractional: <-1; 1-2-15> in Q1.15 format and with minimum positive normalized value 2-15. Also those functions which are not relevant for particular implementation, e.g. saturated functions or shifting for single precision floating point implementation, are not delivered with this package. For detailed information about available functions please refer to Function Index. NOTE The fixed-point 32-bit fractional and fixed-point 16-bit fractional functions are implemented based on the unity model. Which means that the input and output numbers are normalized to fit between the <-1; 1-2-31> or <-1; 1-2-15> range representing the Q1.31 or Q1.15 format. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 78 NXP Semiconductors Chapter 3 Introduction The Automotive Math and Motor Control Library Set for KEAx devices was tested using two different test methods. To test the precision of each function implementation, the testing based on Matlab reference models was used. This release was tested using the Matlab R2014a version. To test the implementation on the embedded side, the target-inloop testing was performed on the Automotive Math and Motor Control Library Set for KEAx devices. This release was tested using the SFIO toolbox version 2.2 and Matlab R2014a version. 3.3 Multiple Implementation Support In order to allow the user to utilize arbitrary implementation within one user application without any limitations, three different function call methods are supported in the Automotive Math and Motor Control Library Set for KEAx devices: • Global configuration option • Additional parameter option • API postfix option Each of these method calls the API postfix function. Thus, for each implementation ( 32bit fixed-point, 16-bit fixed point ) only one function is available within the package. This approach is based on ANSI-C99 ISO/IEC 9899:1999 function overloading. By default the support of all implementations is turned off, thus the error message "Define at least one supported implementation in SWLIBS_Config.h file." is displayed during the compilation if no implementation is selected, preventing the user application building. Following are the macro definitions enabling or disabling the implementation support: • SWLIBS_SUPPORT_F32 for 32-bit fixed-point implementation support selection • SWLIBS_SUPPORT_F16 for 16-bit fixed-point implementation support selection These macros are defined in the SWLIBS_Config.h file located in Common directory of the Automotive Math and Motor Control Library Set for KEAx devices installation destination. To enable the support of each individual implementation the relevant macro definition has to be set to SWLIBS_STD_ON. 3.3.1 Global Configuration Option This function call supports the user legacy applications, which were based on older version of Motor Control Library. Prior to any Automotive Math and Motor Control Library Set for KEAx devices function call using the Global configuration option, the SWLIBS_DEFAULT_IMPLEMENTATION macro definition has to be setup properly. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 79 Multiple Implementation Support This macro definition is not defined by default thus the error message "Define default implementation in SWLIBS_Config.h file." is displayed during the compilation, preventing the user application building. The SWLIBS_DEFAULT_IMPLEMENTATION macro is defined in the SWLIBS_Config.h file located in Common directory of the Automotive Math and Motor Control Library Set for KEAx devices installation destination. The SWLIBS_DEFAULT_IMPLEMENTATION can be defined as the one of the following supported implementations: • SWLIBS_DEFAULT_IMPLEMENTATION_F32 for 32-bit fixed-point implementation • SWLIBS_DEFAULT_IMPLEMENTATION_F16 for 16-bit fixed-point implementation After proper definition of SWLIBS_DEFAULT_IMPLEMENTATION macro the Automotive Math and Motor Control Library Set for KEAx devices functions can be called using standard legacy API convention, e.g. GFLIB_Sin(x). For example if the SWLIBS_DEFAULT_IMPLEMENTATION macro definition is set to SWLIBS_DEFAULT_IMPLEMENTATION_F32, the 32-bit fixed-point implementation of sine function is invoked after the GFLIB_Sin(x) API call. Note that all standard legacy API calls will invoke the 32-bit fixed-point implementation in this example. NOTE As the Automotive Math and Motor Control Library Set for KEAx devices supports the global configuration option, it is highly recommended to copy the SWLIBS_Config.h file to your local structure and refer the configuration to this local copy. This approach will prevent the incorrect setup of default configuration option, in case multiple projects with different default configuration are used. 3.3.2 Additional Parameter Option In order to support the free selection of used implementation in the user application while keeping the function name same as in standard legacy API approach, the additional parameter option is implemented in the Automotive Math and Motor Control Library Set for KEAx devices. In this option the additional parameter is used to distinguish which implementation shall be invoked. There are the following possible switches selecting the implementation: • F32 for 32-bit fixed-point implementation • F16 for 16-bit fixed-point implementation Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 80 NXP Semiconductors Chapter 3 Introduction For example, if the user application needs to invoke the 16-bit fixed-point implementation of sine function, the GFLIB_Sin(x, F16) API call needs to be used. Note that there is a possibility to call any implementation of the functions in user application without any limitation. 3.3.3 API Postfix Option In order to support the free selection of used implementation in the user application while keeping the number of parameters same as in standard legacy API approach, the API postfix option is implemented in the Automotive Math and Motor Control Library Set for KEAx devices. In this option the implementation postfix is used to distinguish which implementation shall be invoked. There are the following possible API postfixes selecting the implementation: • F32 for 32-bit fixed-point implementation • F16 for 16-bit fixed-point implementation For example, if the user application needs to invoke the 32-bit implementation of sine function, the GFLIB_Sin_F32 API call needs to be used. Note that there is a possibility to call any implementation of the functions in user application without any limitation. 3.4 Supported Compilers The Automotive Math and Motor Control Library Set for KEAx devices is written in ANSI-C99 ISO/IEC 9899:1999 standard language. The library was built and tested using the following compilers: 1. Green Hills MULTI version 2015.1.4 2. CodeWarrior Development Studio for Microcontrollers version 10.6.4 The library is delivered in a library module "KEAx_AMMCLIB.a" for the Green Hills compiler. The library module is located in "C:\Freescale\AMMCLIB \KEAx_AMMCLIB_v1.1.5\lib\ghs" folder (considering the default installation path). For the CodeWarrior Eclipse IDE, two library modules are delivered: • "KEAx_AMMCLIB_SC.a" for signed char data type • "KEAx_AMMCLIB_UC.a" for unsigned char data type These library modules are located in "C:\Freescale\AMMCLIB \KEAx_AMMCLIB_v1.1.5\lib\cw10x" folder (considering the default installation path). Together with the pre-compiled library modules, these are all the necessary header files. The interfaces to the algorithms included in this library have been combined into a single public interface header file for each respective sub-library, i.e. mlib.h, gflib.h, gdflib.h Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 81 Matlab Integration and gmclib.h. This was done to simplify the number of files required for inclusion by application programs. Refer to the specific algorithm sections of this document for details on the software Application Programming Interface (API), definitions and functionality provided for the individual algorithms. 3.5 Matlab Integration In addition to the Automotive Math and Motor Control Library Set for KEAx devices library modules, the Bit Accurate Models (BAM) are delivered in the installation package. These models can be used in the Matlab Simulink Toolbox to model the behavior of each function in real implementation. As there are two versions of Matlab environment depending on the operation system, both 32-bit and 64-bit Bit Accurate Models are supported. Each model consists of these four files: 1. <libID>_<funcID>_BAM_<implementation>.mdl (e.g. GFLIB_Acos_BAM_F32.mdl): Contains the Bit Accurate Model (BAM) which can be included in the user Matlab Simulink model and refers to the S-function C file, and the S-function executable file. 2. <libID>_<funcID>_SF_<implementation>.c (e.g. GFLIB_Acos_SF_F32.c): The Sfunction C file that calls a simple legacy function during the simulation. 3. <libID>_<funcID>_SF_<implementation>.mexw32 (e.g. GFLIB_Acos_SF_F32.mexw32): Contains the compiled MATLAB S-function executable file created from the function C source file compiled for 32-bit Matlab environment. 4. <libID>_<funcID>_SF_<implementation>.mexw64 (e.g. GFLIB_Acos_SF_F32.mexw64): Contains the compiled MATLAB S-function executable file created from the function C source file compiled for 64-bit Matlab environment. All delivered functions are provided with Bit Accurate Models in all applicable implementation versions and were compiled using Matlab 2014a and Windows SDK v7.1 in case of 64-bit models and using LCC compiler in case of 32-bit Bit Accurate Models. The user is thus responsible for selecting appropriate version of the Bit Accurate Model considering also the version of the Matlab environment. To include the Bit Accurate Model in the user Simulink scheme, simply copy the BAM model into the Simulink scheme. All Matlab/Simulink models are available as a standalone model in the appropriate library in the "bam" folder or, to make work easier, in one single model library "ammclib_bam.mdl" file which can be used for Matlab/Simulink scheme creation. The BAM models can be pulled out from this unified model and can be easily placed into your Matlab/Simulink scheme. Note that the BAM parameters need to be properly set up. The structure of the Matlab files delivered with the Automotive Math and Motor Control Library Set for KEAx devices is depicted in Figure 3-2. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 82 NXP Semiconductors Chapter 3 Introduction Figure 3-2. AMMCLib Matlab file structure An example of Matlab Simulink model utilizing the Automotive Math and Motor Control Library Set for KEAx devices Bit Accurate Models is depicted in Figure 3-3. Note that this schema is for the illustration only. Figure 3-3. Example of Matlab Simulink model utilizing the Bit Accurate Models 3.6 Installation The Automotive Math and Motor Control Library Set for KEAx devices is delivered as a single executable file. To install the Automotive Math and Motor Control Library Set for KEAx devices on a user computer, it is necessary to run the installation file and follow these steps: 1. On welcome page select the Next to start the installation Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 83 Installation Figure 3-4. AMMCLib installation - step 1. Highlighted "MCU Platform" and "ReleaseID" identifies the actual release, which is the KEAx_AMMCLIB_v1.1.5 2. Accept the license agreement Figure 3-5. AMMCLib installation - step 2 3. Select the destination directory Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 84 NXP Semiconductors Chapter 3 Introduction Figure 3-6. AMMCLib installation - step 3. Highlighted "Platform" and "ReleaseID" identifies the actual release installation path, which is the KEAx_AMMCLIB_v1.1.5 4. Check the destination directory and confirm the installation Figure 3-7. AMMCLib installation - step 4. Highlighted "Platform" and "ReleaseID" identifies the actual release installation path, which is the KEAx_AMMCLIB_v1.1.5 5. After installation carefully read the Release notes with important additional information about the release Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 85 Library File Structure Figure 3-8. AMMCLib installation - step 5. Highlighted "Platform" and "ReleaseID" identifies the actual release, which is the KEAx_AMMCLIB_v1.1.5 6. Select Finish to end the installation Figure 3-9. MCLib installation - step 6 3.7 Library File Structure After a successful installation, the Automotive Math and Motor Control Library Set for KEAx devices is added by default into the "C:\Freescale\AMMCLIB \KEAx_AMMCLIB_v1.1.5" subfolder. This folder will contain other nested subfolders and files required by the Automotive Math and Motor Control Library Set for KEAx devices, as shown in Figure 3-10. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 86 NXP Semiconductors Chapter 3 Introduction Figure 3-10. AMMCLIB directory structure A list of the installed directories/files, and their brief description, is given below: • bam - contains Bit Accurate Models of all the functions for Matlab/Simulink • doc - contains the User Manual • include - contains all the header files, including the master header files of each library to be included in the user application • lib - contains the compiled library file to be included in the user application In order to integrate the Automotive Math and Motor Control Library Set for KEAx devices into a new Green Hills compiler based project, the steps described in Library Integration into a Green Hills Multi Development Environment section must be performed. For integration of the Automotive Math and Motor Control Library Set for KEAx devices into a new Eclipse-based CodeWarrior based project, the steps described in section Library Integration into a Freescale CodeWarrior Eclipse IDE must be performed. The header files structure of the Automotive Math and Motor Control Library Set for KEAx devices is depicted in Figure 3-11. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 87 Integration Assumption Figure 3-11. AMMCLIB header file structure 3.8 Integration Assumption In order to successfully integrate the Automotive Math and Motor Control Library Set for KEAx devices to the customer application, the following assumptions need to be considered: 1. The C-99 language has to be enabled in the user application (please refer to User manual of your compiler to enable this feature). 2. In case the Freescale CodeWarrior Eclipse IDE is used, the C++ extension has to be switched off. 3.9 Library Integration into a Green Hills Multi Development Environment The Automotive Math and Motor Control Library Set for KEAx devices is added into a new Green Hills Multi project using the following steps: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 88 NXP Semiconductors Chapter 3 Introduction 1. Open a new empty C project in the Green Hills Multi IDE. See the Green Hills Multi user manual for instructions. 2. Once you have successfully created and opened a new C project, right click on the project file *.gpj in the GHS Multi Project Manager. Select <Set Build Options...> from the pop-up menu, as shown in Figure 3-12 Figure 3-12. Project build options 3. In the <Basic Options> tab of the <Build Options> window, expand section <Project> and double click on the item <Include Directories (-I)>. Here, the directory where the builder should look for all the project header files, including the library header files, shall be specified as shown in Figure 3-13. Considering default settings, the following path shall be added: "C:\Freescale\AMMCLIB \KEAx_AMMCLIB_v1.1.5\include. " Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 89 Library Integration into a Green Hills Multi Development Environment Figure 3-13. Adding a path to the library header files 4. While still in the <Project> section, double click on <Libraries (-l)> and enter a path and a pre-compiled library object file into the dialogue box, as shown in Figure 3-14. Figure 3-14. Adding a path to the library object files Considering default settings, you should add "C:\Freescale\AMMCLIB \KEAx_AMMCLIB_v1.1.5\lib\ghs\KEAx_AMMCLIB.a" 5. In order to use the library functions, the library master header files must be included into the application source code. This is done using the pre-processor directive \#include "<libID>.h", where <libID> can be gdflib, gflib, gmclib, depending on which library is to be employed. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 90 NXP Semiconductors Chapter 3 Introduction The master header files contain several additional header files that are needed for the Automotive Math and Motor Control Library Set for KEAx devices integration into any user application. They include the "SWLIBS_Typedefs.h" header file which contains all general purpose data type definitions, the "mlib.h" header file containing all general math functions, the "SWLIBS_Defines.h" file containing common macro definitions and the "SWLIBS_MacroDisp.h" allowing the implementation based API call. NOTE Remember that by default there is no default implementation selected in the "SWLIBS_Config.h" thus the error message will be displayed during the compilation requesting the default implementation selection. Figure 3-15. Opening the C editor for editing the application source code Figure 3-16. Using the pre-processor directive to include library master header files Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 91 Library Integration into a Freescale CodeWarrior Eclipse IDE At this point, the Automotive Math and Motor Control Library Set for KEAx devices is linked with the user project file, and hence the library functions can be exploited and flawlessly compiled/linked with the user application. 3.10 Library Integration into a Freescale CodeWarrior Eclipse IDE The release provides two library versions for the Eclipse-based CodeWarrior environment. The library versions are different in the compilation options that were set while the library was compiled: • The library file with the suffix: _SC.a, compilation options used: KEAx family, char type is signed. • The library file with the suffix: _UC.a, compilation options used: KEAx family, char type is unsigned. The selection of the library version should follow those compilation options set for the CodeWarrior Eclipse IDE project. If the Automotive Math and Motor Control Library Set for KEAx devices options and project options are different, warnings would be reported. All described steps assume that there is an existing Eclipse project ("mclib_example_cw10x" name is used on below pictures). In order to use the Automotive Math and Motor Control Library Set for KEAx devices within a Eclipse-based CodeWarrior GUI environment, it is necessary to provide the Eclipse-based CodeWarrior GUI with access paths to the Automotive Math and Motor Control Library Set for KEAx devices files. The following files shall be added to the user project: • Library binary files located in the directory "C:\Freescale\AMMCLIB \KEAx_AMMCLIB_v1.1.5\lib\cw10x" (note: this is the default location and may be modified during library installation) • Header files located in the directory "C:\Freescale\AMMCLIB \KEAx_AMMCLIB_v1.1.5\include" (note: this is the default location and may be modified during library installation) To add these files, select your project in the <Project Explorer> in the left tab, and from the <Project> menu select the <Properties> option as described in Figure 3-17. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 92 NXP Semiconductors Chapter 3 Introduction Figure 3-17. Selection of the project property in the CodeWarrior Eclipse IDE In the <Properties> window, select the <Paths and Symbols> from the left-hand list and choose the <Includes> tab and <C Source File> under the <Languages> section, as described in Figure 3-18. Figure 3-18. Selecting the include paths in the CodeWarrior Eclipse IDE By selecting the <Add..> button, add the directories, where the builder should look for all the header files. Considering the default settings, the path shown in Figure 3-19 shall be added. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 93 Library Integration into a Freescale CodeWarrior Eclipse IDE Figure 3-19. Adding the header files path to the CodeWarrior Eclipse IDE project After adding of the Automotive Math and Motor Control Library Set for KEAx devices header files path, the library object file shall be add to the Eclipse-based CodeWarrior project. In the <Properties> window, select the <Paths and Symbols> from the left-hand list and choose the <Libraries> tab, as described in Figure 3-20. Figure 3-20. Selecting the library object in the CodeWarrior Eclipse IDE By selecting the <Add..> button, add the library object file (consider the project setting of char data type representation). Considering the default settings, the path shown in Figure 3-21 shall be added. Figure 3-21. Adding the library object file to the CodeWarrior Eclipse IDE project Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 94 NXP Semiconductors Chapter 3 Introduction In order to use the library functions, the library master header files must be included into the application source code. This is done using the pre-processor directive \#include "<libID>.h", where <libID> can be gdflib, gflib, gmclib, depending on which library is to be employed. The master header files contain several additional header files that are needed for the Automotive Math and Motor Control Library Set for KEAx devices integration into any user application. They include the "SWLIBS_Typedefs.h" header file which contains all general purpose data type definitions, the "mlib.h" header file containing all general math functions, the "SWLIBS_Defines.h" file containing common macro definitions and the "SWLIBS_MacroDisp.h" allowing the implementation based API call. NOTE Remember that by default there is no default implementation selected in the "SWLIBS_Config.h" thus the error message will be displayed during the compilation requesting the default implementation selection. At this point, the Automotive Math and Motor Control Library Set for KEAx devices is linked with the user project file, and hence the library functions can be exploited and flawlessly compiled/linked with the user application. 3.11 Library Testing In order to validate the implementation of the Automotive Math and Motor Control Library Set for KEAx devices, the comparison of results from the MATLAB Reference Model and outputs from the tested library function is used. To ensure the Automotive Math and Motor Control Library Set for KEAx devices precision, two test methods are used: • Matlab Simulink Toolbox based testing (refer to AMMCLIB Testing based on the MATLAB Simulink Toolbox for more details). • Target-in-loop based testing (refer to AMMCLIB target-in-loop Testing based on the SFIO Toolbox for detailed information). The Figure 3-22 shows the testing principle: • Input vector represents the test vector which enters simultaneously into the Reference Model and into the Unit Under Test (UUT). • Reference Model (RM) implements the real model of the UUT. For simple functions, the models are a part of the MATLAB Simulink Toolbox. Advanced functions such as filters or controllers had been designed separately. • By the type of test method used, the Unit Under Test (UUT) may be: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 95 Library Testing • Bit Accurate Model (BAM) - the "C" implementation of the tested function compiled in the MATLAB environment. The compilation result, called the binary MEX-file, is a dynamically-linked subroutine that the MATLAB interpreter can load and execute. • SFIO Model represents the tested function running directly on the target MCU. Results from the UUT and Reference Model are saved in the final report, together with the calculated error which is simply the difference between the output value from the Reference Model and the output value from the UUT, recalculated to an equivalent precision. The equivalent precision is the same for all supported implementations of the Automotive Math and Motor Control Library Set for KEAx devices. For the 32-bit and 16-bit fixedpoint implementations, the output precision of non-approximation function is greater or equal to +/-1 LSB in 16-bit arithmetic, and is greater or equal to +/-3 LSB in 16-bit arithmetic for approximation functions. The output value of the function is determined by the following expressions: • Approximation function with precision +/-3 LSB: • 32-bit fixed point: <PRECISE_VALUE> +/- 3*2^-15 • 16-bit fixed point: <PRECISE_VALUE> +/- 3*2^-15 • Non-approximation function with precision +/-1 LSB: • 32-bit fixed point: <PRECISE_VALUE> +/- 2^-15 • 16-bit fixed point: <PRECISE_VALUE> +/- 2^-15 Figure 3-22. Principle of AMMCLIB testing In order to test the UUT under all conditions, three types of test vector sets are used: • Deterministic vectors - a specifically defined set of input values over the entire input range. • Stochastic vectors - a pseudo-randomly generated set of values (non-deterministic values fully covering the input range). • Boundary vectors - a set of input values for which the potential weaknesses of the tested function are expected. This test is performed only on functions where these limit conditions might occur. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 96 NXP Semiconductors Chapter 3 Introduction Each function is considered tested if the required accuracy during deterministic, stochastic and boundary tests has been achieved. The following two subchapters AMMCLIB Testing based on the MATLAB Simulink Toolbox and AMMCLIB target-inloop Testing based on the SFIO Toolbox describe the differences between AMMCLIB testing based on BAM models and target-in-loop testing based on SFIO models. 3.11.1 AMMCLIB Testing based on the MATLAB Simulink Toolbox An example of the testing principle based on the BAM is depicted in the Clark transformation function (Figure 3-23). The Bit Accurate Model contains the binary MEXfile built from the GMCLIB_Clark function using the MATLAB compiler. This file is called inside the BAM model, see Figure 3-24. The Reference Model of the Clark transformation is not included in the MATLAB Simulink Toolbox and hence its mathematical representation had to be created. A detailed scheme of the Clark RM is in Figure 3-25. Figure 3-23. Testing of the GMCLIB_Clark function based on the MATLAB Simulink Toolbox Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 97 Library Testing Figure 3-24. Bit Accurate Model parameters of the Clark transformation Figure 3-25. Reference Model of the GMCLIB_Clark function 3.11.2 AMMCLIB target-in-loop Testing based on the SFIO Toolbox The testing method in Figure 3-26 is the similar to that described in the previous chapter with exception that the BAM model is replaced by the SFIO model. The SFIO Toolbox realizes the bridge between Matlab and the Embedded target. During testing, the function GMCLIB_Clark is called directly from the application running on the target MCU. Unlike testing based on MATLAB, the target-in-loop method verifies that the implementation of the Automotive Math and Motor Control Library Set for KEAx devices functions works correctly on the target MCU. Moreover, the SFIO application running on the processor is used to measure performance of the functions. The SFIO block Set-up allows the setting of communication parameters which are common to the whole scheme. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 98 NXP Semiconductors Chapter 3 Introduction Figure 3-26. Target-in-loop testing example based on the SFIO Toolbox 3.12 Functions Precision The maximum allowed error of the Automotive Math and Motor Control Library Set for KEAx devices functions vary based on the implementation, and based on the character of the function. The output error is calculated as the difference between the implemented function and double-precision reference model, as described in the Library Testing section. The actual output error of the function for current input values is smaller or equal to the maximum allowed error described in the table below. The output error of the 32-bit and 16-bit fixed-point implementations is calculated as the absolute error. The following table describes the maximum allowed error of the functions: Table 3-1. Function precision in [LSB] Function name F32 F16 GDFLIB_FilterFIR 3 3 GDFLIB_FilterFIRInit 0 0 GDFLIB_FilterIIR1 1 1 GDFLIB_FilterIIR1Init 0 0 GDFLIB_FilterIIR2 1 1 GDFLIB_FilterIIR2Init 0 0 GDFLIB_FilterMA 1 1 GDFLIB_FilterMAInit 0 0 GFLIB_Acos 3 3 Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 99 Functions Precision Table 3-1. Function precision in [LSB] (continued) Function name F32 F16 GFLIB_Asin 3 3 GFLIB_Atan 3 3 GFLIB_AtanYX 3 3 GFLIB_AtanYXShifted 3 3 GFLIB_ControllerPIp 3 3 GFLIB_ControllerPIpAW 3 3 GFLIB_ControllerPIr 3 3 GFLIB_ControllerPIrAW 3 3 GFLIB_Cos 3 3 GFLIB_Hyst 1 1 GFLIB_IntegratorTR 3 3 GFLIB_Limit 1 1 GFLIB_LowerLimit 1 1 GFLIB_Lut1D 3 3 GFLIB_Lut2D 3 3 GFLIB_Ramp 1 1 GFLIB_Sign 1 1 GFLIB_Sin 3 3 GFLIB_SinCos 3 3 GFLIB_Sqrt 1 3 GFLIB_Tan 3 3 GFLIB_UpperLimit 1 1 GFLIB_VectorLimit 3 3 GMCLIB_Clark 1 3 GMCLIB_ClarkInv 1 3 GMCLIB_DecouplingPMSM 1 3 GMCLIB_ElimDcBusRip 3 3 GMCLIB_Park 1 1 GMCLIB_ParkInv 1 1 GMCLIB_SvmStd 1 3 MLIB_Abs 1 1 MLIB_AbsSat 1 1 MLIB_Add 1 1 MLIB_AddSat 1 1 MLIB_Convert_F16F32 1 1 MLIB_Convert_F32F16 1 1 MLIB_ConvertPU_F16F32 1 1 MLIB_ConvertPU_F32F16 1 1 Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 100 NXP Semiconductors Chapter 3 Introduction Table 3-1. Function precision in [LSB] (continued) Function name F32 F16 MLIB_Div 3 1 MLIB_DivSat 3 1 MLIB_Mac 1 1 MLIB_MacSat 1 1 MLIB_Mul 1 1 MLIB_MulSat 1 1 MLIB_Neg 1 1 MLIB_NegSat 1 1 MLIB_Norm 1 1 MLIB_RndSat 1 1 MLIB_Round 1 1 MLIB_ShBi 1 1 MLIB_ShBiSat 1 1 MLIB_ShL 1 1 MLIB_ShLSat 1 1 MLIB_ShR 1 1 MLIB_Sub 1 1 MLIB_SubSat 1 1 MLIB_VMac 1 2 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 101 Functions Precision Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 102 NXP Semiconductors Chapter 4 4.1 Function Index Table 4-1. Quick function reference Type Name Arguments void GDFLIB_FilterFIRInit_F16 const GDFLIB_FILTERFIR_PARAM_T_F16 *const pParam GDFLIB_FILTERFIR_STATE_T_F16 *const pState tFrac16 * pInBuf void GDFLIB_FilterFIRInit_F32 const GDFLIB_FILTERFIR_PARAM_T_F32 *const pParam GDFLIB_FILTERFIR_STATE_T_F32 *const pState tFrac32 * pInBuf tFrac16 GDFLIB_FilterFIR_F16 tFrac16 f16In const GDFLIB_FILTERFIR_PARAM_T_F16 *const pParam GDFLIB_FILTERFIR_STATE_T_F16 *const pState tFrac32 GDFLIB_FilterFIR_F32 tFrac32 f32In const GDFLIB_FILTERFIR_PARAM_T_F32 *const pParam GDFLIB_FILTERFIR_STATE_T_F32 *const pState void GDFLIB_FilterIIR1Init_F16 GDFLIB_FILTER_IIR1_T_F16 *const pParam void GDFLIB_FilterIIR1Init_F32 GDFLIB_FILTER_IIR1_T_F32 *const pParam tFrac16 GDFLIB_FilterIIR1_F16 tFrac16 f16In GDFLIB_FILTER_IIR1_T_F16 *const pParam tFrac32 GDFLIB_FilterIIR1_F32 tFrac32 f32In GDFLIB_FILTER_IIR1_T_F32 *const pParam void GDFLIB_FilterIIR2Init_F16 GDFLIB_FILTER_IIR2_T_F16 *const pParam void GDFLIB_FilterIIR2Init_F32 GDFLIB_FILTER_IIR2_T_F32 *const pParam tFrac16 GDFLIB_FilterIIR2_F16 tFrac16 f16In GDFLIB_FILTER_IIR2_T_F16 *const pParam tFrac32 GDFLIB_FilterIIR2_F32 tFrac32 f32In GDFLIB_FILTER_IIR2_T_F32 *const pParam void GDFLIB_FilterMAInit_F16 GDFLIB_FILTER_MA_T_F16 * pParam void GDFLIB_FilterMAInit_F32 GDFLIB_FILTER_MA_T_F32 * pParam tFrac16 GDFLIB_FilterMA_F16 tFrac16 f16In GDFLIB_FILTER_MA_T_F16 * pParam tFrac32 GDFLIB_FilterMA_F32 tFrac32 f32In Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 103 Function Index Table 4-1. Quick function reference (continued) Type Name Arguments GDFLIB_FILTER_MA_T_F32 * pParam tFrac16 GFLIB_Acos_F16 tFrac16 f16In const GFLIB_ACOS_T_F16 *const pParam tFrac32 GFLIB_Acos_F32 tFrac32 f32In const GFLIB_ACOS_T_F32 *const pParam tFrac16 GFLIB_Asin_F16 tFrac16 f16In const GFLIB_ASIN_T_F16 *const pParam tFrac32 GFLIB_Asin_F32 tFrac32 f32In const GFLIB_ASIN_T_F32 *const pParam tFrac16 GFLIB_AtanYXShifted_F16 tFrac16 f16InY tFrac16 f16InX const GFLIB_ATANYXSHIFTED_T_F16 * pParam tFrac32 GFLIB_AtanYXShifted_F32 tFrac32 f32InY tFrac32 f32InX const GFLIB_ATANYXSHIFTED_T_F32 * pParam tFrac16 GFLIB_AtanYX_F16 tFrac16 f16InY tFrac16 f16InX tFrac32 GFLIB_AtanYX_F32 tFrac32 f32InY tFrac32 f32InX tFrac16 GFLIB_Atan_F16 tFrac16 f16In const GFLIB_ATAN_T_F16 *const pParam tFrac32 GFLIB_Atan_F32 tFrac32 f32In const GFLIB_ATAN_T_F32 *const pParam tFrac16 GFLIB_ControllerPIpAW_F16 tFrac16 f16InErr GFLIB_CONTROLLER_PIAW_P_T_F16 *const pParam tFrac32 GFLIB_ControllerPIpAW_F32 tFrac32 f32InErr GFLIB_CONTROLLER_PIAW_P_T_F32 *const pParam tFrac16 GFLIB_ControllerPIp_F16 tFrac16 f16InErr GFLIB_CONTROLLER_PI_P_T_F16 *const pParam tFrac32 GFLIB_ControllerPIp_F32 tFrac32 f32InErr GFLIB_CONTROLLER_PI_P_T_F32 *const pParam tFrac16 GFLIB_ControllerPIrAW_F16 tFrac16 f16InErr GFLIB_CONTROLLER_PIAW_R_T_F16 *const pParam tFrac32 GFLIB_ControllerPIrAW_F32 tFrac32 f32InErr GFLIB_CONTROLLER_PIAW_R_T_F32 *const pParam tFrac16 GFLIB_ControllerPIr_F16 tFrac16 f16InErr GFLIB_CONTROLLER_PI_R_T_F16 *const pParam tFrac32 GFLIB_ControllerPIr_F32 tFrac32 f32InErr GFLIB_CONTROLLER_PI_R_T_F32 *const pParam tFrac16 GFLIB_Cos_F16 tFrac16 f16In const GFLIB_COS_T_F16 *const pParam tFrac32 GFLIB_Cos_F32 tFrac32 f32In const GFLIB_COS_T_F32 *const pParam Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 104 NXP Semiconductors Chapter 4 Table 4-1. Quick function reference (continued) Type Name Arguments tFrac16 GFLIB_Hyst_F16 tFrac16 f16In GFLIB_HYST_T_F16 *const pParam tFrac32 GFLIB_Hyst_F32 tFrac32 f32In GFLIB_HYST_T_F32 *const pParam tFrac16 GFLIB_IntegratorTR_F16 tFrac16 f16In GFLIB_INTEGRATOR_TR_T_F16 *const pParam tFrac32 GFLIB_IntegratorTR_F32 tFrac32 f32In GFLIB_INTEGRATOR_TR_T_F32 *const pParam tFrac16 GFLIB_Limit_F16 tFrac16 f16In const GFLIB_LIMIT_T_F16 *const pParam tFrac32 GFLIB_Limit_F32 tFrac32 f32In const GFLIB_LIMIT_T_F32 *const pParam tFrac16 GFLIB_LowerLimit_F16 tFrac16 f16In const GFLIB_LOWERLIMIT_T_F16 *const pParam tFrac32 GFLIB_LowerLimit_F32 tFrac32 f32In const GFLIB_LOWERLIMIT_T_F32 *const pParam tFrac16 GFLIB_Lut1D_F16 tFrac16 f16In const GFLIB_LUT1D_T_F16 *const pParam tFrac32 GFLIB_Lut1D_F32 tFrac32 f32In const GFLIB_LUT1D_T_F32 *const pParam tFrac16 GFLIB_Lut2D_F16 tFrac16 f16In1 tFrac16 f16In2 const GFLIB_LUT2D_T_F16 *const pParam tFrac32 GFLIB_Lut2D_F32 tFrac32 f32In1 tFrac32 f32In2 const GFLIB_LUT2D_T_F32 *const pParam tFrac16 GFLIB_Ramp_F16 tFrac16 f16In GFLIB_RAMP_T_F16 *const pParam tFrac32 GFLIB_Ramp_F32 tFrac32 f32In GFLIB_RAMP_T_F32 *const pParam tFrac16 GFLIB_Sign_F16 tFrac16 f16In tFrac32 GFLIB_Sign_F32 tFrac32 f32In void GFLIB_SinCos_F16 tFrac16 f16In SWLIBS_2Syst_F16 * pOut const GFLIB_SINCOS_T_F16 *const pParam void GFLIB_SinCos_F32 tFrac32 f32In SWLIBS_2Syst_F32 * pOut const GFLIB_SINCOS_T_F32 *const pParam tFrac16 GFLIB_Sin_F16 tFrac16 f16In const GFLIB_SIN_T_F16 *const pParam tFrac32 GFLIB_Sin_F32 tFrac32 f32In const GFLIB_SIN_T_F32 *const pParam tFrac16 GFLIB_Sqrt_F16 tFrac16 f16In tFrac32 GFLIB_Sqrt_F32 tFrac32 f32In tFrac16 GFLIB_Tan_F16 tFrac16 f16In const GFLIB_TAN_T_F16 *const pParam Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 105 Function Index Table 4-1. Quick function reference (continued) Type Name Arguments tFrac32 GFLIB_Tan_F32 tFrac32 f32In const GFLIB_TAN_T_F32 *const pParam tFrac16 GFLIB_UpperLimit_F16 tFrac16 f16In const GFLIB_UPPERLIMIT_T_F16 *const pParam tFrac32 GFLIB_UpperLimit_F32 tFrac32 f32In const GFLIB_UPPERLIMIT_T_F32 *const pParam tBool GFLIB_VectorLimit_F16 const SWLIBS_2Syst_F16 *const pIn SWLIBS_2Syst_F16 *const pOut const GFLIB_VECTORLIMIT_T_F16 *const pParam tBool GFLIB_VectorLimit_F32 const SWLIBS_2Syst_F32 *const pIn SWLIBS_2Syst_F32 *const pOut const GFLIB_VECTORLIMIT_T_F32 *const pParam void GMCLIB_ClarkInv_F16 const SWLIBS_2Syst_F16 *const pIn SWLIBS_3Syst_F16 *const pOut void GMCLIB_ClarkInv_F32 const SWLIBS_2Syst_F32 *const pIn SWLIBS_3Syst_F32 *const pOut void GMCLIB_Clark_F16 const SWLIBS_3Syst_F16 *const pIn SWLIBS_2Syst_F16 *const pOut void GMCLIB_Clark_F32 const SWLIBS_3Syst_F32 *const pIn SWLIBS_2Syst_F32 *const pOut void GMCLIB_DecouplingPMSM_F16 SWLIBS_2Syst_F16 *const pUdqDec const SWLIBS_2Syst_F16 *const pUdq const SWLIBS_2Syst_F16 *const pIdq tFrac16 f16AngularVel const GMCLIB_DECOUPLINGPMSM_T_F16 *const pParam void GMCLIB_DecouplingPMSM_F32 SWLIBS_2Syst_F32 *const pUdqDec const SWLIBS_2Syst_F32 *const pUdq const SWLIBS_2Syst_F32 *const pIdq tFrac32 f32AngularVel const GMCLIB_DECOUPLINGPMSM_T_F32 *const pParam void GMCLIB_ElimDcBusRip_F16 SWLIBS_2Syst_F16 *const pOut const SWLIBS_2Syst_F16 *const pIn const GMCLIB_ELIMDCBUSRIP_T_F16 *const pParam void GMCLIB_ElimDcBusRip_F32 SWLIBS_2Syst_F32 *const pOut const SWLIBS_2Syst_F32 *const pIn const GMCLIB_ELIMDCBUSRIP_T_F32 *const pParam void GMCLIB_ParkInv_F16 SWLIBS_2Syst_F16 *const pOut const SWLIBS_2Syst_F16 *const pInAngle const SWLIBS_2Syst_F16 *const pIn void GMCLIB_ParkInv_F32 SWLIBS_2Syst_F32 *const pOut const SWLIBS_2Syst_F32 *const pInAngle const SWLIBS_2Syst_F32 *const pIn void GMCLIB_Park_F16 SWLIBS_2Syst_F16 * pOut const SWLIBS_2Syst_F16 *const pInAngle const SWLIBS_2Syst_F16 *const pIn Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 106 NXP Semiconductors Chapter 4 Table 4-1. Quick function reference (continued) Type Name Arguments void GMCLIB_Park_F32 SWLIBS_2Syst_F32 * pOut const SWLIBS_2Syst_F32 *const pInAngle const SWLIBS_2Syst_F32 *const pIn tU16 GMCLIB_SvmStd_F16 SWLIBS_3Syst_F16 * pOut const SWLIBS_2Syst_F16 *const pIn tU32 GMCLIB_SvmStd_F32 SWLIBS_3Syst_F32 * pOut const SWLIBS_2Syst_F32 *const pIn tFrac16 MLIB_AbsSat_F16 register tFrac16 f16In tFrac32 MLIB_AbsSat_F32 register tFrac32 f32In tFrac16 MLIB_Abs_F16 register tFrac16 f16In tFrac32 MLIB_Abs_F32 register tFrac32 f32In tFrac16 MLIB_AddSat_F16 register tFrac16 f16In1 register tFrac16 f16In2 tFrac32 MLIB_AddSat_F32 register tFrac32 f32In1 register tFrac32 f32In2 tFrac16 MLIB_Add_F16 register tFrac16 f16In1 register tFrac16 f16In2 tFrac32 MLIB_Add_F32 register tFrac32 f32In1 register tFrac32 f32In2 tFrac16 MLIB_ConvertPU_F16F32 register tFrac32 f32In tFrac32 MLIB_ConvertPU_F32F16 register tFrac16 f16In tFrac16 MLIB_Convert_F16F32 register tFrac32 f32In1 register tFrac32 f32In2 tFrac32 MLIB_Convert_F32F16 register tFrac16 f16In1 register tFrac16 f16In2 tFrac16 MLIB_DivSat_F16 register tFrac16 f16In1 register tFrac16 f16In2 tFrac32 MLIB_DivSat_F32 register tFrac32 f32In1 register tFrac32 f32In2 tFrac16 MLIB_Div_F16 register tFrac16 f16In1 register tFrac16 f16In2 tFrac32 MLIB_Div_F32 register tFrac32 f32In1 register tFrac32 f32In2 tFrac16 MLIB_MacSat_F16 register tFrac16 f16In1 register tFrac16 f16In2 register tFrac16 f16In3 tFrac32 MLIB_MacSat_F32 register tFrac32 f32In1 register tFrac32 f32In2 register tFrac32 f32In3 tFrac32 MLIB_MacSat_F32F16F16 register tFrac32 f32In1 register tFrac16 f16In2 register tFrac16 f16In3 tFrac16 MLIB_Mac_F16 register tFrac16 f16In1 register tFrac16 f16In2 register tFrac16 f16In3 tFrac32 MLIB_Mac_F32 register tFrac32 f32In1 Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 107 Function Index Table 4-1. Quick function reference (continued) Type Name Arguments register tFrac32 f32In2 register tFrac32 f32In3 tFrac32 MLIB_Mac_F32F16F16 register tFrac32 f32In1 register tFrac16 f16In2 register tFrac16 f16In3 tFrac16 MLIB_Mnac_F16 register tFrac16 f16In1 register tFrac16 f16In2 register tFrac16 f16In3 tFrac32 MLIB_Mnac_F32 register tFrac32 f32In1 register tFrac32 f32In2 register tFrac32 f32In3 tFrac32 MLIB_Mnac_F32F16F16 register tFrac32 f32In1 register tFrac16 f16In2 register tFrac16 f16In3 tFrac16 MLIB_Msu_F16 register tFrac16 f16In1 register tFrac16 f16In2 register tFrac16 f16In3 tFrac32 MLIB_Msu_F32 register tFrac32 f32In1 register tFrac32 f32In2 register tFrac32 f32In3 tFrac32 MLIB_Msu_F32F16F16 register tFrac32 f32In1 register tFrac16 f16In2 register tFrac16 f16In3 tFrac16 MLIB_MulSat_F16 register tFrac16 f16In1 register tFrac16 f16In2 tFrac32 MLIB_MulSat_F32 register tFrac32 f32In1 register tFrac32 f32In2 tFrac32 MLIB_MulSat_F32F16F16 register tFrac16 f16In1 register tFrac16 f16In2 tFrac16 MLIB_Mul_F16 register tFrac16 f16In1 register tFrac16 f16In2 tFrac32 MLIB_Mul_F32 register tFrac32 f32In1 register tFrac32 f32In2 tFrac32 MLIB_Mul_F32F16F16 register tFrac16 f16In1 register tFrac16 f16In2 tFrac16 MLIB_NegSat_F16 register tFrac16 f16In tFrac32 MLIB_NegSat_F32 register tFrac32 f32In tFrac16 MLIB_Neg_F16 register tFrac16 f16In tFrac32 MLIB_Neg_F32 register tFrac32 f32In tU16 MLIB_Norm_F16 register tFrac16 f16In tU16 MLIB_Norm_F32 register tFrac32 f32In tFrac16 MLIB_RndSat_F16F32 register tFrac32 f32In tFrac16 MLIB_Round_F16 register tFrac16 f16In1 register tU16 u16In2 tFrac32 MLIB_Round_F32 register tFrac32 f32In1 register tU16 u16In2 Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 108 NXP Semiconductors Chapter 4 Table 4-1. Quick function reference (continued) Type Name Arguments tFrac16 MLIB_ShBiSat_F16 register tFrac16 f16In1 register tS16 s16In2 tFrac32 MLIB_ShBiSat_F32 register tFrac32 f32In1 register tS16 s16In2 tFrac16 MLIB_ShBi_F16 register tFrac16 f16In1 register tS16 s16In2 tFrac32 MLIB_ShBi_F32 register tFrac32 f32In1 register tS16 s16In2 tFrac16 MLIB_ShLSat_F16 register tFrac16 f16In1 register tU16 u16In2 tFrac32 MLIB_ShLSat_F32 register tFrac32 f32In1 register tU16 u16In2 tFrac16 MLIB_ShL_F16 register tFrac16 f16In1 register tU16 u16In2 tFrac32 MLIB_ShL_F32 register tFrac32 f32In1 register tU16 u16In2 tFrac16 MLIB_ShR_F16 register tFrac16 f16In1 register tU16 u16In2 tFrac32 MLIB_ShR_F32 register tFrac32 f32In1 register tU16 u16In2 tFrac16 MLIB_SubSat_F16 register tFrac16 f16In1 register tFrac16 f16In2 tFrac32 MLIB_SubSat_F32 register tFrac32 f32In1 register tFrac32 f32In2 tFrac16 MLIB_Sub_F16 register tFrac16 f16In1 register tFrac16 f16In2 tFrac32 MLIB_Sub_F32 register tFrac32 f32In1 register tFrac32 f32In2 tFrac16 MLIB_VMac_F16 register tFrac16 f16In1 register tFrac16 f16In2 register tFrac16 f16In3 register tFrac16 f16In4 tFrac32 MLIB_VMac_F32 register tFrac32 f32In1 register tFrac32 f32In2 register tFrac32 f32In3 register tFrac32 f32In4 tFrac32 MLIB_VMac_F32F16F16 register tFrac16 f16In1 register tFrac16 f16In2 register tFrac16 f16In3 register tFrac16 f16In4 SWLIBS_GetVersion const SWLIBS_VERSION_ T* void Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 109 Function Index Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 110 NXP Semiconductors Chapter 5 API References This section describes in details the Application Interface for all functions available in Automotive Math and Motor Control Library Set for KEAx devices. 5.1 Function GDFLIB_FilterFIRInit_F32 This function initializes the FIR filter buffers. 5.1.1 Declaration void GDFLIB_FilterFIRInit_F32(const GDFLIB_FILTERFIR_PARAM_T_F32 *const pParam, GDFLIB_FILTERFIR_STATE_T_F32 *const pState, tFrac32 *pInBuf); 5.1.2 Arguments Table 5-1. GDFLIB_FilterFIRInit_F32 arguments Type Name Direction Description const pParam GDFLIB_FILTERFIR_P ARAM_T_F32 *const input Pointer to the parameters structure. GDFLIB_FILTERFIR_S pState TATE_T_F32 *const input, output Pointer to the state structure. tFrac32 * input, output Pointer to a buffer for storing filter input signal values, must point to a R/W memory region and must be a filter order + 1 long. pInBuf Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 111 Function GDFLIB_FilterFIRInit_F32 5.1.3 Return void 5.1.4 Description The function performs the initialization procedure for the GDFLIB_FilterFIR_F32 function. In particular, the function performs the following operations: 1. Resets the input buffer index to zero. 2. Initializes the input buffer pointer to the pointer provided as an argument. 3. Resets the input buffer. After initialization, made by the function, the parameters and state structures should be provided as arguments to calls of the GDFLIB_FilterFIR_F32 function. Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). The input buffer pointer (State->pInBuf) must point to a Read/ Write memory region, which must be at least the number of the filter taps long. The number of taps in a filter is equal to the filter order + 1. There is no restriction as to the location of the parameters structure as long as it is readable. CAUTION No check is performed for R/W capability and the length of the input buffer (pState->pInBuf). In case of passing incorrect pointer to the function, an unexpected behavior of the function might be expected including the incorrect memory access exception. 5.1.5 Re-entrancy The function is re-entrant only if the calling code is provided with a distinct instance of the structure pointed to by pState. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 112 NXP Semiconductors Chapter 5 API References 5.1.6 Code Example #include "gdflib.h" #define FIR_NUMTAPS 16 #define FIR_NUMTAPS_MAX 64 #define FIR_ORDER (FIR_NUMTAPS - 1) GDFLIB_FILTERFIR_PARAM_T_F32 Param; GDFLIB_FILTERFIR_STATE_T_F32 State0, State1, State2; tFrac32 f32InBuf[FIR_NUMTAPS_MAX]; tFrac32 f32CoefBuf[FIR_NUMTAPS_MAX]; #define OUT_LEN 16 void main(void) { int ii; tFrac32 f32OutBuf0[OUT_LEN]; tFrac32 f32OutBuf1[OUT_LEN]; tFrac32 f32OutBuf2[OUT_LEN]; // Define a simple low-pass filter // The filter coefficients were calculated by the following // Matlab function (coefficients are contained in Hd.Numerator): // // function Hd = fir_example // FIR_EXAMPLE Returns a discrete-time filter object. // N = 15; // F6dB = 0.5; // // h = fdesign.lowpass('n,fc', N, F6dB); // // Hd = design(h, 'window'); // return; ii = 0; f32CoefBuf[ii++] = 0xFFB10C14; f32CoefBuf[ii++] = 0xFF779D25; f32CoefBuf[ii++] = 0x01387DD7; f32CoefBuf[ii++] = 0x028E6845; f32CoefBuf[ii++] = 0xFB245142; f32CoefBuf[ii++] = 0xF7183CC7; f32CoefBuf[ii++] = 0x11950A3C; f32CoefBuf[ii++] = 0x393ED867; f32CoefBuf[ii++] = 0x393ED867; f32CoefBuf[ii++] = 0x11950A3C; f32CoefBuf[ii++] = 0xF7183CC7; f32CoefBuf[ii++] = 0xFB245142; f32CoefBuf[ii++] = 0x028E6845; f32CoefBuf[ii++] = 0x01387DD7; f32CoefBuf[ii++] = 0xFF779D25; f32CoefBuf[ii++] = 0xFFB10C14; Param.u32Order = 15; Param.pCoefBuf = &f32CoefBuf[0]; // Initialize FIR filter GDFLIB_FilterFIRInit_F32 (&Param, &State0, &f32InBuf[0]); // Initialize FIR filter GDFLIB_FilterFIRInit (&Param, &State1, &f32InBuf[0], F32); // // // // ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 113 Function GDFLIB_FilterFIR_F32 // Initialize FIR filter GDFLIB_FilterFIRInit (&Param, &State2, &f32InBuf[0]); // Compute step response of the filter for(ii=0; ii < OUT_LEN; ii++) { // f32OutBuf0 contains step response of the filter f32OutBuf0[ii] = GDFLIB_FilterFIR_F32 (0x7FFFFFFF, &Param, &State0); // f32OutBuf1 contains step response of the filter f32OutBuf1[ii] = GDFLIB_FilterFIR (0x7FFFFFFF, &Param, &State1, F32); // // // // ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // f32OutBuf2 contains step response of the filter f32OutBuf2[ii] = GDFLIB_FilterFIR (0x7FFFFFFF, &Param, &State2); } // After the loop the f32OutBuf0, f32OutBuf1, f32OutBuf2 shall contains the following values: // {0xFFB1009E, 0xFF2801B0, 0x005FFF40, 0x02EDFA24, 0xFE1203DC, 0xF52A15AC, 0x06BEF282, 0x3FFC8006, // 0x793A0D8A, 0x7FFFFFFF, 0x7FFFFFFF, 0x7D0B05E8, 0x7F9900CC, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FF9000C} } 5.2 Function GDFLIB_FilterFIR_F32 The function performs a single iteration of an FIR filter. 5.2.1 Declaration tFrac32 GDFLIB_FilterFIR_F32(tFrac32 f32In, const GDFLIB_FILTERFIR_PARAM_T_F32 *const pParam, GDFLIB_FILTERFIR_STATE_T_F32 *const pState); 5.2.2 Arguments Table 5-2. GDFLIB_FilterFIR_F32 arguments Type Name Direction Description input Input value. const pParam GDFLIB_FILTERFIR_P ARAM_T_F32 *const input Pointer to the parameter structure. GDFLIB_FILTERFIR_S pState TATE_T_F32 *const input, output Pointer to the filter state structure. tFrac32 f32In Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 114 NXP Semiconductors Chapter 5 API References 5.2.3 Return The value of a filtered signal after processing by an FIR filter. 5.2.4 Description The function performs the operation of an FIR filter on a sample-by-sample basis. At each new input to the FIR filter, the function should be called, which will return a new filtered value. The FIR filter is defined by the following formula: Equation GDFLIB_FilterFIR_Eq1 where: x[n] is the input signal, y[n] is the output signal, h i are the filter coefficients, and N is the filter order. It should be noted, that the number of taps of the filter is N + 1 in this case. The multiply and accumulate operations are performed with 64 accumulation, which means that no saturation is performed during computations. However, if the final value cannot fit in the return data type, saturation may occur. It should be noted, although rather theoretically, that no saturation is performed on the accumulation guard bits and an overflow over the accumulation guard bits may occur. The function assumes that the filter order is at least one, which is equivalent to two taps. The filter also cannot contain more than 0xffffffff(hexadecimal) taps, which is equivalent to the order of 0xfffffffe (hexadecimal). The input values are recorded by the function in the provided state structure in a circular buffer, pointed to by the state structure member pState->pInBuf. The buffer index is stored in pState->u32Idx, which points to the buffer element where a new input signal sample will be stored. The filter coefficients are stored in the parameter structure, in the structure member pParam->pCoefBuf. The first call to the function must be preceded by an initialization, which can be made through the GDFLIB_FilterFIRInit_F32 function. The GDFLIB_FilterFIRInit_F32 and then the GDFLIB_FilterFIR_F32 functions should be called with the same parameters. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 115 Function GDFLIB_FilterFIR_F32 Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). 5.2.5 Re-entrancy The function is re-entrant only if the calling code is provided with a distinct instance of the structure pointed to by pState. Note From the performance point of view, the function is designed to work with filters with a larger number of taps (equal order + 1). As a rule of thumb, if the number of taps is lower than 5, a different algorithm should be considered. CAUTION No check is performed for R/W capability and the length of the input buffer (pState->pInBuf). In case of passing incorrect pointer to the function, an unexpected behavior of the function might be expected including the incorrect memory access exception. 5.2.6 Code Example #include "gdflib.h" #define FIR_NUMTAPS 16 #define FIR_NUMTAPS_MAX 64 #define FIR_ORDER (FIR_NUMTAPS - 1) GDFLIB_FILTERFIR_PARAM_T_F32 Param; GDFLIB_FILTERFIR_STATE_T_F32 State0, State1, State2; tFrac32 f32InBuf[FIR_NUMTAPS_MAX]; tFrac32 f32CoefBuf[FIR_NUMTAPS_MAX]; #define OUT_LEN 16 void main(void) { int ii; tFrac32 f32OutBuf0[OUT_LEN]; tFrac32 f32OutBuf1[OUT_LEN]; tFrac32 f32OutBuf2[OUT_LEN]; // // // // // // Define a simple low-pass filter The filter coefficients were calculated by the following Matlab function (coefficients are contained in Hd.Numerator): function Hd = fir_example FIR_EXAMPLE Returns a discrete-time filter object. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 116 NXP Semiconductors Chapter 5 API References // N = 15; // F6dB = 0.5; // // h = fdesign.lowpass('n,fc', N, F6dB); // // Hd = design(h, 'window'); // return; ii = 0; f32CoefBuf[ii++] = 0xFFB10C14; f32CoefBuf[ii++] = 0xFF779D25; f32CoefBuf[ii++] = 0x01387DD7; f32CoefBuf[ii++] = 0x028E6845; f32CoefBuf[ii++] = 0xFB245142; f32CoefBuf[ii++] = 0xF7183CC7; f32CoefBuf[ii++] = 0x11950A3C; f32CoefBuf[ii++] = 0x393ED867; f32CoefBuf[ii++] = 0x393ED867; f32CoefBuf[ii++] = 0x11950A3C; f32CoefBuf[ii++] = 0xF7183CC7; f32CoefBuf[ii++] = 0xFB245142; f32CoefBuf[ii++] = 0x028E6845; f32CoefBuf[ii++] = 0x01387DD7; f32CoefBuf[ii++] = 0xFF779D25; f32CoefBuf[ii++] = 0xFFB10C14; Param.u32Order = 15; Param.pCoefBuf = &f32CoefBuf[0]; // Initialize FIR filter GDFLIB_FilterFIRInit_F32 (&Param, &State0, &f32InBuf[0]); // Initialize FIR filter GDFLIB_FilterFIRInit (&Param, &State1, &f32InBuf[0], F32); // // // // ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // Initialize FIR filter GDFLIB_FilterFIRInit (&Param, &State2, &f32InBuf[0]); // Compute step response of the filter for(ii=0; ii < OUT_LEN; ii++) { // f32OutBuf0 contains step response of the filter f32OutBuf0[ii] = GDFLIB_FilterFIR_F32 (0x7FFFFFFF, &Param, &State0); // f32OutBuf1 contains step response of the filter f32OutBuf1[ii] = GDFLIB_FilterFIR (0x7FFFFFFF, &Param, &State1, F32); // // // // ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // f32OutBuf2 contains step response of the filter f32OutBuf2[ii] = GDFLIB_FilterFIR (0x7FFFFFFF, &Param, &State2); } // After the loop the f32OutBuf0, f32OutBuf1, f32OutBuf2 shall contains the following values: // {0xFFB1009E, 0xFF2801B0, 0x005FFF40, 0x02EDFA24, 0xFE1203DC, 0xF52A15AC, 0x06BEF282, 0x3FFC8006, // 0x793A0D8A, 0x7FFFFFFF, 0x7FFFFFFF, 0x7D0B05E8, 0x7F9900CC, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FF9000C} } Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 117 Function GDFLIB_FilterFIRInit_F16 5.3 Function GDFLIB_FilterFIRInit_F16 This function initializes the FIR filter buffers. 5.3.1 Declaration void GDFLIB_FilterFIRInit_F16(const GDFLIB_FILTERFIR_PARAM_T_F16 *const pParam, GDFLIB_FILTERFIR_STATE_T_F16 *const pState, tFrac16 *pInBuf); 5.3.2 Arguments Table 5-3. GDFLIB_FilterFIRInit_F16 arguments Type Name Direction Description const pParam GDFLIB_FILTERFIR_P ARAM_T_F16 *const input Pointer to the parameters structure. GDFLIB_FILTERFIR_S pState TATE_T_F16 *const input, output Pointer to the state structure. tFrac16 * input, output Pointer to a buffer for storing filter input signal values, must point to a R/W memory region and must be a filter order + 1 long. pInBuf 5.3.3 Return void 5.3.4 Description The function performs the initialization procedure for the GDFLIB_FilterFIR_F16 function. In particular, the function performs the following operations: 1. Resets the input buffer index to zero. 2. Initializes the input buffer pointer to the pointer provided as an argument. 3. Resets the input buffer. After initialization, made by the function, the parameters and state structures should be provided as arguments to calls of the GDFLIB_FilterFIR_F16 function. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 118 NXP Semiconductors Chapter 5 API References Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). The input buffer pointer (State->pInBuf) must point to a Read/ Write memory region, which must be at least the number of the filter taps long. The number of taps in a filter is equal to the filter order + 1. There is no restriction as to the location of the parameters structure as long as it is readable. CAUTION No check is performed for R/W capability and the length of the input buffer (pState->pInBuf). In case of passing incorrect pointer to the function, an unexpected behavior of the function might be expected including the incorrect memory access exception. 5.3.5 Re-entrancy The function is re-entrant only if the calling code is provided with a distinct instance of the structure pointed to by pState. 5.3.6 Code Example #include "gdflib.h" #define FIR_NUMTAPS 16 #define FIR_NUMTAPS_MAX 64 #define FIR_ORDER (FIR_NUMTAPS - 1) GDFLIB_FILTERFIR_PARAM_T_F16 Param; GDFLIB_FILTERFIR_STATE_T_F16 State0, State1, State2; tFrac16 f16InBuf[FIR_NUMTAPS_MAX]; tFrac16 f16CoefBuf[FIR_NUMTAPS_MAX]; #define OUT_LEN 16 void main(void) { int ii; tFrac16 f16OutBuf0[OUT_LEN]; tFrac16 f16OutBuf1[OUT_LEN]; tFrac16 f16OutBuf2[OUT_LEN]; // // // // // Define a simple low-pass filter The filter coefficients were calculated by the following Matlab function (coefficients are contained in Hd.Numerator): function Hd = fir_example Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 119 Function GDFLIB_FilterFIR_F16 // FIR_EXAMPLE Returns a discrete-time filter object. // N = 15; // F6dB = 0.5; // // h = fdesign.lowpass('n,fc', N, F6dB); // // Hd = design(h, 'window'); // return; ii = 0; f16CoefBuf[ii++] = 0xFFB1; f16CoefBuf[ii++] = 0xFF77; f16CoefBuf[ii++] = 0x0138; f16CoefBuf[ii++] = 0x028E; f16CoefBuf[ii++] = 0xFB24; f16CoefBuf[ii++] = 0xF718; f16CoefBuf[ii++] = 0x1195; f16CoefBuf[ii++] = 0x393E; f16CoefBuf[ii++] = 0x393E; f16CoefBuf[ii++] = 0x1195; f16CoefBuf[ii++] = 0xF718; f16CoefBuf[ii++] = 0xFB24; f16CoefBuf[ii++] = 0x028E; f16CoefBuf[ii++] = 0x0138; f16CoefBuf[ii++] = 0xFF77; f16CoefBuf[ii++] = 0xFFB1; Param.u16Order = 15; Param.pCoefBuf = &f16CoefBuf[0]; // Initialize FIR filter GDFLIB_FilterFIRInit_F16 (&Param, &State0, &f16InBuf[0]); // Initialize FIR filter GDFLIB_FilterFIRInit (&Param, &State1, &f16InBuf[0], F16); // // // // ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // Initialize FIR filter GDFLIB_FilterFIRInit (&Param, &State2, &f16InBuf[0]); // Compute step response of the filter for(ii=0; ii < OUT_LEN; ii++) { // f16OutBuf0 contains step response of the filter f16OutBuf0[ii] = GDFLIB_FilterFIR_F16 (0x7FFF, &Param, &State0); // f16OutBuf1 contains step response of the filter f16OutBuf1[ii] = GDFLIB_FilterFIR (0x7FFF, &Param, &State1, F16); // // // // ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // f16OutBuf2 contains step response of the filter f16OutBuf2[ii] = GDFLIB_FilterFIR (0x7FFF, &Param, &State2); } // After the loop the f16OutBuf0, f16OutBuf1, f16OutBuf2 shall contains the following values: // {0xFFB1, 0xFF28, 0x005F, 0x02ED, 0xFE12, 0xF52A, 0x06BE, 0x3FFC, // 0x793A, 0x7FFF, 0x7FFF, 0x7D0B, 0x7F99, 0x7FFF, 0x7FFF, 0x7FF9} } Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 120 NXP Semiconductors Chapter 5 API References 5.4 Function GDFLIB_FilterFIR_F16 The function performs a single iteration of an FIR filter. 5.4.1 Declaration tFrac16 GDFLIB_FilterFIR_F16(tFrac16 f16In, const GDFLIB_FILTERFIR_PARAM_T_F16 *const pParam, GDFLIB_FILTERFIR_STATE_T_F16 *const pState); 5.4.2 Arguments Table 5-4. GDFLIB_FilterFIR_F16 arguments Type Name Direction Description input Input value. const pParam GDFLIB_FILTERFIR_P ARAM_T_F16 *const input Pointer to the parameter structure. GDFLIB_FILTERFIR_S pState TATE_T_F16 *const input, output Pointer to the filter state structure. tFrac16 f16In 5.4.3 Return The value of a filtered signal after processing by an FIR filter. 5.4.4 Description The function performs the operation of an FIR filter on a sample-by-sample basis. At each new input to the FIR filter, the function should be called, which will return a new filtered value. The FIR filter is defined by the following formula: Equation GDFLIB_FilterFIR_Eq1 where: x[n] is the input signal, y[n] is the output signal, h i are the filter coefficients, and N is the filter order. It should be noted, that the number of taps of the filter is N + 1 in this case. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 121 Function GDFLIB_FilterFIR_F16 The multiply and accumulate operations are performed with 32 accumulation, which means that no saturation is performed during computations. However, if the final value cannot fit in the return data type, saturation may occur. It should be noted, although rather theoretically, that no saturation is performed on the accumulation guard bits and an overflow over the accumulation guard bits may occur. The function assumes that the filter order is at least one, which is equivalent to two taps. The filter also cannot contain more than 0xffff(hexadecimal) taps, which is equivalent to the order of 0xfffe (hexadecimal). The input values are recorded by the function in the provided state structure in a circular buffer, pointed to by the state structure member pState->pInBuf. The buffer index is stored in pState->u16Idx, which points to the buffer element where a new input signal sample will be stored. The filter coefficients are stored in the parameter structure, in the structure member pParam->pCoefBuf. The first call to the function must be preceded by an initialization, which can be made through the GDFLIB_FilterFIRInit_F16 function. The GDFLIB_FilterFIRInit_F16 and then the GDFLIB_FilterFIR_F16 functions should be called with the same parameters. Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). 5.4.5 Re-entrancy The function is re-entrant only if the calling code is provided with a distinct instance of the structure pointed to by pState. Note From the performance point of view, the function is designed to work with filters with a larger number of taps (equal order + 1). As a rule of thumb, if the number of taps is lower than 5, a different algorithm should be considered. CAUTION No check is performed for R/W capability and the length of the input buffer (pState->pInBuf). In case of passing incorrect pointer to the function, an unexpected behavior of the function might be expected including the incorrect memory access exception. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 122 NXP Semiconductors Chapter 5 API References 5.4.6 Code Example #include "gdflib.h" #define FIR_NUMTAPS 16 #define FIR_NUMTAPS_MAX 64 #define FIR_ORDER (FIR_NUMTAPS - 1) GDFLIB_FILTERFIR_PARAM_T_F16 Param; GDFLIB_FILTERFIR_STATE_T_F16 State0, State1, State2; tFrac16 f16InBuf[FIR_NUMTAPS_MAX]; tFrac16 f16CoefBuf[FIR_NUMTAPS_MAX]; #define OUT_LEN 16 void main(void) { int ii; tFrac16 f16OutBuf0[OUT_LEN]; tFrac16 f16OutBuf1[OUT_LEN]; tFrac16 f16OutBuf2[OUT_LEN]; // Define a simple low-pass filter // The filter coefficients were calculated by the following // Matlab function (coefficients are contained in Hd.Numerator): // // function Hd = fir_example // FIR_EXAMPLE Returns a discrete-time filter object. // N = 15; // F6dB = 0.5; // // h = fdesign.lowpass('n,fc', N, F6dB); // // Hd = design(h, 'window'); // return; ii = 0; f16CoefBuf[ii++] = 0xFFB1; f16CoefBuf[ii++] = 0xFF77; f16CoefBuf[ii++] = 0x0138; f16CoefBuf[ii++] = 0x028E; f16CoefBuf[ii++] = 0xFB24; f16CoefBuf[ii++] = 0xF718; f16CoefBuf[ii++] = 0x1195; f16CoefBuf[ii++] = 0x393E; f16CoefBuf[ii++] = 0x393E; f16CoefBuf[ii++] = 0x1195; f16CoefBuf[ii++] = 0xF718; f16CoefBuf[ii++] = 0xFB24; f16CoefBuf[ii++] = 0x028E; f16CoefBuf[ii++] = 0x0138; f16CoefBuf[ii++] = 0xFF77; f16CoefBuf[ii++] = 0xFFB1; Param.u16Order = 15; Param.pCoefBuf = &f16CoefBuf[0]; // Initialize FIR filter GDFLIB_FilterFIRInit_F16 (&Param, &State0, &f16InBuf[0]); // Initialize FIR filter GDFLIB_FilterFIRInit (&Param, &State1, &f16InBuf[0], F16); // ############################################################## // Available only if 16-bit fractional implementation selected Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 123 Function GDFLIB_FilterIIR1Init_F32 // as default // ############################################################## // Initialize FIR filter GDFLIB_FilterFIRInit (&Param, &State2, &f16InBuf[0]); // Compute step response of the filter for(ii=0; ii < OUT_LEN; ii++) { // f16OutBuf0 contains step response of the filter f16OutBuf0[ii] = GDFLIB_FilterFIR_F16 (0x7FFF, &Param, &State0); // f16OutBuf1 contains step response of the filter f16OutBuf1[ii] = GDFLIB_FilterFIR (0x7FFF, &Param, &State1, F16); // // // // ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // f16OutBuf2 contains step response of the filter f16OutBuf2[ii] = GDFLIB_FilterFIR (0x7FFF, &Param, &State2); } // After the loop the f16OutBuf0, f16OutBuf1, f16OutBuf2 shall contains the following values: // {0xFFB1, 0xFF28, 0x005F, 0x02ED, 0xFE12, 0xF52A, 0x06BE, 0x3FFC, // 0x793A, 0x7FFF, 0x7FFF, 0x7D0B, 0x7F99, 0x7FFF, 0x7FFF, 0x7FF9} } 5.5 Function GDFLIB_FilterIIR1Init_F32 This function initializes the first order IIR filter buffers. 5.5.1 Declaration void GDFLIB_FilterIIR1Init_F32(GDFLIB_FILTER_IIR1_T_F32 *const pParam); 5.5.2 Arguments Table 5-5. GDFLIB_FilterIIR1Init_F32 arguments Type Name GDFLIB_FILTER_IIR1_ pParam T_F32 *const Direction input, output Description Pointer to filter structure with filter buffer and filter parameters. 5.5.3 Return Function returns no value. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 124 NXP Semiconductors Chapter 5 API References 5.5.4 Description This function clears the internal buffers of a first order IIR filter. It shall be called after filter parameter initialization and whenever the filter initialization is required. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). This function shall not be called together with GDFLIB_FilterIIR1_F32 unless periodic clearing of filter buffers is required. 5.5.5 Re-entrancy The function is re-entrant. 5.5.6 Code Example #include "gdflib.h" GDFLIB_FILTER_IIR1_T_F32 f32trMyIIR1 = GDFLIB_FILTER_IIR1_DEFAULT_F32; void main(void) { // function returns no value GDFLIB_FilterIIR1Init_F32 (&f32trMyIIR1); // function returns no value GDFLIB_FilterIIR1Init (&f32trMyIIR1, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // function returns no value GDFLIB_FilterIIR1Init (&f32trMyIIR1); 5.6 Function GDFLIB_FilterIIR1_F32 This function implements the first order IIR filter. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 125 Function GDFLIB_FilterIIR1_F32 5.6.1 Declaration tFrac32 GDFLIB_FilterIIR1_F32(tFrac32 f32In, GDFLIB_FILTER_IIR1_T_F32 *const pParam); 5.6.2 Arguments Table 5-6. GDFLIB_FilterIIR1_F32 arguments Type Name tFrac32 f32In GDFLIB_FILTER_IIR1_ pParam T_F32 *const Direction Description input Value of input signal to be filtered in step (k). The value is a 32-bit number in the 1.31 fractional format. input, output Pointer to the filter structure with a filter buffer and filter parameters. 5.6.3 Return The function returns a 32-bit value in fractional format 1.31, representing the filtered value of the input signal in step (k). 5.6.4 Description This function calculates the first order infinite impulse (IIR) filter. The IIR filters are also called recursive filters because both the input and the previously calculated output values are used for calculation of the filter equation in each step. This form of feedback enables transfer of the energy from the output to the input, which theoretically leads to an infinitely long impulse response (IIR). A general form of the IIR filter expressed as a transfer function in the Z-domain is described as follows: Equation GDFLIB_FilterIIR1_Eq1 where N denotes the filter order. The first order IIR filter in the Z-domain is therefore given from equation GDFLIB_FilterIIR1_Eq1 as: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 126 NXP Semiconductors Chapter 5 API References Equation GDFLIB_FilterIIR1_Eq2 In order to implement the first order IIR filter on a microcontroller, the discrete time domain representation of the filter, described by equation GDFLIB_FilterIIR1_Eq2, must be transformed into a time difference equation as follows: Equation GDFLIB_FilterIIR1_Eq3 Equation GDFLIB_FilterIIR1_Eq3 represents a Direct Form I implementation of a first order IIR filter. It is well known that Direct Form I (DF-I) and Direct Form II (DF-II) implementations of an IIR filter are generally sensitive to parameter quantization if a finite precision arithmetic is considered. This, however, can be neglected when the filter transfer function is broken down into low order sections, i.e. first or second order. The main difference between DF-I and DF-II implementations of an IIR filter is in the number of delay buffers and in the number of guard bits required to handle the potential overflow. The DF-II implementation requires less delay buffers than DF-I, hence less data memory is utilized. On the other hand, since the poles come first in the DF-II realization, the signal entering the state delay-line typically requires a larger dynamic range than the output signal y(k). Therefore, overflow can occur at the delay-line input of the DF-II implementation, unlike in the DF-I implementation. Because there are two delay buffers necessary for both DF-I and DF-II implementation of the first order IIR filter, the DF-I implementation was chosen to be used in the GDFLIB_FilterIIR1_F32 function. Figure 5-1. Direct Form 1 first order IIR filter The coefficients of the filter depicted in Figure 5-1 can be designed to meet the requirements for the first order Low (LPF) or High Pass (HPF) filters. Filter coefficients can be calculated using various tools, for example, the Matlab butter function. In order to avoid overflow during the calculation of the GDFLIB_FilterIIR1_F32 function, filter Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 127 Function GDFLIB_FilterIIR1_F32 coefficients must be divided by eight. The coefficient quantization error due to finite precision arithmetic can be neglected in the case of a first order filter. Therefore, the calculation of coefficients can be done using Matlab as follows: freq_cut = 100; T_sampling = 100e-6; [b,a]=butter(1,[freq_cut*T_sampling*2],'low'); sys=tf(b,a,T_sampling); bode(sys) f32B0 = b(1); f32B1 = b(2); f32A1 = a(2); disp('Coefficients for GDFLIB_FilterIIR1 function:'); disp(['f32B0 = FRAC32 (' num2str(f32B0,'%1.15f') '/8);']); disp(['f32B1 = FRAC32 (' num2str(f32B1,'%1.15f') '/8);']); disp(['f32A1 = FRAC32 (' num2str(f32A1,'%1.15f') '/8);']); Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The filter delay line includes two delay buffers which should be reset after filter initialization. This can be done by assigning to the filter instance a GDFLIB_FILTER_IIR1_DEFAULT_F32 macro during instance declaration or by calling the GDFLIB_FilterIIR1Init_F32 function. CAUTION Because of fixed point implementation, and to avoid overflow during the calculation of the GDFLIB_FilterIIR1_F32 function, filter coefficients must be divided by eight. Function output is internally multiplied by eight to correct the coefficient scaling. 5.6.5 Re-entrancy The function is re-entrant. 5.6.6 Code Example #include "gdflib.h" tFrac32 f32In; tFrac32 f32Out; GDFLIB_FILTER_IIR1_T_F32 f32trMyIIR1 = GDFLIB_FILTER_IIR1_DEFAULT_F32; Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 128 NXP Semiconductors Chapter 5 API References void main(void) { // input value = 0.25 f32In = FRAC32 (0.25); // filter coefficients (LPF 100Hz, Ts=100e-6) f32trMyIIR1.trFiltCoeff.f32B0 = FRAC32 (0.030468747091254/8); f32trMyIIR1.trFiltCoeff.f32B1 = FRAC32 (0.030468747091254/8); f32trMyIIR1.trFiltCoeff.f32A1 = FRAC32 (-0.939062505817492/8); // output should be 0x00F99998 ~ FRAC32(0.007617) GDFLIB_FilterIIR1Init_F32 (&f32trMyIIR1); f32Out = GDFLIB_FilterIIR1_F32 (f32In, &f32trMyIIR1); // output should be 0x00F99998 ~ FRAC32(0.007617) GDFLIB_FilterIIR1Init (&f32trMyIIR1, F32); f32Out = GDFLIB_FilterIIR1 (f32In, &f32trMyIIR1, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x00F99998 ~ FRAC32(0.007617) GDFLIB_FilterIIR1Init (&f32trMyIIR1); f32Out = GDFLIB_FilterIIR1 (f32In, &f32trMyIIR1); 5.7 Function GDFLIB_FilterIIR1Init_F16 This function initializes the first order IIR filter buffers. 5.7.1 Declaration void GDFLIB_FilterIIR1Init_F16(GDFLIB_FILTER_IIR1_T_F16 *const pParam); 5.7.2 Arguments Table 5-7. GDFLIB_FilterIIR1Init_F16 arguments Type Name GDFLIB_FILTER_IIR1_ pParam T_F16 *const Direction input, output Description Pointer to filter structure with filter buffer and filter parameters. 5.7.3 Return Function returns no value. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 129 Function GDFLIB_FilterIIR1_F16 5.7.4 Description This function clears the internal buffers of a first order IIR filter. It shall be called after filter parameter initialization and whenever the filter initialization is required. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). This function shall not be called together with GDFLIB_FilterIIR1_F16 unless periodic clearing of filter buffers is required. 5.7.5 Re-entrancy The function is re-entrant. 5.7.6 Code Example #include "gdflib.h" GDFLIB_FILTER_IIR1_T_F16 f16trMyIIR1 = GDFLIB_FILTER_IIR1_DEFAULT_F16; void main(void) { // function returns no value GDFLIB_FilterIIR1Init_F16 (&f16trMyIIR1); // function returns no value GDFLIB_FilterIIR1Init (&f16trMyIIR1, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // function returns no value GDFLIB_FilterIIR1Init (&f16trMyIIR1); 5.8 Function GDFLIB_FilterIIR1_F16 This function implements the first order IIR filter. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 130 NXP Semiconductors Chapter 5 API References 5.8.1 Declaration tFrac16 GDFLIB_FilterIIR1_F16(tFrac16 f16In, GDFLIB_FILTER_IIR1_T_F16 *const pParam); 5.8.2 Arguments Table 5-8. GDFLIB_FilterIIR1_F16 arguments Type Name tFrac16 f16In GDFLIB_FILTER_IIR1_ pParam T_F16 *const Direction Description input Value of input signal to be filtered in step (k). The value is a 16-bit number in the 1.15 fractional format. input, output Pointer to the filter structure with a filter buffer and filter parameters. 5.8.3 Return The function returns a 16-bit value in fractional format 1.15, representing the filtered value of the input signal in step (k). 5.8.4 Description This function calculates the first order infinite impulse (IIR) filter. The IIR filters are also called recursive filters because both the input and the previously calculated output values are used for calculation of the filter equation in each step. This form of feedback enables transfer of the energy from the output to the input, which theoretically leads to an infinitely long impulse response (IIR). A general form of the IIR filter expressed as a transfer function in the Z-domain is described as follows: Equation GDFLIB_FilterIIR1_Eq1 where N denotes the filter order. The first order IIR filter in the Z-domain is therefore given from equation GDFLIB_FilterIIR1_Eq1 as: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 131 Function GDFLIB_FilterIIR1_F16 Equation GDFLIB_FilterIIR1_Eq2 In order to implement the first order IIR filter on a microcontroller, the discrete time domain representation of the filter, described by equation GDFLIB_FilterIIR1_Eq2, must be transformed into a time difference equation as follows: Equation GDFLIB_FilterIIR1_Eq3 Equation GDFLIB_FilterIIR1_Eq3 represents a Direct Form I implementation of a first order IIR filter. It is well known that Direct Form I (DF-I) and Direct Form II (DF-II) implementations of an IIR filter are generally sensitive to parameter quantization if a finite precision arithmetic is considered. This, however, can be neglected when the filter transfer function is broken down into low order sections, i.e. first or second order. The main difference between DF-I and DF-II implementations of an IIR filter is in the number of delay buffers and in the number of guard bits required to handle the potential overflow. The DF-II implementation requires less delay buffers than DF-I, hence less data memory is utilized. On the other hand, since the poles come first in the DF-II realization, the signal entering the state delay-line typically requires a larger dynamic range than the output signal y(k). Therefore, overflow can occur at the delay-line input of the DF-II implementation, unlike in the DF-I implementation. Because there are two delay buffers necessary for both DF-I and DF-II implementation of the first order IIR filter, the DF-I implementation was chosen to be used in the GDFLIB_FilterIIR1_F16 function. Figure 5-2. Direct Form 1 first order IIR filter The coefficients of the filter depicted in Figure 5-2 can be designed to meet the requirements for the first order Low (LPF) or High Pass (HPF) filters. Filter coefficients can be calculated using various tools, for example, the Matlab butter function. The coefficient quantization error due to finite precision arithmetic can be neglected in the case of a first order filter. Therefore, the calculation of coefficients can be done using Matlab as follows: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 132 NXP Semiconductors Chapter 5 API References freq_cut T_sampling = 100; = 100e-6; [b,a]=butter(1,[freq_cut*T_sampling*2],'low'); sys=tf(b,a,T_sampling); bode(sys) f16B0 = b(1); f16B1 = b(2); f16A1 = a(2); disp('Coefficients for GDFLIB_FilterIIR1 function:'); disp(['f16B0 = FRAC16 (' num2str(f16B0,'%1.15f') '/8);']); disp(['f16B1 = FRAC16 (' num2str(f16B1,'%1.15f') '/8);']); disp(['f16A1 = FRAC16 (' num2str(f16A1,'%1.15f') '/8);']); Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The filter delay line includes two delay buffers which should be reset after filter initialization. This can be done by assigning to the filter instance a GDFLIB_FILTER_IIR1_DEFAULT_F16 macro during instance declaration or by calling the GDFLIB_FilterIIR1Init_F16 function. CAUTION Because of fixed point implementation, and to avoid overflow during the calculation of the GDFLIB_FilterIIR1_F16 function, filter coefficients must be divided by eight. Function output is internally multiplied by eight to correct the coefficient scaling. 5.8.5 Re-entrancy The function is re-entrant. 5.8.6 Code Example #include "gdflib.h" tFrac16 f16In; tFrac16 f16Out; GDFLIB_FILTER_IIR1_T_F16 f16trMyIIR1 = GDFLIB_FILTER_IIR1_DEFAULT_F16; void main(void) { // input value = 0.25 f16In = FRAC16 (0.25); // filter coefficients (LPF 100Hz, Ts=100e-6) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 133 Function GDFLIB_FilterIIR2Init_F32 f16trMyIIR1.trFiltCoeff.f16B0 = FRAC16 (0.030468747091254/8); f16trMyIIR1.trFiltCoeff.f16B1 = FRAC16 (0.030468747091254/8); f16trMyIIR1.trFiltCoeff.f16A1 = FRAC16 (-0.939062505817492/8); // output should be 0x00F9 ~ FRAC16(0.007617) GDFLIB_FilterIIR1Init_F16 (&f16trMyIIR1); f16Out = GDFLIB_FilterIIR1_F16 (f16In, &f16trMyIIR1); // output should be 0x00F9 ~ FRAC16(0.007617) GDFLIB_FilterIIR1Init (&f16trMyIIR1, F16); f16Out = GDFLIB_FilterIIR1 (f16In, &f16trMyIIR1, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x00F9 ~ FRAC16(0.007617) GDFLIB_FilterIIR1Init (&f16trMyIIR1); f16Out = GDFLIB_FilterIIR1 (f16In, &f16trMyIIR1); 5.9 Function GDFLIB_FilterIIR2Init_F32 This function initializes the second order IIR filter buffers. 5.9.1 Declaration void GDFLIB_FilterIIR2Init_F32(GDFLIB_FILTER_IIR2_T_F32 *const pParam); 5.9.2 Arguments Table 5-9. GDFLIB_FilterIIR2Init_F32 arguments Type Name GDFLIB_FILTER_IIR2_ pParam T_F32 *const Direction input, output Description Pointer to the filter structure with a filter buffer and filter parameters. 5.9.3 Return Function returns no value. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 134 NXP Semiconductors Chapter 5 API References 5.9.4 Description This function clears the internal buffers of a second order IIR filter. It shall be called after filter parameter initialization and whenever the filter initialization is required. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). This function shall not be called together with GDFLIB_FilterIIR2_F32 unless periodic clearing of filter buffers is required. 5.9.5 Re-entrancy The function is re-entrant. 5.9.6 Code Example #include "gdflib.h" GDFLIB_FILTER_IIR2_T_F32 f32trMyIIR2 = GDFLIB_FILTER_IIR2_DEFAULT_F32; void main(void) { // function returns no value GDFLIB_FilterIIR2Init_F32 (&f32trMyIIR2); // function returns no value GDFLIB_FilterIIR2Init (&f32trMyIIR2, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // function returns no value GDFLIB_FilterIIR2Init (&f32trMyIIR2); 5.10 Function GDFLIB_FilterIIR2_F32 This function implements the second order IIR filter. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 135 Function GDFLIB_FilterIIR2_F32 5.10.1 Declaration tFrac32 GDFLIB_FilterIIR2_F32(tFrac32 f32In, GDFLIB_FILTER_IIR2_T_F32 *const pParam); 5.10.2 Arguments Table 5-10. GDFLIB_FilterIIR2_F32 arguments Type tFrac32 Name f32In GDFLIB_FILTER_IIR2_ pParam T_F32 *const Direction Description input Value of input signal to be filtered in step (k). The value is a 32-bit number in the 1.31 fractional format. input, output Pointer to the filter structure with a filter buffer and filter parameters. 5.10.3 Return The function returns a 32-bit value in fractional format 1.31, representing the filtered value of the input signal in step (k). 5.10.4 Description This function calculates the second order infinite impulse (IIR) filter. The IIR filters are also called recursive filters because both the input and the previously calculated output values are used for calculation of the filter equation in each step. This form of feedback enables transfer of the energy from the output to the input, which theoretically leads to an infinitely long impulse response (IIR). A general form of the IIR filter expressed as a transfer function in the Z-domain is described as follows: Equation GDFLIB_FilterIIR2_Eq1 where N denotes the filter order. The second order IIR filter in the Z-domain is therefore given from eq. GDFLIB_FilterIIR2_Eq1 as: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 136 NXP Semiconductors Chapter 5 API References Equation GDFLIB_FilterIIR2_Eq2 In order to implement the second order IIR filter on a microcontroller, the discrete time domain representation of the filter, described by eq. GDFLIB_FilterIIR2_Eq2, must be transformed into a time difference equation as follows: Equation GDFLIB_FilterIIR2_Eq3 Equation GDFLIB_FilterIIR2_Eq3 represents a Direct Form I implementation of a second order IIR filter. It is well known that Direct Form I (DF-I) and Direct Form II (DF-II) implementations of an IIR filter are generally sensitive to parameter quantization if a finite precision arithmetic is considered. This, however, can be neglected when the filter transfer function is broken down into low order sections, i.e. first or second order. The main difference between DF-I and DF-II implementations of an IIR filter is in the number of delay buffers and in the number of guard bits required to handle the potential overflow. The DF-II implementation requires less delay buffers than DF-I, hence less data memory is utilized. On the other hand, since the poles come first in the DF-II realization, the signal entering the state delay-line typically requires a larger dynamic range than the output signal y(k). Therefore, overflow can occur at the delay-line input of the DF-II implementation, unlike in the DF-I implementation. Figure 5-3. Direct Form 1 second order IIR filter The coefficients of the filter depicted in Figure 5-3 can be designed to meet the requirements for the second order Band Pass (BPF) or Band Stop (BSF) filters. Filter coefficients can be calculated using various tools, for example the Matlab butter function. In order to avoid overflow during the calculation of the GDFLIB_FilterIIR2_F32 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 137 Function GDFLIB_FilterIIR2_F32 function, filter coefficients must be divided by eight. The coefficient quantization error due to finite precision arithmetic can be neglected in the case of a second order filter. Therefore, calculation of coefficients can be done using Matlab as follows: freq_bot freq_top T_sampling = 400; = 625; = 100e-6; [b,a]= butter(1,[freq_bot freq_top]*T_sampling *2, 'bandpass'); sys =tf(b,a,T_sampling); bode(sys,[freq_bot:1:freq_top]*2*pi) f32B0 = f32B1 = f32B2 = f32A1 = f32A2 = disp (' disp ([ disp ([ disp ([ disp ([ disp ([ b(1); b(2); b(3); a(2); a(3); Coefficients for GDFLIB_FilterIIR2 function 'f32B0 = FRAC32(' num2str( f32B0,'%1.15f' ) 'f32B1 = FRAC32(' num2str( f32B1,'%1.15f' ) 'f32B2 = FRAC32(' num2str( f32B2,'%1.15f' ) 'f32A1 = FRAC32(' num2str( f32A1,'%1.15f' ) 'f32A2 = FRAC32(' num2str( f32A2,'%1.15f' ) :'); '/8);']); '/8);']); '/8);']); '/8);']); '/8);']); Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The filter delay line includes four delay buffers which should be reset after filter initialization. This can be done by assigning to the filter instance a GDFLIB_FILTER_IIR2_DEFAULT_F32 macro during instance declaration or by calling the GDFLIB_FilterIIR2Init_F32 function. CAUTION Because of fixed point implementation, and to avoid overflow during the calculation of the GDFLIB_FilterIIR2_F32 function, filter coefficients must be divided by eight. Function output is internally multiplied by eight to correct the coefficient scaling. 5.10.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 138 NXP Semiconductors Chapter 5 API References 5.10.6 Code Example #include "gdflib.h" tFrac32 f32In; tFrac32 f32Out; GDFLIB_FILTER_IIR2_T_F32 f32trMyIIR2 = GDFLIB_FILTER_IIR2_DEFAULT_F32; void main(void) { // input value = 0.25 f32In = FRAC32 (0.25); // filter coefficients (BPF 400-625Hz, f32trMyIIR2.trFiltCoeff.f32B0 = FRAC32 f32trMyIIR2.trFiltCoeff.f32B1 = FRAC32 f32trMyIIR2.trFiltCoeff.f32B2 = FRAC32 f32trMyIIR2.trFiltCoeff.f32A1 = FRAC32 f32trMyIIR2.trFiltCoeff.f32A2 = FRAC32 Ts=100e-6) (0.066122101544579/8); (0/8); (-0.066122101544579/8); (-1.776189018043779/8); (0.867755796910841/8); // output should be 0x021DAC18 ~ FRAC32(0.0165305) GDFLIB_FilterIIR2Init_F32 (&f32trMyIIR2); f32Out = GDFLIB_FilterIIR2_F32 (f32In, &f32trMyIIR2); // output should be 0x021DAC18 ~ FRAC32(0.0165305) GDFLIB_FilterIIR2Init (&f32trMyIIR2, F32); f32Out = GDFLIB_FilterIIR2 (f32In, &f32trMyIIR2, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x021DAC18 ~ FRAC32(0.0165305) GDFLIB_FilterIIR2Init (&f32trMyIIR2); f32Out = GDFLIB_FilterIIR2 (f32In, &f32trMyIIR2); 5.11 Function GDFLIB_FilterIIR2Init_F16 This function initializes the second order IIR filter buffers. 5.11.1 Declaration void GDFLIB_FilterIIR2Init_F16(GDFLIB_FILTER_IIR2_T_F16 *const pParam); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 139 Function GDFLIB_FilterIIR2Init_F16 5.11.2 Arguments Table 5-11. GDFLIB_FilterIIR2Init_F16 arguments Type Name GDFLIB_FILTER_IIR2_ pParam T_F16 *const Direction input, output Description Pointer to the filter structure with a filter buffer and filter parameters. 5.11.3 Return Function returns no value. 5.11.4 Description This function clears the internal buffers of a second order IIR filter. The function shall be called after filter parameter initialization and whenever the filter initialization is required. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). This function shall not be called together with GDFLIB_FilterIIR2_F16 unless periodic clearing of filter buffers is required. 5.11.5 Re-entrancy The function is re-entrant. 5.11.6 Code Example #include "gdflib.h" GDFLIB_FILTER_IIR2_T_F16 f16trMyIIR2 = GDFLIB_FILTER_IIR2_DEFAULT_F16; void main(void) { // function returns no value GDFLIB_FilterIIR2Init_F16 (&f16trMyIIR2); // function returns no value GDFLIB_FilterIIR2Init (&f16trMyIIR2, F16); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 140 NXP Semiconductors Chapter 5 API References // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // function returns no value GDFLIB_FilterIIR2Init (&f16trMyIIR2); 5.12 Function GDFLIB_FilterIIR2_F16 This function implements the second order IIR filter. 5.12.1 Declaration tFrac16 GDFLIB_FilterIIR2_F16(tFrac16 f16In, GDFLIB_FILTER_IIR2_T_F16 *const pParam); 5.12.2 Arguments Table 5-12. GDFLIB_FilterIIR2_F16 arguments Type Name tFrac16 f16In GDFLIB_FILTER_IIR2_ pParam T_F16 *const Direction Description input Value of input signal to be filtered in step (k). The value is a 16-bit number in the 1.15 fractional format. input, output Pointer to the filter structure with a filter buffer and filter parameters. 5.12.3 Return The function returns a 16-bit value in fractional format 1.15, representing the filtered value of the input signal in step (k). 5.12.4 Description This function calculates the second order infinite impulse (IIR) filter. The IIR filters are also called recursive filters because both the input and the previously calculated output values are used for calculation of the filter equation in each step. This form of feedback enables transfer of the energy from the output to the input, which theoretically leads to an infinitely long impulse response (IIR). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 141 Function GDFLIB_FilterIIR2_F16 A general form of the IIR filter expressed as a transfer function in the Z-domain is described as follows: Equation GDFLIB_FilterIIR2_Eq1 where N denotes the filter order. The second order IIR filter in the Z-domain is therefore given from eq. GDFLIB_FilterIIR2_Eq1 as: Equation GDFLIB_FilterIIR2_Eq2 In order to implement the second order IIR filter on a microcontroller, the discrete time domain representation of the filter, described by eq. GDFLIB_FilterIIR2_Eq2, must be transformed into a time difference equation as follows: Equation GDFLIB_FilterIIR2_Eq3 Equation GDFLIB_FilterIIR2_Eq3 represents a Direct Form I implementation of a second order IIR filter. It is well known that Direct Form I (DF-I) and Direct Form II (DF-II) implementations of an IIR filter are generally sensitive to parameter quantization if a finite precision arithmetic is considered. This, however, can be neglected when the filter transfer function is broken down into low order sections, i.e. first or second order. The main difference between DF-I and DF-II implementations of an IIR filter is in the number of delay buffers and in the number of guard bits required to handle the potential overflow. The DF-II implementation requires less delay buffers than DF-I, hence less data memory is utilized. On the other hand, since the poles come first in the DF-II realization, the signal entering the state delay-line typically requires a larger dynamic range than the output signal y(k). Therefore, overflow can occur at the delay-line input of the DF-II implementation, unlike in the DF-I implementation. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 142 NXP Semiconductors Chapter 5 API References Figure 5-4. Direct Form 1 second order IIR filter The coefficients of the filter depicted in Figure 5-4 can be designed to meet the requirements for the second order Band Pass (BPF) or Band Stop (BSF) filters. Filter coefficients can be calculated using various tools, for example the Matlab butter function. In order to avoid overflow during the calculation of the GDFLIB_FilterIIR2_F16 function, filter coefficients must be divided by eight. The coefficient quantization error due to finite precision arithmetic can be neglected in the case of a second order filter. Therefore, calculation of coefficients can be done using Matlab as follows: freq_bot freq_top T_sampling = 400; = 625; = 100e-6; [b,a]= butter(1,[freq_bot freq_top]*T_sampling *2, 'bandpass'); sys =tf(b,a,T_sampling); bode(sys,[freq_bot:1:freq_top]*2*pi) f16B0 = f16B1 = f16B2 = f16A1 = f16A2 = disp (' disp ([ disp ([ disp ([ disp ([ disp ([ b(1); b(2); b(3); a(2); a(3); Coefficients for GDFLIB_FilterIIR2 function 'f16B0 = FRAC16(' num2str( f16B0,'%1.15f' ) 'f16B1 = FRAC16(' num2str( f16B1,'%1.15f' ) 'f16B2 = FRAC16(' num2str( f16B2,'%1.15f' ) 'f16A1 = FRAC16(' num2str( f16A1,'%1.15f' ) 'f16A2 = FRAC16(' num2str( f16A2,'%1.15f' ) :'); '/8);']); '/8);']); '/8);']); '/8);']); '/8);']); Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The filter delay line includes four delay buffers which should be reset after filter initialization. This can be done by assigning to the filter instance a GDFLIB_FILTER_IIR2_DEFAULT_F16 macro during Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 143 Function GDFLIB_FilterMAInit_F32 instance declaration or by calling the GDFLIB_FilterIIR2Init_F16 function. CAUTION Because of fixed point implementation, and to avoid overflow during the calculation of the GDFLIB_FilterIIR2_F16 function, filter coefficients must be divided by eight. Function output is internally multiplied by eight to correct the coefficient scaling. 5.12.5 Re-entrancy The function is re-entrant. 5.12.6 Code Example #include "gdflib.h" tFrac16 f16In; tFrac16 f16Out; GDFLIB_FILTER_IIR2_T_F16 f16trMyIIR2 = GDFLIB_FILTER_IIR2_DEFAULT_F16; void main(void) { // input value = 0.25 f16In = FRAC16 (0.25); // filter coefficients (BPF 400-625Hz, f16trMyIIR2.trFiltCoeff.f16B0 = FRAC16 f16trMyIIR2.trFiltCoeff.f16B1 = FRAC16 f16trMyIIR2.trFiltCoeff.f16B2 = FRAC16 f16trMyIIR2.trFiltCoeff.f16A1 = FRAC16 f16trMyIIR2.trFiltCoeff.f16A2 = FRAC16 Ts=100e-6) (0.066122101544579/8); (0/8); (-0.066122101544579/8); (-1.776189018043779/8); (0.867755796910841/8); // output should be 0x021D ~ FRAC16(0.01651) GDFLIB_FilterIIR2Init_F16 (&f16trMyIIR2); f16Out = GDFLIB_FilterIIR2_F16 (f16In, &f16trMyIIR2); // output should be 0x021D ~ FRAC16(0.01651) GDFLIB_FilterIIR2Init (&f16trMyIIR2, F16); f16Out = GDFLIB_FilterIIR2 (f16In, &f16trMyIIR2, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x021D ~ FRAC16(0.01651) GDFLIB_FilterIIR2Init (&f16trMyIIR2); f16Out = GDFLIB_FilterIIR2 (f16In, &f16trMyIIR2); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 144 NXP Semiconductors Chapter 5 API References 5.13 Function GDFLIB_FilterMAInit_F32 This function clears the internal filter accumulator. 5.13.1 Declaration void GDFLIB_FilterMAInit_F32(GDFLIB_FILTER_MA_T_F32 *pParam); 5.13.2 Arguments Table 5-13. GDFLIB_FilterMAInit_F32 arguments Type Name GDFLIB_FILTER_MA_ pParam T_F32 * Direction input, output Description Pointer to the filter structure with a filter accumulator and a smoothing factor. 5.13.3 Return void 5.13.4 Description This function clears the internal accumulator of a moving average filter. It shall be called after filter parameter initialization and whenever the filter initialization is required. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). This function shall not be called together with GDFLIB_FilterMA_F32 unless periodic clearing of filter buffers is required. 5.13.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 145 Function GDFLIB_FilterMA_F32 5.13.6 Code Example #include "gdflib.h" GDFLIB_FILTER_MA_T_F32 f32trMyMA = GDFLIB_FILTER_MA_DEFAULT_F32; void main(void) { // filter window = 2^5 = 32 samples f32trMyMA.u16NSamples = 5; GDFLIB_FilterMAInit_F32 (&f32trMyMA); GDFLIB_FilterMAInit (&f32trMyMA,F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## GDFLIB_FilterMAInit (&f32trMyMA); 5.14 Function GDFLIB_FilterMA_F32 This function implements an exponential moving average filter. 5.14.1 Declaration tFrac32 GDFLIB_FilterMA_F32(tFrac32 f32In, GDFLIB_FILTER_MA_T_F32 *pParam); 5.14.2 Arguments Table 5-14. GDFLIB_FilterMA_F32 arguments Type tFrac32 Name f32In GDFLIB_FILTER_MA_ pParam T_F32 * Direction Description input Value of input signal to be filtered in step (k). The value is a 32-bit number in the Q1.31 format. input, output Pointer to the filter structure with a filter accumulator and a smoothing factor. 5.14.3 Return The function returns a 32-bit value in format Q1.31, representing the filtered value of the input signal in step (k). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 146 NXP Semiconductors Chapter 5 API References 5.14.4 Description This function calculates one iteration of an exponential moving average filter (also known as the exponentially weighted moving average, EWMA). The filter is characterized by the following difference equation: Equation GDFLIB_FilterMA_Eq2 where x(k) is the filter input, y(k) is the filter output in the current step, y(k-1) is the filter output of the previous step and λ is a smoothing factor, 0 < λ < 1. Values of λ close to one lead to less smoothing and give greater weight to recent changes in the input data, while values of λ closer to zero cause greater smoothing and the filter is less responsive to recent changes. There is no direct equivalence between the smoothing factor λ of the exponential moving average filter and the number of averaged samples N of a uniform sliding-window moving average filter. Nevertheless, the implementation uses the following approximation to relate the two filtering approaches: Equation GDFLIB_FilterMA_Eq3 The library function expects the smoothing factor to be supplied in the form of the u16NSamples variable stored within the filter structure. This variable represents the binary logarithm of the number of averaged samples N of the corresponding uniform sliding-window moving average filter: Equation GDFLIB_FilterMA_Eq4 Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The recalculated smoothing factor u16NSamples needs to be defined prior to calling this function and must be equal to or greater than 0, and equal to or smaller than 31 (0 < Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 147 Function GDFLIB_FilterMAInit_F16 u16NSamples < 31). Incorrect setting of this parameter will yield meaningless results. 5.14.5 Re-entrancy The function is re-entrant. 5.14.6 Code Example #include "gdflib.h" tFrac32 f32Input; tFrac32 f32Output; GDFLIB_FILTER_MA_T_F32 f32trMyMA = GDFLIB_FILTER_MA_DEFAULT_F32; void main(void) { // input value = 0.25 f32Input = FRAC32 (0.25); // filter window = 2^5 = 32 samples f32trMyMA.u16NSamples = 5; GDFLIB_FilterMAInit_F32 (&f32trMyMA); // output should be 0x1000000 = FRAC32(0.0078125) f32Output = GDFLIB_FilterMA_F32 (f32Input,&f32trMyMA); // output should be 0x1000000 = FRAC32(0.0078125) f32Output = GDFLIB_FilterMA (f32Input,&f32trMyMA,F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x1000000 = FRAC32(0.0078125) f32Output = GDFLIB_FilterMA (f32Input,&f32trMyMA); 5.15 Function GDFLIB_FilterMAInit_F16 This function clears the internal filter accumulator. 5.15.1 Declaration void GDFLIB_FilterMAInit_F16(GDFLIB_FILTER_MA_T_F16 *pParam); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 148 NXP Semiconductors Chapter 5 API References 5.15.2 Arguments Table 5-15. GDFLIB_FilterMAInit_F16 arguments Type Name GDFLIB_FILTER_MA_ pParam T_F16 * Direction input, output Description Pointer to the filter structure with a filter accumulator and a smoothing factor. 5.15.3 Return void 5.15.4 Description This function clears the internal accumulator of a moving average filter. It shall be called after filter parameter initialization and whenever the filter initialization is required. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). This function shall not be called together with GDFLIB_FilterMA_F16 unless periodic clearing of filter buffers is required. 5.15.5 Re-entrancy The function is re-entrant. 5.15.6 Code Example #include "gdflib.h" GDFLIB_FILTER_MA_T_F16 f16trMyMA = GDFLIB_FILTER_MA_DEFAULT_F16; void main(void) { // filter window = 2^3 = 8 samples f16trMyMA.u16NSamples = 3; GDFLIB_FilterMAInit_F16 (&f16trMyMA); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 149 Function GDFLIB_FilterMA_F16 GDFLIB_FilterMAInit (&f16trMyMA,F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## GDFLIB_FilterMAInit (&f16trMyMA); 5.16 Function GDFLIB_FilterMA_F16 This function implements an exponential moving average filter. 5.16.1 Declaration tFrac16 GDFLIB_FilterMA_F16(tFrac16 f16In, GDFLIB_FILTER_MA_T_F16 *pParam); 5.16.2 Arguments Table 5-16. GDFLIB_FilterMA_F16 arguments Type tFrac16 Name f16In GDFLIB_FILTER_MA_ pParam T_F16 * Direction Description input Value of input signal to be filtered in step (k). The value is a 16-bit number in the Q1.15 format. input, output Pointer to the filter structure with a filter accumulator and a smoothing factor. 5.16.3 Return The function returns a 16-bit value in format Q1.15, representing the filtered value of the input signal in step (k). 5.16.4 Description This function calculates one iteration of an exponential moving average filter (also known as the exponentially weighted moving average, EWMA). The filter is characterized by the following difference equation: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 150 NXP Semiconductors Chapter 5 API References Equation GDFLIB_FilterMA_Eq2 where x(k) is the filter input, y(k) is the filter output in the current step, y(k-1) is the filter output of the previous step and λ is a smoothing factor, 0 < λ < 1. Values of λ close to one lead to less smoothing and give greater weight to recent changes in the input data, while values of λ closer to zero cause greater smoothing and the filter is less responsive to recent changes. There is no direct equivalence between the smoothing factor λ of the exponential moving average filter and the number of averaged samples N of a uniform sliding-window moving average filter. Nevertheless, the implementation uses the following approximation to relate the two filtering approaches: Equation GDFLIB_FilterMA_Eq3 The library function expects the smoothing factor to be supplied in the form of the u16NSamples variable stored within the filter structure. This variable represents the binary logarithm of the number of averaged samples N of the corresponding uniform sliding-window moving average filter: Equation GDFLIB_FilterMA_Eq4 Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The recalculated smoothing factor u16NSamples needs to be defined prior to calling this function and must be equal to or greater than 0, and equal to or smaller than 16 (0 < u16NSamples < 16). Incorrect setting of this parameter will yield meaningless results. In case the filter window size is greater than 8, the output error may exceed the guaranteed range. 5.16.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 151 Function GFLIB_Acos_F32 5.16.6 Code Example #include "gdflib.h" tFrac16 f16Input; tFrac16 f16Output; GDFLIB_FILTER_MA_T_F16 f16trMyMA = GDFLIB_FILTER_MA_DEFAULT_F16; void main(void) { // input value = 0.25 f16Input = FRAC16 (0.25); // filter window = 2^3 = 8 samples f16trMyMA.u16NSamples = 3; GDFLIB_FilterMAInit_F16 (&f16trMyMA); // output should be 0x0400 = FRAC16(0.03125) f16Output = GDFLIB_FilterMA_F16 (f16Input,&f16trMyMA); // output should be 0x0400 = FRAC16(0.03125) f16Output = GDFLIB_FilterMA (f16Input,&f16trMyMA,F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x0400 = FRAC16(0.03125) f16Output = GDFLIB_FilterMA (f16Input,&f16trMyMA); 5.17 Function GFLIB_Acos_F32 This function implements polynomial approximation of arccosine function. 5.17.1 Declaration tFrac32 GFLIB_Acos_F32(tFrac32 f32In, const GFLIB_ACOS_T_F32 *const pParam); 5.17.2 Arguments Table 5-17. GFLIB_Acos_F32 arguments Type tFrac32 Name f32In Direction input Description Input argument is a 32-bit number that contains a value between [-1,1). Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 152 NXP Semiconductors Chapter 5 API References Table 5-17. GFLIB_Acos_F32 arguments (continued) Type Name const GFLIB_ACOS_T_F32 *const pParam Direction input Description Pointer to an array of Taylor coefficients. 5.17.3 Return The function returns arccos(f32In)/ π as a fixed point 32-bit number, normalized between [0,1). 5.17.4 Description The GFLIB_Acos_F32 function provides a computational method for calculation of the standard inverse trigonometric arccosine function arccos(x), using the piece-wise polynomial approximation. Function arccos(x) takes the ratio of the length of the adjacent side to the length of the hypotenuse and returns the angle. Figure 5-5. Course of the function GFLIB_Acos The computational algorithm uses the symmetry of the arccos(x) function around the point (0, π/2), which allows for computing the function values just in the interval [0, 1) and to compute the function values in the interval [-1, 0) by the simple formula: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 153 Function GFLIB_Acos_F32 Equation GFLIB_Acos_Eq1 where: • y[-1, 0) is the arccos(x) function value in the interval [-1, 0) • y[0, 1) is the arccos(x) function value in the interval [0, 1) Additionally, because the arccos(x) function is difficult for polynomial approximation for x approaching 1 (or -1 by symmetry), due to its derivatives approaching infinity, a special transformation is used to transform the range of x from [0.5, 1) to (0, 0.5]: Equation GFLIB_Acos_Eq2 In this way, the computation of the arccos(x) function in the range [0.5, 1) can be replaced by the computation in the range (0, 0.5], in which approximation is easier. Moreover for interval [0.997, 1), different approximation coeficients are used to eliminate the imprecision of the polynom in this range. For the interval (0, 0.5], the algorithm uses a polynomial approximation as follows: Equation GFLIB_Acos_Eq3 Equation GFLIB_Acos_Eq4 The division of the [0,1) interval into three sub-intervals, with polynomial coefficients calculated for each sub-interval, is noted in Table 5-18. Table 5-18. Integer polynomial coefficients for each interval Interval a0 a1 a2 a3 a4 <0, 1/2) 91918582 66340080 9729967 682829947 12751 Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 154 NXP Semiconductors Chapter 5 API References Table 5-18. Integer polynomial coefficients for each interval (continued) <1/2, 0.997) -52453538 -36708911 -15136243 -964576326 1073630175 <0.997, 1) -52453538 -36708911 -15136243 -966167437 1073739175 The implementation of the GFLIB_Acos_F32 is almost the same as in the function GFLIB_Asin_F32. However, the output of the GFLIB_Acos_F32 is corrected as follows: Equation GFLIB_Acos_Eq5 The polynomial coefficients were obtained using the Matlab fitting function, where a polynomial of 5th order was used for the fitting of each respective sub-interval. The functions arcsine and arccosine are similar, therefore the GFLIB_Acos_F32 function uses the same polynomial coefficients as he GFLIB_Asin_F32 function. Figure 5-6. acos(x) vs. GFLIB_Acos(s32In) Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 155 Function GFLIB_Acos_F32 The output angle is normalized into the range [0,1). The function call is slightly different from common approach in the library set. The function can be called in four different ways: • With implementation postfix (i.e. GFLIB_Acos_F32(f32In, &pParam)), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_ACOS_DEFAULT_F32 symbol. The &pParam parameter is mandatory. • With additional implementation parameter (i.e. GFLIB_Acos(f32In, &pParam, F32), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_ACOS_DEFAULT_F32 symbol. The &pParam parameter is mandatory. • With preselected default implementation (i.e. GFLIB_Acos(f32In, &pParam), where the &pParam is pointer to approximation coefficients. The &pParam parameter is optional and in case it is not used, the default GFLIB_ACOS_DEFAULT_F32 approximation coefficients are used. 5.17.5 Re-entrancy The function is re-entrant. 5.17.6 Code Example #include "gflib.h" tFrac32 f32Input; tFrac32 f32Angle; void main(void) { // input f32Input = 0 f32Input = FRAC32 (0); // output should be 0x400031CE = 0.5 => pi/2 f32Angle = GFLIB_Acos_F32 (f32Input, GFLIB_ACOS_DEFAULT_F32); // output should be 0x400031CE = 0.5 => pi/2 f32Angle = GFLIB_Acos (f32Input, GFLIB_ACOS_DEFAULT_F32, F32); // ############################################################## // Available only if 32-bit fractional implementation selected Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 156 NXP Semiconductors Chapter 5 API References // as default // ############################################################## } // output should be 0x400031CE = 0.5 => pi/2 f32Angle = GFLIB_Acos (f32Input); 5.18 Function GFLIB_Acos_F16 This function implements polynomial approximation of arccosine function. 5.18.1 Declaration tFrac16 GFLIB_Acos_F16(tFrac16 f16In, const GFLIB_ACOS_T_F16 *const pParam); 5.18.2 Arguments Table 5-19. GFLIB_Acos_F16 arguments Type Name Direction Description tFrac16 f16In input Input argument is a 16-bit number that contains a value between [-1,1). const GFLIB_ACOS_T_F16 *const pParam input Pointer to an array of Taylor coefficients. 5.18.3 Return The function returns arccos(f16In)/ π as a fixed point 16-bit number, normalized between [0,1). 5.18.4 Description The GFLIB_Acos_F16 function provides a computational method for calculation of the standard inverse trigonometric arccosine function arccos(x), using the piece-wise polynomial approximation. Function arccos(x) takes the ratio of the length of the adjacent side to the length of the hypotenuse and returns the angle. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 157 Function GFLIB_Acos_F16 Figure 5-7. Course of the function GFLIB_Acos The computational algorithm uses the symmetry of the arccos(x) function around the point (0, π/2), which allows for computing the function values just in the interval [0, 1) and to compute the function values in the interval [-1, 0) by the simple formula: Equation GFLIB_Acos_Eq1 where: • y[-1, 0) is the arccos(x) function value in the interval [-1, 0) • y[0, 1) is the arccos(x) function value in the interval [0, 1) Additionally, because the arccos(x) function is difficult for polynomial approximation for x approaching 1 (or -1 by symmetry), due to its derivatives approaching infinity, a special transformation is used to transform the range of x from [0.5, 1) to (0, 0.5]: Equation GFLIB_Acos_Eq2 In this way, the computation of the arccos(x) function in the range [0.5, 1) can be replaced by the computation in the range (0, 0.5], in which approximation is easier. For the interval (0, 0.5], the algorithm uses a polynomial approximation as follows: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 158 NXP Semiconductors Chapter 5 API References Equation GFLIB_Acos_Eq3 Equation GFLIB_Acos_Eq4 The division of the [0,1) interval into two sub-intervals, with polynomial coefficients calculated for each sub-interval, is noted in Table 5-20. Table 5-20. Integer polynomial coefficients for each interval Interval a0 a1 a2 a3 a4 <0, 1/2) 1403 1012 148 10419 1 <1/2, 1) -800 -560 -231 -14718 16384 The implementation of the GFLIB_Acos_F16 is almost the same as in the function GFLIB_Asin_F16. However, the output of the GFLIB_Acos_F16 is corrected as follows: Equation GFLIB_Acos_Eq5 The polynomial coefficients were obtained using the Matlab fitting function, where a polynomial of 5th order was used for the fitting of each respective sub-interval. The functions arcsine and arccosine are similar, therefore the GFLIB_Acos_F16 function uses the same polynomial coefficients as the GFLIB_Asin_F16 function. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 159 Function GFLIB_Acos_F16 Figure 5-8. acos(x) vs. GFLIB_Acos(f16In) Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The output angle is normalized into the range [0,1). The function call is slightly different from common approach in the library set. The function can be called in four different ways: • With implementation postfix (i.e. GFLIB_Acos_F16(f16In, &pParam)), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_ACOS_DEFAULT_F16 symbol. The &pParam parameter is mandatory. • With additional implementation parameter (i.e. GFLIB_Acos(f16In, &pParam, F16), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_ACOS_DEFAULT_F16 symbol. The &pParam parameter is mandatory. • With preselected default implementation (i.e. GFLIB_Acos(f16In, &pParam), where the &pParam is pointer to approximation coefficients. The &pParam parameter is optional and in case it is not used, the default Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 160 NXP Semiconductors Chapter 5 API References GFLIB_ACOS_DEFAULT_F16 approximation coefficients are used. 5.18.5 Re-entrancy The function is re-entrant. 5.18.6 Code Example #include "gflib.h" tFrac16 f16Input; tFrac16 f16Angle; void main(void) { // input f16Input = 0 f16Input = FRAC16 (0); // output should be 0x4000 = 0.5 => pi/2 f16Angle = GFLIB_Acos_F16 (f16Input, GFLIB_ACOS_DEFAULT_F16); // output should be 0x4000 = 0.5 => pi/2 f16Angle = GFLIB_Acos (f16Input, GFLIB_ACOS_DEFAULT_F16, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x4000 = 0.5 => pi/2 f16Angle = GFLIB_Acos (f16Input); 5.19 Function GFLIB_Asin_F32 This function implements polynomial approximation of arcsine function. 5.19.1 Declaration tFrac32 GFLIB_Asin_F32(tFrac32 f32In, const GFLIB_ASIN_T_F32 *const pParam); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 161 Function GFLIB_Asin_F32 5.19.2 Arguments Table 5-21. GFLIB_Asin_F32 arguments Type Name Direction Description tFrac32 f32In input Input argument is a 32-bit number that contains a value between [-1,1). const GFLIB_ASIN_T_F32 *const pParam input Pointer to an array of Taylor coefficients. 5.19.3 Return The function returns arcsin(f32In)/ π as a fixed point 32-bit number, normalized between [-1,1). 5.19.4 Description The GFLIB_Asin_F32 function provides a computational method for calculation of a standard inverse trigonometric arcsine function arcsin(x), using the piece-wise polynomial approximation. Function arcsin(x) takes the ratio of the length of the opposite side to the length of the hypotenuse and returns the angle. Figure 5-9. Course of the function GFLIB_Asin The computational algorithm uses the symmetry of the arcsin(x) function around the point (0, π/2), which allows to for computing the function values just in the interval [0, 1 ) and to compute the function values in the interval [-1, 0) by the simple formula: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 162 NXP Semiconductors Chapter 5 API References Equation GFLIB_Asin_Eq1 where: • y[-1, 0) is the arcsin(x) function value in the interval [-1, 0) • y[1, 0) is the arcsin(x) function value in the interval [1, 0 ) Additionally, because the arcsin(x) function is difficult for polynomial approximation for x approaching 1 (or -1 by symmetry), due to its derivatives approaching infinity, a special transformation is used to transform the range of x from [0.5, 1) to (0, 0.5] : Equation GFLIB_Asin_Eq2 In this way, the computation of the arcsin(x) function in the range [0.5, 1) can be replaced by the computation in the range (0, 0.5], in which approximation is easier. Moreover for interval [0.997, 1), different approximation coeficients are used to eliminate the imprecision of the polynom in this range. For the interval (0, 0.5], the algorithm uses polynomial approximation as follows: Equation GFLIB_Asin_Eq3 Equation GFLIB_Asin_Eq4 The division of the [0,1) interval into two sub-intervals, with polynomial coefficients calculated for each sub-interval, is noted in Table 5-22. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 163 Function GFLIB_Asin_F32 Table 5-22. Integer polynomial coefficients for each interval Interval a0 a1 a2 a3 a4 <0 , 1/2) 91918582 66340080 9729967 682829947 12751 <1/2, 0.997) -52453538 -36708911 -15136243 -964576326 1073630175 <0.997, 1) -52453538 -36708911 -15136243 -966167437 1073739175 Polynomial coefficients were obtained using the Matlab fitting function, where a polynomial of the 5th order was used for the fitting of each respective sub-interval. The Matlab was used as follows: clear all clc number_of_range = 2; i = 1; range = 0; Range = 1 / number_of_range; x(i,:) = (((i-1)*Range):(1/(2^15)):((i)*Range))'; y(i,:) = asin(x(i,:))/pi; p(i,:) = polyfit((x(i,:)),(y(i,:)),4); i=i+1; Range = 1 / number_of_range; x(i,:) = (((i-1)*Range):(1/(2^15)):((i)*Range))'; y(i,:) = asin(x(i,:))/pi; x1(i,:) = ((x(i,:) - ((i-1)*Range))); x1(i,:) = 0.5 - x1(i,:); x2(i,:) = sqrt(x1(i,:)); p(i,:) = polyfit((x2(i,:)),(y(i,:)),4); i=i+1; f(2,:) = polyval(p(2,:),x2(2,:)); f(1,:) = polyval(p(1,:),x(1,:)); error_1 = abs(f(2,:) - y(2,:)); max(error_1 * (2^15)) error_2 = abs(f(1,:) - y(1,:)); max(error_2 * (2^15)) plot(x(2,:),y(2,:),'-',x(2,:),f(2,:),'-',x(1,:),y(1,:),'-',x(1,:),f(1,:),'-'); coef = round(p * (2^31)) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 164 NXP Semiconductors Chapter 5 API References Figure 5-10. asin(x) vs. GFLIB_Asin(f32In) Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The output angle is normalized into the range [-0.5,0.5). The function call is slightly different from common approach in the library set. The function can be called in four different ways: • With implementation postfix (i.e. GFLIB_Asin_F32(f32In, &pParam)), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_ASIN_DEFAULT_F32 symbol. The &pParam parameter is mandatory. • With additional implementation parameter (i.e. GFLIB_Asin(f32In, &pParam, F32), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 165 Function GFLIB_Asin_F16 replaced with GFLIB_ASIN_DEFAULT_F32 symbol. The &pParam parameter is mandatory. • With preselected default implementation (i.e. GFLIB_Asin(f32In, &pParam), where the &pParam is pointer to approximation coefficients. The &pParam parameter is optional and in case it is not used, the default GFLIB_ASIN_DEFAULT_F32 approximation coefficients are used. 5.19.5 Re-entrancy The function is re-entrant. 5.19.6 Code Example #include "gflib.h" tFrac32 f32Input; tFrac32 f32Angle; void main(void) { // input f32Input = (1-(2^-31)) f32Input = (tFrac32)(0x7FFFFFFF); // output should be 0x3FFFF5A7 = 0.4999987665 f32Angle = GFLIB_Asin_F32 (f32Input, GFLIB_ASIN_DEFAULT_F32); // output should be 0x3FFFF5A7 = 0.4999987665 f32Angle = GFLIB_Asin (f32Input, GFLIB_ASIN_DEFAULT_F32, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x3FFFF5A7 = 0.4999987665 f32Angle = GFLIB_Asin (f32Input); 5.20 Function GFLIB_Asin_F16 This function implements polynomial approximation of arcsine function. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 166 NXP Semiconductors Chapter 5 API References 5.20.1 Declaration tFrac16 GFLIB_Asin_F16(tFrac16 f16In, const GFLIB_ASIN_T_F16 *const pParam); 5.20.2 Arguments Table 5-23. GFLIB_Asin_F16 arguments Type Name Direction Description tFrac16 f16In input Input argument is a 16-bit number that contains a value between [-1,1). const GFLIB_ASIN_T_F16 *const pParam input Pointer to an array of Taylor coefficients. 5.20.3 Return The function returns arcsin(f16In)/ π as a fixed point 16-bit number, normalized between [-1,1). 5.20.4 Description The GFLIB_Asin_F16 function provides a computational method for calculation of a standard inverse trigonometric arcsine function arcsin(x), using the piece-wise polynomial approximation. Function arcsin(x) takes the ratio of the length of the opposite side to the length of the hypotenuse and returns the angle. Figure 5-11. Course of the function GFLIB_Asin Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 167 Function GFLIB_Asin_F16 The computational algorithm uses the symmetry of the arcsin(x) function around the point (0, π/2), which allows to for computing the function values just in the interval [0, 1) and to compute the function values in the interval [-1, 0) by the simple formula: Equation GFLIB_Asin_Eq1 where: • y[-1, 0) is the arcsin(x) function value in the interval [-1, 0) • y[1, 0) is the arcsin(x) function value in the interval [1, 0) Additionally, because the arcsin(x) function is difficult for polynomial approximation for x approaching 1 (or -1 by symmetry), due to its derivatives approaching infinity, a special transformation is used to transform the range of x from [0.5, 1) to (0, 0.5]: Equation GFLIB_Asin_Eq2 In this way, the computation of the arcsin(x) function in the range [0.5, 1) can be replaced by the computation in the range (0, 0.5], in which approximation is easier. For the interval (0, 0.5], the algorithm uses polynomial approximation as follows: Equation GFLIB_Asin_Eq3 Equation GFLIB_Asin_Eq4 The division of the [0,1) interval into two sub-intervals, with polynomial coefficients calculated for each sub-interval, is noted in Table 5-24. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 168 NXP Semiconductors Chapter 5 API References Table 5-24. Integer polynomial coefficients for each interval Interval a0 a1 a2 a3 a4 <0 , 1/2) 1403 1012 148 10419 1 <1/2, 1) -800 -560 -231 -14718 16384 Polynomial coefficients were obtained using the Matlab fitting function, where a polynomial of the 5th order was used for the fitting of each respective sub-interval. The Matlab was used as follows: clear all clc number_of_range = 2; i = 1; range = 0; Range = 1 / number_of_range; x(i,:) = (((i-1)*Range):(1/(2^15)):((i)*Range))'; y(i,:) = asin(x(i,:))/pi; p(i,:) = polyfit((x(i,:)),(y(i,:)),4); i=i+1; Range = 1 / number_of_range; x(i,:) = (((i-1)*Range):(1/(2^15)):((i)*Range))'; y(i,:) = asin(x(i,:))/pi; x1(i,:) = ((x(i,:) - ((i-1)*Range))); x1(i,:) = 0.5 - x1(i,:); x2(i,:) = sqrt(x1(i,:)); p(i,:) = polyfit((x2(i,:)),(y(i,:)),4); i=i+1; f(2,:) = polyval(p(2,:),x2(2,:)); f(1,:) = polyval(p(1,:),x(1,:)); error_1 = abs(f(2,:) - y(2,:)); max(error_1 * (2^15)) error_2 = abs(f(1,:) - y(1,:)); max(error_2 * (2^15)) plot(x(2,:),y(2,:),'-',x(2,:),f(2,:),'-',x(1,:),y(1,:),'-',x(1,:),f(1,:),'-'); coef = round(p * (2^31)) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 169 Function GFLIB_Asin_F16 Figure 5-12. asin(x) vs. GFLIB_Asin(f16In) Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The output angle is normalized into the range [-0.5,0.5). The function call is slightly different from common approach in the library set. The function can be called in four different ways: • With implementation postfix (i.e. GFLIB_Asin_F16(f16In, &pParam)), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_ASIN_DEFAULT_F16 symbol. The &pParam parameter is mandatory. • With additional implementation parameter (i.e. GFLIB_Asin(f16In, &pParam, F16), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_ASIN_DEFAULT_F16 symbol. The &pParam parameter is mandatory. • With preselected default implementation (i.e. GFLIB_Asin(f16In, &pParam), where the &pParam is pointer to approximation coefficients. The &pParam parameter is optional and in case it is not used, the default Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 170 NXP Semiconductors Chapter 5 API References GFLIB_ASIN_DEFAULT_F16 approximation coefficients are used. 5.20.5 Re-entrancy The function is re-entrant. 5.20.6 Code Example #include "gflib.h" tFrac16 f16Input; tFrac16 f16Angle; void main(void) { // input f16Input = (1-(2^-15)) f16Input = (tFrac16)(0x7FFF); // output should be 0x3FAE = 0.4974975 f16Angle = GFLIB_Asin_F16 (f16Input, GFLIB_ASIN_DEFAULT_F16); // output should be 0x3FAE = 0.4974975 f16Angle = GFLIB_Asin (f16Input, GFLIB_ASIN_DEFAULT_F16, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x3FAE = 0.4974975 f16Angle = GFLIB_Asin (f16Input); 5.21 Function GFLIB_Atan_F32 This function implements minimax polynomial approximation of arctangent function. 5.21.1 Declaration tFrac32 GFLIB_Atan_F32(tFrac32 f32In, const GFLIB_ATAN_T_F32 *const pParam); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 171 Function GFLIB_Atan_F32 5.21.2 Arguments Table 5-25. GFLIB_Atan_F32 arguments Type Name Direction Description tFrac32 f32In input Input argument is a 32-bit number between [-1,1). const GFLIB_ATAN_T_F32 *const pParam input Pointer to an array of minimax approximation coefficients. 5.21.3 Return The function returns the atan of the input argument as a fixed point 32-bit number that contains the angle in radians between [- π/4, π/4), normalized between [-0.25,0.25). 5.21.4 Description The GFLIB_Atan_F32 function provides a computational method for calculation of a standard trigonometric arctangent function arctan(x), using the piece-wise minimax polynomial approximation. Function arctan(x) takes a ratio and returns the angle of two sides of a right-angled triangle. The ratio is the length of the side opposite the angle divided by the length of the side adjacent to the angle. The graph of arctan(x) is shown in Figure 5-13. Figure 5-13. Course of the function GFLIB_Atan The GFLIB_Atan_F32 function is implemented with consideration to fixed point fractional arithmetic. As can be further seen from Figure 5-13, the arctangent values are identical for the input ranges [-1, 0) and [0, 1). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 172 NXP Semiconductors Chapter 5 API References Moreover, it can be observed from Figure 5-13 that the course of the arctan(x) function output for a ratio in interval 1. is identical, but with the opposite sign, to the output for a ratio in interval 2. Therefore, the approximation of the arctangent function over the entire defined range of input ratios can be simplified to the approximation for a ratio in range [0, 1), and then, depending on the input ratio, the result will be negated. In order to increase the accuracy of approximation without the need for a higher order polynomial, the interval [0, 1) is further divided into eight equally spaced sub intervals, and minimax polynomial approximation is done for each interval respectively. Such a division results in eight sets of polynomial coefficients. Moreover, it allows using a polynomial of only the 3rd order to achieve an accuracy of less than 0.5LSB (on the upper 16 bits of 32-bit results) across the entire range of input ratios. The GFLIB_Atan_F32 function uses fixed point fractional arithmetic, so to cast the fractional value of the output angle [-0.25, 0.25) into the correct range [- π/4, π/4), the fixed point output angle can be multiplied by π for an angle in radians. Then, the fixed point fractional implementation of the minimax approximation polynomial, used for calculation of each sub sector, is defined as follows: Equation GFLIB_Atan_Eq1 Equation GFLIB_Atan_Eq2 The division of the [0, 1) interval into eight sub-intervals, with polynomial coefficients calculated for each sub-interval, is noted in Table 5-26. Polynomial coefficients were obtained using the Matlab fitting function, where a polynomial of the 3rd order was used for the fitting of each respective sub-interval. Table 5-26. Integer minimax polynomial coefficients for each interval Interval a1 a2 a3 <0, 1/8) -164794 42515925 42667172 <1/8, 2/8) -465182 41238272 126697014 <2/8, 3/8) -690034 38899574 207041074 <3/8, 4/8) -820713 35848645 281909001 <4/8, 5/8) -865105 32453241 350251355 <5/8, 6/8) -845462 29016149 411702516 Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 173 Function GFLIB_Atan_F32 Table 5-26. Integer minimax polynomial coefficients for each interval (continued) <6/8, 7/8) -786689 25743137 466407809 <7/8, 1) -708969 22748418 514828039 Figure 5-14. atan(x) vs. GFLIB_Atan(f32In) Figure 5-14 depicts a floating point arctangent function generated from Matlab and the approximated value of the arctangent function obtained from GFLIB_Atan_F32, plus their difference. The course of calculation accuracy as a function of the input value can be observed from this figure. The achieved accuracy with consideration to the 3rd order piece-wise minimax polynomial approximation and described fixed point scaling is less than 0.5LSB on the upper 16 bits of the 32-bit result. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The output angle is normalized into the range [-0.25, 0.25). The function call is slightly different from common approach in the library set. The function can be called in four different ways: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 174 NXP Semiconductors Chapter 5 API References • With implementation postfix (i.e. GFLIB_Atan_F32(f32In, &pParam)), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_ATAN_DEFAULT_F32 symbol. The &pParam parameter is mandatory. • With additional implementation parameter (i.e. GFLIB_Atan(f32In, &pParam, F32), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_ATAN_DEFAULT_F32 symbol. The &pParam parameter is mandatory. • With preselected default implementation (i.e. GFLIB_Atan(f32In, &pParam), where the &pParam is pointer to approximation coefficients. The &pParam parameter is optional and in case it is not used, the default GFLIB_ATAN_DEFAULT_F32 approximation coefficients are used. 5.21.5 Re-entrancy The function is re-entrant. 5.21.6 Code Example #include "gflib.h" tFrac32 f32Input; tFrac32 f32Angle; void main(void) { // input ratio = 0x7FFFFFFF f32Input = (tFrac32)(0x7FFFFFFF); // output angle should be 0x1FFFF29F = 0.249999 => pi/4 f32Angle = GFLIB_Atan_F32 (f32Input, GFLIB_ATAN_DEFAULT_F32); // output angle should be 0x1FFFF29F = 0.249999 => pi/4 f32Angle = GFLIB_Atan (f32Input, GFLIB_ATAN_DEFAULT_F32, F32); // // // // ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 175 Function GFLIB_Atan_F16 } // output angle should be 0x1FFFF29F = 0.249999 => pi/4 f32Angle = GFLIB_Atan (f32Input); 5.22 Function GFLIB_Atan_F16 This function implements minimax polynomial approximation of arctangent function. 5.22.1 Declaration tFrac16 GFLIB_Atan_F16(tFrac16 f16In, const GFLIB_ATAN_T_F16 *const pParam); 5.22.2 Arguments Table 5-27. GFLIB_Atan_F16 arguments Type Name Direction Description tFrac16 f16In input Input argument is a 16-bit number between [-1, 1). const GFLIB_ATAN_T_F16 *const pParam input Pointer to an array of minimax approximation coefficients. 5.22.3 Return The function returns the atan of the input argument as a fixed point 16-bit number that contains the angle in radians between [- π/4, π/4), normalized between [-0.25, 0.25). 5.22.4 Description The GFLIB_Atan_F16 function provides a computational method for calculation of a standard trigonometric arctangent function arctan(x), using the piece-wise minimax polynomial approximation. Function arctan(x) takes a ratio and returns the angle of two sides of a right-angled triangle. The ratio is the length of the side opposite the angle divided by the length of the side adjacent to the angle. The graph of arctan(x) is shown in Figure 5-15. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 176 NXP Semiconductors Chapter 5 API References Figure 5-15. Course of the function GFLIB_Atan The GFLIB_Atan_F16 function is implemented with consideration to fixed point fractional arithmetic. As can be further seen from Figure 5-15, the arctangent values are identical for the input ranges [-1, 0) and [0, 1). Moreover, it can be observed from Figure 5-15 that the course of the arctan(x) function output for a ratio in interval 1. is identical, but with the opposite sign, to the output for a ratio in interval 2. Therefore, the approximation of the arctangent function over the entire defined range of input ratios can be simplified to the approximation for a ratio in range [0, 1), and then, depending on the input ratio, the result will be negated. In order to increase the accuracy of approximation without the need for a higher order polynomial, the interval [0, 1) is further divided into eight equally spaced sub intervals, and minimax polynomial approximation is done for each interval respectively. Such a division results in eight sets of polynomial coefficients. Moreover, it allows using a minimax polynomial of only the 3rd order to achieve an accuracy of less than 0.5LSB across the entire range of input ratios. The GFLIB_Atan_F16 function uses fixed point fractional arithmetic, so to cast the fractional value of the output angle [-0.25, 0.25) into the correct range [- π/4, π/4), the fixed point output angle can be multiplied by π for an angle in radians. Then, the fixed point fractional implementation of the minimax approximation polynomial, used for calculation of each sub sector, is defined as follows: Equation GFLIB_Atan_Eq1 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 177 Function GFLIB_Atan_F16 Equation GFLIB_Atan_Eq2 The division of the [0, 1) interval into eight sub-intervals, with minimax polynomial coefficients calculated for each sub-interval, is noted in Table 5-28. Minimax polynomial coefficients were obtained using the Matlab fitting function, where a polynomial of the 3rd order was used for the fitting of each respective sub-interval. Table 5-28. Integer polynomial coefficients for each interval Interval a1 a2 a3 <0, 1/8) -3 649 652 <1/8, 2/8) -7 630 1934 <2/8, 3/8) -11 594 3160 <3/8, 4/8) -13 547 4302 <4/8, 5/8) -13 495 5345 <5/8, 6/8) -13 443 6283 <6/8, 7/8) -12 393 7117 <7/8, 1) -11 347 7856 Figure 5-16. atan(x) vs. GFLIB_Atan(f16In) Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 178 NXP Semiconductors Chapter 5 API References The output angle is normalized into the range [-0.25,0.25). The function call is slightly different from common approach in the library set. The function can be called in four different ways: • With implementation postfix (i.e. GFLIB_Atan_F16(f16In, &pParam)), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_ATAN_DEFAULT_F16 symbol. The &pParam parameter is mandatory. • With additional implementation parameter (i.e. GFLIB_Atan(f16In, &pParam, F16), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_ATAN_DEFAULT_F16 symbol. The &pParam parameter is mandatory. • With preselected default implementation (i.e. GFLIB_Atan(f16In, &pParam), where the &pParam is pointer to approximation coefficients. The &pParam parameter is optional and in case it is not used, the default GFLIB_ATAN_DEFAULT_F16 approximation coefficients are used. 5.22.5 Re-entrancy The function is re-entrant. 5.22.6 Code Example #include "gflib.h" tFrac16 f16Input; tFrac16 f16Angle; void main(void) { // input ratio = 0x7FFF f16Input = (tFrac16)(0x7FFF); // output angle should be 0x1FFF = 0.249999 => pi/4 f16Angle = GFLIB_Atan_F16 (f16Input, GFLIB_ATAN_DEFAULT_F16); // output angle should be 0x1FFF = 0.249999 => pi/4 f16Angle = GFLIB_Atan (f16Input, GFLIB_ATAN_DEFAULT_F16, F16); // ############################################################## // Available only if 16-bit fractional implementation selected Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 179 Function GFLIB_AtanYX_F32 // as default // ############################################################## } // output angle should be 0x1FFF = 0.249999 => pi/4 f16Angle = GFLIB_Atan (f16Input); 5.23 Function GFLIB_AtanYX_F32 This function calculate the angle between the positive x-axis and the direction of a vector given by the (x, y) coordinates. 5.23.1 Declaration tFrac32 GFLIB_AtanYX_F32(tFrac32 f32InY, tFrac32 f32InX); 5.23.2 Arguments Table 5-29. GFLIB_AtanYX_F32 arguments Type Name Direction Description tFrac32 f32InY input The ordinate of the input vector (y coordinate). tFrac32 f32InX input The abscissa of the input vector (x coordinate). 5.23.3 Return The function returns the angle between the positive x-axis of a plane and the direction of the vector given by the x and y coordinates provided as parameters. 5.23.4 Description The function returns the angle between the positive x-axis of a plane and the direction of the vector given by the x and y coordinates provided as parameters. The first parameter, f32InY, is the ordinate (the y coordinate) and the second one, f32InX, is the abscissa (the x coordinate). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 180 NXP Semiconductors Chapter 5 API References Both the input parameters are assumed to be in the fractional range of [-1, 1). The computed angle is limited by the fractional range of [-1, 1), which corresponds to the real range of [- π, π). The counter-clockwise direction is assumed to be positive and thus a positive angle will be computed if the provided ordinate (f32InY) is positive. Similarly, a negative angle will be computed for the negative ordinate. The calculations are performed in a few steps. In the first step, the angle is positioned within the correct half-quarter of the circumference of a circle by dividing the angle into two parts: the integral multiple of 45 deg (half-quarter) and the remaining offset within the 45 deg range. Simple geometric properties of the Cartesian coordinate system are used to calculate the coordinates of the vector with the calculated angle offset. In the second step, the vector ordinate is divided by the vector abscissa (y/x) to obtain the tangent value of the angle offset. The angle offset is computed by applying the ordinary arctangent function. The sum of the integral multiple of half-quarters and the angle offset within a single halfquarter form the angle to be computed. The function will return 0 if both input arguments are 0. In comparison to the GFLIB_Atan_F32 function, the GFLIB_AtanYX_F32 function correctly places the calculated angle within the whole fractional range of [-1, 1), which corresponds to the real angle range of [- π, π). Note The function calls the GFLIB_Atan_F32 function. The computed value is within the range of [-1, 1). 5.23.5 Re-entrancy The function is re-entrant. 5.23.6 Code Example #include "gflib.h" tFrac32 f32InY; tFrac32 f32InX; tFrac32 f32Ang; void main(void) { // Angle 45 deg = PI/4 rad f32InY = FRAC32 (0.5); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 181 Function GFLIB_AtanYX_F16 f32InX = FRAC32 (0.5); // output should be close to 0x200034EA f32Ang = GFLIB_AtanYX_F32 (f32InY, f32InX); // output should be close to 0x200034EA f32Ang = GFLIB_AtanYX (f32InY, f32InX, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be close to 0x200034EA f32Ang = GFLIB_AtanYX (f32InY, f32InX); 5.24 Function GFLIB_AtanYX_F16 This function calculate the angle between the positive x-axis and the direction of a vector given by the (x, y) coordinates. 5.24.1 Declaration tFrac16 GFLIB_AtanYX_F16(tFrac16 f16InY, tFrac16 f16InX); 5.24.2 Arguments Table 5-30. GFLIB_AtanYX_F16 arguments Type Name Direction Description tFrac16 f16InY input The ordinate of the input vector (y coordinate). tFrac16 f16InX input The abscissa of the input vector (x coordinate). 5.24.3 Return The function returns the angle between the positive x-axis of a plane and the direction of the vector given by the x and y coordinates provided as parameters. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 182 NXP Semiconductors Chapter 5 API References 5.24.4 Description The function returns the angle between the positive x-axis of a plane and the direction of the vector given by the x and y coordinates provided as parameters. The first parameter, f16InY, is the ordinate (the y coordinate) and the second one, f16InX, is the abscissa (the x coordinate). Both the input parameters are assumed to be in the fractional range of [-1, 1). The computed angle is limited by the fractional range of [-1, 1), which corresponds to the real range of [- π, π). The counter-clockwise direction is assumed to be positive and thus a positive angle will be computed if the provided ordinate (f16InY) is positive. Similarly, a negative angle will be computed for the negative ordinate. The calculations are performed in a few steps. In the first step, the angle is positioned within the correct half-quarter of the circumference of a circle by dividing the angle into two parts: the integral multiple of 45 deg (half-quarter) and the remaining offset within the 45 deg range. Simple geometric properties of the Cartesian coordinate system are used to calculate the coordinates of the vector with the calculated angle offset. In the second step, the vector ordinate is divided by the vector abscissa (y/x) to obtain the tangent value of the angle offset. The angle offset is computed by applying the ordinary arctangent function. The sum of the integral multiple of half-quarters and the angle offset within a single halfquarter form the angle to be computed. The function will return 0 if both input arguments are 0. In comparison to the GFLIB_Atan_F16 function, the GFLIB_AtanYX_F16 function correctly places the calculated angle within the whole fractional range of [-1, 1), which corresponds to the real angle range of [- π, π). Note The function calls the GFLIB_Atan_F16 function. The computed value is within the range of [-1, 1). 5.24.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 183 Function GFLIB_AtanYXShifted_F32 5.24.6 Code Example #include "gflib.h" tFrac16 f16InY; tFrac16 f16InX; tFrac16 f16Ang; void main(void) { // Angle 45 deg = PI/4 rad f16InY = FRAC16 (0.5); f16InX = FRAC16 (0.5); // output should be close to 0x2000 f16Ang = GFLIB_AtanYX_F16 (f16InY, f16InX); // output should be close to 0x2000 f16Ang = GFLIB_AtanYX (f16InY, f16InX, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be close to 0x2000 f16Ang = GFLIB_AtanYX (f16InY, f16InX); 5.25 Function GFLIB_AtanYXShifted_F32 This function calculates the angle of two sine waves shifted in phase to each other. 5.25.1 Declaration tFrac32 GFLIB_AtanYXShifted_F32(tFrac32 f32InY, tFrac32 f32InX, const GFLIB_ATANYXSHIFTED_T_F32 *pParam); 5.25.2 Arguments Table 5-31. GFLIB_AtanYXShifted_F32 arguments Type Name Direction Description tFrac32 f32InY input The value of the first signal, assumed to be sin( θ). tFrac32 f32InX input The value of the second signal, assumed to be sin( θ + Δθ). input, output The parameters for the function. const pParam GFLIB_ATANYXSHIFT ED_T_F32 * Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 184 NXP Semiconductors Chapter 5 API References 5.25.3 Return The function returns the angle of two sine waves shifted in phase to each other. 5.25.4 Description The function calculates the angle of two sinusoidal signals, one shifted in phase to the other. The phase shift between sinusoidal signals does not have to be π/2 and can be any value. It is assumed that the arguments of the function are as follows: Equation GFLIB_AtanYXShifted_Eq1 where: • x, y are respectively, the f32InX, and f32InY arguments • θ is the angle to be computed by the function • Δθ is the phase difference between the x, y signals At the end of computations, an angle offset θOffset is added to the computed angle θ. The angle offset is an additional parameter, which can be used to set the zero of the θ axis. If θOffset is zero, then the angle computed by the function will be exactly θ. The GFLIB_AtanYXShifted_F32 function does not directly use the angle offset θOffset and the phase difference θ. The function's parameters, contained in the function parameters structure GFLIB_ATANYXSHIFTED_T_F32, need to be computed by means of the provided Matlab function (see below). If Δθ= π/2 or Δθ=- π/2, then the function is similar to the GFLIB_AtanYX_F32 function, however, the GFLIB_AtanYX_F32 function in this case is more effective with regard to execution time and accuracy. In order to use the function, the following necessary steps need to be completed: • define Δθ and θOffset, the Δθ shall be known from the input sinusoidal signals, the θOffset needs to be set arbitrarily Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 185 Function GFLIB_AtanYXShifted_F32 • compute values for the function parameters structure by means of the provided Matlab function • convert the computed values into integer format and insert them into the C code (see also the C code example) The function uses the following algorithm for computing the angle: Equation GFLIB_AtanYXShifted_Eq2 where: • • • • • • x, y are respectively, the f32InX, and f32InY θ is the angle to be computed by the function, see the previous equation Δθ is the phase difference between the x, y signals, see the previous equation S is a scaling coefficient, S is almost 1, (S < 1), see also the explanation below a, b intermediate variables θOffset is the additional phase shift, the computed angle will be θ + θOffset The scale coefficient S is used to prevent overflow and to assure symmetry around 0 for the entire fractional range. S shall be less than 1.0, but as large as possible. The algorithm implemented in this function uses the value of 1 - 2 -15. The algorithm can be easily justified by proving the trigonometric identity: Equation GFLIB_AtanYXShifted_Eq3 For the purposes of fractional arithmetic, the algorithm is implemented such that additional values are used as shown in the equation below: Equation GFLIB_AtanYXShifted_Eq4 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 186 NXP Semiconductors Chapter 5 API References where: • C y, C x are the algorithm coefficients for y and x signals • K y is multiplication coefficient of the y signal, represented by the parameters structure member pParam->f32Ky • K x is multiplication coefficient of the x signal, represented by the parameters structure member pParam->f32Kx • N y is scaling coefficient of the y signal, represented the by parameters structure member pParam->s32Ny • N x is scaling coefficient of the x signal, represented by the parameters structure member pParam->s32Nx • θadj is an adjusting angle, represented by the parameters structure member pParam>f32ThetaAdj The multiplication and scaling coefficients, and the adjusting angle, shall be defined in a parameters structure provided as the function input parameter. The function initialization parameters can be calculated as shown in the following Matlab code: function [KY, KX, NY, NX, THETAADJ] = atanyxshiftedpar(dthdeg, thoffsetdeg) // ATANYXSHIFTEDPAR calculation of parameters for atanyxshifted() function // // [KY, KX, NY, NX, THETAADJ] = atanyxshiftedpar(dthdeg, thoffsetdeg) // // dthdeg = phase shift (delta theta) between sine waves in degrees // thoffsetdeg = angle offset (theta offset) in degrees // NY - scaling coefficient of y signal // NX - scaling coefficient of x signal // KY - multiplication coefficient of y signal // KX - multiplication coefficient of x signal // THETAADJ - adjusting angle in radians, scaled from [-pi, pi) to [-1, 1) if (dthdeg < -180) || (dthdeg >= 180) error('atanyxshiftedpar: dthdeg out of range'); end if (thoffsetdeg < -180) || (thoffsetdeg >= 180) error('atanyxshiftedpar: thoffsetdeg out of range'); end dth2 = ((dthdeg/2)/180*pi); thoffset = (thoffsetdeg/180*pi); CY = (1 - 2^-15)/(2*cos(dth2)); CX = (1 - 2^-15)/(2*sin(dth2)); if(abs(CY) >= 1) NY = ceil(log2(abs(CY))); else NY = 0; end if(abs(CX) >= 1) NX = ceil(log2(abs(CX))); else NX = 0; end KY = CY/2^NY; KX = CX/2^NX; THETAADJ = dthdeg/2 - thoffsetdeg; if THETAADJ >= 180 THETAADJ = THETAADJ - 360; elseif THETAADJ < -180 THETAADJ = THETAADJ + 360; Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 187 Function GFLIB_AtanYXShifted_F32 end THETAADJ = THETAADJ/180; return; While applying the function, some general guidelines should be considered as stated below. At some values of the phase shift, and particularly at phase shift approaching -180, 0 or 180 degrees, the algorithm may become numerically unstable, causing any error, contributed by input signal imperfections or through finite precision arithmetic, to be magnified significantly. Therefore, some care should be taken to avoid error where possible. The detailed error analysis of the algorithm is beyond the scope of this documentation, however, general guidelines are provided. There are several sources of error in the function: • • • • error of the supplied signal values due to the finite resolution of the AD conversion error contributed by higher order harmonics appearing in the input signals computational error of the multiplication due to the finite length of registers error of the phase shift Δθ representation in the finite precision arithmetic and in the values • error due to differences in signal amplitudes It should be noted that the function requires both signals to have the same amplitude. To minimize the output error, the amplitude of both signals should be as close to 1.0 as much as possible. The function has been tested to be reliable at a phase shift in the range of [-165, -15] and [15, 165] degrees for perfectly sinusoidal input signals. Beyond this range, the function operates correctly, however, the output error can be beyond the guaranteed value. In a real application, an error, contributed by an AD conversion and by higher order harmonics of the input signals, should be also taken into account. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The function calls the GFLIB_AtanYX_F32 function. The function may become numerically unstable for a phase shift approaching -180, 0 or 180 degrees. The function accuracy is guaranteed for a phase shift in the range of [-165, -15] and [15, 165] degrees at perfect input signals. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 188 NXP Semiconductors Chapter 5 API References CAUTION Due to the cyclic character of the GFLIB_AtanYX_F16, in case the difference between the adjusting angle θadj and the input vector angle is approaching to 1-2 -15 or -1, the GFLIB_AtanYX_F16 function operates correctly, however the output error might exceed the guaranteed limits comparing to the double precision reference. 5.25.5 Re-entrancy The function is re-entrant. 5.25.6 Code Example #include "gflib.h" tFrac32 f32InY; tFrac32 f32InX; tFrac32 f32Ang; GFLIB_ATANYXSHIFTED_T_F32 Param; void main(void) { // dtheta = 69.33deg, thetaoffset = 10deg // CY = (1 - 2^-15)/(2*cos((69.33/2)/180*pi))= 0.60789036201452440 // CX = (1 - 2^-15)/(2*sin((69.33/2)/180*pi))= 0.87905201358520957 // NY = 0 (abs(CY) < 1) // NX = 0 (abs(CX) < 1) // KY = 0.60789/2^0 = 0.60789036201452440 // KX = 0.87905/2^0 = 0.87905201358520957 // THETAADJ = 10/180 = 0.05555555555 Param.f32Ky = FRAC32 (0.60789036201452440); Param.f32Kx = FRAC32 (0.87905201358520957); Param.s32Ny = 0; Param.s32Nx = 0; Param.f32ThetaAdj = FRAC32 (0.05555555555); // theta = 15 deg // Y = sin(theta) = 0.2588190 // X = sin(theta + dtheta) = 0.9951074 f32InY = FRAC32 (0.2588190); f32InX = FRAC32 (0.9951074); // f32Ang output should be close to 0x1C34824A f32Ang = GFLIB_AtanYXShifted_F32 (f32InY, f32InX, &Param); // f32Ang output should be close to 0x1C34824A f32Ang = GFLIB_AtanYXShifted (f32InY, f32InX, &Param, F32); // // // // ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 189 Function GFLIB_AtanYXShifted_F16 } // f32Ang output should be close to 0x1C34824A f32Ang = GFLIB_AtanYXShifted (f32InY, f32InX, &Param); 5.26 Function GFLIB_AtanYXShifted_F16 This function calculates the angle of two sine waves shifted in phase to each other. 5.26.1 Declaration tFrac16 GFLIB_AtanYXShifted_F16(tFrac16 f16InY, tFrac16 f16InX, const GFLIB_ATANYXSHIFTED_T_F16 *pParam); 5.26.2 Arguments Table 5-32. GFLIB_AtanYXShifted_F16 arguments Type Name Direction Description tFrac16 f16InY input The value of the first signal, assumed to be sin( θ). tFrac16 f16InX input The value of the second signal, assumed to be sin( θ + Δθ). input, output The parameters for the function. const pParam GFLIB_ATANYXSHIFT ED_T_F16 * 5.26.3 Return The function returns the angle of two sine waves shifted in phase to each other. 5.26.4 Description The function calculates the angle of two sinusoidal signals, one shifted in phase to the other. The phase shift between sinusoidal signals does not have to be π/2 and can be any value. It is assumed that the arguments of the function are as follows: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 190 NXP Semiconductors Chapter 5 API References Equation GFLIB_AtanYXShifted_Eq1 where: • x, y are respectively, the f16InX, and f16InY arguments • θ is the angle to be computed by the function • Δθ is the phase difference between the x, y signals At the end of computations, an angle offset θOffset is added to the computed angle θ. The angle offset is an additional parameter, which can be used to set the zero of the θ axis. If θOffset is zero, then the angle computed by the function will be exactly θ. The GFLIB_AtanYXShifted_F16 function does not directly use the angle offset θOffset and the phase difference θ. The function's parameters, contained in the function parameters structure GFLIB_ATANYXSHIFTED_T_F16, need to be computed by means of the provided Matlab function (see below). If Δθ= π/2 or Δθ=- π/2, then the function is similar to the GFLIB_AtanYX_F16 function, however, the GFLIB_AtanYX_F16 function in this case is more effective with regard to execution time and accuracy. In order to use the function, the following necessary steps need to be completed: • define Δθ and θOffset, the Δθ shall be known from the input sinusoidal signals, the θOffset needs to be set arbitrarily • compute values for the function parameters structure by means of the provided Matlab function • convert the computed values into integer format and insert them into the C code (see also the C code example) The function uses the following algorithm for computing the angle: Equation GFLIB_AtanYXShifted_Eq2 where: • x, y are respectively, the f16InX, and f16InY • θ is the angle to be computed by the function, see the previous equation • Δθ is the phase difference between the x, y signals, see the previous equation Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 191 Function GFLIB_AtanYXShifted_F16 • S is a scaling coefficient, S is almost 1, (S < 1), see also the explanation below • a, b intermediate variables • θOffset is the additional phase shift, the computed angle will be θ + θOffset The scale coefficient S is used to prevent overflow and to assure symmetry around 0 for the entire fractional range. S shall be less than 1.0, but as large as possible. The algorithm implemented in this function uses the value of 1 - 2 -15. The algorithm can be easily justified by proving the trigonometric identity: Equation GFLIB_AtanYXShifted_Eq3 For the purposes of fractional arithmetic, the algorithm is implemented such that additional values are used as shown in the equation below: Equation GFLIB_AtanYXShifted_Eq4 where: • C y, C x are the algorithm coefficients for y and x signals • K y is multiplication coefficient of the y signal, represented by the parameters structure member pParam->f16Ky • K x is multiplication coefficient of the x signal, represented by the parameters structure member pParam->f16Kx • N y is scaling coefficient of the y signal, represented the by parameters structure member pParam->s16Ny • N x is scaling coefficient of the x signal, represented by the parameters structure member pParam->s16Nx • θadj is an adjusting angle, represented by the parameters structure member pParam>f16ThetaAdj The multiplication and scaling coefficients, and the adjusting angle, shall be defined in a parameters structure provided as the function input parameter. The function initialization parameters can be calculated as shown in the following Matlab code: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 192 NXP Semiconductors Chapter 5 API References function [KY, KX, NY, NX, THETAADJ] = atanyxshiftedpar(dthdeg, thoffsetdeg) // ATANYXSHIFTEDPAR calculation of parameters for atanyxshifted() function // // [KY, KX, NY, NX, THETAADJ] = atanyxshiftedpar(dthdeg, thoffsetdeg) // // dthdeg = phase shift (delta theta) between sine waves in degrees // thoffsetdeg = angle offset (theta offset) in degrees // NY - scaling coefficient of y signal // NX - scaling coefficient of x signal // KY - multiplication coefficient of y signal // KX - multiplication coefficient of x signal // THETAADJ - adjusting angle in radians, scaled from [-pi, pi) to [-1, 1) if (dthdeg < -180) || (dthdeg >= 180) error('atanyxshiftedpar: dthdeg out of range'); end if (thoffsetdeg < -180) || (thoffsetdeg >= 180) error('atanyxshiftedpar: thoffsetdeg out of range'); end dth2 = ((dthdeg/2)/180*pi); thoffset = (thoffsetdeg/180*pi); CY = (1 - 2^-15)/(2*cos(dth2)); CX = (1 - 2^-15)/(2*sin(dth2)); if(abs(CY) >= 1) NY = ceil(log2(abs(CY))); else NY = 0; end if(abs(CX) >= 1) NX = ceil(log2(abs(CX))); else NX = 0; end KY = CY/2^NY; KX = CX/2^NX; THETAADJ = dthdeg/2 - thoffsetdeg; if THETAADJ >= 180 THETAADJ = THETAADJ - 360; elseif THETAADJ < -180 THETAADJ = THETAADJ + 360; end THETAADJ = THETAADJ/180; return; While applying the function, some general guidelines should be considered as stated below. At some values of the phase shift, and particularly at phase shift approaching -180, 0 or 180 degrees, the algorithm may become numerically unstable, causing any error, contributed by input signal imperfections or through finite precision arithmetic, to be magnified significantly. Therefore, some care should be taken to avoid error where possible. The detailed error analysis of the algorithm is beyond the scope of this documentation, however, general guidelines are provided. There are several sources of error in the function: • error of the supplied signal values due to the finite resolution of the AD conversion • error contributed by higher order harmonics appearing in the input signals • computational error of the multiplication due to the finite length of registers Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 193 Function GFLIB_AtanYXShifted_F16 • error of the phase shift Δθ representation in the finite precision arithmetic and in the values • error due to differences in signal amplitudes It should be noted that the function requires both signals to have the same amplitude. To minimize the output error, the amplitude of both signals should be as close to 1.0 as much as possible. The function has been tested to be reliable at a phase shift in the range of [-165, -15] and [15, 165] degrees for perfectly sinusoidal input signals. Beyond this range, the function operates correctly, however, the output error can be beyond the guaranteed value. In a real application, an error, contributed by an AD conversion and by higher order harmonics of the input signals, should be also taken into account. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The function calls the GFLIB_AtanYX_F16 function. The function may become numerically unstable for a phase shift approaching -180, 0 or 180 degrees. The function accuracy is guaranteed for a phase shift in the range of [-175, -5] and [5, 175] degrees at perfect input signals. To eliminate the calculation error the function uses the 32-bit internal accumulators. CAUTION Due to the cyclic character of the GFLIB_AtanYX_F16, in case the difference between the adjusting angle θadj and the input vector angle is approaching to 1-2 -15 or -1, the GFLIB_AtanYX_F16 function operates correctly, however the output error might exceed the guaranteed limits comparing to the double precision reference. 5.26.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 194 NXP Semiconductors Chapter 5 API References 5.26.6 Code Example #include "gflib.h" tFrac16 f16InY; tFrac16 f16InX; tFrac16 f16Ang; GFLIB_ATANYXSHIFTED_T_F16 Param; void main(void) { // dtheta = 69.33deg, thetaoffset = 10deg // CY = (1 - 2^-15)/(2*cos((69.33/2)/180*pi))= 0.60789036201452440 // CX = (1 - 2^-15)/(2*sin((69.33/2)/180*pi))= 0.87905201358520957 // NY = 0 (abs(CY) < 1) // NX = 0 (abs(CX) < 1) // KY = 0.60789/2^0 = 0.60789036201452440 // KX = 0.87905/2^0 = 0.87905201358520957 // THETAADJ = 10/180 = 0.05555555555 Param.f16Ky = FRAC16 (0.60789036201452440); Param.f16Kx = FRAC16 (0.87905201358520957); Param.s16Ny = 0; Param.s16Nx = 0; Param.f16ThetaAdj = FRAC16 (0.05555555555); // theta = 15 deg // Y = sin(theta) = 0.2588190 // X = sin(theta + dtheta) = 0.9951074 f16InY = FRAC16 (0.2588190); f16InX = FRAC16 (0.9951074); // f16Ang output should be close to 0x1C34 f16Ang = GFLIB_AtanYXShifted_F16 (f16InY, f16InX, &Param); // f16Ang output should be close to 0x1C34 f16Ang = GFLIB_AtanYXShifted (f16InY, f16InX, &Param, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // f16Ang output should be close to 0x1C34 f16Ang = GFLIB_AtanYXShifted (f16InY, f16InX, &Param); 5.27 Function GFLIB_ControllerPIp_F32 This function calculates a parallel form of the Proportional-Integral controller, without integral anti-windup. 5.27.1 Declaration tFrac32 GFLIB_ControllerPIp_F32(tFrac32 f32InErr, GFLIB_CONTROLLER_PI_P_T_F32 *const pParam); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 195 Function GFLIB_ControllerPIp_F32 5.27.2 Arguments Table 5-33. GFLIB_ControllerPIp_F32 arguments Type tFrac32 Name f32InErr GFLIB_CONTROLLER pParam _PI_P_T_F32 *const Direction Description input Input error signal to the controller is a 32-bit number normalized between [-1, 1). input, output Pointer to the controller parameters structure. 5.27.3 Return The function returns a 32-bit value in format 1.31, representing the signal to be applied to the controlled system so that the input error is forced to zero. 5.27.4 Description A PI controller attempts to correct the error between a measured process variable and a desired set-point by calculating and then outputting a corrective action that can adjust the process accordingly. The GFLIB_ControllerPIp_F32 function calculates the Proportional-Integral (PI) algorithm according to the equations below. The PI algorithm is implemented in the parallel (non-interacting) form, allowing the user to define the P and I parameters independently without interaction. An anti-windup strategy is not implemented in this function. Nevertheless, the accumulator overflow is prevented by correct saturation of the controller output at maximal values: [-1, 1) in fractional interpretation, or [-2 31,2 31-1) in integer interpretation. The PI algorithm in the continuous time domain can be described as: Equation GFLIB_ControllerPIp_Eq1 where • e(t) - input error in the continuous time domain • u(t) - controller output in the continuous time domain Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 196 NXP Semiconductors Chapter 5 API References • K P - proportional gain • K I - integral gain Equation GFLIB_ControllerPIp_Eq1 can be described using the Laplace transformation as follows: Equation GFLIB_ControllerPIp_Eq2 The proportional part of equation GFLIB_ControllerPIp_Eq2 is transformed into the discrete time domain simply as: Equation GFLIB_ControllerPIp_Eq3 Transforming the integral part of equation GFLIB_ControllerPIp_Eq2 into a discrete time domain using the Bilinear method, also known as trapezoidal approximation, leads to the following equation: Equation GFLIB_ControllerPIp_Eq4 where T s [sec] is the sampling time. In order to implement the discrete equation of the controller on the fixed point arithmetic platform, the maximal values (scales) of the input and output signals have to be known a priori. This is essential for correct casting of the physical signal values into fixed point values: • E MAX - maximal value of the controller input error signal • U MAX - maximal value of the controller output signal The fractional representation of both input and output signals, normalized between [-1, 1), is obtained as follows: Equation GFLIB_ControllerPIp_Eq5 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 197 Function GFLIB_ControllerPIp_F32 Equation GFLIB_ControllerPIp_Eq6 Applying such scaling (normalization) on the proportional term of equation GFLIB_ControllerPIp_Eq3 results in: Equation GFLIB_ControllerPIp_Eq7 where K P_sc is the proportional gain parameter considering input/output scaling. Analogically, scaling the integral term of equation GFLIB_ControllerPIp_Eq4 results in: Equation GFLIB_ControllerPIp_Eq8 where K I_sc is the integral gain parameter considering input/output scaling. The sum of the scaled proportional and integral terms gives a complete equation of the controller: Equation GFLIB_ControllerPIp_Eq9 The problem is however, that either of the gain parameters K P_sc, K I_sc can be out of the [-1, 1) range, hence cannot be directly interpreted as fractional values. To overcome this, it is necessary to scale these gain parameters using the shift values as follows: Equation GFLIB_ControllerPIp_Eq10 and Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 198 NXP Semiconductors Chapter 5 API References Equation GFLIB_ControllerPIp_Eq11 where • • • • f32PropGain - is the scaled value of proportional gain [-1, 1) s16PropGainShift - is the scaling shift for proportional gain [-31,31] f32IntegGain - is the scaled value of integral gain [-1, 1) s16IntegGainShift - is the scaling shift for integral gain [-31,31] Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). All controller parameters and states can be reset during declaration using the GFLIB_CONTROLLER_PI_P_DEFAULT_F32 macro. As the GFLIB_ControllerPIp also contains the integration part, the output result is saddled by cumulative error. To enumerate the computation error in one calculation cycle, the internal integration accumulator is not used for testing purposes and is replaced by output from the previous calculation step of the reference model. 5.27.5 Re-entrancy The function is re-entrant. 5.27.6 Code Example #include "gflib.h" tFrac32 f32InErr; tFrac32 f32Output; GFLIB_CONTROLLER_PI_P_T_F32 trMyPI = GFLIB_CONTROLLER_PI_P_DEFAULT_F32; void main(void) { // input error = 0.25 f32InErr = FRAC32 (0.25); // controller parameters trMyPI.f32PropGain trMyPI.f32IntegGain trMyPI.s16PropGainShift trMyPI.s16IntegGainShift trMyPI.f32IntegPartK_1 = = = = = FRAC32 (0.01); FRAC32 (0.02); 1; 1; 0; Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 199 Function GFLIB_ControllerPIp_F16 // output should be 0x01EB851E f32Output = GFLIB_ControllerPIp_F32 (f32InErr, &trMyPI); // clearing of internal states trMyPI.f32IntegPartK_1 = (tFrac32)0; trMyPI.f32InK_1 = (tFrac32)0; // output should be 0x01EB851E f32Output = GFLIB_ControllerPIp (f32InErr, &trMyPI, F32); // // // // ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // clearing of internal states trMyPI.f32IntegPartK_1 = (tFrac32)0; trMyPI.f32InK_1 = (tFrac32)0; } // output should be 0x01EB851E f32Output = GFLIB_ControllerPIp (f32InErr, &trMyPI); 5.28 Function GFLIB_ControllerPIp_F16 This function calculates a parallel form of the Proportional-Integral controller, without integral anti-windup. 5.28.1 Declaration tFrac16 GFLIB_ControllerPIp_F16(tFrac16 f16InErr, GFLIB_CONTROLLER_PI_P_T_F16 *const pParam); 5.28.2 Arguments Table 5-34. GFLIB_ControllerPIp_F16 arguments Type tFrac16 Name f16InErr GFLIB_CONTROLLER pParam _PI_P_T_F16 *const Direction Description input Input error signal to the controller is a 16-bit number normalized between [-1, 1). input, output Pointer to the controller parameters structure. 5.28.3 Return The function returns a 16-bit value in format 1.15, representing the signal to be applied to the controlled system so that the input error is forced to zero. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 200 NXP Semiconductors Chapter 5 API References 5.28.4 Description A PI controller attempts to correct the error between a measured process variable and a desired set-point by calculating and then outputting a corrective action that can adjust the process accordingly. The GFLIB_ControllerPIp_F16 function calculates the Proportional-Integral (PI) algorithm according to the equations below. The PI algorithm is implemented in the parallel (non-interacting) form, allowing the user to define the P and I parameters independently without interaction. An anti-windup strategy is not implemented in this function. Nevertheless, the accumulator overflow is prevented by correct saturation of the controller output at maximal values: [-1, 1) in fractional interpretation, or [-2 15,2 15-1) in integer interpretation. The PI algorithm in the continuous time domain can be described as: Equation GFLIB_ControllerPIp_Eq1 where • • • • e(t) - input error in the continuous time domain u(t) - controller output in the continuous time domain K P - proportional gain K I - integral gain Equation GFLIB_ControllerPIp_Eq1 can be described using the Laplace transformation as follows: Equation GFLIB_ControllerPIp_Eq2 The proportional part of equation GFLIB_ControllerPIp_Eq2 is transformed into the discrete time domain simply as: Equation GFLIB_ControllerPIp_Eq3 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 201 Function GFLIB_ControllerPIp_F16 Transforming the integral part of equation GFLIB_ControllerPIp_Eq2 into a discrete time domain using the Bilinear method, also known as trapezoidal approximation, leads to the following equation: Equation GFLIB_ControllerPIp_Eq4 where T s [sec] is the sampling time. In order to implement the discrete equation of the controller on the fixed point arithmetic platform, the maximal values (scales) of the input and output signals have to be known a priori. This is essential for correct casting of the physical signal values into fixed point values: • E MAX - maximal value of the controller input error signal • U MAX - maximal value of the controller output signal The fractional representation of both input and output signals, normalized between [-1, 1), is obtained as follows: Equation GFLIB_ControllerPIp_Eq5 Equation GFLIB_ControllerPIp_Eq6 Applying such scaling (normalization) on the proportional term of equation GFLIB_ControllerPIp_Eq3 results in: Equation GFLIB_ControllerPIp_Eq7 where K P_sc is the proportional gain parameter considering input/output scaling. Analogically, scaling the integral term of equation GFLIB_ControllerPIp_Eq4 results in: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 202 NXP Semiconductors Chapter 5 API References Equation GFLIB_ControllerPIp_Eq8 where K I_sc is the integral gain parameter considering input/output scaling. The sum of the scaled proportional and integral terms gives a complete equation of the controller: Equation GFLIB_ControllerPIp_Eq9 The problem is however, that either of the gain parameters K P_sc, K I_sc can be out of the [-1, 1) range, hence cannot be directly interpreted as fractional values. To overcome this, it is necessary to scale these gain parameters using the shift values as follows: Equation GFLIB_ControllerPIp_Eq10 and Equation GFLIB_ControllerPIp_Eq11 where • • • • f16PropGain - is the scaled value of proportional gain [-1, 1) s16PropGainShift - is the scaling shift for proportional gain [-15, 15) f16IntegGain - is the scaled value of integral gain [-1, 1) s16IntegGainShift - is the scaling shift for integral gain [-15, 15) Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). All controller parameters and states can be reset during declaration using the GFLIB_CONTROLLER_PI_P_DEFAULT_F16 macro. As the GFLIB_ControllerPIp also contains the integration part, the output result is saddled by cumulative error. To enumerate the computation error in one calculation cycle, the internal Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 203 Function GFLIB_ControllerPIpAW_F32 integration accumulator is not used for testing purposes and is replaced by output from the previous calculation step of the reference model. 5.28.5 Re-entrancy The function is re-entrant. 5.28.6 Code Example #include "gflib.h" tFrac16 f16InErr; tFrac16 f16Output; GFLIB_CONTROLLER_PI_P_T_F16 trMyPI = GFLIB_CONTROLLER_PI_P_DEFAULT_F16; void main(void) { // input error = 0.25 f16InErr = FRAC16 (0.25); // controller parameters trMyPI.f16PropGain trMyPI.f16IntegGain trMyPI.s16PropGainShift trMyPI.s16IntegGainShift trMyPI.f32IntegPartK_1 = = = = = FRAC16 (0.01); FRAC16 (0.02); 1; 1; 0; // output should be 0x01EB f16Output = GFLIB_ControllerPIp_F16 (f16InErr, &trMyPI); // clearing of internal states trMyPI.f32IntegPartK_1 = (tFrac32)0; trMyPI.f16InK_1 = (tFrac16)0; // output should be 0x01EB f16Output = GFLIB_ControllerPIp (f16InErr, &trMyPI, F16); // // // // ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // clearing of internal states trMyPI.f32IntegPartK_1 = (tFrac32)0; trMyPI.f16InK_1 = (tFrac16)0; } // output should be 0x01EB f16Output = GFLIB_ControllerPIp (f16InErr, &trMyPI); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 204 NXP Semiconductors Chapter 5 API References 5.29 Function GFLIB_ControllerPIpAW_F32 The function calculates the parallel form of the Proportional-Integral (PI) controller with implemented integral anti-windup functionality. 5.29.1 Declaration tFrac32 GFLIB_ControllerPIpAW_F32(tFrac32 f32InErr, GFLIB_CONTROLLER_PIAW_P_T_F32 *const pParam); 5.29.2 Arguments Table 5-35. GFLIB_ControllerPIpAW_F32 arguments Type Name tFrac32 f32InErr GFLIB_CONTROLLER pParam _PIAW_P_T_F32 *const Direction Description input Input error signal to the controller is a 32-bit number normalized between [-1, 1). input, output Pointer to the controller parameters structure. 5.29.3 Return The function returns a 32-bit value in format 1.31, representing the signal to be applied to the controlled system so that the input error is forced to zero. 5.29.4 Description A PI controller attempts to correct the error between a measured process variable and a desired set-point by calculating and then outputting a corrective action that can adjust the process accordingly. The GFLIB_ControllerPIpAW function calculates the ProportionalIntegral (PI) algorithm according to the equations below. The PI algorithm is implemented in the parallel (non-interacting) form, allowing the user to define the P and I parameters independently without interaction. The controller output is limited and the limit values (f32UpperLimit and f32LowerLimit) are defined by the user. The PI controller algorithm also returns a limitation flag. This flag (u16LimitFlag) is a member of the structure of the PI controller parameters (GFLIB_CONTROLLER_PIAW_P_T_F32). If the PI controller output reaches the upper Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 205 Function GFLIB_ControllerPIpAW_F32 or lower limit then u16LimitFlag = 1, otherwise u16LimitFlag = 0 (integer values). An anti-windup strategy is implemented by limiting the integral portion. The integral state is limited by the controller limits, in the same way as the controller output. The PI algorithm in the continuous time domain can be described as: Equation GFLIB_ControllerPIpAW_Eq1 where • • • • e(t) - input error in the continuous time domain u(t) - controller output in the continuous time domain K P - proportional gain K I - integral gain Equation GFLIB_ControllerPIpAW_Eq1 can be described using the Laplace transformation as follows: Equation GFLIB_ControllerPIpAW_Eq2 The proportional part of equation GFLIB_ControllerPIpAW_Eq2 is transformed into the discrete time domain simply as: Equation GFLIB_ControllerPIpAW_Eq3 Transforming the integral part of equation GFLIB_ControllerPIpAW_Eq2 into a discrete time domain using the Bilinear method, also known as trapezoidal approximation, leads to the following equation: Equation GFLIB_ControllerPIpAW_Eq4 where T s [sec] is the sampling time. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 206 NXP Semiconductors Chapter 5 API References In order to implement the discrete equation of the controller on the fixed point arithmetic platform, the maximal values (scales) of input and output signals have to be known a priori. This is essential for correct casting of the physical signal values into fixed point values: • E MAX - maximal value of the controller input error signal • U MAX - maximal value of the controller output signal The fractional representation of both input and output signals, normalized between [-1, 1), is obtained as follows: Equation GFLIB_ControllerPIpAW_Eq5 Equation GFLIB_ControllerPIpAW_Eq6 Applying such scaling (normalization) on the proportional term of equation GFLIB_ControllerPIpAW_Eq3 results in: Equation GFLIB_ControllerPIpAW_Eq7 where K P_sc is the proportional gain parameter considering input/output scaling. Analogically, scaling the integral term of equation GFLIB_ControllerPIpAW_Eq4 results in: Equation GFLIB_ControllerPIpAW_Eq8 where K I_sc is the integral gain parameter considering input/output scaling. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 207 Function GFLIB_ControllerPIpAW_F32 The sum of the scaled proportional and integral terms gives a complete equation of the controller. The problem is however, that either of the gain parameters K P_sc, K I_sc can be out of the [-1, 1) range, hence can not be directly interpreted as fractional values. To overcome this, it is necessary to scale these gain parameters using the shift values as follows: Equation GFLIB_ControllerPIpAW_Eq9 Equation GFLIB_ControllerPIpAW_Eq10 where • • • • f16PropGain - is the scaled value of proportional gain [-1, 1) s16PropGainShift - is the scaling shift for proportional gain [-31, 31) f16IntegGain - is the scaled value of integral gain [-1, 1) s16IntegGainShift - is the scaling shift for integral gain [-31, 31) The sum of the scaled proportional and integral terms gives a complete equation of the controller: Equation GFLIB_ControllerPIpAW_Eq11 The output signal limitation is implemented in this controller. The actual output u(k) is bounded not to exceed the given limit values f32UpperLimit, f32LowerLimit. This is due to either the bounded power of the actuator or to the physical constraints of the plant. Equation GFLIB_ControllerPIpAW_Eq12 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 208 NXP Semiconductors Chapter 5 API References The bounds are described by a limitation element equation GFLIB_ControllerPIpAW_Eq12. When the bounds are exceeded the non-linear saturation characteristic will take effect and influence the dynamic behavior. The described limitation is implemented on the integral part accumulator (limitation during the calculation) and on the overall controller output. Therefore, if the limitation occurs, the controller output is clipped to its bounds and the wind-up occurrence of the accumulator portion is avoided by saturating the actual sum. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). All controller parameters and states can be reset during declaration using the GFLIB_CONTROLLER_PIAW_P_DEFAULT_F32 macro. As the GFLIB_ControllerPIp also contains the integration part, the output result is saddled by cumulative error. To enumerate the computation error in one calculation cycle, the internal integration accumulator is not used for testing purposes and is replaced by output from the previous calculation step of the reference model. 5.29.5 Re-entrancy The function is re-entrant. 5.29.6 Code Example #include "gflib.h" tFrac32 f32InErr; tFrac32 f32Output; GFLIB_CONTROLLER_PIAW_P_T_F32 trMyPI = GFLIB_CONTROLLER_PIAW_P_DEFAULT_F32; void main(void) { // input error = 0.25 f32InErr = FRAC32 (0.25); // controller parameters trMyPI.f32PropGain trMyPI.f32IntegGain trMyPI.s16PropGainShift trMyPI.s16IntegGainShift trMyPI.f32IntegPartK_1 trMyPI.f32UpperLimit = = = = = = FRAC32 FRAC32 1; 1; FRAC32 FRAC32 (0.01); (0.02); (0); (1.0); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 209 Function GFLIB_ControllerPIpAW_F16 trMyPI.f32LowerLimit = FRAC32 (-1.0); // output should be 0x01EB851E f32Output = GFLIB_ControllerPIpAW_F32 (f32InErr, &trMyPI); // clearing of internal states trMyPI.f32IntegPartK_1 = (tFrac32)0; trMyPI.f32InK_1 = (tFrac32)0; // output should be 0x01EB851E f32Output = GFLIB_ControllerPIpAW (f32InErr, &trMyPI, F32); // // // // ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // clearing of internal states trMyPI.f32IntegPartK_1 = (tFrac32)0; trMyPI.f32InK_1 = (tFrac32)0; } // output should be 0x01EB851E f32Output = GFLIB_ControllerPIpAW (f32InErr, &trMyPI); 5.30 Function GFLIB_ControllerPIpAW_F16 The function calculates the parallel form of the Proportional-Integral (PI) controller with implemented integral anti-windup functionality. 5.30.1 Declaration tFrac16 GFLIB_ControllerPIpAW_F16(tFrac16 f16InErr, GFLIB_CONTROLLER_PIAW_P_T_F16 *const pParam); 5.30.2 Arguments Table 5-36. GFLIB_ControllerPIpAW_F16 arguments Type tFrac16 Name f16InErr GFLIB_CONTROLLER pParam _PIAW_P_T_F16 *const Direction Description input Input error signal to the controller is a 16-bit number normalized between [-1, 1). input, output Pointer to the controller parameters structure. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 210 NXP Semiconductors Chapter 5 API References 5.30.3 Return The function returns a 16-bit value in format 1.15, representing the signal to be applied to the controlled system so that the input error is forced to zero. 5.30.4 Description A PI controller attempts to correct the error between a measured process variable and a desired set-point by calculating and then outputting a corrective action that can adjust the process accordingly. The GFLIB_ControllerPIpAW function calculates the ProportionalIntegral (PI) algorithm according to the equations below. The PI algorithm is implemented in the parallel (non-interacting) form, allowing the user to define the P and I parameters independently without interaction. The controller output is limited and the limit values (f16UpperLimit and f16LowerLimit) are defined by the user. The PI controller algorithm also returns a limitation flag. This flag (u16LimitFlag) is a member of the structure of the PI controller parameters (GFLIB_CONTROLLER_PIAW_P_T_F16). If the PI controller output reaches the upper or lower limit then u16LimitFlag = 1, otherwise u16LimitFlag = 0 (integer values). An anti- windup strategy is implemented by limiting the integral portion. The integral state is limited by the controller limits, in the same way as the controller output. The PI algorithm in the continuous time domain can be described as: Equation GFLIB_ControllerPIpAW_Eq1 where • • • • e(t) - input error in the continuous time domain u(t) - controller output in the continuous time domain K P - proportional gain K I - integral gain Equation GFLIB_ControllerPIpAW_Eq1 can be described using the Laplace transformation as follows: Equation GFLIB_ControllerPIpAW_Eq2 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 211 Function GFLIB_ControllerPIpAW_F16 The proportional part of equation GFLIB_ControllerPIpAW_Eq2 is transformed into the discrete time domain simply as: Equation GFLIB_ControllerPIpAW_Eq3 Transforming the integral part of equation GFLIB_ControllerPIpAW_Eq2 into a discrete time domain using the Bilinear method, also known as trapezoidal approximation, leads to the following equation: Equation GFLIB_ControllerPIpAW_Eq4 where T s [sec] is the sampling time. In order to implement the discrete equation of the controller on the fixed point arithmetic platform, the maximal values (scales) of input and output signals have to be known a priori. This is essential for correct casting of the physical signal values into fixed point values: • E MAX - maximal value of the controller input error signal • U MAX - maximal value of the controller output signal The fractional representation of both input and output signals, normalized between [-1, 1), is obtained as follows: Equation GFLIB_ControllerPIpAW_Eq5 Equation GFLIB_ControllerPIpAW_Eq6 Applying such scaling (normalization) on the proportional term of equation GFLIB_ControllerPIpAW_Eq3 results in: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 212 NXP Semiconductors Chapter 5 API References Equation GFLIB_ControllerPIpAW_Eq7 where K P_sc is the proportional gain parameter considering input/output scaling. Analogically, scaling the integral term of equation GFLIB_ControllerPIpAW_Eq4 results in: Equation GFLIB_ControllerPIpAW_Eq8 where K I_sc is the integral gain parameter considering input/output scaling. The sum of the scaled proportional and integral terms gives a complete equation of the controller. The problem is however, that either of the gain parameters K P_sc, K I_sc can be out of the [-1, 1) range, hence can not be directly interpreted as fractional values. To overcome this, it is necessary to scale these gain parameters using the shift values as follows: Equation GFLIB_ControllerPIpAW_Eq9 Equation GFLIB_ControllerPIpAW_Eq10 where • • • • f16PropGain - is the scaled value of proportional gain [-1, 1) s16PropGainShift - is the scaling shift for proportional gain [-31, 31) f16IntegGain - is the scaled value of integral gain [-1, 1) s16IntegGainShift - is the scaling shift for integral gain [-31, 31) The sum of the scaled proportional and integral terms gives a complete equation of the controller: Equation GFLIB_ControllerPIpAW_Eq11 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 213 Function GFLIB_ControllerPIpAW_F16 The output signal limitation is implemented in this controller. The actual output u(k) is bounded not to exceed the given limit values f16UpperLimit, f16LowerLimit. This is due to either the bounded power of the actuator or to the physical constraints of the plant. Equation GFLIB_ControllerPIpAW_Eq12 The bounds are described by a limitation element equation GFLIB_ControllerPIpAW_Eq12. When the bounds are exceeded the non-linear saturation characteristic will take effect and influence the dynamic behavior. The described limitation is implemented on the integral part accumulator (limitation during the calculation) and on the overall controller output. Therefore, if the limitation occurs, the controller output is clipped to its bounds and the wind-up occurrence of the accumulator portion is avoided by saturating the actual sum. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). All controller parameters and states can be reset during declaration using the GFLIB_CONTROLLER_PIAW_P_DEFAULT_F16 macro. To effectively reach the target precision the internal calculation is done in 32-bit fractional arithmetic and internal accumulator is 32-bit wide. As the GFLIB_ControllerPIp also contains the integration part, the output result is saddled by cumulative error. To enumerate the computation error in one calculation cycle, the internal integration accumulator is not used for testing purposes and is replaced by output from the previous calculation step of the reference model. 5.30.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 214 NXP Semiconductors Chapter 5 API References 5.30.6 Code Example #include "gflib.h" tFrac16 f16InErr; tFrac16 f16Output; GFLIB_CONTROLLER_PIAW_P_T_F16 trMyPI = GFLIB_CONTROLLER_PIAW_P_DEFAULT_F16; void main(void) { // input error = 0.25 f16InErr = FRAC16 (0.25); // controller parameters trMyPI.f16PropGain trMyPI.f16IntegGain trMyPI.s16PropGainShift trMyPI.s16IntegGainShift trMyPI.f32IntegPartK_1 trMyPI.f16UpperLimit trMyPI.f16LowerLimit = = = = = = = FRAC16 FRAC16 1; 1; FRAC32 FRAC16 FRAC16 (0.01); (0.02); (0); (1.0); (-1.0); // output should be 0x01EB f16Output = GFLIB_ControllerPIpAW_F16 (f16InErr, &trMyPI); // clearing of internal states trMyPI.f32IntegPartK_1 = (tFrac32)0; trMyPI.f16InK_1 = (tFrac16)0; // output should be 0x01EB f16Output = GFLIB_ControllerPIpAW (f16InErr, &trMyPI, F16); // // // // ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // clearing of internal states trMyPI.f32IntegPartK_1 = (tFrac32)0; trMyPI.f16InK_1 = (tFrac16)0; } // output should be 0x01EB f16Output = GFLIB_ControllerPIpAW (f16InErr, &trMyPI); 5.31 Function GFLIB_ControllerPIr_F32 This function calculates a standard recurrent form of the Proportional-Integral controller, without integral anti-windup. 5.31.1 Declaration tFrac32 GFLIB_ControllerPIr_F32(tFrac32 f32InErr, GFLIB_CONTROLLER_PI_R_T_F32 *const pParam); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 215 Function GFLIB_ControllerPIr_F32 5.31.2 Arguments Table 5-37. GFLIB_ControllerPIr_F32 arguments Type tFrac32 Name f32InErr GFLIB_CONTROLLER pParam _PI_R_T_F32 *const Direction Description input Input error signal to the controller is a 32-bit number normalized between [-1, 1). input, output Pointer to the controller parameters structure. 5.31.3 Return The function returns a 32-bit value in fractional format 1.31, representing the signal to be applied to the controlled system so that the input error is forced to zero. 5.31.4 Description The function GFLIB_ControllerPIr_F32 calculates a standard recurrent form of the Proportional-Integral controller, without integral anti-windup. The continuous time domain representation of the PI controller is defined as: Equation GFLIB_ControllerPIr_Eq1 The transfer function for this kind of PI controller, in a continuous time domain, is described using the Laplace transformation as follows: Equation GFLIB_ControllerPIr_Eq2 Transforming equation GFLIB_ControllerPIr_Eq2 into a discrete time domain leads to the following equation: Equation GFLIB_ControllerPIr_Eq3 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 216 NXP Semiconductors Chapter 5 API References where Kp is proportional gain, Ki is integral gain, Ts is the sampling period, u(k) is the controller output, e(k) is the controller input error signal, CC1 and CC2 are controller coefficients calculated depending on the discretization method used, as shown in Table 5-38. Table 5-38. Calculation of coefficients CC1 and CC2 using various discretization methods Trapezoidal Backward Rect. Forward Rect. CC1= K p+K IT S/2 K p+K IT S Kp CC2= -K p+K IT S/2 -K p -K p+K IT S In order to implement the discrete equation of the controller GFLIB_ControllerPIr_Eq3 on the fixed point arithmetic platform, the maximal values (scales) of the input and output signals • E MAX - maximal value of the controller input error signal • U MAX - maximal value of the controller output signal have to be known a priori. This is essential for correct casting of the physical signal values into fixed point values [-1, 1). Then the fractional representation [-1, 1) of both input and output signals is obtained as follows: Equation GFLIB_ControllerPIr_Eq4 Equation GFLIB_ControllerPIr_Eq5 The resulting controller discrete time domain equation in fixed point fractional representation is therefore given as: Equation GFLIB_ControllerPIr_Eq6 which can be rearranged into the following form: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 217 Function GFLIB_ControllerPIr_F32 Equation GFLIB_ControllerPIr_Eq7 where Equation GFLIB_ControllerPIr_Eq8 are the controller coefficients adapted according to the input and output scale values. In order to implement both coefficients as fractional numbers, both CC1 f and CC2 f must reside in the fractional range [-1, 1). However, depending on values CC1, CC2, E MAX, U MAX, the calculation of CC1 and CC2 may result in values outside this fractional range. f f Therefore, a scaling of CC1 f, CC2 f is introduced as follows: Equation GFLIB_ControllerPIr_Eq9 Equation GFLIB_ControllerPIr_Eq10 The introduced scaling shift u16NShift is chosen such that both coefficients f32CC1sc, f32CC2sc reside in the range [-1, 1). To simplify the implementation, this scaling shift is chosen to be a power of 2, so the final scaling is a simple shift operation. Moreover, the scaling shift cannot be a negative number, so the operation of scaling is always to scale numbers with an absolute value larger than 1 down to fit in the range [-1, 1). Equation GFLIB_ControllerPIr_Eq11 The final, scaled, fractional equation of a recurrent PI controller on a 32-bit fixed point platform is therefore implemented as follows: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 218 NXP Semiconductors Chapter 5 API References Equation GFLIB_ControllerPIr_Eq12 where: • • • • • u f(k) - fractional representation [-1, 1) of the controller output e f(k) - fractional representation [-1, 1) of the controller input (error) f32CC1sc - fractional representation [-1, 1) of the 1st controller coefficient f32CC2sc - fractional representation [-1, 1) of the 2nd controller coefficient u16NShift - in range [0,31] - is chosen such that both coefficients f32CC1sc and f32CC2sc are in the range [-1, 1) Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). All controller parameters and states can be reset during declaration using the GFLIB_CONTROLLER_PI_R_DEFAULT_F32 macro. 5.31.5 Re-entrancy The function is re-entrant. 5.31.6 Code Example #include "gflib.h" tFrac32 f32InErr; tFrac32 f32Output; GFLIB_CONTROLLER_PI_R_T_F32 trMyPI = GFLIB_CONTROLLER_PI_R_DEFAULT_F32; void main(void) { // input error = 0.25 f32InErr = FRAC32 (0.25); // controller parameters trMyPI.f32CC1sc = FRAC32 (0.01); trMyPI.f32CC2sc = FRAC32 (0.02); trMyPI.u16NShift = 1; // output should be 0x00A3D70A f32Output = GFLIB_ControllerPIr_F32 (f32InErr,&trMyPI); // clearing of internal states trMyPI.f32Acc = (tFrac32)0; trMyPI.f32InErrK1 = (tFrac32)0; // output should be 0x00A3D70A Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 219 Function GFLIB_ControllerPIr_F16 f32Output = GFLIB_ControllerPIr (f32InErr,&trMyPI, F32); // // // // ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // clearing of internal states trMyPI.f32Acc = (tFrac32)0; trMyPI.f32InErrK1 = (tFrac32)0; } // output should be 0x00A3D70A f32Output = GFLIB_ControllerPIr (f32InErr,&trMyPI); 5.32 Function GFLIB_ControllerPIr_F16 This function calculates a standard recurrent form of the Proportional-Integral controller, without integral anti-windup. 5.32.1 Declaration tFrac16 GFLIB_ControllerPIr_F16(tFrac16 f16InErr, GFLIB_CONTROLLER_PI_R_T_F16 *const pParam); 5.32.2 Arguments Table 5-39. GFLIB_ControllerPIr_F16 arguments Type tFrac16 Name f16InErr GFLIB_CONTROLLER pParam _PI_R_T_F16 *const Direction Description input Input error signal to the controller is a 16-bit number normalized between [-1, 1). input, output Pointer to the controller parameters structure. 5.32.3 Return The function returns a 16-bit value in fractional format 1.15, representing the signal to be applied to the controlled system so that the input error is forced to zero. 5.32.4 Description The function GFLIB_ControllerPIr_F16 calculates a standard recurrent form of the Proportional-Integral controller, without integral anti-windup. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 220 NXP Semiconductors Chapter 5 API References The continuous time domain representation of the PI controller is defined as: Equation GFLIB_ControllerPIr_Eq1 The transfer function for this kind of PI controller, in a continuous time domain, is described using the Laplace transformation as follows: Equation GFLIB_ControllerPIr_Eq2 Transforming equation GFLIB_ControllerPIr_Eq2 into a discrete time domain leads to the following equation: Equation GFLIB_ControllerPIr_Eq3 where Kp is proportional gain, Ki is integral gain, Ts is the sampling period, u(k) is the controller output, e(k) is the controller input error signal, CC1 and CC2 are controller coefficients calculated depending on the discretization method used, as shown in Table 5-40. Table 5-40. Calculation of coefficients CC1 and CC2 using various discretization methods Trapezoidal Backward Rect. Forward Rect. CC1= K p+K IT S/2 K p+K IT S Kp CC2= -K p+K IT S/2 -K p -K p+K IT S In order to implement the discrete equation of the controller GFLIB_ControllerPIr_Eq3 on the fixed point arithmetic platform, the maximal values (scales) of the input and output signals • E MAX - maximal value of the controller input error signal • U MAX - maximal value of the controller output signal have to be known a priori. This is essential for correct casting of the physical signal values into fixed point values [-1, 1). Then the fractional representation [-1, 1) of both input and output signals is obtained as follows: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 221 Function GFLIB_ControllerPIr_F16 Equation GFLIB_ControllerPIr_Eq4 Equation GFLIB_ControllerPIr_Eq5 The resulting controller discrete time domain equation in fixed point fractional representation is therefore given as: Equation GFLIB_ControllerPIr_Eq6 which can be rearranged into the following form: Equation GFLIB_ControllerPIr_Eq7 where Equation GFLIB_ControllerPIr_Eq8 are the controller coefficients adapted according to the input and output scale values. In order to implement both coefficients as fractional numbers, both CC1 f and CC2 f must reside in the fractional range [-1, 1). However, depending on values CC1, CC2, E MAX, U MAX, the calculation of CC1 and CC2 may result in values outside this fractional range. f f Therefore, a scaling of CC1 f, CC2 f is introduced as follows: Equation GFLIB_ControllerPIr_Eq9 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 222 NXP Semiconductors Chapter 5 API References Equation GFLIB_ControllerPIr_Eq10 The introduced scaling shift u16NShift is chosen such that both coefficients f16CC1sc, f16CC2sc reside in the range [-1, 1). To simplify the implementation, this scaling shift is chosen to be a power of 2, so the final scaling is a simple shift operation. Moreover, the scaling shift cannot be a negative number, so the operation of scaling is always to scale numbers with an absolute value larger than 1 down to fit in the range [-1, 1). Equation GFLIB_ControllerPIr_Eq11 The final, scaled, fractional equation of a recurrent PI controller on a 16-bit fixed point platform is therefore implemented as follows: Equation GFLIB_ControllerPIr_Eq12 where: • • • • • u f(k) - fractional representation [-1, 1) of the controller output e f(k) - fractional representation [-1, 1) of the controller input (error) f16CC1sc - fractional representation [-1, 1) of the 1st controller coefficient f16CC2sc - fractional representation [-1, 1) of the 2nd controller coefficient u16NShift - in range [0,15] - is chosen such that both coefficients f16CC1sc and f16CC2sc are in the range [-1, 1) Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). All controller parameters and states can be reset during declaration using the GFLIB_CONTROLLER_PI_R_DEFAULT_F16 macro. 5.32.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 223 Function GFLIB_ControllerPIrAW_F32 5.32.6 Code Example #include "gflib.h" tFrac16 f16InErr; tFrac16 f16Output; GFLIB_CONTROLLER_PI_R_T_F16 trMyPI = GFLIB_CONTROLLER_PI_R_DEFAULT_F16; void main(void) { // input error = 0.25 f16InErr = FRAC16 (0.25); // controller parameters trMyPI.f16CC1sc = FRAC16 (0.01); trMyPI.f16CC2sc = FRAC16 (0.02); trMyPI.u16NShift = 1; // output should be 0x00A3 f16Output = GFLIB_ControllerPIr_F16 (f16InErr,&trMyPI); // clearing of internal states trMyPI.f32Acc = (tFrac32)0; trMyPI.f16InErrK1 = (tFrac16)0; // output should be 0x00A3 f16Output = GFLIB_ControllerPIr (f16InErr,&trMyPI, F16); // // // // ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // clearing of internal states trMyPI.f32Acc = (tFrac32)0; trMyPI.f16InErrK1 = (tFrac16)0; } // output should be 0x00A3 f16Output = GFLIB_ControllerPIr (f16InErr,&trMyPI); 5.33 Function GFLIB_ControllerPIrAW_F32 This function calculates a standard recurrent form of the Proportional-Integral controller, with integral anti-windup. 5.33.1 Declaration tFrac32 GFLIB_ControllerPIrAW_F32(tFrac32 f32InErr, GFLIB_CONTROLLER_PIAW_R_T_F32 *const pParam); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 224 NXP Semiconductors Chapter 5 API References 5.33.2 Arguments Table 5-41. GFLIB_ControllerPIrAW_F32 arguments Type Name tFrac32 f32InErr GFLIB_CONTROLLER pParam _PIAW_R_T_F32 *const Direction Description input Input error signal to the controller is a 32-bit number normalized between [-1, 1). input, output Pointer to the controller parameters structure. 5.33.3 Return The function returns a 32-bit value in fractional format 1.31, representing the signal to be applied to the controlled system so that the input error is forced to zero. 5.33.4 Description The function GFLIB_ControllerPIrAW calculates a standard recurrent form of the Proportional-Integral controller, with integral anti-windup. The continuous time domain representation of the PI controller is defined as: Equation GFLIB_ControllerPIrAW_Eq1 The transfer function for this kind of PI controller, in a continuous time domain is described using the Laplace transformation as follows: Equation GFLIB_ControllerPIrAW_Eq2 Transforming equation GFLIB_ControllerPIrAW_Eq2 into a discrete time domain leads to the following equation: Equation GFLIB_ControllerPIrAW_Eq3 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 225 Function GFLIB_ControllerPIrAW_F32 where Kp is proportional gain, Ki is integral gain, Ts is the sampling period, u(k) is the controller output, e(k) is the controller input error signal, CC1 and CC2 are the controller coefficients calculated depending on the discretization method used, as shown in Table 5-42. Table 5-42. Calculation of coefficients CC1 and CC2 using various discretization methods Trapezoidal Backward Rect. Forward Rect. CC1= K p+K iT s/2 K p+K iT s Kp CC2= -K p+K iT s/2 -K p -K p+K iT s In order to implement the discrete equation of the controller GFLIB_ControllerPIrAW_Eq3 on the fixed point arithmetic platform, the maximal values (scales) of input and output signals • E MAX - maximal value of the controller input error signal • U MAX - maximal value of the controller output signal have to be known a priori. This is essential for correct casting of the physical signal values into fixed point values [-1, 1). Then the fractional representation [-1, 1) of both input and output signals is obtained as follows: Equation GFLIB_ControllerPIrAW_Eq4 Equation GFLIB_ControllerPIrAW_Eq5 The resulting controller discrete time domain equation in fixed point fractional representation is therefore given as: Equation GFLIB_ControllerPIrAW_Eq6 which can be rearranged into the following form: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 226 NXP Semiconductors Chapter 5 API References Equation GFLIB_ControllerPIrAW_Eq7 where Equation GFLIB_ControllerPIrAW_Eq8 are the controller coefficients adapted according to the input and output scale values. In order to implement both coefficients as fractional numbers, both CC1 f and CC2 f must reside in the fractional range [-1, 1). However, depending on values CC1, CC2, E MAX, U MAX, the calculation of CC1 and CC2 may result in values outside this fractional range. f f Therefore, a scaling of CC1 f, CC2 f is introduced as follows: Equation GFLIB_ControllerPIrAW_Eq9 Equation GFLIB_ControllerPIrAW_Eq10 The introduced scaling shift u16NShift is chosen such that both coefficients f32CC1sc,f32CC2sc reside in the range [-1, 1). To simplify the implementation, this scaling shift is chosen to be a power of 2, so the final scaling is a simple shift operation. Moreover, the scaling shift cannot be a negative number, so the operation of scaling is always to scale numbers with an absolute value larger than 1 down to fit in the range [-1, 1). Equation GFLIB_ControllerPIrAW_Eq11 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 227 Function GFLIB_ControllerPIrAW_F32 The final, scaled, fractional equation of the recurrent PI controller on a 32-bit fixed point platform is therefore implemented as follows: Equation GFLIB_ControllerPIrAW_Eq12 where: • • • • • u f(k) - fractional representation [-1, 1) of the controller output e f(k) - fractional representation [-1, 1) of the controller input (error) f32CC1sc - fractional representation [-1, 1) of the 1st controller coefficient f32CC2sc - fractional representation [-1, 1) of the 2nd controller coefficient u16NShift - in range [0,31] - is chosen such that both coefficients f32CC1sc and f32CC2sc are in the range [-1, 1) The output signal limitation is implemented in this controller. The actual output u(k) is bounded not to exceed the given limit values UpperLimit, LowerLimit. This is due to either the bounded power of the actuator or to the physical constraints of the plant. Equation GFLIB_ControllerPIrAW_Eq13 The bounds are described by a limitation element equation GFLIB_ControllerPIrAW_Eq13. When the bounds are exceeded, the non-linear saturation characteristic will take effect and influence the dynamic behavior. The described limitation is implemented on the output sum. Therefore, if the limitation occurs, the controller output is clipped to its bounds and the wind-up occurrence of the accumulator is avoided by saturating the output sum. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). All controller parameters and states can be reset during declaration using the GFLIB_CONTROLLER_PIAW_R_DEFAULT_F32 macro. As the GFLIB_ControllerPIrAW_F32 also contains the internal accumulator, the output result is saddled by cumulative error. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 228 NXP Semiconductors Chapter 5 API References To enumerate the computation error in one calculation cycle, the internal accumulator is not used for testing purposes and is replaced by output from the previous calculation step of the reference model. The anti-windup mechanism is implemented based on the output limitation. 5.33.5 Re-entrancy The function is re-entrant. 5.33.6 Code Example #include "gflib.h" tFrac32 f32InErr; tFrac32 f32Output; GFLIB_CONTROLLER_PIAW_R_T_F32 trMyPI = GFLIB_CONTROLLER_PIAW_R_DEFAULT_F32; void main(void) { // input error = 0.25 f32InErr = FRAC32 (0.25); // controller parameters trMyPI.f32CC1sc trMyPI.f32CC2sc trMyPI.u16NShift trMyPI.f32UpperLimit trMyPI.f32LowerLimit = = = = = FRAC32 FRAC32 1; FRAC32 FRAC32 (0.01); (0.02); (1.0); (-1.0); // output should be 0x00A3D70A f32Output = GFLIB_ControllerPIrAW_F32 (f32InErr, &trMyPI); // clearing of internal states trMyPI.f32Acc = (tFrac32)0; trMyPI.f32InErrK1 = (tFrac32)0; // output should be 0x00A3D70A f32Output = GFLIB_ControllerPIrAW (f32InErr, &trMyPI, F32); // // // // ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // clearing of internal states trMyPI.f32Acc = (tFrac32)0; trMyPI.f32InErrK1 = (tFrac32)0; } // output should be 0x00A3D70A f32Output = GFLIB_ControllerPIrAW (f32InErr, &trMyPI); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 229 Function GFLIB_ControllerPIrAW_F16 5.34 Function GFLIB_ControllerPIrAW_F16 This function calculates a standard recurrent form of the Proportional-Integral controller, with integral anti-windup. 5.34.1 Declaration tFrac16 GFLIB_ControllerPIrAW_F16(tFrac16 f16InErr, GFLIB_CONTROLLER_PIAW_R_T_F16 *const pParam); 5.34.2 Arguments Table 5-43. GFLIB_ControllerPIrAW_F16 arguments Type tFrac16 Name f16InErr GFLIB_CONTROLLER pParam _PIAW_R_T_F16 *const Direction Description input Input error signal to the controller is a 16-bit number normalized between [-1, 1). input, output Pointer to the controller parameters structure. 5.34.3 Return The function returns a 16-bit value in fractional format 1.16, representing the signal to be applied to the controlled system so that the input error is forced to zero. 5.34.4 Description The function GFLIB_ControllerPIrAW calculates a standard recurrent form of the Proportional-Integral controller, with integral anti-windup. The continuous time domain representation of the PI controller is defined as: Equation GFLIB_ControllerPIrAW_Eq1 The transfer function for this kind of PI controller, in a continuous time domain is described using the Laplace transformation as follows: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 230 NXP Semiconductors Chapter 5 API References Equation GFLIB_ControllerPIrAW_Eq2 Transforming equation GFLIB_ControllerPIrAW_Eq2 into a discrete time domain leads to the following equation: Equation GFLIB_ControllerPIrAW_Eq3 where Kp is proportional gain, Ki is integral gain, Ts is the sampling period, u(k) is the controller output, e(k) is the controller input error signal, CC1 and CC2 are the controller coefficients calculated depending on the discretization method used, as shown in Table 5-44. Table 5-44. Calculation of coefficients CC1 and CC2 using various discretization methods Trapezoidal Backward Rect. Forward Rect. CC1= K p+K iT s/2 K p+K iT s Kp CC2= -K p+K iT s/2 -K p -K p+K iT s In order to implement the discrete equation of the controller GFLIB_ControllerPIrAW_Eq3 on the fixed point arithmetic platform, the maximal values (scales) of input and output signals • E MAX - maximal value of the controller input error signal • U MAX - maximal value of the controller output signal have to be known a priori. This is essential for correct casting of the physical signal values into fixed point values [-1, 1). Then the fractional representation [-1, 1) of both input and output signals is obtained as follows: Equation GFLIB_ControllerPIrAW_Eq4 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 231 Function GFLIB_ControllerPIrAW_F16 Equation GFLIB_ControllerPIrAW_Eq5 The resulting controller discrete time domain equation in fixed point fractional representation is therefore given as: Equation GFLIB_ControllerPIrAW_Eq6 which can be rearranged into the following form: Equation GFLIB_ControllerPIrAW_Eq7 where Equation GFLIB_ControllerPIrAW_Eq8 are the controller coefficients adapted according to the input and output scale values. In order to implement both coefficients as fractional numbers, both CC1 f and CC2 f must reside in the fractional range [-1, 1). However, depending on values CC1, CC2, E MAX, U MAX , the calculation of CC1 and CC2 may result in values outside this fractional f f range. Therefore, a scaling of CC1 f, CC2 f is introduced as follows: Equation GFLIB_ControllerPIrAW_Eq9 Equation GFLIB_ControllerPIrAW_Eq10 The introduced scaling shift u16NShift is chosen such that both coefficients f16CC1sc,f16CC2sc reside in the range [-1, 1). To simplify the implementation, this scaling shift is chosen to be a power of 2, so the final scaling is a simple shift operation. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 232 NXP Semiconductors Chapter 5 API References Moreover, the scaling shift cannot be a negative number, so the operation of scaling is always to scale numbers with an absolute value larger than 1 down to fit in the range [-1, 1). Equation GFLIB_ControllerPIrAW_Eq11 The final, scaled, fractional equation of the recurrent PI controller on a 16-bit fixed point platform is therefore implemented as follows: Equation GFLIB_ControllerPIrAW_Eq12 where: • • • • • u f(k) - fractional representation [-1, 1) of the controller output e f(k) - fractional representation [-1, 1) of the controller input (error) f16CC1sc - fractional representation [-1, 1) of the 1st controller coefficient f16CC2sc - fractional representation [-1, 1) of the 2nd controller coefficient u16NShift - in range [0,15] - is chosen such that both coefficients f16CC1sc and f16CC2sc are in the range [-1, 1) The output signal limitation is implemented in this controller. The actual output u(k) is bounded not to exceed the given limit values UpperLimit, LowerLimit. This is due to either the bounded power of the actuator or to the physical constraints of the plant. Equation GFLIB_ControllerPIrAW_Eq13 The bounds are described by a limitation element equation GFLIB_ControllerPIrAW_Eq13. When the bounds are exceeded, the non-linear saturation characteristic will take effect and influence the dynamic behavior. The described limitation is implemented on the output sum. Therefore, if the limitation occurs, the controller output is clipped to its bounds and the wind-up occurrence of the accumulator is avoided by saturating the output sum. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 233 Function GFLIB_ControllerPIrAW_F16 Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). All controller parameters and states can be reset during declaration using the GFLIB_CONTROLLER_PIAW_R_DEFAULT_F16 macro. As the GFLIB_ControllerPIrAW_F16 also contains the internal accumulator, the output result is saddled by cumulative error. To enumerate the computation error in one calculation cycle, the internal accumulator is not used for testing purposes and is replaced by output from the previous calculation step of the reference model. To eliminate the calculation error the GFLIB_ControllerPIrAW_F16 uses the 32-bit wide internal accumulator. The anti-windup mechanism is implemented based on the output limitation. 5.34.5 Re-entrancy The function is re-entrant. 5.34.6 Code Example #include "gflib.h" tFrac16 f16InErr; tFrac16 f16Output; GFLIB_CONTROLLER_PIAW_R_T_F16 trMyPI = GFLIB_CONTROLLER_PIAW_R_DEFAULT_F16; void main(void) { // input error = 0.25 f16InErr = FRAC16 (0.25); // controller parameters trMyPI.f16CC1sc trMyPI.f16CC2sc trMyPI.u16NShift trMyPI.f16UpperLimit trMyPI.f16LowerLimit = = = = = FRAC16 FRAC16 1; FRAC16 FRAC16 (0.01); (0.02); (1.0); (-1.0); // output should be 0x00A3 f16Output = GFLIB_ControllerPIrAW_F16 (f16InErr, &trMyPI); // clearing of internal states trMyPI.f32Acc = (tFrac32)0; trMyPI.f16InErrK1 = (tFrac16)0; // output should be 0x00A3 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 234 NXP Semiconductors Chapter 5 API References f16Output = GFLIB_ControllerPIrAW (f16InErr, &trMyPI, F16); // // // // ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // clearing of internal states trMyPI.f32Acc = (tFrac32)0; trMyPI.f16InErrK1 = (tFrac16)0; } // output should be 0x00A3 f16Output = GFLIB_ControllerPIrAW (f16InErr, &trMyPI); 5.35 Function GFLIB_Cos_F32 This function implements polynomial approximation of cosine function. 5.35.1 Declaration tFrac32 GFLIB_Cos_F32(tFrac32 f32In, const GFLIB_COS_T_F32 *const pParam); 5.35.2 Arguments Table 5-45. GFLIB_Cos_F32 arguments Type Name Direction Description tFrac32 f32In input Input argument is a 32-bit number that contains an angle in radians between [- π, π) normalized between [-1, 1). const GFLIB_COS_T_F32 *const pParam input Pointer to an array of Taylor coefficients. 5.35.3 Return The function returns the cos of the input argument as a fixed point 32-bit number, normalized between [-1, 1). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 235 Function GFLIB_Cos_F32 5.35.4 Description The GFLIB_Cos_F32 function provides a computational method for calculation of a standard trigonometric cosine function cos(x), using the 9th order Taylor polynomial approximation of the sine function. The following two equations describe the chosen approach of calculating the cosine function: Equation GFLIB_Cos_Eq1 Equation GFLIB_Cos_Eq2 The 9th order polynomial approximation is chosen as sufficient an order to achieve the best ratio between calculation accuracy and speed of calculation. Accuracy criterion is to have the output error within 3LSB on the upper 16 bits of the 32-bit result. Because the GFLIB_Cos_F32 function is implemented with consideration to fixed point fractional arithmetic, all variables are normalized to fit into the [-1, 1) range. Therefore, in order to cast the fractional value of the input angle f32In [-1, 1) into the correct range [- π, π), the input f32In must be multiplied by π. So, the fixed point fractional implementation of the GFLIB_Sin_F32 function, using optimized 9th order Taylor approximation, is given as follows: Equation GFLIB_Cos_Eq3 The 9th order polynomial approximation of the sine function has a very good accuracy in the range [- π/2, π/2) of the argument, but in wider ranges the calculation error quickly increases. To minimize the error without having to use a higher order polynomial, the symmetry of the sine function sin(x) = sin( π - x) is utilized. Therefore, the input argument is transferred to be always in the range [- π/2, π/2) and the Taylor polynomial is calculated only in the range of the argument [- π/2, π/2). To make calculations more precise, the given argument value f32In (that is to be transferred into the range [-0.5, 0.5) due to the sine function symmetry) is shifted by 1 bit to the left (multiplied by 2). Then, the value of f32In 2, used in the calculations, is in the Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 236 NXP Semiconductors Chapter 5 API References range [-1, 1) instead of [-0.25, 0.25]. Shifting the input value by 1 bit to the left will increase the accuracy of the calculated sin( π * f32In) function. Implementing such a scale on the approximation function described by equation GFLIB_Cos_Eq2, results in the following: Equation GFLIB_Cos_Eq4 Equation GFLIB_Cos_Eq3 can be further rewritten into the following form: Equation GFLIB_Cos_Eq5 where a 1...a 5 are coefficients of the approximation polynomial, which are calculated as follows (represented as 32-bit signed fractional numbers): Equation GFLIB_Cos_Eq6 Therefore, the resulting equation has the following form: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 237 Function GFLIB_Cos_F32 Equation GFLIB_Cos_Eq7 Figure 5-17 depicts a floating point cosine function generated from Matlab and the approximated value of the cosine function obtained from GFLIB_Cos_F32, plus their difference. The course of calculation accuracy as a function of the input angle can be observed from this figure. Figure 5-17. cos(x) vs. GFLIB_Cos(f32In) Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The input angle (f32In) is normalized into the range [-1, 1). The function call is slightly different from common approach in the library set. The function can be called in three different ways: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 238 NXP Semiconductors Chapter 5 API References • With implementation postfix (i.e. GFLIB_Cos_F32(f32In, &pParam)), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_COS_DEFAULT_F32 symbol. The &pParam parameter is mandatory. • With additional implementation parameter (i.e. GFLIB_Cos(f32In, &pParam, F32), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_COS_DEFAULT_F32 symbol. The &pParam parameter is mandatory. • With preselected default implementation (i.e. GFLIB_Cos(f32In, &pParam), where &pParam is pointer to approximation coefficients. The &pParam parameter is optional and in case it is not used, the default GFLIB_COS_DEFAULT_F32 approximation coefficients are used. 5.35.5 Re-entrancy The function is re-entrant. 5.35.6 Code Example #include "gflib.h" tFrac32 f32Angle; tFrac32 f32Output; void main(void) { // input angle = 0.25 => pi/4 f32Angle = FRAC32 (0.25); // output should be 0x5A827E94 f32Output = GFLIB_Cos_F32 (f32Angle, GFLIB_COS_DEFAULT_F32); // output should be 0x5A827E94 f32Output = GFLIB_Cos (f32Angle, GFLIB_COS_DEFAULT_F32, F32); // // // // ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 239 Function GFLIB_Cos_F16 } // output should be 0x5A827E94 f32Output = GFLIB_Cos (f32Angle); 5.36 Function GFLIB_Cos_F16 This function implements polynomial approximation of cosine function. 5.36.1 Declaration tFrac16 GFLIB_Cos_F16(tFrac16 f16In, const GFLIB_COS_T_F16 *const pParam); 5.36.2 Arguments Table 5-46. GFLIB_Cos_F16 arguments Type Name Direction Description tFrac16 f16In input Input argument is a 16-bit number that contains an angle in radians between [- π, π) normalized between [-1, 1). const GFLIB_COS_T_F16 *const pParam input Pointer to an array of Taylor coefficients. 5.36.3 Return The function returns the cos of the input argument as a fixed point 16-bit number, normalized between [-1, 1). 5.36.4 Description The GFLIB_Cos_F16 function provides a computational method for calculation of a standard trigonometric cosine function cos(x), using the 7th order Taylor polynomial approximation of the sine function. The following two equations describe the chosen approach of calculating the cosine function: Equation GFLIB_Cos_Eq1 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 240 NXP Semiconductors Chapter 5 API References Equation GFLIB_Cos_Eq2 The 7th order polynomial approximation is chosen as sufficient an order to achieve the best ratio between calculation accuracy and speed of calculation. Because the GFLIB_Cos_F16 function is implemented with consideration to fixed point fractional arithmetic, all variables are normalized to fit into the [-1, 1) range. Therefore, in order to cast the fractional value of the input angle f16In [-1, 1) into the correct range [- π, π ), the input f16In must be multiplied by π. So, the fixed point fractional implementation of the GFLIB_Sin_F16 function, using 9th order Taylor approximation, is given as follows: Equation GFLIB_Cos_Eq3 The 7th order polynomial approximation of the sine function has a good accuracy in the range [- π/2, π/2) of the argument, but in wider ranges the calculation error quickly increases. To minimize the error without having to use a higher order polynomial, the symmetry of the sine function sin(x) = sin( π - x) is utilized. Therefore, the input argument is transferred to be always in the range [- π/2, π/2) and the Taylor polynomial is calculated only in the range of the argument [- π/2, π/2). To make calculations more precise, the given argument value f16In (that is to be transferred into the range [-0.5,0.5) due to the sine function symmetry) is shifted by 1 bit to the left (multiplied by 2). Then, the value of f16In 2, used in the calculations, is in the range [-1, 1) instead of [-0.25, 0.25]. Shifting the input value by 1 bit to the left will increase the accuracy of the calculated sin( π * f16In) function. Implementing such a scale on the approximation function described by equation GFLIB_Cos_Eq2, results in the following: Equation GFLIB_Cos_Eq4 Equation GFLIB_Cos_Eq3 can be further rewritten into the following form: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 241 Function GFLIB_Cos_F16 Equation GFLIB_Cos_Eq5 where a 1...a 5 are coefficients of the approximation polynomial, which are calculated as follows (represented as 16-bit signed fractional numbers): Equation GFLIB_Cos_Eq6 Therefore, the resulting equation has the following form: Equation GFLIB_Cos_Eq7 Figure 5-18 depicts a floating point cosine function generated from Matlab and the approximated value of the cosine function obtained from GFLIB_Cos_F16, plus their difference. The course of calculation accuracy as a function of the input angle can be observed from this figure. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 242 NXP Semiconductors Chapter 5 API References Figure 5-18. cos(x) vs. GFLIB_Cos(f16In) Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The input angle (f16In) is normalized into the range [-1, 1). The function call is slightly different from common approach in the library set. The function can be called in three different ways: • With implementation postfix (i.e. GFLIB_Cos_F16(f16In, &pParam)), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_COS_DEFAULT_F16 symbol. The &pParam parameter is mandatory. • With additional implementation parameter (i.e. GFLIB_Cos(f16In, &pParam, F16), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_COS_DEFAULT_F16 symbol. The &pParam parameter is mandatory. • With preselected default implementation (i.e. GFLIB_Cos(f16In, &pParam), where the &pParam is pointer to approximation coefficients. The &pParam parameter is optional and in case it is not used, the default Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 243 Function GFLIB_Hyst_F32 GFLIB_COS_DEFAULT_F16 approximation coefficients are used. 5.36.5 Re-entrancy The function is re-entrant. 5.36.6 Code Example #include "gflib.h" tFrac16 f16Angle; tFrac16 f16Output; void main(void) { // input angle = 0.25 => pi/4 f16Angle = FRAC16 (0.25); // output should be 0x5A82 f16Output = GFLIB_Cos_F16 (f16Angle, GFLIB_COS_DEFAULT_F16); // output should be 0x5A82 f16Output = GFLIB_Cos (f16Angle, GFLIB_COS_DEFAULT_F16, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x5A82 f16Output = GFLIB_Cos (f16Angle); 5.37 Function GFLIB_Hyst_F32 This function implements the hysteresis functionality. 5.37.1 Declaration tFrac32 GFLIB_Hyst_F32(tFrac32 f32In, GFLIB_HYST_T_F32 *const pParam); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 244 NXP Semiconductors Chapter 5 API References 5.37.2 Arguments Table 5-47. GFLIB_Hyst_F32 arguments Type Name Direction Description tFrac32 f32In input Input signal in the form of a 32-bit fixed point number, normalized between [-1, 1). GFLIB_HYST_T_F32 *const pParam input, output Pointer to the structure with parameters and states of the hysteresis function. Arguments of the structure contain fixed point 32-bit values, normalized between [-1, 1). 5.37.3 Return The function returns the value of the hysteresis output, which is equal to either f32OutValOn or f32OutValOff depending on the value of the input and the state of the function output in the previous calculation step. The output value is interpreted as a fixed point 32-bit number, normalized between [-1, 1). 5.37.4 Description The GFLIB_Hyst function provides a computational method for the calculation of a hysteresis (relay) function. The function switches the output between the two predefined values stored in the f32OutValOn and f32OutValOff members of structure GFLIB_HYST_T_F32. When the value of the input is higher than the upper threshold f32HystOn, then the output value is equal to f32OutValOn. On the other hand, when the input value is lower than the lower threshold f32HystOff, then the output value is equal to f32OutValOff. When the input value is between these two threshold values then the output retains its value (the previous state). Equation GFLIB_Hyst_Eq1 A graphical description of GFLIB_Hyst functionality is shown in Figure 5-19. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 245 Function GFLIB_Hyst_F32 Figure 5-19. Hysteresis function Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). CAUTION For correct functionality, the threshold f32HystOn value must be greater than the f32HystOff value. Note All parameters and states used by the function can be reset during declaration using the GFLIB_HYST_DEFAULT_F32 macro. 5.37.5 Re-entrancy The function is re-entrant. 5.37.6 Code Example #include "gflib.h" tFrac32 f32In; tFrac32 f32Out; GFLIB_HYST_T_F32 f32trMyHyst = GFLIB_HYST_DEFAULT_F32; void main(void) { // Setting parameters for hysteresis f32trMyHyst.f32HystOn = FRAC32 (0.1289); f32trMyHyst.f32HystOff = FRAC32 (-0.3634); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 246 NXP Semiconductors Chapter 5 API References f32trMyHyst.f32OutValOn = FRAC32 (0.589); f32trMyHyst.f32OutValOff = FRAC32 (-0.123); f32trMyHyst.f32OutState = FRAC32 (-0.3333); // input value = -0.41115 f32In = FRAC32 (-0.41115); // output should be 0x8FBE76C8 ~ FRAC32(-0.123) f32Out = GFLIB_Hyst_F32 (f32In,&f32trMyHyst); // output should be 0x8FBE76C8 ~ FRAC32(-0.123) f32trMyHyst.f32OutState = FRAC32 (0); f32Out = GFLIB_Hyst (f32In, &f32trMyHyst, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x8FBE76C8 ~ FRAC32(-0.123) f32trMyHyst.f32OutState = FRAC32 (0); f32Out = GFLIB_Hyst (f32In, &f32trMyHyst); 5.38 Function GFLIB_Hyst_F16 This function implements the hysteresis functionality. 5.38.1 Declaration tFrac16 GFLIB_Hyst_F16(tFrac16 f16In, GFLIB_HYST_T_F16 *const pParam); 5.38.2 Arguments Table 5-48. GFLIB_Hyst_F16 arguments Type Name Direction Description tFrac16 f16In input Input signal in the form of a 16-bit fixed point number, normalized between [-1, 1). GFLIB_HYST_T_F16 *const pParam input, output Pointer to the structure with parameters and states of the hysteresis function. Arguments of the structure contain fixed point 16-bit values, normalized between [-1, 1). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 247 Function GFLIB_Hyst_F16 5.38.3 Return The function returns the value of the hysteresis output, which is equal to either f16OutValOn or f16OutValOff depending on the value of the input and the state of the function output in the previous calculation step. The output value is interpreted as a fixed point 16-bit number, normalized between [-1, 1). 5.38.4 Description The GFLIB_Hyst function provides a computational method for the calculation of a hysteresis (relay) function. The function switches the output between the two predefined values stored in the f16OutValOn and f16OutValOff members of structure GFLIB_HYST_T_F16. When the value of the input is higher than the upper threshold f16HystOn, then the output value is equal to f16OutValOn. On the other hand, when the input value is lower than the lower threshold f16HystOff, then the output value is equal to f16OutValOff. When the input value is between these two threshold values then the output retains its value (the previous state). Equation GFLIB_Hyst_Eq1 A graphical description of GFLIB_Hyst functionality is shown in Figure 5-20. Figure 5-20. Hysteresis function Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 248 NXP Semiconductors Chapter 5 API References Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). CAUTION For correct functionality, the threshold f16HystOn value must be greater than the f16HystOff value. Note All parameters and states used by the function can be reset during declaration using the GFLIB_HYST_DEFAULT_F16 macro. 5.38.5 Re-entrancy The function is re-entrant. 5.38.6 Code Example #include "gflib.h" tFrac16 f16In; tFrac16 f16Out; GFLIB_HYST_T_F16 f16trMyHyst = GFLIB_HYST_DEFAULT_F16; void main(void) { // Setting parameters for hysteresis f16trMyHyst.f16HystOn = FRAC16 (0.1289); f16trMyHyst.f16HystOff = FRAC16 (-0.3634); f16trMyHyst.f16OutValOn = FRAC16 (0.589); f16trMyHyst.f16OutValOff = FRAC16 (-0.123); f16trMyHyst.f16OutState = FRAC16 (-0.3333); // input value = -0.41115 f16In = FRAC16 (-0.41115); // output should be 0x8FBE ~ FRAC16(-0.123) f16Out = GFLIB_Hyst_F16 (f16In,&f16trMyHyst); // output should be 0x8FBE ~ FRAC16(-0.123) f16trMyHyst.f16OutState = FRAC16 (0); f16Out = GFLIB_Hyst (f16In, &f16trMyHyst, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x8FBE ~ FRAC16(-0.123) f16trMyHyst.f16OutState = FRAC16 (0); f16Out = GFLIB_Hyst (f16In, &f16trMyHyst); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 249 Function GFLIB_IntegratorTR_F32 5.39 Function GFLIB_IntegratorTR_F32 The function calculates a discrete implementation of the integrator (sum), discretized using a trapezoidal (Bilinear) transformation with overflow on range boundaries. 5.39.1 Declaration tFrac32 GFLIB_IntegratorTR_F32(tFrac32 f32In, GFLIB_INTEGRATOR_TR_T_F32 *const pParam); 5.39.2 Arguments Table 5-49. GFLIB_IntegratorTR_F32 arguments Type tFrac32 Name f32In GFLIB_INTEGRATOR_ pParam TR_T_F32 *const Direction Description input Input argument to be integrated. input, output Pointer to the integrator parameters structure. 5.39.3 Return The function returns a 32-bit value in format Q1.31, which represents the actual integrated value of the input signal with overflow on range boundaries. 5.39.4 Description The function GFLIB_IntegratorTR_F32 implements a discrete integrator using trapezoidal (Bilinear) transformation with overflow on range boundaries. The continuous time domain representation of the integrator is defined as: Equation GFLIB_IntegratorTR_Eq1 The transfer function for this integrator, in a continuous time domain, is described using the Laplace transformation as follows: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 250 NXP Semiconductors Chapter 5 API References Equation GFLIB_IntegratorTR_Eq2 Transforming equation GFLIB_IntegratorTR_Eq2 into a digital time domain using Bilinear transformation, leads to the following transfer function: Equation GFLIB_IntegratorTR_Eq3 where T s is the sampling period of the system. The discrete implementation of the digital transfer function GFLIB_IntegratorTR_Eq3 is as follows: Equation GFLIB_IntegratorTR_Eq4 Considering fractional maths implementation, the integrator input and output maximal values (scales) must be known. Then the discrete implementation is given as follows: Equation GFLIB_IntegratorTR_Eq5 where E MAX is the input scale and U MAX is the output scale. Then integrator constant C1 is defined as: Equation GFLIB_IntegratorTR_Eq6 In order to implement the discrete form integrator as in GFLIB_IntegratorTR_Eq5 on a fixed point platform, the value of C1 f coefficient must reside in a the fractional range [-1,1). Therefore, scaling must be introduced as follows: Equation GFLIB_IntegratorTR_Eq7 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 251 Function GFLIB_IntegratorTR_F32 The introduced scaling is chosen such that coefficient f32C1 fits into fractional range [-1,1). To simplify the implementation, this scaling is chosen to be a power of 2, so the final scaling is a simple shift operation using the u16NShift variable. Hence, the shift is calculated as: Equation GFLIB_IntegratorTR_Eq8 If the output exceeds the fractional range [-1,1), an overflow occurs. This behavior allows continual integration of an angular velocity of a rotor to obtain the actual rotor position, assuming the output range corresponds to one complete revolution. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). All parameters and states used by the function can be reset during declaration using the GFLIB_INTEGRATOR_TR_DEFAULT_F32 macro. The specified accuracy of the function is not guaranteed in cases when any of the terms in GFLIB_IntegratorTR_Eq5 overflows. 5.39.5 Re-entrancy The function is re-entrant. 5.39.6 Code Example #include "gflib.h" tFrac32 f32In; tFrac32 f32Out; // Definition of one integrator instance GFLIB_INTEGRATOR_TR_T_F32 trMyIntegrator = GFLIB_INTEGRATOR_TR_DEFAULT_F32; void main(void) { // Setting parameters for integrator, Ts = 100e-4, E_MAX=U_MAX=1 trMyIntegrator.f32C1 = FRAC32 (100e-4/2); trMyIntegrator.u16NShift = (tU16)0; Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 252 NXP Semiconductors Chapter 5 API References // input value = 0.5 f32In = FRAC32 (0.5); // output should be 0x0051EB85 f32Out = GFLIB_IntegratorTR_F32 (f32In, &trMyIntegrator); // clearing of the internal states trMyIntegrator.f32State = (tFrac32)0; trMyIntegrator.f32InK1 = (tFrac32)0; // output should be 0x0051EB85 f32Out = GFLIB_IntegratorTR (f32In, &trMyIntegrator, F32); // // // // ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // clearing of the internal states trMyIntegrator.f32State = (tFrac32)0; trMyIntegrator.f32InK1 = (tFrac32)0; } // output should be 0x0051EB85 f32Out = GFLIB_IntegratorTR (f32In, &trMyIntegrator); 5.40 Function GFLIB_IntegratorTR_F16 The function calculates a discrete implementation of the integrator (sum), discretized using a trapezoidal (Bilinear) transformation with overflow on range boundaries. 5.40.1 Declaration tFrac16 GFLIB_IntegratorTR_F16(tFrac16 f16In, GFLIB_INTEGRATOR_TR_T_F16 *const pParam); 5.40.2 Arguments Table 5-50. GFLIB_IntegratorTR_F16 arguments Type Name tFrac16 f16In GFLIB_INTEGRATOR_ pParam TR_T_F16 *const Direction Description input Input argument to be integrated. input, output Pointer to the integrator parameters structure. 5.40.3 Return The function returns a 16-bit value in format Q1.15, which represents the actual integrated value of the input signal with overflow on range boundaries. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 253 Function GFLIB_IntegratorTR_F16 5.40.4 Description The function GFLIB_IntegratorTR_F16 implements a discrete integrator using trapezoidal (Bilinear) transformation with overflow on range boundaries. The continuous time domain representation of the integrator is defined as: Equation GFLIB_IntegratorTR_Eq1 The transfer function for this integrator, in a continuous time domain, is described using the Laplace transformation as follows: Equation GFLIB_IntegratorTR_Eq2 Transforming equation GFLIB_IntegratorTR_Eq2 into a digital time domain using Bilinear transformation, leads to the following transfer function: Equation GFLIB_IntegratorTR_Eq3 where T s is the sampling period of the system. The discrete implementation of the digital transfer function GFLIB_IntegratorTR_Eq3 is as follows: Equation GFLIB_IntegratorTR_Eq4 Considering fractional maths implementation, the integrator input and output maximal values (scales) must be known. Then the discrete implementation is given as follows: Equation GFLIB_IntegratorTR_Eq5 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 254 NXP Semiconductors Chapter 5 API References where E MAX is the input scale and U MAX is the output scale. Then integrator constant C1 is defined as: Equation GFLIB_IntegratorTR_Eq6 In order to implement the discrete form integrator as in GFLIB_IntegratorTR_Eq5 on a fixed point platform, the value of C1 f coefficient must reside in a the fractional range [-1,1). Therefore, scaling must be introduced as follows: Equation GFLIB_IntegratorTR_Eq7 The introduced scaling is chosen such that coefficient f16C1 fits into fractional range [-1,1). To simplify the implementation, this scaling is chosen to be a power of 2, so the final scaling is a simple shift operation using the u16NShift variable. Hence, the shift is calculated as: Equation GFLIB_IntegratorTR_Eq8 If the output exceeds the fractional range [-1,1), an overflow occurs. This behavior allows continual integration of an angular velocity of a rotor to obtain the actual rotor position, assuming the output range corresponds to one complete revolution. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). All parameters and states used by the function can be reset during declaration using the GFLIB_INTEGRATOR_TR_DEFAULT_F16 macro. The specified accuracy of the function is not guaranteed in cases when any of the terms in GFLIB_IntegratorTR_Eq5 overflows. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 255 Function GFLIB_Limit_F32 5.40.5 Re-entrancy The function is re-entrant. 5.40.6 Code Example #include "gflib.h" tFrac16 f16In; tFrac16 f16Out; // Definition of one integrator instance GFLIB_INTEGRATOR_TR_T_F16 trMyIntegrator = GFLIB_INTEGRATOR_TR_DEFAULT_F16; void main(void) { // Setting parameters for integrator, Ts = 100e-4, E_MAX=U_MAX=1 trMyIntegrator.f16C1 = FRAC16 (100e-4/2); trMyIntegrator.u16NShift = (tU16)0; // input value = 0.5 f16In = FRAC16 (0.5); // output should be 0x0051 f16Out = GFLIB_IntegratorTR_F16 (f16In, &trMyIntegrator); // clearing of the internal states trMyIntegrator.f32State = (tFrac32)0; trMyIntegrator.f16InK1 = (tFrac16)0; // output should be 0x0051 f16Out = GFLIB_IntegratorTR (f16In, &trMyIntegrator, F16); // // // // ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // clearing of the internal states trMyIntegrator.f32State = (tFrac32)0; trMyIntegrator.f16InK1 = (tFrac16)0; } // output should be 0x0051 f16Out = GFLIB_IntegratorTR (f16In, &trMyIntegrator); 5.41 Function GFLIB_Limit_F32 This function tests whether the input value is within the upper and lower limits. 5.41.1 Declaration tFrac32 GFLIB_Limit_F32(tFrac32 f32In, const GFLIB_LIMIT_T_F32 *const pParam); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 256 NXP Semiconductors Chapter 5 API References 5.41.2 Arguments Table 5-51. GFLIB_Limit_F32 arguments Type Name Direction Description tFrac32 f32In input Input value. const GFLIB_LIMIT_T_F32 *const pParam input Pointer to the limits structure. 5.41.3 Return The input value in case the input value is below the limits, or the upper or lower limit if the input value is above these limits. 5.41.4 Description The GFLIB_Limit function tests whether the input value is within the upper and lower limits. If so, the input value will be returned. If the input value is above the upper limit, the upper limit will be returned. Similarly, if the input value is below the lower limit, the lower limit will be returned. The upper and lower limits can be found in the limits structure, supplied to the function as a pointer pParam. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The function assumes that the upper limit f32UpperLimit is greater than the lower limit f32LowerLimit. Otherwise, the function returns an undefined value. 5.41.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 257 Function GFLIB_Limit_F16 5.41.6 Code Example #include "gflib.h" tFrac32 f32In; tFrac32 f32Out; GFLIB_LIMIT_T_F32 f32trMyLimit = GFLIB_LIMIT_DEFAULT_F32; void main(void) { // upper/lower limits f32trMyLimit.f32UpperLimit = FRAC32 (0.5); f32trMyLimit.f32LowerLimit = FRAC32 (-0.5); // input value = 0.75 f32In = FRAC32 (0.75); // output should be 0x40000000 ~ FRAC32(0.5) f32Out = GFLIB_Limit_F32 (f32In, &f32trMyLimit); // output should be 0x40000000 ~ FRAC32(0.5) f32Out = GFLIB_Limit (f32In, &f32trMyLimit, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x40000000 ~ FRAC32(0.5) f32Out = GFLIB_Limit (f32In, &f32trMyLimit); 5.42 Function GFLIB_Limit_F16 This function tests whether the input value is within the upper and lower limits. 5.42.1 Declaration tFrac16 GFLIB_Limit_F16(tFrac16 f16In, const GFLIB_LIMIT_T_F16 *const pParam); 5.42.2 Arguments Table 5-52. GFLIB_Limit_F16 arguments Type Name Direction Description tFrac16 f16In input Input value. const GFLIB_LIMIT_T_F16 *const pParam input Pointer to the limits structure. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 258 NXP Semiconductors Chapter 5 API References 5.42.3 Return The input value in case the input value is below the limits, or the upper or lower limit if the input value is above these limits. 5.42.4 Description The GFLIB_Limit function tests whether the input value is within the upper and lower limits. If so, the input value will be returned. If the input value is above the upper limit, the upper limit will be returned. Similarly, if the input value is below the lower limit, the lower limit will be returned. The upper and lower limits can be found in the limits structure, supplied to the function as a pointer pParam. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The function assumes that the upper limit f16UpperLimit is greater than the lower limit f16LowerLimit. Otherwise, the function returns an undefined value. 5.42.5 Re-entrancy The function is re-entrant. 5.42.6 Code Example #include "gflib.h" tFrac16 f16In; tFrac16 f16Out; GFLIB_LIMIT_T_F16 f16trMyLimit = GFLIB_LIMIT_DEFAULT_F16; void main(void) { // upper/lower limits f16trMyLimit.f16UpperLimit = FRAC16 (0.5); f16trMyLimit.f16LowerLimit = FRAC16 (-0.5); // input value = 0.75 f16In = FRAC16 (0.75); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 259 Function GFLIB_LowerLimit_F32 // output should be 0x4000 ~ FRAC16(0.5) f16Out = GFLIB_Limit_F16 (f16In, &f16trMyLimit); // output should be 0x4000 ~ FRAC16(0.5) f16Out = GFLIB_Limit (f16In, &f16trMyLimit, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x4000 ~ FRAC16(0.5) f16Out = GFLIB_Limit (f16In, &f16trMyLimit); 5.43 Function GFLIB_LowerLimit_F32 This function tests whether the input value is above the lower limit. 5.43.1 Declaration tFrac32 GFLIB_LowerLimit_F32(tFrac32 f32In, const GFLIB_LOWERLIMIT_T_F32 *const pParam); 5.43.2 Arguments Table 5-53. GFLIB_LowerLimit_F32 arguments Type tFrac32 Name f32In const pParam GFLIB_LOWERLIMIT_ T_F32 *const Direction Description input Input value. input Pointer to the limits structure. 5.43.3 Return The input value in case the input value is above the limit, or the lower limit if the input value is below the limit. 5.43.4 Description The function tests whether the input value is above the lower limit. If so, the input value will be returned. Otherwise, if the input value is below the lower limit, the lower limit will be returned. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 260 NXP Semiconductors Chapter 5 API References The lower limit f32LowerLimit can be found in the limits structure, supplied to the function as a pointer pParam. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). 5.43.5 Re-entrancy The function is re-entrant. 5.43.6 Code Example #include "gflib.h" tFrac32 f32In; tFrac32 f32Out; GFLIB_LOWERLIMIT_T_F32 f32trMyLowerLimit = GFLIB_LOWERLIMIT_DEFAULT_F32; void main(void) { // lower limit f32trMyLowerLimit.f32LowerLimit = FRAC32 (0.5); // input value = 0.75 f32In = FRAC32 (0.75); // output should be 0x60000000 ~ FRAC32(0.75) f32Out = GFLIB_LowerLimit_F32 (f32In,&f32trMyLowerLimit); // output should be 0x60000000 ~ FRAC32(0.75) f32Out = GFLIB_LowerLimit (f32In,&f32trMyLowerLimit,F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x60000000 ~ FRAC32(0.75) f32Out = GFLIB_LowerLimit (f32In,&f32trMyLowerLimit); 5.44 Function GFLIB_LowerLimit_F16 This function tests whether the input value is above the lower limit. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 261 Function GFLIB_LowerLimit_F16 5.44.1 Declaration tFrac16 GFLIB_LowerLimit_F16(tFrac16 f16In, const GFLIB_LOWERLIMIT_T_F16 *const pParam); 5.44.2 Arguments Table 5-54. GFLIB_LowerLimit_F16 arguments Type tFrac16 Name f16In const pParam GFLIB_LOWERLIMIT_ T_F16 *const Direction Description input Input value. input Pointer to the limits structure. 5.44.3 Return The input value in case the input value is above the limit, or the lower limit if the input value is below the limit. 5.44.4 Description The function tests whether the input value is above the lower limit. If so, the input value will be returned. Otherwise, if the input value is below the lower limit, the lower limit will be returned. The lower limit f32LowerLimit can be found in the limits structure, supplied to the function as a pointer pParam. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). 5.44.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 262 NXP Semiconductors Chapter 5 API References 5.44.6 Code Example #include "gflib.h" tFrac16 f16In; tFrac16 f16Out; GFLIB_LOWERLIMIT_T_F16 f16trMyLowerLimit = GFLIB_LOWERLIMIT_DEFAULT_F16; void main(void) { // lower limit f16trMyLowerLimit.f16LowerLimit = FRAC16 (0.5); // input value = 0.75 f16In = FRAC16 (0.75); // output should be 0x6000 ~ FRAC16(0.75) f16Out = GFLIB_LowerLimit_F16 (f16In,&f16trMyLowerLimit); // output should be 0x6000 ~ FRAC16(0.75) f16Out = GFLIB_LowerLimit (f16In,&f16trMyLowerLimit,F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x6000 ~ FRAC16(0.75) f16Out = GFLIB_LowerLimit (f16In,&f16trMyLowerLimit); 5.45 Function GFLIB_Lut1D_F32 This function implements the one-dimensional look-up table. 5.45.1 Declaration tFrac32 GFLIB_Lut1D_F32(tFrac32 f32In, const GFLIB_LUT1D_T_F32 *const pParam); 5.45.2 Arguments Table 5-55. GFLIB_Lut1D_F32 arguments Type Name Direction Description tFrac32 f32In input The abscissa for which 1D interpolation is performed. const GFLIB_LUT1D_T_F32 *const pParam input Pointer to the parameters structure with parameters of the look-up table function. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 263 Function GFLIB_Lut1D_F32 5.45.3 Return The interpolated value from the look-up table with 16-bit accuracy. 5.45.4 Description The GFLIB_Lut1D_F32 function performs one dimensional linear interpolation over a table of data. The data is assumed to represent a one dimensional function sampled at equidistant points. The following interpolation formula is used: Equation GFLIB_Lut1D_Eq1 where: • y is the interpolated value • y 1 and y 2 are the ordinate values at, respectively, the beginning and the end of the interpolating interval • x 1 and x 2 are the abscissa values at, respectively, the beginning and the end of the interpolating interval • the x is the input value provided to the function in the f32In argument The interpolating intervals are defined in the table provided by the pf32Table member of the parameters structure. The table contains ordinate values consecutively over the entire interpolating range. The abscissa values are assumed to be defined implicitly by a single interpolating interval length and a table index, while the interpolating index zero is the table element pointed to by the pf32Table parameter. The abscissa value is equal to the multiplication of the interpolating index and the interpolating interval length. For example, let's consider the following interpolating table: Table 5-56. GFLIB_Lut1D example table ordinate (y) interpolating index abscissa (x) -0.5 -1 -1*(2 -1) pf32Table{rarrow} 0.0 0 0*(2 -1) 0.25 1 1*(2 -1) 0.5 N/A 2*(2 -1) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 264 NXP Semiconductors Chapter 5 API References The Table 5-56 contains 4 interpolating points (note four rows). The interpolating interval length in this example is equal to 2 -1 . The pf32Table parameter points to the second row, defining also the interpolating index 0. The x-coordinates of the interpolating points are calculated in the right column. It should be noted that the pf32Table pointer does not have to point to the start of the memory area of ordinate values. Therefore, the interpolating index can be positive or negative or, even, does not have to have zero in its range. A special algorithm is used to make the computation efficient, however, under some additional assumptions, as provided below: • the values of the interpolated function are 32 bits long • the length of each interpolating interval is equal to 2 -n, where n is an integer in the range of 1, 2, ... 29 • the provided abscissa for interpolation is 32 bits long The algorithm performs the following steps: 1. Compute the index representing the interval, in which the linear interpolation will be performed: Equation GFLIB_Lut1D_Eq2 where I is the interval index and the s Interval the shift amount provided in the parameters structure as the member s32ShamIntvl. The operator >> represents the binary arithmetic right shift. 2. Compute the abscissa offset within an interpolating interval: Equation GFLIB_Lut1D_Eq3 where Δ{x} is the abscissa offset within an interval and the s Offset is the shift amount provided in the parameters structure. The operators << and & represent, respectively, the binary left shift and the bitwise logical conjunction. It should be noted that the computation represents the extraction of some least significant bits of the x with the sign bit cleared. 3. Compute the interpolated value by the linear interpolation between the ordinates read from the table at the start and the end of the computed interval. The computed abscissa offset is used for the linear interpolation. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 265 Function GFLIB_Lut1D_F32 Equation GFLIB_Lut1D_Eq4 where y, y 1 and y 2 are, respectively, the interpolated value, the ordinate at the start of the interpolating interval, the ordinate at the end of the interpolating interval. The pTable is the address provided in the parameters structure pParam->f32Table. It should be noted that due to assumption of equidistant data points, division by the interval length is avoided. It should be noted that the computations are performed with a 16-bit accuracy. In particular, the 16 least significant bits are ignored in all multiplications. The shift amounts shall be provided in the parameters structure (pParam>u32ShamOffset). The address of the table with the data, the pTable, shall be defined by the parameter structure member pParam->pf32Table. The shift amounts, the s Interval and s Offset, can be computed with the following formulas: Equation GFLIB_Lut1D_Eq5 where n is the integer defining the length of the interpolating interval in the range of -1, -2, ... -29. The computation of the abscissa offset and the interval index can be viewed also in the following way. The input abscissa value can be divided into two parts. The first n most significant bits of the 32-bit word, after the sign bit, compose the interval index, in which interpolation is performed. The rest of the bits form the abscissa offset within the interpolating interval. This simple way to calculate the interpolating interval index and the abscissa offset is the consequence of assuming that all interpolating interval lengths equal 2 -n. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 266 NXP Semiconductors Chapter 5 API References It should be noted that the input abscissa value can be positive or negative. If it is, positive then the ordinate values are read as in the ordinary data array, that is, at or after the data pointer provided in the parameters structure (pParam->pf32Table). However, if it is negative, then the ordinate values are read from the memory, which is located behind the pParam->pf32Table pointer. Note The input pointer must contain a valid address and the range of the input abscissa values must fall within the range of the interpolating data table otherwise a fault may occur (HardFault). The function performs a linear interpolation. CAUTION The function does not check whether the input abscissa value is within the range allowed by the interpolating data table pParam->pf32Table. If the computed interval index points to data outside the provided data table, then the interpolation will be computed with invalid data. The range of the input abscissa value depends on the position of the pointer in the interpolating data table. Sum of the absolute values of the lower and upper border values is equal to the FRACT_MAX. For a better understanding, please, see the extended code example. 5.45.5 Re-entrancy The function is re-entrant. 5.45.6 Code Example #include "gflib.h" tFrac32 f32In; tFrac32 f32Out; GFLIB_LUT1D_T_F32 trf32MyLut1D = GFLIB_LUT1D_DEFAULT_F32; tFrac32 pf32Table1D[9] = {FRAC32 (0.8),FRAC32 (0.1),FRAC32 (-0.2),FRAC32 (0.7),FRAC32 (0.2),FRAC32 (-0.3),FRAC32 (-0.8),FRAC32 (0.91),FRAC32 (0.99)}; void main(void) { // #################################################################### // Pointer is located in the middle of the interpolating data table. // #################################################################### // setting parameters for Lut1D function trf32MyLut1D.u32ShamOffset = (tU32)3; Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 267 Function GFLIB_Lut1D_F16 trf32MyLut1D.pf32Table = &(pf32Table1D[4]); // input vector = -0.5 f32In = FRAC32 (-0.5); // output should be 0x66666666 ~ FRAC32(0.8) f32Out = GFLIB_Lut1D_F32 (f32In,&trf32MyLut1D); // output should be 0x66666666 ~ FRAC32(0.8) f32Out = GFLIB_Lut1D (f32In,&trf32MyLut1D,F32); // available only if 32-bit fractional implementation selected as default // output should be 0x66666666 ~ FRAC32(0.8) f32Out = GFLIB_Lut1D (f32In,&trf32MyLut1D); // #################################################################### // Pointer is located at the beginning of the interpolating data table. // #################################################################### // setting parameters for Lut1D function trf32MyLut1D.u32ShamOffset = (tU32)3; trf32MyLut1D.pf32Table = &(pf32Table1D[0]); // input vector = 0 f32In = FRAC32 (0); // output should be 0x66666666 ~ FRAC32(0.8) f32Out = GFLIB_Lut1D_F32 (f32In,&trf32MyLut1D); // output should be 0x66666666 ~ FRAC32(0.8) f32Out = GFLIB_Lut1D (f32In,&trf32MyLut1D,F32); // available only if 32-bit fractional implementation selected as default // output should be 0x66666666 ~ FRAC32(0.8) f32Out = GFLIB_Lut1D (f32In,&trf32MyLut1D); // #################################################################### // Pointer is located at the end of the interpolating data table. // #################################################################### // setting parameters for Lut1D function trf32MyLut1D.u32ShamOffset = (tU32)3; trf32MyLut1D.pf32Table = &(pf32Table1D[8]); // input vector = -1 f32In = FRAC32 (-1); // output should be 0x66666666 ~ FRAC32(0.8) f32Out = GFLIB_Lut1D_F32 (f32In,&trf32MyLut1D); // output should be 0x66666666 ~ FRAC32(0.8) f32Out = GFLIB_Lut1D (f32In,&trf32MyLut1D,F32); } // available only if 32-bit fractional implementation selected as default // output should be 0x66666666 ~ FRAC32(0.8) f32Out = GFLIB_Lut1D (f32In,&trf32MyLut1D); 5.46 Function GFLIB_Lut1D_F16 This function implements the one-dimensional look-up table. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 268 NXP Semiconductors Chapter 5 API References 5.46.1 Declaration tFrac16 GFLIB_Lut1D_F16(tFrac16 f16In, const GFLIB_LUT1D_T_F16 *const pParam); 5.46.2 Arguments Table 5-57. GFLIB_Lut1D_F16 arguments Type Name Direction Description tFrac16 f16In input The abscissa for which 1D interpolation is performed. const GFLIB_LUT1D_T_F16 *const pParam input Pointer to the parameters structure with parameters of the look-up table function. 5.46.3 Return The interpolated value from the look-up table. 5.46.4 Description The GFLIB_Lut1D_F16 function performs one dimensional linear interpolation over a table of data. The data is assumed to represent a one dimensional function sampled at equidistant points. The following interpolation formula is used: Equation GFLIB_Lut1D_Eq1 where: • y is the interpolated value • y 1 and y 2 are the ordinate values at, respectively, the beginning and the end of the interpolating interval • x 1 and x 2 are the abscissa values at, respectively, the beginning and the end of the interpolating interval • the x is the input value provided to the function in the f16In argument Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 269 Function GFLIB_Lut1D_F16 The interpolating intervals are defined in the table provided by the pf16Table member of the parameters structure. The table contains ordinate values consecutively over the entire interpolating range. The abscissa values are assumed to be defined implicitly by a single interpolating interval length and a table index, while the interpolating index zero is the table element pointed to by the pf16Table parameter. The abscissa value is equal to the multiplication of the interpolating index and the interpolating interval length. For example, let's consider the following interpolating table: Table 5-58. GFLIB_Lut1D example table ordinate (y) interpolating index abscissa (x) -0.5 -1 -1*(2 -1) pf16Table{rarrow} 0.0 0 0*(2 -1) 0.25 1 1*(2 -1) 0.5 N/A 2*(2 -1) The Table 5-58 contains 4 interpolating points (note four rows). The interpolating interval length in this example is equal to 2 -1. The pf16Table parameter points to the second row, defining also the interpolating index 0. The x-coordinates of the interpolating points are calculated in the right column. It should be noted that the pf16Table pointer does not have to point to the start of the memory area of ordinate values. Therefore, the interpolating index can be positive or negative or, even, does not have to have zero in its range. A special algorithm is used to make the computation efficient, however, under some additional assumptions, as provided below: • the values of the interpolated function are 16 bits long • the length of each interpolating interval is equal to 2 -n, where n is an integer in the range of 1, 2, ... 13 • the provided abscissa for interpolation is 16 bits long The algorithm performs the following steps: 1. Compute the index representing the interval, in which the linear interpolation will be performed: Equation GFLIB_Lut1D_Eq2 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 270 NXP Semiconductors Chapter 5 API References where I is the interval index and the s Interval the shift amount provided in the parameters structure as the member s16ShamIntvl. The operator >> represents the binary arithmetic right shift. 2. Compute the abscissa offset within an interpolating interval: Equation GFLIB_Lut1D_Eq3 where Δ{x} is the abscissa offset within an interval and the s Offset is the shift amount provided in the parameters structure. The operators << and & represent, respectively, the binary left shift and the bitwise logical conjunction. It should be noted that the computation represents the extraction of some least significant bits of the x with the sign bit cleared. 3. Compute the interpolated value by the linear interpolation between the ordinates read from the table at the start and the end of the computed interval. The computed abscissa offset is used for the linear interpolation. Equation GFLIB_Lut1D_Eq4 where y, y 1 and y 2 are, respectively, the interpolated value, the ordinate at the start of the interpolating interval, the ordinate at the end of the interpolating interval. The pTable is the address provided in the parameters structure pParam->f16Table. It should be noted that due to assumption of equidistant data points, division by the interval length is avoided. It should be noted that the computations are performed with a 16-bit accuracy. In particular, the 16 least significant bits are ignored in all multiplications. The shift amounts shall be provided in the parameters structure (pParam>u16ShamOffset). The address of the table with the data, the pTable, shall be defined by the parameter structure member pParam->pf16Table. The shift amounts, the s Interval and s Offset, can be computed with the following formulas: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 271 Function GFLIB_Lut1D_F16 Equation GFLIB_Lut1D_Eq5 where n is the integer defining the length of the interpolating interval in the range of -1, -2, ... -15. The computation of the abscissa offset and the interval index can be viewed also in the following way. The input abscissa value can be divided into two parts. The first n most significant bits of the 16-bit halfword, after the sign bit, compose the interval index, in which interpolation is performed. The rest of the bits form the abscissa offset within the interpolating interval. This simple way to calculate the interpolating interval index and the abscissa offset is the consequence of assuming that all interpolating interval lengths equal 2 -n. It should be noted that the input abscissa value can be positive or negative. If it is, positive then the ordinate values are read as in the ordinary data array, that is, at or after the data pointer provided in the parameters structure (pParam->pf16Table). However, if it is negative, then the ordinate values are read from the memory, which is located behind the pParam->pf16Table pointer. Note The input pointer must contain a valid address and the range of the input abscissa values must fall within the range of the interpolating data table otherwise a fault may occur (HardFault). The function performs a linear interpolation. CAUTION The function does not check whether the input abscissa value is within the range allowed by the interpolating data table pParam->pf16Table. If the computed interval index points to data outside the provided data table, then the interpolation will be computed with invalid data. The range of the input abscissa value depends on the position of the pointer in the interpolating data table. Sum of the absolute values of the lower and upper border values is equal to the SFRACT_MAX. For a better understanding, please, see the extended code example. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 272 NXP Semiconductors Chapter 5 API References 5.46.5 Re-entrancy The function is re-entrant. 5.46.6 Code Example #include "gflib.h" tFrac16 f16In; tFrac16 f16Out; GFLIB_LUT1D_T_F16 trf16MyLut1D = GFLIB_LUT1D_DEFAULT_F16; tFrac16 pf16Table1D[9] = {FRAC16 (0.8),FRAC16 (0.1),FRAC16 (-0.2),FRAC16 (0.7),FRAC16 (0.2),FRAC16 (-0.3),FRAC16 (-0.8),FRAC16 (0.91),FRAC16 (0.99)}; void main(void) { // #################################################################### // Pointer is located in the middle of the interpolating data table. // #################################################################### // setting parameters for Lut1D function trf16MyLut1D.u16ShamOffset = (tU16)3; trf16MyLut1D.pf16Table = &(pf16Table1D[4]); // input vector = -0.5 f16In = FRAC16 (-0.5); // output should be 0x6666 ~ FRAC16(0.8) f16Out = GFLIB_Lut1D_F16 (f16In,&trf16MyLut1D); // output should be 0x6666 ~ FRAC16(0.8) f16Out = GFLIB_Lut1D (f16In,&trf16MyLut1D,F16); // available only if 16-bit fractional implementation selected as default // output should be 0x6666 ~ FRAC16(0.8) f16Out = GFLIB_Lut1D (f16In,&trf16MyLut1D); // #################################################################### // Pointer is located at the beginning of the interpolating data table. // #################################################################### // setting parameters for Lut1D function trf16MyLut1D.u16ShamOffset = (tU16)3; trf16MyLut1D.pf16Table = &(pf16Table1D[0]); // input vector = 0 f16In = FRAC16 (0); // output should be 0x6666 ~ FRAC16(0.8) f16Out = GFLIB_Lut1D_F16 (f16In,&trf16MyLut1D); // output should be 0x6666 ~ FRAC16(0.8) f16Out = GFLIB_Lut1D (f16In,&trf16MyLut1D,F16); // available only if 16-bit fractional implementation selected as default // output should be 0x6666 ~ FRAC16(0.8) f16Out = GFLIB_Lut1D (f16In,&trf16MyLut1D); // #################################################################### // Pointer is located at the end of the interpolating data table. // #################################################################### // setting parameters for Lut1D function trf16MyLut1D.u16ShamOffset = (tU16)3; trf16MyLut1D.pf16Table = &(pf16Table1D[8]); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 273 Function GFLIB_Lut2D_F32 // input vector = -1 f16In = FRAC16 (-1); // output should be 0x6666 ~ FRAC16(0.8) f16Out = GFLIB_Lut1D_F16 (f16In,&trf16MyLut1D); // output should be 0x6666 ~ FRAC16(0.8) f16Out = GFLIB_Lut1D (f16In,&trf16MyLut1D,F16); } // available only if 16-bit fractional implementation selected as default // output should be 0x6666 ~ FRAC16(0.8) f16Out = GFLIB_Lut1D (f16In,&trf16MyLut1D); 5.47 Function GFLIB_Lut2D_F32 This function implements the two-dimensional look-up table. 5.47.1 Declaration tFrac32 GFLIB_Lut2D_F32(tFrac32 f32In1, tFrac32 f32In2, const GFLIB_LUT2D_T_F32 *const pParam); 5.47.2 Arguments Table 5-59. GFLIB_Lut2D_F32 arguments Type Name Direction Description tFrac32 f32In1 input First input variable for which 2D interpolation is performed. tFrac32 f32In2 input Second input variable for which 2D interpolation is performed. const GFLIB_LUT2D_T_F32 *const pParam input Pointer to the parameters structure with parameters of the two dimensional look-up table function. 5.47.3 Return The interpolated value from the look-up table with 16-bit accuracy. 5.47.4 Description The GFLIB_Lut2D_F32 function performs two dimensional linear interpolation over a 2D table of data. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 274 NXP Semiconductors Chapter 5 API References The following interpolation formulas are used: Equation GFLIB_Lut2D_Eq1 Equation GFLIB_Lut2D_Eq2 Equation GFLIB_Lut2D_Eq3 where: • f[x,y] is the interpolated value • f[x,y 1] and f[x,y 2] are the ordinate values at, respectively, the beginning and the end of the final interpolating interval • x 1, x 2, y 1 and y 2 are the area values, respectively, the interpolated area • the x, y are the input values provided to the function in the f32In1 and f32In2 arguments The interpolating intervals are defined in the table provided by the pf32Table member of the parameters structure. The table contains ordinate values consecutively over the whole interpolating range. The abscissa values are assumed to be defined implicitly by a single interpolating interval length and a table index while the interpolating index zero is the table element pointed to by the pf32Table parameter. The abscissa value is equal to the multiplication of the interpolating index and the interpolating interval length. For example let's consider the following interpolating table: Table 5-60. GFLIB_Lut2D example table ordinate (f[x,y]) interpolating index abscissa (x) -1) abscissa (y) -1*(2 -1) -0.5 -1 -1*(2 pf32Table{rarrow} 0.0 0 0*(2 -1) 0*(2 -1) 0.5 1 1*(2 -1) 1*(2 -1) 1.0 N/A 2*(2 -1) 2*(2 -1) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 275 Function GFLIB_Lut2D_F32 The Table 5-60 contains 4 interpolating points (note four rows). Interpolating interval length in this example is equal to 2 -1 . The pf32Table parameter points to the second row, defining also the interpolating index 0. The x-coordinates of the interpolating points are calculated in the right column. It should be noticed that the pf32Table pointer does not have to point to the start of the memory area with ordinate values. Therefore the interpolating index can be positive or negative or, even, does not have to have zero in its range. Special algorithm is used to make the computation efficient, however under some additional assumptions as provided below: • the values of the interpolated function are 32-bit long • the length of each interpolating interval is equal to 2 -n, where n is an integer in the range of 1, 2, ... 29 • the provided abscissa for interpolation is 32-bit long The algorithm performs the following steps: 1. Compute the index representing the interval, in which the bilinear interpolation will be performed in each axis: Equation GFLIB_Lut2D_Eq4 Equation GFLIB_Lut2D_Eq5 where I x and I y is the interval index and the s IntervalX and s IntervalY are the shift amounts provided in the parameters structure as a member u32ShamOffset1 or u32ShamOffset2. The operator >> represents the binary arithmetic right shift. 2. Compute the abscissas offset for both axis within an interpolating intervals: Equation GFLIB_Lut2D_Eq6 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 276 NXP Semiconductors Chapter 5 API References Equation GFLIB_Lut2D_Eq7 where Δ{x} and Δ{y} are the abscissas offset within an Xinterval and Yinterval. The s Offset1 and s Offset2 are the shift amounts provided in the parameters structure. The operators << and & represent the binary left shift and the bitwise logical conjunction. It should be noted that the computation represents extraction of some least significant bits of the x and y with the sign bit cleared. 3. Compute the interpolated value by the linear interpolation in X-axis by y 1 value between the ordinates x1 and x 2 readed from the table at the start and the end of the computed interval in X-axis way. The computed abscissa offset is used for the linear interpolation: Equation GFLIB_Lut2D_Eq8 Equation GFLIB_Lut2D_Eq9 Equation GFLIB_Lut2D_Eq10 where f[x,y 1] is interpolated value, f[x 1,y 1] and f[x 2,y 1] are, the ordinate at the start of the interpolating interval and the ordinate at the end of the interpolating interval. The pTable} is the address provided in the parameters structure pParam>f32Table. 4. The same computation as shown above in X-axis by y 2 value. Interpolation formulas are the same as paragraph 3: Equation GFLIB_Lut2D_Eq11 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 277 Function GFLIB_Lut2D_F32 Equation GFLIB_Lut2D_Eq12 Equation GFLIB_Lut2D_Eq13 5. Final linear interpolation in Y-axis way Interpolation formulas are the same as paragraph 3 or 4: Equation GFLIB_Lut2D_Eq14 Equation GFLIB_Lut2D_Eq15 Equation GFLIB_Lut2D_Eq16 It should be noted that due to assumption of the equidistant data points, the division by the interval length is avoided. It should be noted that the computations are performed with the 16-bit accuracy. In particular the 16 least significant bits are ignored in all multiplications. The shift amounts shall be provided in the parameters structure (pParam>u32ShamOffset1 and pParam->u32ShamOffset2). The address of the table with the data, the pTable}, shall be defined by the parameter structure member pParam>pf32Table. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 278 NXP Semiconductors Chapter 5 API References The shift amounts, the s Interval1,2 and s Offset1,2, can be computed with the following formulas: Equation GFLIB_Lut2D_Eq17 where n is the integer defining the length of the interpolating interval in the range of -1, -2, ... -29. The computation of the abscissa offset and the interval index can be viewed also in the following way. The input abscissa value can be divided into two parts. The first n most significant bits of the 32-bit word, after the sign bit, compose the interval index, in which interpolation is performed. The rest of the bits form the abscissa offset within the interpolating interval. This simple way to calculate the interpolating interval index and the abscissa offset is the consequence of assumption of all interpolating interval lengths equal 2 -n. It should be noted that the input abscissa value can be positive or negative. If it is positive then the ordinate values are read as in the ordinary data array, that is at or after the data pointer provided in the parameters structure (pParam->pf32Table). However, if it is negative, then the ordinate values are read from the memory, which is located behind the pParam->pf32Table pointer. Note The input pointer must contain a valid address and the range of the input values must fall within the range of the interpolating data table otherwise a fault may occur (HardFault). The function performs the bilinear interpolation with 16-bit accuracy. CAUTION The function does not check whether the input values are within a range allowed by the interpolating data table pParam>pf32Table. If the computed interval index points to data outside the provided data table then the interpolation will be computed with invalid data. The range of the input abscissa value depends on the position of the pointer in the interpolating data table. Sum of the absolute values of the lower and upper border values is equal to the FRACT_MAX. For a better understanding, please, see the extended code example. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 279 Function GFLIB_Lut2D_F32 5.47.5 Re-entrancy The function is re-entrant. 5.47.6 Code Example #include "gflib.h" (0.03), FRAC32 (0.13), FRAC32 (0.23), FRAC32 (0.33), FRAC32 (0.43), FRAC32 (0.53), FRAC32 (0.63), FRAC32 (0.73), FRAC32 (0.83), FRAC32 tFrac32 f32In1; tFrac32 f32In2; tFrac32 f32Out; GFLIB_LUT2D_T_F32 tr32tMyLut2D = GFLIB_LUT2D_DEFAULT_F32; tFrac32 pf32Table2D[81] = {FRAC32 (0.9), FRAC32 (0.01), FRAC32 (0.02), (0.04), FRAC32 (0.05), FRAC32 (0.06), FRAC32 (0.07), FRAC32 (0.08), FRAC32 (0.1), FRAC32 (0.11), FRAC32 (0.12), (0.14), FRAC32 (0.15), FRAC32 (0.16), FRAC32 (0.17), FRAC32 (0.18), FRAC32 (0.2), FRAC32 (0.21), FRAC32 (0.22), (0.24), FRAC32 (0.25), FRAC32 (0.26), FRAC32 (0.27), FRAC32 (0.28), FRAC32 (0.3), FRAC32 (0.31), FRAC32 (0.32), (0.34), FRAC32 (0.35), FRAC32 (0.36), FRAC32 (0.37), FRAC32 (0.38), FRAC32 (0.4), FRAC32 (0.41), FRAC32 (0.42), (0.44), FRAC32 (0.45), FRAC32 (0.46), FRAC32 (0.47), FRAC32 (0.48), FRAC32 (0.5), FRAC32 (0.51), FRAC32 (0.52), (0.54), FRAC32 (0.55), FRAC32 (0.56), FRAC32 (0.57), FRAC32 (0.58), FRAC32 (0.6), FRAC32 (0.61), FRAC32 (0.62), (0.64), FRAC32 (0.65), FRAC32 (0.66), FRAC32 (0.67), FRAC32 (0.68), FRAC32 (0.7), FRAC32 (0.71), FRAC32 (0.72), (0.74), FRAC32 (0.75), FRAC32 (0.76), FRAC32 (0.77), FRAC32 (0.78), FRAC32 (0.8), FRAC32 (0.81), FRAC32 (0.82), (0.84), FRAC32 (0.85), FRAC32 (0.86), FRAC32 (0.87), FRAC32 (0.88)}; FRAC32 FRAC32 FRAC32 FRAC32 FRAC32 FRAC32 FRAC32 FRAC32 FRAC32 void main(void) { // #################################################################### // Pointer is located in the middle of the interpolating data table. // #################################################################### // setting parameters for Lut2D function tr32tMyLut2D.u32ShamOffset1 = (tU32)3; tr32tMyLut2D.u32ShamOffset2 = (tU32)3; tr32tMyLut2D.pf32Table = &(pf32Table2D[40]); // input vector f32In1 = FRAC32 (-0.5); f32In2 = FRAC32 (-0.5); // output should be 0x73333333 ~ FRAC32(0.9) f32Out = GFLIB_Lut2D_F32 (f32In1,f32In2,&tr32tMyLut2D); // output should be 0x73333333 ~ FRAC32(0.9) f32Out = GFLIB_Lut2D (f32In1,f32In2,&tr32tMyLut2D,F32); // available only if 32-bit fractional implementation selected as default // output should be 0x73333333 ~ FRAC32(0.9) f32Out = GFLIB_Lut2D (f32In1,f32In2,&tr32tMyLut2D); // #################################################################### // Pointer is located at the beginning of the interpolating data table. // #################################################################### // setting parameters for Lut2D function tr32tMyLut2D.u32ShamOffset1 = (tU32)3; tr32tMyLut2D.u32ShamOffset2 = (tU32)3; Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 280 NXP Semiconductors Chapter 5 API References tr32tMyLut2D.pf32Table = &(pf32Table2D[0]); // input vector f32In1 = FRAC32 (0); f32In2 = FRAC32 (0); // output should be 0x73333333 ~ FRAC32(0.9) f32Out = GFLIB_Lut2D_F32 (f32In1,f32In2,&tr32tMyLut2D); // output should be 0x73333333 ~ FRAC32(0.9) f32Out = GFLIB_Lut2D (f32In1,f32In2,&tr32tMyLut2D,F32); // available only if 32-bit fractional implementation selected as default // output should be 0x73333333 ~ FRAC32(0.9) f32Out = GFLIB_Lut2D (f32In1,f32In2,&tr32tMyLut2D); // #################################################################### // Pointer is located at the end of the interpolating data table. // #################################################################### // setting parameters for Lut2D function tr32tMyLut2D.u32ShamOffset1 = (tU32)3; tr32tMyLut2D.u32ShamOffset2 = (tU32)3; tr32tMyLut2D.pf32Table = &(pf32Table2D[80]); // input vector f32In1 = FRAC32 (-1); f32In2 = FRAC32 (-1); // output should be 0x73333333 ~ FRAC32(0.9) f32Out = GFLIB_Lut2D_F32 (f32In1,f32In2,&tr32tMyLut2D); // output should be 0x73333333 ~ FRAC32(0.9) f32Out = GFLIB_Lut2D (f32In1,f32In2,&tr32tMyLut2D,F32); } // available only if 32-bit fractional implementation selected as default // output should be 0x73333333 ~ FRAC32(0.9) f32Out = GFLIB_Lut2D (f32In1,f32In2,&tr32tMyLut2D); 5.48 Function GFLIB_Lut2D_F16 This function implements the two-dimensional look-up table. 5.48.1 Declaration tFrac16 GFLIB_Lut2D_F16(tFrac16 f16In1, tFrac16 f16In2, const GFLIB_LUT2D_T_F16 *const pParam); 5.48.2 Arguments Table 5-61. GFLIB_Lut2D_F16 arguments Type Name tFrac16 f16In1 Direction input Description First input variable for which 2D interpolation is performed. Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 281 Function GFLIB_Lut2D_F16 Table 5-61. GFLIB_Lut2D_F16 arguments (continued) Type Name Direction Description tFrac16 f16In2 input Second input variable for which 2D interpolation is performed. const GFLIB_LUT2D_T_F16 *const pParam input Pointer to the parameters structure with parameters of the two dimensional look-up table function. 5.48.3 Return The interpolated value from the look-up table. 5.48.4 Description The GFLIB_Lut2D_F16 function performs two dimensional linear interpolation over a 2D table of data. The following interpolation formulas are used: Equation GFLIB_Lut2D_Eq1 Equation GFLIB_Lut2D_Eq2 Equation GFLIB_Lut2D_Eq3 where: • f[x,y] is the interpolated value • f[x,y 1] and f[x,y 2] are the ordinate values at, respectively, the beginning and the end of the final interpolating interval Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 282 NXP Semiconductors Chapter 5 API References • x 1, x 2, y 1 and y 2 are the area values, respectively, the interpolated area • the x, y are the input values provided to the function in the f16In1 and f16In2 arguments The interpolating intervals are defined in the table provided by the pf16Table member of the parameters structure. The table contains ordinate values consecutively over the whole interpolating range. The abscissa values are assumed to be defined implicitly by a single interpolating interval length and a table index while the interpolating index zero is the table element pointed to by the pf16Table parameter. The abscissa value is equal to the multiplication of the interpolating index and the interpolating interval length. For example let's consider the following interpolating table: Table 5-62. GFLIB_Lut2D example table ordinate (f[x,y]) interpolating index abscissa (x) -1) abscissa (y) -1*(2 -1) -0.5 -1 -1*(2 pf16Table{rarrow} 0.0 0 0*(2 -1) 0*(2 -1) 0.5 1 1*(2 -1) 1*(2 -1) 1.0 N/A 2*(2 -1) 2*(2 -1) The Table 5-62 contains 4 interpolating points (note four rows). Interpolating interval length in this example is equal to 2 -1 . The pf16Table parameter points to the second row, defining also the interpolating index 0. The x-coordinates of the interpolating points are calculated in the right column. It should be noticed that the pf16Table pointer does not have to point to the start of the memory area with ordinate values. Therefore the interpolating index can be positive or negative or, even, does not have to have zero in its range. Special algorithm is used to make the computation efficient, however under some additional assumptions as provided below: • the values of the interpolated function are 16-bit long • the length of each interpolating interval is equal to 2 -n, where n is an integer in the range of 1, 2, ... 13 • the provided abscissa for interpolation is 16-bit long The algorithm performs the following steps: 1. Compute the index representing the interval, in which the bilinear interpolation will be performed in each axis: Equation GFLIB_Lut2D_Eq4 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 283 Function GFLIB_Lut2D_F16 Equation GFLIB_Lut2D_Eq5 where I x and I y is the interval index and the s IntervalX and s IntervalY are the shift amounts provided in the parameters structure as a member u16ShamOffset1 or u16ShamOffset2. The operator >> represents the binary arithmetic right shift. 2. Compute the abscissas offset for both axis within an interpolating intervals: Equation GFLIB_Lut2D_Eq6 Equation GFLIB_Lut2D_Eq7 where Δ{x} and Δ{y} are the abscissas offset within an Xinterval and Yinterval. The s Offset1 and s Offset2 are the shift amounts provided in the parameters structure. The operators << and & represent the binary left shift and the bitwise logical conjunction. It should be noted that the computation represents extraction of some least significant bits of the x and y with the sign bit cleared. 3. Compute the interpolated value by the linear interpolation in X-axis by y 1 value between the ordinates x1 and x 2 readed from the table at the start and the end of the computed interval in X-axis way. The computed abscissa offset is used for the linear interpolation: Equation GFLIB_Lut2D_Eq8 Equation GFLIB_Lut2D_Eq9 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 284 NXP Semiconductors Chapter 5 API References Equation GFLIB_Lut2D_Eq10 where f[x,y 1] is interpolated value, f[x 1,y 1] and f[x 2,y 1] are, the ordinate at the start of the interpolating interval and the ordinate at the end of the interpolating interval. The pTable} is the address provided in the parameters structure pParam>f16Table. 4. The same computation as shown above in X-axis by y 2 value. Interpolation formulas are the same as paragraph 3: Equation GFLIB_Lut2D_Eq11 Equation GFLIB_Lut2D_Eq12 Equation GFLIB_Lut2D_Eq13 5. Final linear interpolation in Y-axis way Interpolation formulas are the same as paragraph 3 or 4: Equation GFLIB_Lut2D_Eq14 Equation GFLIB_Lut2D_Eq15 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 285 Function GFLIB_Lut2D_F16 Equation GFLIB_Lut2D_Eq16 It should be noted that due to assumption of the equidistant data points, the division by the interval length is avoided. It should be noted that the computations are performed with the 16-bit accuracy. In particular the 16 least significant bits are ignored in all multiplications. The shift amounts shall be provided in the parameters structure (pParam>u16ShamOffset1 and pParam->u16ShamOffset2). The address of the table with the data, the pTable}, shall be defined by the parameter structure member pParam>pf16Table. The shift amounts, the s Interval1,2 and s Offset1,2, can be computed with the following formulas: Equation GFLIB_Lut2D_Eq17 where n is the integer defining the length of the interpolating interval in the range of -1, -2, ... -29. The computation of the abscissa offset and the interval index can be viewed also in the following way. The input abscissa value can be divided into two parts. The first n most significant bits of the 16-bit halfword, after the sign bit, compose the interval index, in which interpolation is performed. The rest of the bits form the abscissa offset within the interpolating interval. This simple way to calculate the interpolating interval index and the abscissa offset is the consequence of assumption of all interpolating interval lengths equal 2 -n. It should be noted that the input abscissa value can be positive or negative. If it is positive then the ordinate values are read as in the ordinary data array, that is at or after the data pointer provided in the parameters structure (pParam->pf16Table). However, if it is negative, then the ordinate values are read from the memory, which is located behind the pParam->pf16Table pointer. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 286 NXP Semiconductors Chapter 5 API References Note The input pointer must contain a valid address and the range of the input values must fall within the range of the interpolating data table otherwise a fault may occur (HardFault). The function performs the bilinear interpolation. CAUTION The function does not check whether the input values are within a range allowed by the interpolating data table pParam>pf16Table. If the computed interval index points to data outside the provided data table then the interpolation will be computed with invalid data. The range of the input abscissa value depends on the position of the pointer in the interpolating data table. Sum of the absolute values of the lower and upper border values is equal to the SFRACT_MAX. For a better understanding, please, see the extended code example. 5.48.5 Re-entrancy The function is re-entrant. 5.48.6 Code Example #include "gflib.h" (0.03), FRAC16 (0.13), FRAC16 (0.23), FRAC16 (0.33), FRAC16 (0.43), FRAC16 (0.53), FRAC16 (0.63), FRAC16 (0.73), FRAC16 (0.83), FRAC16 tFrac16 f16In1; tFrac16 f16In2; tFrac16 f16Out; GFLIB_LUT2D_T_F16 tr16tMyLut2D = GFLIB_LUT2D_DEFAULT_F16; tFrac16 pf16Table2D[81] = {FRAC16 (0.9), FRAC16 (0.01), FRAC16 (0.02), (0.04), FRAC16 (0.05), FRAC16 (0.06), FRAC16 (0.07), FRAC16 (0.08), FRAC16 (0.1), FRAC16 (0.11), FRAC16 (0.12), (0.14), FRAC16 (0.15), FRAC16 (0.16), FRAC16 (0.17), FRAC16 (0.18), FRAC16 (0.2), FRAC16 (0.21), FRAC16 (0.22), (0.24), FRAC16 (0.25), FRAC16 (0.26), FRAC16 (0.27), FRAC16 (0.28), FRAC16 (0.3), FRAC16 (0.31), FRAC16 (0.32), (0.34), FRAC16 (0.35), FRAC16 (0.36), FRAC16 (0.37), FRAC16 (0.38), FRAC16 (0.4), FRAC16 (0.41), FRAC16 (0.42), (0.44), FRAC16 (0.45), FRAC16 (0.46), FRAC16 (0.47), FRAC16 (0.48), FRAC16 (0.5), FRAC16 (0.51), FRAC16 (0.52), (0.54), FRAC16 (0.55), FRAC16 (0.56), FRAC16 (0.57), FRAC16 (0.58), FRAC16 (0.6), FRAC16 (0.61), FRAC16 (0.62), (0.64), FRAC16 (0.65), FRAC16 (0.66), FRAC16 (0.67), FRAC16 (0.68), FRAC16 (0.7), FRAC16 (0.71), FRAC16 (0.72), (0.74), FRAC16 (0.75), FRAC16 (0.76), FRAC16 (0.77), FRAC16 (0.78), FRAC16 (0.8), FRAC16 (0.81), FRAC16 (0.82), (0.84), FRAC16 (0.85), FRAC16 (0.86), FRAC16 (0.87), FRAC16 (0.88)}; FRAC16 FRAC16 FRAC16 FRAC16 FRAC16 FRAC16 FRAC16 FRAC16 FRAC16 void main(void) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 287 Function GFLIB_Lut2D_F16 { // #################################################################### // Pointer is located in the middle of the interpolating data table. // #################################################################### // setting parameters for Lut2D function tr16tMyLut2D.u16ShamOffset1 = (tU16)3; tr16tMyLut2D.u16ShamOffset2 = (tU16)3; tr16tMyLut2D.pf16Table = &(pf16Table2D[40]); // input vector f16In1 = FRAC16 (-0.5); f16In2 = FRAC16 (-0.5); // output should be 0x7333 ~ FRAC16(0.9) f16Out = GFLIB_Lut2D_F16 (f16In1,f16In2,&tr16tMyLut2D); // output should be 0x7333 ~ FRAC16(0.9) f16Out = GFLIB_Lut2D (f16In1,f16In2,&tr16tMyLut2D,F16); // available only if 16-bit fractional implementation selected as default // output should be 0x7333 ~ FRAC16(0.9) f16Out = GFLIB_Lut2D (f16In1,f16In2,&tr16tMyLut2D); // #################################################################### // Pointer is located at the beginning of the interpolating data table. // #################################################################### // setting parameters for Lut2D function tr16tMyLut2D.u16ShamOffset1 = (tU16)3; tr16tMyLut2D.u16ShamOffset2 = (tU16)3; tr16tMyLut2D.pf16Table = &(pf16Table2D[0]); // input vector f16In1 = FRAC16 (0); f16In2 = FRAC16 (0); // output should be 0x7333 ~ FRAC16(0.9) f16Out = GFLIB_Lut2D_F16 (f16In1,f16In2,&tr16tMyLut2D); // output should be 0x7333 ~ FRAC16(0.9) f16Out = GFLIB_Lut2D (f16In1,f16In2,&tr16tMyLut2D,F16); // available only if 16-bit fractional implementation selected as default // output should be 0x7333 ~ FRAC16(0.9) f16Out = GFLIB_Lut2D (f16In1,f16In2,&tr16tMyLut2D); // #################################################################### // Pointer is located at the end of the interpolating data table. // #################################################################### // setting parameters for Lut2D function tr16tMyLut2D.u16ShamOffset1 = (tU16)3; tr16tMyLut2D.u16ShamOffset2 = (tU16)3; tr16tMyLut2D.pf16Table = &(pf16Table2D[80]); // input vector f16In1 = FRAC16 (-1); f16In2 = FRAC16 (-1); // output should be 0x7333 ~ FRAC16(0.9) f16Out = GFLIB_Lut2D_F16 (f16In1,f16In2,&tr16tMyLut2D); // output should be 0x7333 ~ FRAC16(0.9) f16Out = GFLIB_Lut2D (f16In1,f16In2,&tr16tMyLut2D,F16); } // available only if 16-bit fractional implementation selected as default // output should be 0x7333 ~ FRAC16(0.9) f16Out = GFLIB_Lut2D (f16In1,f16In2,&tr16tMyLut2D); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 288 NXP Semiconductors Chapter 5 API References 5.49 Function GFLIB_Ramp_F32 The function calculates the up/down ramp with the step increment/decrement defined in the pParam structure. 5.49.1 Declaration tFrac32 GFLIB_Ramp_F32(tFrac32 f32In, GFLIB_RAMP_T_F32 *const pParam); 5.49.2 Arguments Table 5-63. GFLIB_Ramp_F32 arguments Type Name Direction Description tFrac32 f32In input Input argument representing the desired output value. GFLIB_RAMP_T_F32 *const pParam input, output Pointer to the ramp parameters structure. 5.49.3 Return The function returns a 32-bit value in format Q1.31, which represents the actual ramp output value. This, in time, is approaching the desired (input) value by step increments defined in the pParam structure. 5.49.4 Description The GFLIB_Ramp function, denoting ANSI-C compatible source code implementation, can be called via the function alias GFLIB_Ramp. If the desired (input) value is greater than the ramp output value, the function adds the f32RampUp value to the actual output value. The output cannot be greater than the desired value. If the desired value is lower than the actual value, the function subtracts the f32RampDown value from the actual value. The output cannot be lower than the desired value. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 289 Function GFLIB_Ramp_F32 Functionality of the implemented ramp algorithm can be explained with use of Figure 5-21 Figure 5-21. GFLIB_Ramp functionality Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). All parameters and states used by the function can be reset during declaration using the #GFLIB_RAMP_DEFAULT macro. 5.49.5 Re-entrancy The function is re-entrant. 5.49.6 Code Example #include "gflib.h" tFrac32 f32In; tFrac32 f32Out; GFLIB_RAMP_T_F32 f32trMyRamp = GFLIB_RAMP_DEFAULT_F32; void main(void) { // increment/decrement coefficients f32trMyRamp.f32RampUp = FRAC32 (0.1); f32trMyRamp.f32RampDown = FRAC32 (0.03333333); // input value = 0.5 f32In = FRAC32 (0.5); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 290 NXP Semiconductors Chapter 5 API References // output should be 0x0CCCCCCC ~ FRAC32(0.1) f32Out = GFLIB_Ramp_F32 (f32In, &f32trMyRamp); // clearing of the internal states f32trMyRamp.f32State = (tFrac32)0; // output should be 0x0CCCCCCC ~ FRAC32(0.1) f32Out = GFLIB_Ramp (f32In, &f32trMyRamp, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // clearing of the internal states f32trMyRamp.f32State = (tFrac32)0; // output should be 0x0CCCCCCC ~ FRAC32(0.1) f32Out = GFLIB_Ramp (f32In, &f32trMyRamp); 5.50 Function GFLIB_Ramp_F16 The function calculates the up/down ramp with the step increment/decrement defined in the pParam structure. 5.50.1 Declaration tFrac16 GFLIB_Ramp_F16(tFrac16 f16In, GFLIB_RAMP_T_F16 *const pParam); 5.50.2 Arguments Table 5-64. GFLIB_Ramp_F16 arguments Type Name Direction Description tFrac16 f16In input Input argument representing the desired output value. GFLIB_RAMP_T_F16 *const pParam input, output Pointer to the ramp parameters structure. 5.50.3 Return The function returns a 16-bit value in format Q1.15, which represents the actual ramp output value. This, in time, is approaching the desired (input) value by step increments defined in the pParam structure. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 291 Function GFLIB_Ramp_F16 5.50.4 Description The GFLIB_Ramp function, denoting ANSI-C compatible source code implementation, can be called via the function alias GFLIB_Ramp. If the desired (input) value is greater than the ramp output value, the function adds the f16RampUp value to the actual output value. The output cannot be greater than the desired value. If the desired value is lower than the actual value, the function subtracts the f16RampDown value from the actual value. The output cannot be lower than the desired value. Functionality of the implemented ramp algorithm can be explained with use of Figure 5-22 Figure 5-22. GFLIB_Ramp functionality Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). All parameters and states used by the function can be reset during declaration using the #GFLIB_RAMP_DEFAULT macro. 5.50.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 292 NXP Semiconductors Chapter 5 API References 5.50.6 Code Example #include "gflib.h" tFrac16 f16In; tFrac16 f16Out; GFLIB_RAMP_T_F16 f16trMyRamp = GFLIB_RAMP_DEFAULT_F16; void main(void) { // increment/decrement coefficients f16trMyRamp.f16RampUp = FRAC16 (0.1); f16trMyRamp.f16RampDown = FRAC16 (0.03333333); // input value = 0.5 f16In = FRAC16 (0.5); // output should be 0x0CCC ~ FRAC16(0.1) f16Out = GFLIB_Ramp_F16 (f16In, &f16trMyRamp); // clearing of the internal states f16trMyRamp.f16State = (tFrac16)0; // output should be 0x0CCC ~ FRAC16(0.1) f16Out = GFLIB_Ramp (f16In, &f16trMyRamp, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // clearing of the internal states f16trMyRamp.f16State = (tFrac16)0; // output should be 0x0CCC ~ FRAC16(0.1) f16Out = GFLIB_Ramp (f16In, &f16trMyRamp); 5.51 Function GFLIB_Sign_F32 This function returns the signum of input value. 5.51.1 Declaration tFrac32 GFLIB_Sign_F32(tFrac32 f32In); 5.51.2 Arguments Table 5-65. GFLIB_Sign_F32 arguments Type Name tFrac32 f32In Direction input Description Input argument. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 293 Function GFLIB_Sign_F32 5.51.3 Return The function returns the sign of the input argument. 5.51.4 Description The GFLIB_Sign function calculates the sign of the input argument. The function return value is computed as follows. If the input value is negative, then the return value will be set to "-1" (0x80000000 hex), if the input value is zero, then the function returns "0" (0x0 hex), otherwise if the input value is greater than zero, the return value will be "1" (0x7fffffff hex). In mathematical terms, the function works according to the equation below: Equation GFLIB_Sign_Eq1 where: • y out is the return value • x in is the input value provided as the f32In parameter Note The input and the output values are in the 32-bit fixed point fractional data format. 5.51.5 Re-entrancy The function is re-entrant. 5.51.6 Code Example #include "gflib.h" tFrac32 f32In; tFrac32 f32Out; void main(void) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 294 NXP Semiconductors Chapter 5 API References { // input value = 0.5 f32In = FRAC32 (0.5); // output should be 0x7FFFFFFF ~ FRAC32(1-(2^-31)) f32Out = GFLIB_Sign_F32 (f32In); // output should be 0x7FFFFFFF ~ FRAC32(1-(2^-31)) f32Out = GFLIB_Sign (f32In,F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x7FFFFFFF ~ FRAC32(1-(2^-31)) f32Out = GFLIB_Sign (f32In); 5.52 Function GFLIB_Sign_F16 This function returns the signum of input value. 5.52.1 Declaration tFrac16 GFLIB_Sign_F16(tFrac16 f16In); 5.52.2 Arguments Table 5-66. GFLIB_Sign_F16 arguments Type Name tFrac16 f16In Direction input Description Input argument. 5.52.3 Return The function returns the sign of the input argument. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 295 Function GFLIB_Sign_F16 5.52.4 Description The GFLIB_Sign function calculates the sign of the input argument. The function return value is computed as follows. If the input value is negative, then the return value will be set to "-1" (0x8000 hex), if the input value is zero, then the function returns "0" (0x0 hex), otherwise if the input value is greater than zero, the return value will be "1" (0x7fff hex). In mathematical terms, the function works according to the equation below: Equation GFLIB_Sign_Eq1 where: • y out is the return value • x in is the input value provided as the f16In parameter Note The input and the output values are in the 16-bit fixed point fractional data format. 5.52.5 Re-entrancy The function is re-entrant. 5.52.6 Code Example #include "gflib.h" tFrac16 f16In; tFrac16 f16Out; void main(void) { // input value = 0.5 f16In = FRAC16 (0.5); // output should be 0x7FFF ~ FRAC16(1-(2^-15)) f16Out = GFLIB_Sign_F16 (f16In); // output should be 0x7FFF ~ FRAC16(1-(2^-15)) f16Out = GFLIB_Sign (f16In,F16); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 296 NXP Semiconductors Chapter 5 API References // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x7FFF ~ FRAC16(1-(2^-15)) f16Out = GFLIB_Sign (f16In); 5.53 Function GFLIB_Sin_F32 This function implements polynomial approximation of sine function. 5.53.1 Declaration tFrac32 GFLIB_Sin_F32(tFrac32 f32In, const GFLIB_SIN_T_F32 *const pParam); 5.53.2 Arguments Table 5-67. GFLIB_Sin_F32 arguments Type Name Direction Description tFrac32 f32In input Input argument is a 32-bit number that contains an angle in radians between [- π, π) normalized between [-1, 1). const GFLIB_SIN_T_F32 *const pParam input Pointer to an array of Taylor coefficients. 5.53.3 Return The function returns the sin of the input argument as a fixed point 32-bit number, normalized between [-1, 1). 5.53.4 Description The GFLIB_Sin_F32 function provides a computational method for calculation of a standard trigonometric sine function sin(x), using the 9th order Taylor polynomial approximation. The Taylor polynomial approximation of a sine function is described as follows: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 297 Function GFLIB_Sin_F32 Equation GFLIB_Sin_Eq1 where x is the input angle. The 9th order polynomial approximation is chosen as sufficient an order to achieve the best ratio between calculation accuracy and speed of calculation. Because the GFLIB_Sin_F32 function is implemented with consideration to fixed point fractional arithmetic, all variables are normalized to fit into the [-1, 1) range. Therefore, in order to cast the fractional value of the input angle f32In [-1, 1) into the correct range [- π, π), the input f32In must be multiplied by π. So the fixed point fractional implementation of the GFLIB_Sin_F32 function, using optimized 9th order Taylor approximation, is given as follows: Equation GFLIB_Sin_Eq2 The 9th order polynomial approximation of the sine function has a very good accuracy in the range [- π/2, π/2) of the argument, but in wider ranges the calculation error quickly increases. To minimize the error without having to use a higher order polynomial, the symmetry of the sine function sin(x) = sin( π - x) is utilized. Therefore, the input argument is transferred to be always in the range [- π/2, π/2) and the Taylor polynomial is calculated only in the range of the argument [- π/2, π/2). To make calculations more precise, the given argument value f32In (that is to be transferred into the range [-0.5, 0.5) due to the sine function symmetry) is shifted by 1 bit to the left (multiplied by 2). Then, the value of f32In 2, used in the calculations, is in the range [-1, 1) instead of [-0.25, 0.25). Shifting the input value by 1 bit to the left will increase the accuracy of the calculated sin( π * f32In) function. Implementing such a scale on the approximation function described by equation GFLIB_Sin_Eq2, results in the following: Equation GFLIB_Sin_Eq3 Equation GFLIB_Sin_Eq3 can be further rewritten into the following form: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 298 NXP Semiconductors Chapter 5 API References Equation GFLIB_Sin_Eq4 where a 1 ... a 5 are coefficients of the approximation polynomial, which are calculated as follows (represented as 32-bit signed fractional numbers): Equation GFLIB_Sin_Eq5 Therefore, the resulting equation has the following form: Equation GFLIB_Sin_Eq6 Figure 5-23 depicts a floating point sine function generated from Matlab and the approximated value of the sine function obtained from GFLIB_Sin_F32, plus their difference. The course of calculation accuracy as a function of the input angle can be observed from this figure. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 299 Function GFLIB_Sin_F32 Figure 5-23. sin(x) vs. GFLIB_Sin_F32(f32In) Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The input angle (f32In) is normalized into the range [-1, 1). The function call is slightly different from common approach in the library set. The function can be called in three different ways: • With implementation postfix (i.e. GFLIB_Sin_F32(f32In, &pParam)), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_SIN_DEFAULT_F32 symbol. The &pParam parameter is mandatory. • With additional implementation parameter (i.e. GFLIB_Sin(f32In, &pParam, F32), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_SIN_DEFAULT_F32 symbol. The &pParam parameter is mandatory. • With preselected default implementation (i.e. GFLIB_Sin(f32In, &pParam), where the &pParam is pointer to approximation coefficients. The &pParam parameter is optional and in case it is not used, the default Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 300 NXP Semiconductors Chapter 5 API References GFLIB_SIN_DEFAULT_F32 approximation coefficients are used. 5.53.5 Re-entrancy The function is re-entrant. 5.53.6 Code Example #include "gflib.h" tFrac32 f32Angle; tFrac32 f32Output; void main(void) { // input angle = 0.5 => pi/2 f32Angle = FRAC32 (0.5); // output should be 0x7FFFFFFF f32Output = GFLIB_Sin_F32 (f32Angle, GFLIB_SIN_DEFAULT_F32); // output should be 0x7FFFFFFF f32Output = GFLIB_Sin (f32Angle, GFLIB_SIN_DEFAULT_F32, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x7FFFFFFF f32Output = GFLIB_Sin (f32Angle); 5.54 Function GFLIB_Sin_F16 This function implements polynomial approximation of sine function. 5.54.1 Declaration tFrac16 GFLIB_Sin_F16(tFrac16 f16In, const GFLIB_SIN_T_F16 *const pParam); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 301 Function GFLIB_Sin_F16 5.54.2 Arguments Table 5-68. GFLIB_Sin_F16 arguments Type Name Direction Description tFrac16 f16In input Input argument is a 16-bit number that contains an angle in radians between [- π, π) normalized between [-1, 1). const GFLIB_SIN_T_F16 *const pParam input Pointer to an array of Taylor coefficients. 5.54.3 Return The function returns the sin of the input argument as a fixed point 16-bit number, normalized between [-1, 1). 5.54.4 Description The GFLIB_Sin_F16 function provides a computational method for calculation of a standard trigonometric sine function sin(x), using the 7th order Taylor polynomial approximation. The Taylor polynomial approximation of a sine function is described as follows: Equation GFLIB_Sin_Eq1 where x is the input angle. The 7th order polynomial approximation is chosen as sufficient an order to achieve the best ratio between calculation accuracy and speed of calculation. Because the GFLIB_Sin_F16 function is implemented with consideration to fixed point fractional arithmetic, all variables are normalized to fit into the [-1, 1) range. Therefore, in order to cast the fractional value of the input angle f16In [-1, 1) into the correct range [- π, π), the input f16In must be multiplied by π. So the fixed point fractional implementation of the GFLIB_Sin_F16 function, using 7th order Taylor approximation, is given as follows: Equation GFLIB_Sin_Eq2 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 302 NXP Semiconductors Chapter 5 API References The 7th order polynomial approximation of the sine function has a very good accuracy in the range [- π/2, π/2) of the argument, but in wider ranges the calculation error quickly increases. To minimize the error without having to use a higher order polynomial, the symmetry of the sine function sin(x) = sin( π - x) is utilized. Therefore, the input argument is transferred to be always in the range [- π/2, π/2) and the Taylor polynomial is calculated only in the range of the argument [- π/2, π/2). To make calculations more precise, the given argument value f16In (that is to be transferred into the range [-0.5, 0.5) due to the sine function symmetry) is shifted by 1 bit to the left (multiplied by 2). Then, the value of f16In 2, used in the calculations, is in the range [-1, 1) instead of [-0.25, 0.25). Shifting the input value by 1 bit to the left will increase the accuracy of the calculated sin( π * f16In) function. Implementing such a scale on the approximation function described by equation GFLIB_Sin_Eq2, results in the following: Equation GFLIB_Sin_Eq3 Equation GFLIB_Sin_Eq3 can be further rewritten into the following form: Equation GFLIB_Sin_Eq4 where a 1 ... a 4 are coefficients of the approximation polynomial, which are calculated as follows (represented as 16-bit signed fractional numbers): Equation GFLIB_Sin_Eq5 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 303 Function GFLIB_Sin_F16 Therefore, the resulting equation has the following form: Equation GFLIB_Sin_Eq6 Figure 5-24 depicts a floating point sine function generated from Matlab and the approximated value of the sine function obtained from GFLIB_Sin_F16, plus their difference. The course of calculation accuracy as a function of the input angle can be observed from this figure. Figure 5-24. sin(x) vs. GFLIB_Sin_F16(f16In) Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The input angle (f16In) is normalized into the range [-1, 1). The function call is slightly different from common approach in the library set. The function can be called in three different ways: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 304 NXP Semiconductors Chapter 5 API References • With implementation postfix (i.e. GFLIB_Sin_F16(f16In, &pParam)), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_SIN_DEFAULT_F16 symbol. The &pParam parameter is mandatory. • With additional implementation parameter (i.e. GFLIB_Sin(f16In, &pParam, F16), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_SIN_DEFAULT_F16 symbol. The &pParam parameter is mandatory. • With preselected default implementation (i.e. GFLIB_Sin(f16In, &pParam), where the &pParam is pointer to approximation coefficients. The &pParam parameter is optional and in case it is not used, the default GFLIB_SIN_DEFAULT_F16 approximation coefficients are used. 5.54.5 Re-entrancy The function is re-entrant. 5.54.6 Code Example #include "gflib.h" tFrac16 f16Angle; tFrac16 f16Output; void main(void) { // input angle = 0.5 => pi/2 f16Angle = FRAC16 (0.5); // output should be 0x7FFF f16Output = GFLIB_Sin_F16 (f16Angle, GFLIB_SIN_DEFAULT_F16); // output should be 0x7FFF f16Output = GFLIB_Sin (f16Angle, GFLIB_SIN_DEFAULT_F16, F16); // // // // ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 305 Function GFLIB_SinCos_F32 } // output should be 0x7FFF f16Output = GFLIB_Sin (f16Angle); 5.55 Function GFLIB_SinCos_F32 This function implements polynomial approximation of sine and cosine function. 5.55.1 Declaration void GFLIB_SinCos_F32(tFrac32 f32In, SWLIBS_2Syst_F32 *pOut, const GFLIB_SINCOS_T_F32 *const pParam); 5.55.2 Arguments Table 5-69. GFLIB_SinCos_F32 arguments Type Name Direction Description tFrac32 f32In input Input argument is a 32-bit number that contains an angle in radians between [- π, π) normalized between [-1, 1). SWLIBS_2Syst_F32 * pOut output Pointer to the structure where the values of the sine and cosine of the input angle are stored. The function returns the sine and cosine of the input argument as a fixed point 32-bit number, normalized between [-1, 1). The sine of input angle is returned in first item of the structure and the cosine of input angle is returned in second item of the structure. const GFLIB_SINCOS_T_F3 2 *const pParam input Pointer to an array of Taylor coefficients. 5.55.3 Return void Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 306 NXP Semiconductors Chapter 5 API References 5.55.4 Description The GFLIB_SinCos_F32 function provides a computational method for calculation of a standard trigonometric sine function sin(x) and cosine function cos(x), using the 9th order Taylor polynomial approximation. The Taylor polynomial approximation of a sine function is used for both, sine and cosine function. The relation between cosine and sine function of the same input angle is: Equation GFLIB_SinCos_Eq1 Both results, sin(x) and cos(x), are calculated using the same approach, thus the calculation steps will be discussed for sin(x) function only. The Taylor polynomial approximation of sine function is described by the following equation: Equation GFLIB_SinCos_Eq2 where x is the input angle. The 9th order polynomial approximation is chosen as sufficient an order to achieve the best ratio between calculation accuracy and speed of calculation. Because the GFLIB_SinCos_F32 function is implemented with consideration to fixed point fractional arithmetic, all variables are normalized to fit into the [-1, 1) range. Therefore, in order to cast the fractional value of the input angle f32In [-1, 1) into the correct range [- π, π), the input f32In must be multiplied by π. So the fixed point fractional implementation of the GFLIB_SinCos_F32 function, using optimized 9th order Taylor approximation, is given as follows: Equation GFLIB_SinCos_Eq3 The 9th order polynomial approximation of the sine function has a very good accuracy in the range [- π/2, π/2) of the argument, but in wider ranges the calculation error quickly increases. To minimize the error without having to use a higher order polynomial, the symmetry of the sine function sin(x) = sin( π - x) is utilized. Therefore, the input argument is transferred to be always in the range [- π/2, π/2) and the Taylor polynomial is calculated only in the range of the argument [- π/2, π/2). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 307 Function GFLIB_SinCos_F32 To make calculations more precise, the given argument value f32In (that is to be transferred into the range [-0.5, 0.5) due to the sine function symmetry) is shifted by 1 bit to the left (multiplied by 2). Then, the value of f32In 2, used in the calculations, is in the range [-1, 1) instead of [-0.25, 0.25). Shifting the input value by 1 bit to the left will increase the accuracy of the calculated sin( π * f32In) function. Implementing such a scale on the approximation function described by equation GFLIB_SinCos_Eq3, results in the following: Equation GFLIB_SinCos_Eq4 Equation GFLIB_SinCos_Eq4 can be further rewritten into the following form: Equation GFLIB_SinCos_Eq5 where a 1 ... a 5 are coefficients of the approximation polynomial, which are calculated as follows (represented as 32-bit signed fractional numbers): Equation GFLIB_SinCos_Eq6 Therefore, the resulting equation has the following form: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 308 NXP Semiconductors Chapter 5 API References Equation GFLIB_SinCos_Eq7 Figure 5-25 depicts a floating point sine function generated from Matlab and the approximated value of the sine function obtained from GFLIB_SinCos_F32, plus their difference. The course of calculation accuracy as a function of the input angle can be observed from this figure. Figure 5-25. sin(x) vs. GFLIB_SinCos_F32(f32In) Figure 5-26 depicts a floating point cosine function generated from Matlab and the approximated value of the cosine function obtained from GFLIB_SinCos_F32, plus their difference. The course of calculation accuracy as a function of the input angle can be observed from this figure. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 309 Function GFLIB_SinCos_F32 Figure 5-26. cos(x) vs. GFLIB_SinCos_F32(f32In) Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). The input angle (f32In) is normalized into the range [-1, 1). The function call is slightly different from common approach in the library set. The function can be called in three different ways: • With implementation postfix (i.e. GFLIB_SinCos_F32(f32In, &pOut, &pParam)), where the &pOut is the pointer to output values and &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_SINCOS_DEFAULT_F32 symbol. The &pParam parameter is mandatory. • With additional implementation parameter (i.e. GFLIB_SinCos(f32In, &pOut, &pParam, F32)), where the &pOut is the pointer to output values and &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_SINCOS_DEFAULT_F32 symbol. The &pParam parameter is mandatory. • With preselected default implementation (i.e. GFLIB_SinCos(f32In, &pOut, &pParam)), where the Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 310 NXP Semiconductors Chapter 5 API References &pOut is the pointer to output values and &pParam is pointer to approximation coefficients. The &pParam parameter is optional and in case it is not used, the default GFLIB_SINCOS_DEFAULT_F32 approximation coefficients are used. 5.55.5 Re-entrancy The function is re-entrant. 5.55.6 Code Example #include "gflib.h" tFrac32 f32Angle; SWLIBS_2Syst_F32 pf32Output; void main(void) { // input angle = 0.5 => pi/2 f32Angle = FRAC32 (0.5); // output should be: // pf32Output.f32Arg1 ~ sin(f32Angle) = 0x7FFF0000 // pf32Output.f32Arg2 ~ cos(f32Angle) = 0x00000000 GFLIB_SinCos_F32 (f32Angle, &pf32Output, GFLIB_SINCOS_DEFAULT_F32); // output should be: // pf32Output.f32Arg1 ~ sin(f32Angle) = 0x7FFF0000 // pf32Output.f32Arg2 ~ cos(f32Angle) = 0x00000000 GFLIB_SinCos (f32Angle, &pf32Output, GFLIB_SINCOS_DEFAULT_F32, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be: // pf32Output.f32Arg1 ~ sin(f32Angle) = 0x7FFF0000 // pf32Output.f32Arg2 ~ cos(f32Angle) = 0x00000000 GFLIB_SinCos (f32Angle, &pf32Output); 5.56 Function GFLIB_SinCos_F16 This function implements polynomial approximation of sine and cosine function. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 311 Function GFLIB_SinCos_F16 5.56.1 Declaration void GFLIB_SinCos_F16(tFrac16 f16In, SWLIBS_2Syst_F16 *pOut, const GFLIB_SINCOS_T_F16 *const pParam); 5.56.2 Arguments Table 5-70. GFLIB_SinCos_F16 arguments Type Name Direction Description tFrac16 f16In input Input argument is a 16-bit number that contains an angle in radians between [- π, π) normalized between [-1, 1). SWLIBS_2Syst_F16 * pOut output Pointer to the structure where the values of the sine and cosine of the input angle are stored. The function returns the sine and cosine of the input argument as a fixed point 16-bit number, normalized between [-1, 1). The sine of input angle is returned in first item of the structure and the cosine of input angle is returned in second item of the structure. const GFLIB_SINCOS_T_F1 6 *const pParam input Pointer to an array of Taylor coefficients. 5.56.3 Return void 5.56.4 Description The GFLIB_SinCos_F16 function provides a computational method for calculation of a standard trigonometric sine function sin(x) and cosine function cos(x), using the 7th order Taylor polynomial approximation. The Taylor polynomial approximation of a sine function is used for both, sine and cosine function. The realation between cosine and sine function of the same input angle is: Equation GFLIB_SinCos_Eq1 Both results, sin(x) and cos(x), are calculated using the same approach, thus the calculation steps will be discussed for sin(x) function only. The Taylor polynomial approximation of sine function is described by the following equation: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 312 NXP Semiconductors Chapter 5 API References Equation GFLIB_SinCos_Eq2 where x is the input angle. The 7th order polynomial approximation is chosen as sufficient an order to achieve the best ratio between calculation accuracy and speed of calculation. Because the GFLIB_SinCos_F16 function is implemented with consideration to fixed point fractional arithmetic, all variables are normalized to fit into the [-1, 1) range. Therefore, in order to cast the fractional value of the input angle f16In [-1, 1) into the correct range [- π, π), the input f16In must be multiplied by π. So the fixed point fractional implementation of the GFLIB_SinCos_F16 function, using 7th order Taylor approximation, is given as follows: Equation GFLIB_SinCos_Eq3 The 7th order polynomial approximation of the sine function has a very good accuracy in the range [- π/2, π/2) of the argument, but in wider ranges the calculation error quickly increases. To minimize the error without having to use a higher order polynomial, the symmetry of the sine function sin(x) = sin( π - x) is utilized. Therefore, the input argument is transferred to be always in the range [- π/2, π/2) and the Taylor polynomial is calculated only in the range of the argument [- π/2, π/2). To make calculations more precise, the given argument value f16In (that is to be transferred into the range [-0.5, 0.5) due to the sine function symmetry) is shifted by 1 bit to the left (multiplied by 2). Then, the value of f16In 2, used in the calculations, is in the range [-1, 1) instead of [-0.25, 0.25). Shifting the input value by 1 bit to the left will increase the accuracy of the calculated sin( π * f16In) function. Implementing such a scale on the approximation function described by equation GFLIB_SinCos_Eq3, results in the following: Equation GFLIB_SinCos_Eq4 Equation GFLIB_SinCos_Eq4 can be further rewritten into the following form: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 313 Function GFLIB_SinCos_F16 Equation GFLIB_SinCos_Eq5 where a 1 ... a 4 are coefficients of the approximation polynomial, which are calculated as follows (represented as 16-bit signed fractional numbers): Equation GFLIB_SinCos_Eq6 Therefore, the resulting equation has the following form: Equation GFLIB_SinCos_Eq7 Figure 5-27 depicts a floating point sine function generated from Matlab and the approximated value of the sine function obtained from GFLIB_SinCos_F16, plus their difference. The course of calculation accuracy as a function of the input angle can be observed from this figure. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 314 NXP Semiconductors Chapter 5 API References Figure 5-27. sin(x) vs. GFLIB_SinCos_F16(f16In) Figure 5-28 depicts a floating point cosine function generated from Matlab and the approximated value of the cosine function obtained from GFLIB_SinCos_F16, plus their difference. The course of calculation accuracy as a function of the input angle can be observed from this figure. Figure 5-28. cos(x) vs. GFLIB_SinCos_F16(f16In) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 315 Function GFLIB_SinCos_F16 Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). The input angle (f16In) is normalized into the range [-1, 1). The function call is slightly different from common approach in the library set. The function can be called in three different ways: • With implementation postfix (i.e. GFLIB_SinCos_F16(f16In, &pOut, &pParam)), where the &pOut is the pointer to output values and &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_SINCOS_DEFAULT_F16 symbol. The &pParam parameter is mandatory. • With additional implementation parameter (i.e. GFLIB_SinCos(f16In, &pOut, &pParam, F16)), where the &pOut is the pointer to output values and &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_SINCOS_DEFAULT_F16 symbol. The &pParam parameter is mandatory. • With preselected default implementation (i.e. GFLIB_SinCos(f16In, &pOut, &pParam)), where the &pOut is the pointer to output values and &pParam is pointer to approximation coefficients. The &pParam parameter is optional and in case it is not used, the default GFLIB_SINCOS_DEFAULT_F16 approximation coefficients are used. 5.56.5 Re-entrancy The function is re-entrant. 5.56.6 Code Example #include "gflib.h" tFrac16 f16Angle; SWLIBS_2Syst_F16 pf16Output; void main(void) { Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 316 NXP Semiconductors Chapter 5 API References // input angle = 0.5 => pi/2 f16Angle = FRAC16 (0.5); // output should be: // pf16Output.f16Arg1 ~ sin(f16Angle) = 0x7FFF // pf16Output.f16Arg2 ~ cos(f16Angle) = 0x0000 GFLIB_SinCos_F16 (f16Angle, &pf16Output, GFLIB_SINCOS_DEFAULT_F16); // output should be: // pf16Output.f16Arg1 ~ sin(f16Angle) = 0x7FFF // pf16Output.f16Arg2 ~ cos(f16Angle) = 0x0000 GFLIB_SinCos (f16Angle, &pf16Output, GFLIB_SINCOS_DEFAULT_F16, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be: // pf16Output.f16Arg1 ~ sin(f16Angle) = 0x7FFF // pf16Output.f16Arg2 ~ cos(f16Angle) = 0x0000 GFLIB_SinCos (f16Angle, &pf16Output); 5.57 Function GFLIB_Sqrt_F32 This function returns the square root of input value. 5.57.1 Declaration tFrac32 GFLIB_Sqrt_F32(tFrac32 f32In); 5.57.2 Arguments Table 5-71. GFLIB_Sqrt_F32 arguments Type Name tFrac32 f32In Direction input Description The input value. 5.57.3 Return The function returns the square root of the input value. The return value is within the [0, 1) fraction range. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 317 Function GFLIB_Sqrt_F32 5.57.4 Description The GFLIB_Sqrt_F32 function computes the square root of the input value. The computations are made by a simple iterative testing of each bit starting from the most significant one. In total, 15 iterations are made, each performing the following steps: 1. Add to the tentative square root value a single testing bit. 2. Square the tentative square root value and test whether it is greater or lower than the input value. 3. If greater, then clear the bit in the tentative square root value. 4. Shift the single testing bit right Figure 5-29. real sqrt(x) vs. GFLIB_Sqrt(f32In) Note The input value is limited to the range [0, 1), if not within this range the function returns zero. 5.57.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 318 NXP Semiconductors Chapter 5 API References 5.57.6 Code Example #include "gflib.h" tFrac32 f32In; tFrac32 f32Out; void main(void) { // input value = 0.5 f32In = FRAC32 (0.5); // output should be 0x5A820000 ~ FRAC32(0.70710678) f32Out = GFLIB_Sqrt_F32 (f32In); // output should be 0x5A820000 ~ FRAC32(0.70710678) f32Out = GFLIB_Sqrt (f32In,F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x5A820000 ~ FRAC32(0.70710678) f32Out = GFLIB_Sqrt (f32In); 5.58 Function GFLIB_Sqrt_F16 This function returns the square root of input value. 5.58.1 Declaration tFrac16 GFLIB_Sqrt_F16(tFrac16 f16In); 5.58.2 Arguments Table 5-72. GFLIB_Sqrt_F16 arguments Type Name tFrac16 f16In Direction input Description The input value. 5.58.3 Return The function returns the square root of the input value. The return value is within the [0, 1) fraction range. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 319 Function GFLIB_Sqrt_F16 5.58.4 Description The GFLIB_Sqrt_F16 function computes the square root of the input value. The computations are made by a simple iterative testing of each bit starting from the most significant one. In total, 15 iterations are made, each performing the following steps: 1. Add to the tentative square root value a single testing bit. 2. Square the tentative square root value and test whether it is greater or lower than the input value. 3. If greater, then clear the bit in the tentative square root value. 4. Shift the single testing bit right Figure 5-30. real sqrt(x) vs. GFLIB_Sqrt(f16In) Note The input value is limited to the range [0, 1), if not within this range the function returns zero. 5.58.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 320 NXP Semiconductors Chapter 5 API References 5.58.6 Code Example #include "gflib.h" tFrac16 f16In; tFrac16 f16Out; void main(void) { // input value = 0.5 f16In = FRAC16 (0.5); // output should be 0x5A82 ~ FRAC16(0.70710678) f16Out = GFLIB_Sqrt_F16 (f16In); // output should be 0x5A82 ~ FRAC16(0.70710678) f16Out = GFLIB_Sqrt (f16In,F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x5A82 ~ FRAC16(0.70710678) f16Out = GFLIB_Sqrt (f16In); 5.59 Function GFLIB_Tan_F32 This function implements polynomial approximation of tangent function. 5.59.1 Declaration tFrac32 GFLIB_Tan_F32(tFrac32 f32In, const GFLIB_TAN_T_F32 *const pParam); 5.59.2 Arguments Table 5-73. GFLIB_Tan_F32 arguments Type Name Direction Description tFrac32 f32In input Input argument is a 32-bit number that contains an angle in radians between [- π, π) normalized between [-1, 1). const GFLIB_TAN_T_F32 *const pParam input Pointer to an array of Taylor coefficients. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 321 Function GFLIB_Tan_F32 5.59.3 Return The function returns tan( π * f32In) as a fixed point 32-bit number, normalized between [-1, 1). 5.59.4 Description The GFLIB_Tan_F32 function provides a computational method for calculation of a standard trigonometric tangent function tan(x), using the piece-wise polynomial approximation. Function tan(x) takes an angle and returns the ratio of two sides of a right-angled triangle. The ratio is the length of the side opposite the angle divided by the length of the side adjacent to the angle. Therefore, the tangent function is defined by: Equation GFLIB_Tan_Eq1 Because both sin(x) and cos(x) are defined on interval [- π, π), function tan(x) is equal to zero when sin(x)=0 and is equal to infinity when cos(x)=0. Therefore, the tangent function has asymptotes at n*π/2 for n=1, 3, 5,... The graph of tan(x) is shown in Figure 5-31. Figure 5-31. Course of the function GFLIB_Tan Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 322 NXP Semiconductors Chapter 5 API References The GFLIB_Tan_F32 function is implemented with consideration to fixed point fractional arithmetic, hence all tangent values falling beyond [-1, 1) are truncated to -1 and 1 respectively. This truncation is applied for angles in the ranges [-3 π/4, - π/4) and [ π/4, 3 π/4). As can be further seen from Figure 5-31, tangent values are identical for angles in the ranges: 1. [- π/4, 0) and [3 π/4, π) 2. [- π, -3 π/4) and [0, π/4) Moreover, it can be observed from Figure 5-31 that the course of the tan(x) function output for angles in interval 1. is identical, but with the opposite sign, to output for angles in interval 2. Therefore, the approximation of the tangent function over the entire defined range of input angles can be simplified to an approximation for angles in the range [0, π/4), and then, depending on the input angle, the result will be negated. In order to increase the accuracy of approximation without the need for a higher order polynomial, the interval [0, π/4) is further divided into eight equally spaced sub intervals, and polynomial approximation is done for each interval respectively. Such a division results in eight sets of polynomial coefficients. Moreover, it allows using a polynomial of only the 4th order to achieve an accuracy of less than 0.5LSB (on the upper 16 bits of 32-bit results) across the full range of input angles. The GFLIB_Tan_F32 function uses fixed point fractional arithmetic, so to cast the fractional value of the input angle f32In [-1, 1) into the correct range [- π, π), the fixed point input angle f32In must be multiplied by π. Then the fixed point fractional implementation of the approximation polynomial, used for calculation of each sub sector, is defined as follows: Equation GFLIB_Tan_Eq2 Equation GFLIB_Tan_Eq3 The division of the [0, π/4) interval into eight sub-intervals, with polynomial coefficients calculated for each sub-interval, is noted in Table 5-74. Polynomial coefficients were obtained using the Matlab fitting function, where a polynomial of the 4th order was used for the fitting of each respective sub-interval. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 323 Function GFLIB_Tan_F32 Table 5-74. Integer polynomial coefficients for each interval Interval a1 a2 a3 a4 <0, π/32) 688168 1024000 211337216 105498624 < π/32, 2 π/32) 737280 3145728 107732992 318550016 <2 π/32, 3 π/32) 851968 5521408 224055296 537917440 <3 π/32, 4 π/32) 1064960 8364032 237821952 768380928 <4 π/32, 5 π/32) 1392640 12001280 257990656 1015683072 <5 π/32, 6 π/32) 1916928 16900096 286568448 1287151616 <6 π/32, 7 π/32) 2785280 23855104 326795264 1592680448 <7 π/32, 8 π/32) 4292608 34275328 384016384 1946363904 Figure 5-32. tan(x) vs. GFLIB_Tan(f32In) Figure 5-32 depicts a floating point tangent function generated from Matlab and the approximated value of the tangent function obtained from GFLIB_Tan_F32, plus their difference. The course of calculation accuracy as a function of the input angle can be observed from this figure. The achieved accuracy with consideration to the 4th order piece-wise polynomial approximation and described fixed point scaling is less than 0.5LSB on the upper 16 bits of the 32-bit result. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 324 NXP Semiconductors Chapter 5 API References The input angle (f32In) is normalized into the range [-1, 1). The function call is slightly different from common approach in the library set. The function can be called in three different ways: • With implementation postfix (i.e. GFLIB_Tan_F32(f32In, &pParam)), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_TAN_DEFAULT_F32 symbol. The &pParam parameter is mandatory. • With additional implementation parameter (i.e. GFLIB_Tan(f32In, &pParam, F32), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_TAN_DEFAULT_F32 symbol. The &pParam parameter is mandatory. • With preselected default implementation (i.e. GFLIB_Tan(f32In, &pParam), where the &pParam is pointer to approximation coefficients. The &pParam parameter is optional and in case it is not used, the default GFLIB_TAN_DEFAULT_F32 approximation coefficients are used. 5.59.5 Re-entrancy The function is re-entrant. 5.59.6 Code Example #include "gflib.h" tFrac32 f32Angle; tFrac32 f32Output; void main(void) { // input angle = 0.25 => pi/4 f32Angle = FRAC32 (0.25); // output should be 0x7FFFFFFF = 1 f32Output = GFLIB_Tan_F32 (f32Angle, GFLIB_TAN_DEFAULT_F32); // output should be 0x7FFFFFFF = 1 f32Output = GFLIB_Tan (f32Angle, GFLIB_TAN_DEFAULT_F32, F32); // ############################################################## // Available only if 32-bit fractional implementation selected Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 325 Function GFLIB_Tan_F16 // as default // ############################################################## } // output should be 0x7FFFFFFF = 1 f32Output = GFLIB_Tan (f32Angle); 5.60 Function GFLIB_Tan_F16 This function implements polynomial approximation of tangent function. 5.60.1 Declaration tFrac16 GFLIB_Tan_F16(tFrac16 f16In, const GFLIB_TAN_T_F16 *const pParam); 5.60.2 Arguments Table 5-75. GFLIB_Tan_F16 arguments Type Name Direction Description tFrac16 f16In input Input argument is a 16-bit number that contains an angle in radians between [- π, π) normalized between [-1, 1). const GFLIB_TAN_T_F16 *const pParam input Pointer to an array of Taylor coefficients. 5.60.3 Return The function returns tan( π * f16In) as a fixed point 16-bit number, normalized between [-1, 1). 5.60.4 Description The GFLIB_Tan_F16 function provides a computational method for calculation of a standard trigonometric tangent function tan(x), using the piece-wise polynomial approximation. Function tan(x) takes an angle and returns the ratio of two sides of a right-angled triangle. The ratio is the length of the side opposite the angle divided by the length of the side adjacent to the angle. Therefore, the tangent function is defined by: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 326 NXP Semiconductors Chapter 5 API References Equation GFLIB_Tan_Eq1 Because both sin(x) and cos(x) are defined on interval [- π, π), function tan(x) is equal to zero when sin(x)=0 and is equal to infinity when cos(x)=0. Therefore, the tangent function has asymptotes at n*π/2 for n=1, 3, 5,... The graph of tan(x) is shown in Figure 5-33. Figure 5-33. Course of the function GFLIB_Tan The GFLIB_Tan_F16 function is implemented with consideration to fixed point fractional arithmetic, hence all tangent values falling beyond [-1, 1) are truncated to -1 and 1 respectively. This truncation is applied for angles in the ranges [-3 π/4, - π/4) and [ π/4, 3 π/4). As can be further seen from Figure 5-33, tangent values are identical for angles in the ranges: 1. [- π/4, 0) and [3 π/4, π) 2. [- π,- 3 π/4) and [0, π/4) Moreover, it can be observed from Figure 5-33 that the course of the tan(x) function output for angles in interval 1. is identical, but with the opposite sign, to output for angles in interval 2. Therefore, the approximation of the tangent function over the entire defined range of input angles can be simplified to an approximation for angles in the range [0, π/4), and then, depending on the input angle, the result will be negated. In order to increase the accuracy of approximation without the need for a higher order polynomial, the interval [0, π/4) is further divided into eight equally spaced sub intervals, and polynomial approximation is done for each interval respectively. Such a division results in eight sets of polynomial coefficients. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 327 Function GFLIB_Tan_F16 The GFLIB_Tan_F16 function uses fixed point fractional arithmetic, so to cast the fractional value of the input angle f16In [-1, 1) into the correct range [- π, π), the fixed point input angle f16In must be multiplied by π. Then the fixed point fractional implementation of the approximation polynomial, used for calculation of each sub sector, is defined as follows: Equation GFLIB_Tan_Eq2 Equation GFLIB_Tan_Eq3 The division of the [0, π/4) interval into eight sub-intervals, with polynomial coefficients calculated for each sub-interval, is noted in Table 5-76. Polynomial coefficients were obtained using the Matlab fitting function, where a polynomial of the 4th order was used for the fitting of each respective sub-interval. Table 5-76. Integer polynomial coefficients for each interval Interval a1 a2 a3 a4 <0, π/32) 11 160 3225 1610 < π/32, 2 π/32) 11 48 3288 4861 <2 π/32, 3 π/32) 13 84 3419 8208 <3 π/32, 4 π/32) 16 128 3629 11725 <4 π/32, 5 π/32) 21 183 3937 15498 <5 π/32, 6 π/32) 29 258 4373 19640 <6 π/32, 7 π/32) 43 364 4987 24302 <7 π/32, 8 π/32) 66 523 5860 29699 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 328 NXP Semiconductors Chapter 5 API References Figure 5-34. tan(x) vs. GFLIB_Tan(f16In) Figure 5-34 depicts a floating point tangent function generated from Matlab and the approximated value of the tangent function obtained from GFLIB_Tan_F16, plus their difference. The course of calculation accuracy as a function of the input angle can be observed from this figure. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). The input angle (f16In) is normalized into the range [-1, 1). The function call is slightly different from common approach in the library set. The function can be called in three different ways: • With implementation postfix (i.e. GFLIB_Tan_F16(f16In, &pParam)), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be replaced with GFLIB_TAN_DEFAULT_F16 symbol. The &pParam parameter is , mandatory. • With additional implementation parameter (i.e. GFLIB_Tan(f16In, &pParam, F16), where the &pParam is pointer to approximation coefficients. In case the default approximation coefficients are used, the &pParam must be Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 329 Function GFLIB_UpperLimit_F32 replaced with GFLIB_TAN_DEFAULT_F16 symbol. The &pParam parameter is mandatory. • With preselected default implementation (i.e. GFLIB_Tan(f16In, &pParam), where the &pParam is pointer to approximation coefficients. The &pParam parameter is optional and in case it is not used, the default GFLIB_TAN_DEFAULT_F16 approximation coefficients are used. 5.60.5 Re-entrancy The function is re-entrant. 5.60.6 Code Example #include "gflib.h" tFrac16 f16Angle; tFrac16 f16Output; void main(void) { // input angle = 0.25 => pi/4 f16Angle = FRAC16 (0.25); // output should be 0x7FFF = 1 f16Output = GFLIB_Tan_F16 (f16Angle, GFLIB_TAN_DEFAULT_F16); // output should be 0x7FFF = 1 f16Output = GFLIB_Tan (f16Angle, GFLIB_TAN_DEFAULT_F16, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x7FFF = 1 f16Output = GFLIB_Tan (f16Angle); 5.61 Function GFLIB_UpperLimit_F32 This function tests whether the input value is below the upper limit. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 330 NXP Semiconductors Chapter 5 API References 5.61.1 Declaration tFrac32 GFLIB_UpperLimit_F32(tFrac32 f32In, const GFLIB_UPPERLIMIT_T_F32 *const pParam); 5.61.2 Arguments Table 5-77. GFLIB_UpperLimit_F32 arguments Type Name tFrac32 f32In const pParam GFLIB_UPPERLIMIT_T _F32 *const Direction Description input Input value. input Pointer to the limits structure. 5.61.3 Return The input value in case the input value is below the limit, or the upper limit if the input value is above the limit. 5.61.4 Description The GFLIB_UpperLimit function tests whether the input value is below the upper limit. If so, the input value will be returned. Otherwise, if the input value is above the upper limit, the upper limit will be returned. The upper limit f32UpperLimit can be found in the parameters structure, supplied to the function as a pointer pParam. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). 5.61.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 331 Function GFLIB_UpperLimit_F16 5.61.6 Code Example #include "gflib.h" tFrac32 f32In; tFrac32 f32Out; GFLIB_UPPERLIMIT_T_F32 f32trMyUpperLimit = GFLIB_UPPERLIMIT_DEFAULT_F32; void main(void) { // upper limit f32trMyUpperLimit.f32UpperLimit = FRAC32 (0.5); // input value = 0.75 f32In = FRAC32 (0.75); // output should be 0x40000000 ~ FRAC32(0.5) f32Out = GFLIB_UpperLimit_F32 (f32In,&f32trMyUpperLimit); // output should be 0x40000000 ~ FRAC32(0.5) f32Out = GFLIB_UpperLimit (f32In,&f32trMyUpperLimit,F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x40000000 ~ FRAC32(0.5) f32Out = GFLIB_UpperLimit (f32In,&f32trMyUpperLimit); 5.62 Function GFLIB_UpperLimit_F16 This function tests whether the input value is below the upper limit. 5.62.1 Declaration tFrac16 GFLIB_UpperLimit_F16(tFrac16 f16In, const GFLIB_UPPERLIMIT_T_F16 *const pParam); 5.62.2 Arguments Table 5-78. GFLIB_UpperLimit_F16 arguments Type tFrac16 Name f16In const pParam GFLIB_UPPERLIMIT_T _F16 *const Direction Description input Input value. input Pointer to the limits structure. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 332 NXP Semiconductors Chapter 5 API References 5.62.3 Return The input value in case the input value is below the limit, or the upper limit if the input value is above the limit. 5.62.4 Description The GFLIB_UpperLimit function tests whether the input value is below the upper limit. If so, the input value will be returned. Otherwise, if the input value is above the upper limit, the upper limit will be returned. The upper limit f16UpperLimit can be found in the parameters structure, supplied to the function as a pointer pParam. Note The input pointer must contain a valid address otherwise a fault may occur (HardFault). 5.62.5 Re-entrancy The function is re-entrant. 5.62.6 Code Example #include "gflib.h" tFrac16 f16In; tFrac16 f16Out; GFLIB_UPPERLIMIT_T_F16 f16trMyUpperLimit = GFLIB_UPPERLIMIT_DEFAULT_F16; void main(void) { // upper limit f16trMyUpperLimit.f16UpperLimit = FRAC16 (0.5); // input value = 0.75 f16In = FRAC16 (0.75); // output should be 0x4000 ~ FRAC16(0.5) f16Out = GFLIB_UpperLimit_F16 (f16In,&f16trMyUpperLimit); // output should be 0x4000 ~ FRAC16(0.5) f16Out = GFLIB_UpperLimit (f16In,&f16trMyUpperLimit,F16); // // // // ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 333 Function GFLIB_VectorLimit_F32 } // output should be 0x4000 ~ FRAC16(0.5) f16Out = GFLIB_UpperLimit (f16In,&f16trMyUpperLimit); 5.63 Function GFLIB_VectorLimit_F32 This function limits the magnitude of the input vector. 5.63.1 Declaration tBool GFLIB_VectorLimit_F32(SWLIBS_2Syst_F32 *const pOut, const SWLIBS_2Syst_F32 *const pIn, const GFLIB_VECTORLIMIT_T_F32 *const pParam); 5.63.2 Arguments Table 5-79. GFLIB_VectorLimit_F32 arguments Type Name Direction Description const SWLIBS_2Syst_F32 *const pIn input Pointer to the structure of the input vector. SWLIBS_2Syst_F32 *const pOut output Pointer to the structure of the limited output vector. const GFLIB_VECTORLIMIT _T_F32 *const pParam input Pointer to the parameters structure. 5.63.3 Return The function will return true "TRUE" if the input vector is being limited, or false "FALSE" otherwise. 5.63.4 Description The GFLIB_VectorLimit function limits the magnitude of the input vector, keeping its direction unchanged. Limitation is performed as follows: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 334 NXP Semiconductors Chapter 5 API References Equation GFLIB_VectorLimit_Eq1 Equation GFLIB_VectorLimit_Eq2 Where: • x in, y in and x out, y out are the co-ordinates of the input and output vector, respectively • L is the maximum magnitude of the vector The input vector co-ordinates are defined by the structure pointed to by the pIn parameter, and the output vector co-ordinates be found in the structure pointed by the pOut parameter. The maximum vector magnitude is defined in the parameters structure pointed to by the pParam function parameter. A graphical interpretation of the function can be seen in the figure below. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 335 Function GFLIB_VectorLimit_F32 Figure 5-35. Graphical interpretation of the GFLIB_VectorLimit function. If an actual limitation occurs, the function will return the logical true (TRUE), otherwise the logical false will be returned (FALSE). For computational reasons, the output vector will be computed as zero if the input vector magnitude is lower than 2 -15, regardless of the set maximum magnitude of the input vector. The function returns the logical true (TRUE) in this case. Also, the 16 least significant bits of the maximum vector magnitude in the parameters structure, the pParam->f32Limit, are ignored. This means that the defined magnitude must be equal to or greater than 2 -15, otherwise the result is undefined. Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). The function calls the AMMCLIB square root routine GFLIB_Sqrt. CAUTION The maximum vector magnitude in the parameters structure, the pParam->f32Limit, must be positive and equal to or greater than 2 -15, otherwise the result is undefined. The function does not check for the valid range of pParam->f32Limit. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 336 NXP Semiconductors Chapter 5 API References 5.63.5 Re-entrancy The function is re-entrant. 5.63.6 Code Example #include "gflib.h" SWLIBS_2Syst_F32 f32pIn; SWLIBS_2Syst_F32 f32pOut; GFLIB_VECTORLIMIT_T_F32 f32trMyVectorLimit = GFLIB_VECTORLIMIT_DEFAULT_F32; tBool bLim; void main(void) { // desired magnitude of the input vector f32trMyVectorLimit.f32Limit = FRAC32 (0.25); // input vector f32pIn.f32Arg1 = FRAC32 (0.25); f32pIn.f32Arg2 = FRAC32 (0.25); // output should be: // bLim = TRUE; // f32pOut.f32Arg1 = 0x16A08000 ~ FRAC32(0.17677) // f32pOut.f32Arg2 = 0x16A08000 ~ FRAC32(0.17677) bLim = GFLIB_VectorLimit_F32 (&f32pOut,&f32pIn,&f32trMyVectorLimit); // output should be: // bLim = TRUE; // f32pOut.f32Arg1 = 0x16A08000 ~ FRAC32(0.17677) // f32pOut.f32Arg2 = 0x16A08000 ~ FRAC32(0.17677) bLim = GFLIB_VectorLimit (&f32pOut,&f32pIn,&f32trMyVectorLimit,F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be: // bLim = TRUE; // f32pOut.f32Arg1 = 0x16A08000 ~ FRAC32(0.17677) // f32pOut.f32Arg2 = 0x16A08000 ~ FRAC32(0.17677) bLim = GFLIB_VectorLimit (&f32pOut,&f32pIn,&f32trMyVectorLimit); 5.64 Function GFLIB_VectorLimit_F16 This function limits the magnitude of the input vector. 5.64.1 Declaration tBool GFLIB_VectorLimit_F16(SWLIBS_2Syst_F16 *const pOut, const SWLIBS_2Syst_F16 *const pIn, const GFLIB_VECTORLIMIT_T_F16 *const pParam); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 337 Function GFLIB_VectorLimit_F16 5.64.2 Arguments Table 5-80. GFLIB_VectorLimit_F16 arguments Type Name Direction Description const SWLIBS_2Syst_F16 *const pIn input Pointer to the structure of the input vector. SWLIBS_2Syst_F16 *const pOut output Pointer to the structure of the limited output vector. const GFLIB_VECTORLIMIT _T_F16 *const pParam input Pointer to the parameters structure. 5.64.3 Return The function will return true "TRUE" if the input vector is being limited, or false "FALSE" otherwise. 5.64.4 Description The GFLIB_VectorLimit function limits the magnitude of the input vector, keeping its direction unchanged. Limitation is performed as follows: Equation GFLIB_VectorLimit_Eq1 Equation GFLIB_VectorLimit_Eq2 Where: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 338 NXP Semiconductors Chapter 5 API References • x in, y in and x out, y out are the co-ordinates of the input and output vector, respectively • L is the maximum magnitude of the vector The input vector co-ordinates are defined by the structure pointed to by the pIn parameter, and the output vector co-ordinates be found in the structure pointed by the pOut parameter. The maximum vector magnitude is defined in the parameters structure pointed to by the pParam function parameter. A graphical interpretation of the function can be seen in the figure below. Figure 5-36. Graphical interpretation of the GFLIB_VectorLimit function. If an actual limitation occurs, the function will return the logical true (TRUE), otherwise the logical false will be returned (FALSE). Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). The function calls the AMMCLIB square root routine GFLIB_Sqrt. CAUTION The maximum vector magnitude in the parameters structure, the pParam->f16Limit, must be positive and equal to or greater than "0", otherwise the result is undefined. The function does not check for the valid range of the parameter pParam>f16Limit. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 339 Function GMCLIB_Clark_F32 5.64.5 Re-entrancy The function is re-entrant. 5.64.6 Code Example #include "gflib.h" SWLIBS_2Syst_F16 f16pIn; SWLIBS_2Syst_F16 f16pOut; GFLIB_VECTORLIMIT_T_F16 f16trMyVectorLimit = GFLIB_VECTORLIMIT_DEFAULT_F16; tBool bLim; void main(void) { // desired magnitude of the input vector f16trMyVectorLimit.f16Limit = FRAC16 (0.25); // input vector f16pIn.f16Arg1 = FRAC16 (0.25); f16pIn.f16Arg2 = FRAC16 (0.25); // output should be: // bLim = TRUE; // f16pOut.f16Arg1 = 0x16A0 ~ FRAC16(0.17677) // f16pOut.f16Arg2 = 0x16A0 ~ FRAC16(0.17677) bLim = GFLIB_VectorLimit_F16 (&f16pOut,&f16pIn,&f16trMyVectorLimit); // output should be: // bLim = TRUE; // f16pOut.f16Arg1 = 0x16A0 ~ FRAC16(0.17677) // f16pOut.f16Arg2 = 0x16A0 ~ FRAC16(0.17677) bLim = GFLIB_VectorLimit (&f16pOut,&f16pIn,&f16trMyVectorLimit,F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be: // bLim = TRUE; // f16pOut.f16Arg1 = 0x16A0 ~ FRAC16(0.17677) // f16pOut.f16Arg2 = 0x16A0 ~ FRAC16(0.17677) bLim = GFLIB_VectorLimit (&f16pOut,&f16pIn,&f16trMyVectorLimit); 5.65 Function GMCLIB_Clark_F32 The function implements the Clarke transformation. 5.65.1 Declaration void GMCLIB_Clark_F32(SWLIBS_2Syst_F32 *const pOut, const SWLIBS_3Syst_F32 *const pIn); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 340 NXP Semiconductors Chapter 5 API References 5.65.2 Arguments Table 5-81. GMCLIB_Clark_F32 arguments Type Name Direction Description const SWLIBS_3Syst_F32 *const pIn input Pointer to the structure containing data of the three-phase stationary system (f32A-f32B-f32C). Arguments of the structure contain fixed point 32-bit values. SWLIBS_2Syst_F32 *const pOut output Pointer to the structure containing data of the two-phase stationary orthogonal system ( α- β). Arguments of the structure contain fixed point 32-bit values. 5.65.3 Return Function returns no value. 5.65.4 Description The Clarke Transformation is used to transform values from the three-phase (A-B-C) coordinate system to the two-phase ( α- β) orthogonal coordinate system, according to the following equations: Equation GMCLIB_Clark_Eq1 Equation GMCLIB_Clark_Eq2 where it is assumed that the axis f32A (axis of the first phase) and the axis α are in the same direction. Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 341 Function GMCLIB_Clark_F16 The inputs and the outputs are normalized to fit in the range [-1, 1). 5.65.5 Re-entrancy The function is re-entrant. 5.65.6 Code Example #include "gmclib.h" SWLIBS_3Syst_F32 f32trAbc; SWLIBS_2Syst_F32 f32trAlBe; void main(void) { // input phase A // input phase B // input phase C f32trAbc.f32Arg1 f32trAbc.f32Arg2 f32trAbc.f32Arg3 ~ ~ ~ = = = sin(45) ~ 0.707106781 sin(45 + 120) ~ 0.258819045 sin(45 - 120) ~ -0.965925826 FRAC32 (0.707106781); FRAC32 (0.258819045); FRAC32 (-0.965925826); // output should be f32trAlBe.f32Arg1 = 0x5A827999 ~ FRAC32(0.707106781) // output should be f32trAlBe.f32Arg2 = 0x5A827999 ~ FRAC32(0.707106781) GMCLIB_Clark_F32 (&f32trAlBe,&f32trAbc); // output should be f32trAlBe.f32Arg1 = 0x5A827999 ~ FRAC32(0.707106781) // output should be f32trAlBe.f32Arg2 = 0x5A827999 ~ FRAC32(0.707106781) GMCLIB_Clark (&f32trAlBe,&f32trAbc,F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be f32trAlBe.f32Arg1 = 0x5A827999 ~ FRAC32(0.707106781) // output should be f32trAlBe.f32Arg2 = 0x5A827999 ~ FRAC32(0.707106781) GMCLIB_Clark (&f32trAlBe,&f32trAbc); 5.66 Function GMCLIB_Clark_F16 The function implements the Clarke transformation. 5.66.1 Declaration void GMCLIB_Clark_F16(SWLIBS_2Syst_F16 *const pOut, const SWLIBS_3Syst_F16 *const pIn); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 342 NXP Semiconductors Chapter 5 API References 5.66.2 Arguments Table 5-82. GMCLIB_Clark_F16 arguments Type Name Direction Description const SWLIBS_3Syst_F16 *const pIn input Pointer to the structure containing data of the three-phase stationary system (f16A-f16B-f16C). Arguments of the structure contain fixed point 16-bit values. SWLIBS_2Syst_F16 *const pOut output Pointer to the structure containing data of the two-phase stationary orthogonal system ( α- β). Arguments of the structure contain fixed point 16-bit values. 5.66.3 Return Function returns no value. 5.66.4 Description The Clarke Transformation is used to transform values from the three-phase (A-B-C) coordinate system to the two-phase ( α- β) orthogonal coordinate system, according to the following equations: Equation GMCLIB_Clark_Eq1 Equation GMCLIB_Clark_Eq2 where it is assumed that the axis f16A (axis of the first phase) and the axis α are in the same direction. Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). The inputs and the outputs are normalized to fit in the range [-1, 1). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 343 Function GMCLIB_ClarkInv_F32 5.66.5 Re-entrancy The function is re-entrant. 5.66.6 Code Example #include "gmclib.h" SWLIBS_3Syst_F16 f16trAbc; SWLIBS_2Syst_F16 f16trAlBe; void main(void) { // input phase A // input phase B // input phase C f16trAbc.f16Arg1 f16trAbc.f16Arg2 f16trAbc.f16Arg3 ~ ~ ~ = = = sin(45) ~ 0.707106781 sin(45 + 120) ~ 0.258819045 sin(45 - 120) ~ -0.965925826 FRAC16 (0.707106781); FRAC16 (0.258819045); FRAC16 (-0.965925826); // output should be f16trAlBe.f16Arg1 = 0x5A82 ~ FRAC16(0.707106781) // output should be f16trAlBe.f16Arg2 = 0x5A82 ~ FRAC16(0.707106781) GMCLIB_Clark_F16 (&f16trAlBe,&f16trAbc); // output should be f16trAlBe.f16Arg1 = 0x5A82 ~ FRAC16(0.707106781) // output should be f16trAlBe.f16Arg2 = 0x5A82 ~ FRAC16(0.707106781) GMCLIB_Clark (&f16trAlBe,&f16trAbc,F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be f16trAlBe.f16Arg1 = 0x5A82 ~ FRAC16(0.707106781) // output should be f16trAlBe.f16Arg2 = 0x5A82 ~ FRAC16(0.707106781) GMCLIB_Clark (&f16trAlBe,&f16trAbc); 5.67 Function GMCLIB_ClarkInv_F32 The function implements the inverse Clarke transformation. 5.67.1 Declaration void GMCLIB_ClarkInv_F32(SWLIBS_3Syst_F32 *const pOut, const SWLIBS_2Syst_F32 *const pIn); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 344 NXP Semiconductors Chapter 5 API References 5.67.2 Arguments Table 5-83. GMCLIB_ClarkInv_F32 arguments Type Name Direction Description const SWLIBS_2Syst_F32 *const pIn input Pointer to the structure containing data of the two-phase stationary orthogonal system ( α- β). Arguments of the structure contain fixed point 32-bit values. SWLIBS_3Syst_F32 *const pOut output Pointer to the structure containing data of the three-phase stationary system (f32A-f32B-f32C). Arguments of the structure contain fixed point 32-bit values. 5.67.3 Return Function returns no value. 5.67.4 Description The GMCLIB_ClarkInv function calculates the Inverse Clarke transformation, which is used to transform values from the two-phase ( α- β) orthogonal coordinate system to the three-phase (f32A-f32B-f32C) coordinate system, according to these equations: Equation GMCLIB_ClarkInv_Eq1 Equation GMCLIB_ClarkInv_Eq2 Equation GMCLIB_ClarkInv_Eq3 Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 345 Function GMCLIB_ClarkInv_F16 The inputs and the outputs are normalized to fit in the range [-1, 1). 5.67.5 Re-entrancy The function is re-entrant. 5.67.6 Code Example #include "gmclib.h" SWLIBS_2Syst_F32 f32trAlBe; SWLIBS_3Syst_F32 f32trAbc; void main(void) { // input phase alpha ~ sin(45) ~ 0.707106781 // input phase beta ~ cos(45) ~ 0.707106781 f32trAlBe.f32Arg1 = FRAC32 (0.707106781); f32trAlBe.f32Arg2 = FRAC32 (0.707106781); // output should be // output should be // output should be GMCLIB_ClarkInv_F32 f32trAbc.f32Arg1 = 0x5A827999 ~ FRAC32(0.707106781) f32trAbc.f32Arg2 = 0x2120FB83 ~ FRAC32(0.258819045) f32trAbc.f32Arg3 = 0x845C8AE5 ~ FRAC32(-0.965925826) (&f32trAbc,&f32trAlBe); // output should be f32trAbc.f32Arg1 = 0x5A827999 ~ FRAC32(0.707106781) // output should be f32trAbc.f32Arg2 = 0x2120FB83 ~ FRAC32(0.258819045) // output should be f32trAbc.f32Arg3 = 0x845C8AE5 ~ FRAC32(-0.965925826) GMCLIB_ClarkInv (&f32trAbc,&f32trAlBe,F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be f32trAbc.f32Arg1 = 0x5A827999 ~ FRAC32(0.707106781) // output should be f32trAbc.f32Arg2 = 0x2120FB83 ~ FRAC32(0.258819045) // output should be f32trAbc.f32Arg3 = 0x845C8AE5 ~ FRAC32(-0.965925826) GMCLIB_ClarkInv (&f32trAbc,&f32trAlBe); 5.68 Function GMCLIB_ClarkInv_F16 The function implements the inverse Clarke transformation. 5.68.1 Declaration void GMCLIB_ClarkInv_F16(SWLIBS_3Syst_F16 *const pOut, const SWLIBS_2Syst_F16 *const pIn); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 346 NXP Semiconductors Chapter 5 API References 5.68.2 Arguments Table 5-84. GMCLIB_ClarkInv_F16 arguments Type Name Direction Description const SWLIBS_2Syst_F16 *const pIn input Pointer to the structure containing data of the two-phase stationary orthogonal system ( α- β). Arguments of the structure contain fixed point 16-bit values. SWLIBS_3Syst_F16 *const pOut output Pointer to the structure containing data of the three-phase stationary system (f16A-f16B-f16C). Arguments of the structure contain fixed point 16-bit values. 5.68.3 Return Function returns no value. 5.68.4 Description The GMCLIB_ClarkInv function calculates the Inverse Clarke transformation, which is used to transform values from the two-phase ( α- β) orthogonal coordinate system to the three-phase (f16A-f16B-f16C) coordinate system, according to these equations: Equation GMCLIB_ClarkInv_Eq1 Equation GMCLIB_ClarkInv_Eq2 Equation GMCLIB_ClarkInv_Eq3 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 347 Function GMCLIB_DecouplingPMSM_F32 Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). The inputs and the outputs are normalized to fit in the range [-1, 1). 5.68.5 Re-entrancy The function is re-entrant. 5.68.6 Code Example #include "gmclib.h" SWLIBS_2Syst_F16 f16trAlBe; SWLIBS_3Syst_F16 f16trAbc; void main(void) { // input phase alpha ~ sin(45) ~ 0.707106781 // input phase beta ~ cos(45) ~ 0.707106781 f16trAlBe.f16Arg1 = FRAC16 (0.707106781); f16trAlBe.f16Arg2 = FRAC16 (0.707106781); // output should be // output should be // output should be GMCLIB_ClarkInv_F16 f16trAbc.f16Arg1 = 0x5A82 ~ FRAC16(0.707106781) f16trAbc.f16Arg2 = 0x2120 ~ FRAC16(0.258819045) f16trAbc.f16Arg3 = 0x845C ~ FRAC16(-0.965925826) (&f16trAbc,&f16trAlBe); // output should be f16trAbc.f16Arg1 = 0x5A82 ~ FRAC16(0.707106781) // output should be f16trAbc.f16Arg2 = 0x2120 ~ FRAC16(0.258819045) // output should be f16trAbc.f16Arg3 = 0x845C ~ FRAC16(-0.965925826) GMCLIB_ClarkInv (&f16trAbc,&f16trAlBe,F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be f16trAbc.f16Arg1 = 0x5A82 ~ FRAC16(0.707106781) // output should be f16trAbc.f16Arg2 = 0x2120 ~ FRAC16(0.258819045) // output should be f16trAbc.f16Arg3 = 0x845C ~ FRAC16(-0.965925826) GMCLIB_ClarkInv (&f16trAbc,&f16trAlBe); 5.69 Function GMCLIB_DecouplingPMSM_F32 This function calculates the cross-coupling voltages to eliminate the dq axis coupling causing on-linearity of the field oriented control. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 348 NXP Semiconductors Chapter 5 API References 5.69.1 Declaration void GMCLIB_DecouplingPMSM_F32(SWLIBS_2Syst_F32 *const pUdqDec, const SWLIBS_2Syst_F32 *const pUdq, const SWLIBS_2Syst_F32 *const pIdq, tFrac32 f32AngularVel, const GMCLIB_DECOUPLINGPMSM_T_F32 *const pParam); 5.69.2 Arguments Table 5-85. GMCLIB_DecouplingPMSM_F32 arguments Type Name Direction Description SWLIBS_2Syst_F32 *const pUdqDec output Pointer to the structure containing direct (u df_dec) and quadrature (u qf_dec) components of the decoupled stator voltage vector to be applied on the motor terminals. const SWLIBS_2Syst_F32 *const pUdq input Pointer to the structure containing direct (u df) and quadrature (u qf) components of the stator voltage vector generated by the current controllers. const SWLIBS_2Syst_F32 *const pIdq input Pointer to the structure containing direct (i df) and quadrature (i qf) components of the stator current vector measured on the motor terminals. tFrac32 f32AngularVel input Rotor angular velocity in rad/sec, referred to as ( ωef) in the detailed section of the documentation. input Pointer to the structure containing k df and k qf coefficients (see the detailed section of the documentation) and scale parameters (k d_shift) and (k q_shift). const pParam GMCLIB_DECOUPLIN GPMSM_T_F32 *const 5.69.3 Return Function returns no value. 5.69.4 Description The quadrature phase model of a PMSM motor, in a synchronous reference frame, is very popular for field oriented control structures because both controllable quantities, current and voltage, are DC values. This allows employing only simple controllers to force the machine currents into the defined states. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 349 Function GMCLIB_DecouplingPMSM_F32 The voltage equations of this model can be obtained by transforming the motor three phase voltage equations into a quadrature phase rotational frame, which is aligned and rotates synchronously with the rotor. Such a transformation, after some mathematical corrections, yields the following set of equations, describing the quadrature phase model of a PMSM motor, in a synchronous reference frame: Equation GMCLIB_DecouplingPMSM_Eq1 It can be seen that GMCLIB_DecouplingPMSM_Eq1 represents a non-linear cross dependent system. The linear voltage components cover the model of the phase winding, which is simplified to a resistance in series with inductance (R-L circuit). The crosscoupling components represent the mutual coupling between the two phases of the quadrature phase model, and the back-EMF component (visible only in q-axis voltage) represents the generated back EMF voltage caused by rotor rotation. In order to achieve dynamic torque, speed and positional control, the non-linear and back-EMF components from GMCLIB_DecouplingPMSM_Eq1 must be compensated for. This will result in a fully decoupled flux and torque control of the machine and simplifies the PMSM motor model into two independent R-L circuit models as follows: Equation GMCLIB_DecouplingPMSM_Eq2 Such a simplification of the PMSM model also greatly simplifies the design of both the d-q current controllers. Therefore, it is advantageous to compensate for the cross-coupling terms in GMCLIB_DecouplingPMSM_Eq1, using the feed-forward voltages overline{u_dq_comp} given from GMCLIB_DecouplingPMSM_Eq1 as follows: Equation GMCLIB_DecouplingPMSM_Eq3 The feed-forward voltages overline{u_dq_comp} are added to the voltages generated by the current controllers overline{u_dq}, which cover the R-L model. The resulting voltages represent the direct u q_dec and quadrature u q_decq components of the decoupled Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 350 NXP Semiconductors Chapter 5 API References voltage vector that is to be applied on the motor terminals (using a pulse width modulator). The back EMF voltage component is already considered to be compensated by an external function. The function GMCLIB_DecouplingPMSM_F32 calculates the cross-coupling voltages overline{u_dq_comp} and adds these to the input overline{u_dq} voltage vector. Because the back EMF voltage component is considered compensated, this component is equal to zero. Therefore, calculations performed by GMCLIB_DecouplingPMSM_F32 are derived from these two equations: Equation GMCLIB_DecouplingPMSM_Eq4 where overline{u_dq} is the voltage vector calculated by the controllers (with the already compensated back EMF component), overline{u_dq_comp} is the feed-forward compensating voltage vector described in GMCLIB_DecouplingPMSM_Eq3, and overline{u_dq_dec} is the resulting decoupled voltage vector to be applied on the motor terminals. Substituting GMCLIB_DecouplingPMSM_Eq3 into GMCLIB_DecouplingPMSM_Eq4, and normalizing GMCLIB_DecouplingPMSM_Eq4, results in the following set of equations: Equation GMCLIB_DecouplingPMSM_Eq5 where subscript f denotes the fractional representation of the respective quantity, and U max, I max, Ωmax are the maximal values (scale values) for the voltage, current and angular velocity respectively. Real quantities are converted to the fractional range [-1, 1) using the following equations: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 351 Function GMCLIB_DecouplingPMSM_F32 Equation GMCLIB_DecouplingPMSM_Eq6 Further, rearranging GMCLIB_DecouplingPMSM_Eq5 results in: Equation GMCLIB_DecouplingPMSM_Eq7 where k d and k q are coefficients calculated as: Equation GMCLIB_DecouplingPMSM_Eq8 Because function GMCLIB_DecouplingPMSM_F32 is implemented using the fractional arithmetic, both the k d and k q coefficients also have to be scaled to fit into the fractional range [-1, 1). For that purpose, two additional scaling coefficients are defined as: Equation GMCLIB_DecouplingPMSM_Eq9 Using scaling coefficients GMCLIB_DecouplingPMSM_Eq9, the fractional representation of coefficients k d and k q from GMCLIB_DecouplingPMSM_Eq8 are derived as follows: Equation GMCLIB_DecouplingPMSM_Eq10 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 352 NXP Semiconductors Chapter 5 API References Substituting GMCLIB_DecouplingPMSM_Eq8 - GMCLIB_DecouplingPMSM_Eq10 into GMCLIB_DecouplingPMSM_Eq7 results in the final form of the equation set, actually implemented in the GMCLIB_DecouplingPMSM_F32 function: Equation GMCLIB_DecouplingPMSM_Eq11 Scaling of both equations into the fractional range is done using a multiplication by 2 k_d_shift, 2 k_q_shift, respectively. Therefore, it is implemented as a simple left shift with overflow protection. Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). All parameters can be reset during declaration using the GMCLIB_DECOUPLINGPMSM_DEFAULT_F32 macro. 5.69.5 Re-entrancy The function is re-entrant. 5.69.6 Code Example #include "gmclib.h" #define #define #define #define #define L_D L_Q U_MAX I_MAX W_MAX (50.0e-3) (100.0e-3) (50.0) (10.0) (2000.0) // // // // // Ld inductance = 50mH Lq inductance = 100mH scale for voltage = 50V scale for current = 10A scale for angular velocity = 2000rad/sec GMCLIB_DECOUPLINGPMSM_T_F32 f32trDec = GMCLIB_DECOUPLINGPMSM_DEFAULT_F32; SWLIBS_2Syst_F32 f32trUDQ; SWLIBS_2Syst_F32 f32trIDQ; SWLIBS_2Syst_F32 f32trUDecDQ; tFrac32 f32We; void main(void) { // input values - scaling coefficients of given decoupling algorithm f32trDec.f32Kd = FRAC32 (0.625); f32trDec.s16KdShift = (tS16)6; f32trDec.f32Kq = FRAC32 (0.625); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 353 Function GMCLIB_DecouplingPMSM_F16 f32trDec.s16KqShift = (tS16)5; // d quantity of input voltage vector 5[V] f32trUDQ.f32Arg1 = FRAC32 (5.0/U_MAX); // q quantity of input voltage vector 10[V] f32trUDQ.f32Arg2 = FRAC32 (10.0/U_MAX); // d quantity of measured current vector 6[A] f32trIDQ.f32Arg1 = FRAC32 (6.0/I_MAX); // q quantity of measured current vector 4[A] f32trIDQ.f32Arg2 = FRAC32 (4.0/I_MAX); // rotor angular velocity f32We = FRAC32 (100.0/W_MAX); // output should be f32trUDecDQ.f32Arg1 ~ 0xA6666666 ~ FRAC32(-0.7)*50V ~=-35[V] // output should be f32trUDecDQ.f32Arg2 ~ 0x66666666 ~ FRAC32(0.8)*50V ~=40[V] GMCLIB_DecouplingPMSM_F32 (&f32trUDecDQ,&f32trUDQ,&f32trIDQ,f32We,&f32trDec); // output should be f32trUDecDQ.f32Arg1 ~ 0xA6666666 ~ FRAC32(-0.7)*50V ~=-35[V] // output should be f32trUDecDQ.f32Arg2 ~ 0x66666666 ~ FRAC32(0.8)*50V ~=40[V] GMCLIB_DecouplingPMSM (&f32trUDecDQ,&f32trUDQ,&f32trIDQ,f32We,&f32trDec,F32); // // // // ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be f32trUDecDQ.f32Arg1 ~ 0xA6666666 ~ FRAC32(-0.7)*50V ~=-35[V] // output should be f32trUDecDQ.f32Arg2 ~ 0x66666666 ~ FRAC32(0.8)*50V ~=40[V] } GMCLIB_DecouplingPMSM (&f32trUDecDQ,&f32trUDQ,&f32trIDQ,f32We,&f32trDec); 5.70 Function GMCLIB_DecouplingPMSM_F16 This function calculates the cross-coupling voltages to eliminate the dq axis coupling causing non-linearity of the field oriented control. 5.70.1 Declaration void GMCLIB_DecouplingPMSM_F16(SWLIBS_2Syst_F16 *const pUdqDec, const SWLIBS_2Syst_F16 *const pUdq, const SWLIBS_2Syst_F16 *const pIdq, tFrac16 f16AngularVel, const GMCLIB_DECOUPLINGPMSM_T_F16 *const pParam); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 354 NXP Semiconductors Chapter 5 API References 5.70.2 Arguments Table 5-86. GMCLIB_DecouplingPMSM_F16 arguments Type Name Direction Description SWLIBS_2Syst_F16 *const pUdqDec output Pointer to the structure containing direct (u df_dec) and quadrature (u qf_dec) components of the decoupled stator voltage vector to be applied on the motor terminals. const SWLIBS_2Syst_F16 *const pUdq input Pointer to the structure containing direct (u df) and quadrature (u qf) components of the stator voltage vector generated by the current controllers. const SWLIBS_2Syst_F16 *const pIdq input Pointer to the structure containing direct (i df) and quadrature (i qf) components of the stator current vector measured on the motor terminals. tFrac16 f16AngularVel input Rotor angular velocity in rad/sec, referred to as ( omegaef) in the detailed section of the documentation. input Pointer to the structure containing k df and k qf coefficients (see the detailed section of the documentation) and scale parameters (k d_shift) and (k q_shift). const pParam GMCLIB_DECOUPLIN GPMSM_T_F16 *const 5.70.3 Return Function returns no value. 5.70.4 Description The quadrature phase model of a PMSM motor, in a synchronous reference frame, is very popular for field oriented control structures because both controllable quantities, current and voltage, are DC values. This allows employing only simple controllers to force the machine currents into the defined states. The voltage equations of this model can be obtained by transforming the motor three phase voltage equations into a quadrature phase rotational frame, which is aligned and rotates synchronously with the rotor. Such a transformation, after some mathematical corrections, yields the following set of equations, describing the quadrature phase model of a PMSM motor, in a synchronous reference frame: Equation GMCLIB_DecouplingPMSM_Eq1 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 355 Function GMCLIB_DecouplingPMSM_F16 It can be seen that GMCLIB_DecouplingPMSM_Eq1 represents a non-linear cross dependent system. The linear voltage components cover the model of the phase winding, which is simplified to a resistance in series with inductance (R-L circuit). The crosscoupling components represent the mutual coupling between the two phases of the quadrature phase model, and the back-EMF component (visible only in q-axis voltage) represents the generated back EMF voltage caused by rotor rotation. In order to achieve dynamic torque, speed and positional control, the non-linear and back-EMF components from GMCLIB_DecouplingPMSM_Eq1 must be compensated for. This will result in a fully decoupled flux and torque control of the machine and simplifies the PMSM motor model into two independent R-L circuit models as follows: Equation GMCLIB_DecouplingPMSM_Eq2 Such a simplification of the PMSM model also greatly simplifies the design of both the d-q current controllers. Therefore, it is advantageous to compensate for the cross-coupling terms in GMCLIB_DecouplingPMSM_Eq1, using the feed-forward voltages overline{u_dq_comp} given from GMCLIB_DecouplingPMSM_Eq1 as follows: Equation GMCLIB_DecouplingPMSM_Eq3 The feed-forward voltages overline{u_dq_comp} are added to the voltages generated by the current controllers overline{u_dq}, which cover the R-L model. The resulting voltages represent the direct u q_dec and quadrature u q_decq components of the decoupled voltage vector that is to be applied on the motor terminals (using a pulse width modulator). The back EMF voltage component is already considered to be compensated by an external function. The function GMCLIB_DecouplingPMSM_F16 calculates the cross-coupling voltages overline{u_dq_comp} and adds these to the input overline{u_dq} voltage vector. Because the back EMF voltage component is considered compensated, this component is equal to zero. Therefore, calculations performed by GMCLIB_DecouplingPMSM_F16 are derived from these two equations: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 356 NXP Semiconductors Chapter 5 API References Equation GMCLIB_DecouplingPMSM_Eq4 where overline{u_dq} is the voltage vector calculated by the controllers (with the already compensated back EMF component), overline{u_dq_comp} is the feed-forward compensating voltage vector described in GMCLIB_DecouplingPMSM_Eq3, and overline{u_dq_dec} is the resulting decoupled voltage vector to be applied on the motor terminals. Substituting GMCLIB_DecouplingPMSM_Eq3 into GMCLIB_DecouplingPMSM_Eq4, and normalizing GMCLIB_DecouplingPMSM_Eq4, results in the following set of equations: Equation GMCLIB_DecouplingPMSM_Eq5 where subscript f denotes the fractional representation of the respective quantity, and U max, I max, Ωmax are the maximal values (scale values) for the voltage, current and angular velocity respectively. Real quantities are converted to the fractional range [-1, 1) using the following equations: Equation GMCLIB_DecouplingPMSM_Eq6 Further, rearranging GMCLIB_DecouplingPMSM_Eq5 results in: Equation GMCLIB_DecouplingPMSM_Eq7 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 357 Function GMCLIB_DecouplingPMSM_F16 where k d and k q are coefficients calculated as: Equation GMCLIB_DecouplingPMSM_Eq8 Because function GMCLIB_DecouplingPMSM_F16 is implemented using the fractional arithmetic, both the k d and k q coefficients also have to be scaled to fit into the fractional range [-1, 1). For that purpose, two additional scaling coefficients are defined as: Equation GMCLIB_DecouplingPMSM_Eq9 Using scaling coefficients GMCLIB_DecouplingPMSM_Eq9, the fractional representation of coefficients k d and k q from GMCLIB_DecouplingPMSM_Eq8 are derived as follows: Equation GMCLIB_DecouplingPMSM_Eq10 Substituting GMCLIB_DecouplingPMSM_Eq8 - GMCLIB_DecouplingPMSM_Eq10 into GMCLIB_DecouplingPMSM_Eq7 results in the final form of the equation set, actually implemented in the GMCLIB_DecouplingPMSM_F16 function: Equation GMCLIB_DecouplingPMSM_Eq11 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 358 NXP Semiconductors Chapter 5 API References Scaling of both equations into the fractional range is done using a multiplication by 2 2 k_q_shift, respectively. Therefore, it is implemented as a simple left shift with overflow protection. k_d_shift, Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). All parameters can be reset during declaration using the GMCLIB_DECOUPLINGPMSM_DEFAULT_F16 macro. 5.70.5 Re-entrancy The function is re-entrant. 5.70.6 Code Example #include "gmclib.h" #define #define #define #define #define L_D L_Q U_MAX I_MAX W_MAX (50.0e-3) (100.0e-3) (50.0) (10.0) (2000.0) // // // // // Ld inductance = 50mH Lq inductance = 100mH scale for voltage = 50V scale for current = 10A scale for angular velocity = 2000rad/sec GMCLIB_DECOUPLINGPMSM_T_F16 f16trDec = GMCLIB_DECOUPLINGPMSM_DEFAULT_F16; SWLIBS_2Syst_F16 f16trUDQ; SWLIBS_2Syst_F16 f16trIDQ; SWLIBS_2Syst_F16 f16trUDecDQ; tFrac16 f16We; void main(void) { // input values - scaling coefficients of given decoupling algorithm f16trDec.f16Kd = FRAC16 (0.625); f16trDec.s16KdShift = (tS16)6; f16trDec.f16Kq = FRAC16 (0.625); f16trDec.s16KqShift = (tS16)5; // d quantity of input voltage vector 5[V] f16trUDQ.f16Arg1 = FRAC16 (5.0/U_MAX); // q quantity of input voltage vector 10[V] f16trUDQ.f16Arg2 = FRAC16 (10.0/U_MAX); // d quantity of measured current vector 6[A] f16trIDQ.f16Arg1 = FRAC16 (6.0/I_MAX); // q quantity of measured current vector 4[A] f16trIDQ.f16Arg2 = FRAC16 (4.0/I_MAX); // rotor angular velocity f16We = FRAC16 (100.0/W_MAX); //output should be f16trUDecDQ.f16Arg1 ~ 0xA666 ~ FRAC16(-0.7)*50V ~=-35[V] //output should be f16trUDecDQ.f16Arg2 ~ 0x6666 ~ FRAC16(0.8)*50V ~=40[V] GMCLIB_DecouplingPMSM_F16 (&f16trUDecDQ,&f16trUDQ,&f16trIDQ,f16We,&f16trDec); //output should be f16trUDecDQ.f16Arg1 ~ 0xA666 ~ FRAC16(-0.7)*50V ~=-35[V] Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 359 Function GMCLIB_ElimDcBusRip_F32 //output should be f16trUDecDQ.f16Arg2 ~ 0x6666 ~ FRAC16(0.8)*50V ~=40[V] GMCLIB_DecouplingPMSM (&f16trUDecDQ,&f16trUDQ,&f16trIDQ,f16We,&f16trDec,F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## //output should be f16trUDecDQ.f16Arg1 ~ 0xA666 ~ FRAC16(-0.7)*50V ~=-35[V] //output should be f16trUDecDQ.f16Arg2 ~ 0x6666 ~ FRAC16(0.8)*50V ~=40[V] GMCLIB_DecouplingPMSM (&f16trUDecDQ,&f16trUDQ,&f16trIDQ,f16We,&f16trDec); 5.71 Function GMCLIB_ElimDcBusRip_F32 This function implements the DC Bus voltage ripple elimination. 5.71.1 Declaration void GMCLIB_ElimDcBusRip_F32(SWLIBS_2Syst_F32 *const pOut, const SWLIBS_2Syst_F32 *const pIn, const GMCLIB_ELIMDCBUSRIP_T_F32 *const pParam); 5.71.2 Arguments Table 5-87. GMCLIB_ElimDcBusRip_F32 arguments Type Name Direction Description SWLIBS_2Syst_F32 *const pOut output Pointer to the structure with direct ( α) and quadrature ( β) components of the required stator voltage vector re-calculated so as to compensate for voltage ripples on the DC bus. const SWLIBS_2Syst_F32 *const pIn input Pointer to the structure with direct ( α) and quadrature ( β) components of the required stator voltage vector before compensation of voltage ripples on the DC bus. input Pointer to the parameters structure. const pParam GMCLIB_ELIMDCBUS RIP_T_F32 *const 5.71.3 Return Function returns no value. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 360 NXP Semiconductors Chapter 5 API References 5.71.4 Description The GMCLIB_ElimDcBusRip function provides a computational method for the recalculation of the direct ( α) and quadrature ( β) components of the required stator voltage vector, so as to compensate for voltage ripples on the DC bus of the power stage. Considering a cascaded type structure of the control system in a standard motor control application, the required voltage vector to be applied on motor terminals is generated by a set of controllers (usually P, PI or PID) only with knowledge of the maximal value of the DC bus voltage. The amplitude and phase of the required voltage vector are then used by the pulse width modulator (PWM) for generation of appropriate duty-cycles for the power inverter switches. Obviously, the amplitude of the generated phase voltage (averaged across one switching period) does not only depend on the actual on/off times of the given phase switches and the maximal value of the DC bus voltage. The actual amplitude of the phase voltage is also directly affected by the actual value of the available DC bus voltage. Therefore, any variations in amplitude of the actual DC bus voltage must be accounted for by modifying the amplitude of the required voltage so that the output phase voltage remains unaffected. For a better understanding, let's consider the following two simple examples: Example 1: • • • • amplitude of the required phase voltage U reg=50[V] maximal amplitude of the DC bus voltage U DC_BUS_MAX=100[V] actual amplitude of the DC bus voltage U DC_BUS_ACTUAL=100[V] voltage to be applied to the PWM modulator to generate U reg=50[V] on the inverter phase output: Equation GMCLIB_ElimDcBusRip_Eq1 • • • • Example 2: amplitude of the required phase voltage U reg=50[V] maximal amplitude of the DC bus voltage U DC_BUS_MAX=100[V] actual amplitude of the DC bus voltage U DC_BUS_ACTUAL=90[V] voltage to be applied to the PWM modulator to generate U reg=50[V] on the inverter phase output: Equation GMCLIB_ElimDcBusRip_Eq2 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 361 Function GMCLIB_ElimDcBusRip_F32 The imperfections of the DC bus voltage are compensated for by the modification of amplitudes of the direct- α and the quadrature- β components of the stator reference voltage vector. The following formulas are used: • for the α-component: Equation GMCLIB_ElimDcBusRip_Eq3 • for the β-component: Equation GMCLIB_ElimDcBusRip_Eq4 where: f32ModIndex is the inverse modulation index, f32ArgDcBusMsr is the measured DC bus voltage, the u α and u β are the input voltages, and the u α* and u β* are the output duty-cycle ratios. The f32ModIndex and f32ArgDcBusMsr are supplied to the function within the parameters structure through its members. The u α, u β correspond respectively to the f32Arg1 and f32Arg2 members of the input structure, and the u α* and u β* respectively to the f32Arg1 and f32Arg2 members of the output structure. It should be noted that although the modulation index (see the parameters structure, the f32ModIndex member) is assumed to be equal to or greater than zero, the possible values are restricted to those values resulting from the use of Space Vector Modulation techniques. In order to correctly handle the discontinuity at f32ArgDcBusMsr approaching 0, and for efficiency reasons, the function will assign 0 to the output duty cycle ratios if the f32ArgDcBusMsr is below the threshold of 2 -15. In other words, the 16 least significant bits of the f32DcBusMsr are ignored. Also, the computed output of the u α* and u β* components may have an inaccuracy in the 16 least significant bits. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 362 NXP Semiconductors Chapter 5 API References Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). Both the inverse modulation index pIn->f32ModIndex and the measured DC bus voltage pIn->f32DcBusMsr must be equal to or greater than 0, otherwise the results are undefined. 5.71.5 Re-entrancy The function is re-entrant. 5.71.6 Code Example #include "gmclib.h" #define U_MAX (36.0) // voltage scale SWLIBS_2Syst_F32 f32AB; SWLIBS_2Syst_F32 f32OutAB; GMCLIB_ELIMDCBUSRIP_T_F32 f32trMyElimDcBusRip = GMCLIB_ELIMDCBUSRIP_DEFAULT_F32; void main(void) { // inverse modulation coefficient for standard space vector modulation f32trMyElimDcBusRip.f32ModIndex = FRAC32 (0.866025403784439); // Input voltage vector 15V @ angle 30deg // alpha component of input voltage vector = 12.99[V] f32AB.f32Arg1 = FRAC32 (12.99/U_MAX); // beta component of input voltage vector = 7.5[V] f32AB.f32Arg2 = FRAC32 (7.5/U_MAX); // value of the measured DC bus voltage 17[V] f32trMyElimDcBusRip.f32ArgDcBusMsr = FRAC32 (17.0/U_MAX); // output alpha component of the output vector should be // f32OutAB.f32Arg1 = (12.99/36)*0.8660/(17.0/36/2) = 1.3235 -> FRAC32(1.0) ~ 0x7FFFFFFF // output beta component of the output vector should be // f32OutAB.f32Arg2 = (7.5/36)*0.8660/(17.0/36/2) = 0.7641 -> FRAC32(0.7641) ~ 0x61CF8000 GMCLIB_ElimDcBusRip_F32 (&f32OutAB,&f32AB,&f32trMyElimDcBusRip); // output alpha component of the output vector should be // f32OutAB.f32Arg1 = (12.99/36)*0.8660/(17.0/36/2) = 1.3235 -> FRAC32(1.0) ~ 0x7FFFFFFF // output beta component of the output vector should be // f32OutAB.f32Arg2 = (7.5/36)*0.8660/(17.0/36/2) = 0.7641 -> FRAC32(0.7641) ~ 0x61CF8000 GMCLIB_ElimDcBusRip (&f32OutAB,&f32AB,&f32trMyElimDcBusRip,F32); // // // // ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output alpha component of the output vector should be Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 363 Function GMCLIB_ElimDcBusRip_F16 // f32OutAB.f32Arg1 = (12.99/36)*0.8660/(17.0/36/2) = 1.3235 -> FRAC32(1.0) ~ 0x7FFFFFFF // output beta component of the output vector should be // f32OutAB.f32Arg2 = (7.5/36)*0.8660/(17.0/36/2) = 0.7641 -> FRAC32(0.7641) ~ 0x61CF8000 GMCLIB_ElimDcBusRip (&f32OutAB,&f32AB,&f32trMyElimDcBusRip); } 5.72 Function GMCLIB_ElimDcBusRip_F16 This function implements the DC Bus voltage ripple elimination. 5.72.1 Declaration void GMCLIB_ElimDcBusRip_F16(SWLIBS_2Syst_F16 *const pOut, const SWLIBS_2Syst_F16 *const pIn, const GMCLIB_ELIMDCBUSRIP_T_F16 *const pParam); 5.72.2 Arguments Table 5-88. GMCLIB_ElimDcBusRip_F16 arguments Type Name Direction Description SWLIBS_2Syst_F16 *const pOut output Pointer to the structure with direct ( α) and quadrature ( β) components of the required stator voltage vector re-calculated so as to compensate for voltage ripples on the DC bus. const SWLIBS_2Syst_F16 *const pIn input Pointer to the structure with direct ( α) and quadrature ( β) components of the required stator voltage vector before compensation of voltage ripples on the DC bus. input Pointer to the parameters structure. const pParam GMCLIB_ELIMDCBUS RIP_T_F16 *const 5.72.3 Return Function returns no value. 5.72.4 Description The GMCLIB_ElimDcBusRip function provides a computational method for the recalculation of the direct ( α) and quadrature ( β) components of the required stator voltage vector, so as to compensate for voltage ripples on the DC bus of the power stage. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 364 NXP Semiconductors Chapter 5 API References Considering a cascaded type structure of the control system in a standard motor control application, the required voltage vector to be applied on motor terminals is generated by a set of controllers (usually P, PI or PID) only with knowledge of the maximal value of the DC bus voltage. The amplitude and phase of the required voltage vector are then used by the pulse width modulator (PWM) for generation of appropriate duty-cycles for the power inverter switches. Obviously, the amplitude of the generated phase voltage (averaged across one switching period) does not only depend on the actual on/off times of the given phase switches and the maximal value of the DC bus voltage. The actual amplitude of the phase voltage is also directly affected by the actual value of the available DC bus voltage. Therefore, any variations in amplitude of the actual DC bus voltage must be accounted for by modifying the amplitude of the required voltage so that the output phase voltage remains unaffected. For a better understanding, let's consider the following two simple examples: Example 1: • • • • amplitude of the required phase voltage U reg=50[V] maximal amplitude of the DC bus voltage U DC_BUS_MAX=100[V] actual amplitude of the DC bus voltage U DC_BUS_ACTUAL=100[V] voltage to be applied to the PWM modulator to generate U reg=50[V] on the inverter phase output: Equation GMCLIB_ElimDcBusRip_Eq1 • • • • amplitude of the required phase voltage U reg=50[V] maximal amplitude of the DC bus voltage U DC_BUS_MAX=100[V] actual amplitude of the DC bus voltage U DC_BUS_ACTUAL=90[V] voltage to be applied to the PWM modulator to generate U reg=50[V] on the inverter phase output: Equation GMCLIB_ElimDcBusRip_Eq2 Equation GMCLIB_ElimDcBusRip_Eq3 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 365 Function GMCLIB_ElimDcBusRip_F16 • for the β-component: Equation GMCLIB_ElimDcBusRip_Eq4 where: f16ModIndex is the inverse modulation index, f16ArgDcBusMsr is the measured DC bus voltage, the u α and u β are the input voltages, and the u α* and u β* are the output duty-cycle ratios. The f16ModIndex and f16ArgDcBusMsr are supplied to the function within the parameters structure through its members. The u α, u β correspond respectively to the f16Arg1 and f16Arg2 members of the input structure, and the u α* and u β* respectively to the f16Arg1 and f16Arg2 members of the output structure. It should be noted that although the modulation index (see the parameters structure, the f16ModIndex member) is assumed to be equal to or greater than zero, the possible values are restricted to those values resulting from the use of Space Vector Modulation techniques. In order to correctly handle the discontinuity at f16ArgDcBusMsr approaching 0, and for efficiency reasons, the function will assign 0 to the output duty cycle ratios if the f16ArgDcBusMsr is below the threshold of 2 -15. In other words, the 16 least significant bits of the f16DcBusMsr are ignored. Also, the computed output of the u α* and u β* components may have an inaccuracy in the 16 least significant bits. Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). Both the inverse modulation index pIn->f16ModIndex and the measured DC bus voltage pIn->f16DcBusMsr must be equal to or greater than 0, otherwise the results are undefined. 5.72.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 366 NXP Semiconductors Chapter 5 API References 5.72.6 Code Example #include "gmclib.h" #define U_MAX (36.0) // voltage scale SWLIBS_2Syst_F16 f16AB; SWLIBS_2Syst_F16 f16OutAB; GMCLIB_ELIMDCBUSRIP_T_F16 f16trMyElimDcBusRip = GMCLIB_ELIMDCBUSRIP_DEFAULT_F16; void main(void) { // inverse modulation coefficient for standard space vector modulation f16trMyElimDcBusRip.f16ModIndex = FRAC16 (0.866025403784439); // Input voltage vector 15V @ angle 30deg // alpha component of input voltage vector = 12.99[V] f16AB.f16Arg1 = FRAC16 (12.99/U_MAX); // beta component of input voltage vector = 7.5[V] f16AB.f16Arg2 = FRAC16 (7.5/U_MAX); // value of the measured DC bus voltage 17[V] f16trMyElimDcBusRip.f16ArgDcBusMsr = FRAC16 (17.0/U_MAX); // output alpha component of the output vector should be // f16OutAB.f16Arg1 = (12.99/36)*0.8660/(17.0/36/2) = 1.3235 -> FRAC16(1.0) ~ 0x7FFF // output beta component of the output vector should be // f16OutAB.f16Arg2 = (7.5/36)*0.8660/(17.0/36/2) = 0.7641 -> FRAC16(0.7641) ~ 0x61CF GMCLIB_ElimDcBusRip_F16 (&f16OutAB,&f16AB,&f16trMyElimDcBusRip); // output alpha component of the output vector should be // f16OutAB.f16Arg1 = (12.99/36)*0.8660/(17.0/36/2) = 1.3235 -> FRAC16(1.0) ~ 0x7FFF // output beta component of the output vector should be // f16OutAB.f16Arg2 = (7.5/36)*0.8660/(17.0/36/2) = 0.7641 -> FRAC16(0.7641) ~ 0x61CF GMCLIB_ElimDcBusRip (&f16OutAB,&f16AB,&f16trMyElimDcBusRip,F16); // // // // ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output alpha component of the output vector should be // f16OutAB.f16Arg1 = (12.99/36)*0.8660/(17.0/36/2) = 1.3235 -> FRAC16(1.0) ~ 0x7FFF // output beta component of the output vector should be // f16OutAB.f16Arg2 = (7.5/36)*0.8660/(17.0/36/2) = 0.7641 -> FRAC16(0.7641) ~ 0x61CF GMCLIB_ElimDcBusRip (&f16OutAB,&f16AB,&f16trMyElimDcBusRip); } 5.73 Function GMCLIB_Park_F32 This function implements the calculation of Park transformation. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 367 Function GMCLIB_Park_F32 5.73.1 Declaration void GMCLIB_Park_F32(SWLIBS_2Syst_F32 *pOut, const SWLIBS_2Syst_F32 *const pInAngle, const SWLIBS_2Syst_F32 *const pIn); 5.73.2 Arguments Table 5-89. GMCLIB_Park_F32 arguments Type Name Direction Description SWLIBS_2Syst_F32 * pOut input, output Pointer to the structure containing data of the two-phase rotational orthogonal system (d-q). const SWLIBS_2Syst_F32 *const pInAngle input Pointer to the structure where the values of the sine and cosine of the rotor position are stored. const SWLIBS_2Syst_F32 *const pIn input Pointer to the structure containing data of the two-phase stationary orthogonal system ( α- β). 5.73.3 Return void 5.73.4 Description The GMCLIB_Park_F32 function calculates the Park Transformation, which transforms values (flux, voltage, current) from the two-phase ( α- β) stationary orthogonal coordinate system to the two-phase (d-q) rotational orthogonal coordinate system, according to these equations: Equation GMCLIB_Park_Eq1 Equation GMCLIB_Park_Eq2 where θe represents the electrical position of the rotor flux. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 368 NXP Semiconductors Chapter 5 API References Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). The inputs and the outputs are normalized to fit in the range [-1, 1). 5.73.5 Re-entrancy The function is re-entrant. 5.73.6 Code Example #include "gmclib.h" SWLIBS_2Syst_F32 tr32Angle; SWLIBS_2Syst_F32 tr32AlBe; SWLIBS_2Syst_F32 tr32Dq; void main(void) { // input angle sin(60) = 0.866025403 // input angle cos(60) = 0.5 tr32Angle.f32Arg1 = FRAC32 (0.866025403); tr32Angle.f32Arg2 = FRAC32 (0.5); // input alpha = 0.123 // input beta = 0.654 tr32AlBe.f32Arg1 = FRAC32 (0.123); tr32AlBe.f32Arg2 = FRAC32 (0.654); // output should be // tr32Dq.f32Arg1 ~ d = 0x505E6455 // tr32Dq.f32Arg2 ~ q = 0x1C38ABDC GMCLIB_Park_F32 (&tr32Dq,&tr32Angle,&tr32AlBe); // output should be // tr32Dq.f32Arg1 ~ d = 0x505E6455 // tr32Dq.f32Arg2 ~ q = 0x1C38ABDC GMCLIB_Park (&tr32Dq,&tr32Angle,&tr32AlBe,F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be // tr32Dq.f32Arg1 ~ d = 0x505E6455 // tr32Dq.f32Arg2 ~ q = 0x1C38ABDC GMCLIB_Park (&tr32Dq,&tr32Angle,&tr32AlBe); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 369 Function GMCLIB_Park_F16 5.74 Function GMCLIB_Park_F16 This function implements the calculation of Park transformation. 5.74.1 Declaration void GMCLIB_Park_F16(SWLIBS_2Syst_F16 *pOut, const SWLIBS_2Syst_F16 *const pInAngle, const SWLIBS_2Syst_F16 *const pIn); 5.74.2 Arguments Table 5-90. GMCLIB_Park_F16 arguments Type Name Direction Description SWLIBS_2Syst_F16 * pOut input, output Pointer to the structure containing data of the two-phase rotational orthogonal system (d-q). const SWLIBS_2Syst_F16 *const pInAngle input Pointer to the structure where the values of the sine and cosine of the rotor position are stored. const SWLIBS_2Syst_F16 *const pIn input Pointer to the structure containing data of the two-phase stationary orthogonal system ( α- β). 5.74.3 Return void 5.74.4 Description The GMCLIB_Park_F16 function calculates the Park Transformation, which transforms values (flux, voltage, current) from the two-phase ( α- β) stationary orthogonal coordinate system to the two-phase (d-q) rotational orthogonal coordinate system, according to these equations: Equation GMCLIB_Park_Eq1 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 370 NXP Semiconductors Chapter 5 API References Equation GMCLIB_Park_Eq2 where θe represents the electrical position of the rotor flux. Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). The inputs and the outputs are normalized to fit in the range [-1, 1). 5.74.5 Re-entrancy The function is re-entrant. 5.74.6 Code Example #include "gmclib.h" SWLIBS_2Syst_F16 tr16Angle; SWLIBS_2Syst_F16 tr16AlBe; SWLIBS_2Syst_F16 tr16Dq; void main(void) { // input angle sin(60) = 0.866025403 // input angle cos(60) = 0.5 tr16Angle.f16Arg1 = FRAC16 (0.866025403); tr16Angle.f16Arg2 = FRAC16 (0.5); // input alpha = 0.123 // input beta = 0.654 tr16AlBe.f16Arg1 = FRAC16 (0.123); tr16AlBe.f16Arg2 = FRAC16 (0.654); // output should be // tr16Dq.f16Arg1 ~ d = 0x505E // tr16Dq.f16Arg2 ~ q = 0x1C38 GMCLIB_Park_F16 (&tr16Dq,&tr16Angle,&tr16AlBe); // output should be // tr16Dq.f16Arg1 ~ d = 0x505E // tr16Dq.f16Arg2 ~ q = 0x1C38 GMCLIB_Park (&tr16Dq,&tr16Angle,&tr16AlBe,F16); // // // // ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be // tr16Dq.f16Arg1 ~ d = 0x505E Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 371 Function GMCLIB_ParkInv_F32 } // tr16Dq.f16Arg2 ~ q = 0x1C38 GMCLIB_Park (&tr16Dq,&tr16Angle,&tr16AlBe); 5.75 Function GMCLIB_ParkInv_F32 This function implements the inverse Park transformation. 5.75.1 Declaration void GMCLIB_ParkInv_F32(SWLIBS_2Syst_F32 *const pOut, const SWLIBS_2Syst_F32 *const pInAngle, const SWLIBS_2Syst_F32 *const pIn); 5.75.2 Arguments Table 5-91. GMCLIB_ParkInv_F32 arguments Type Name Direction Description SWLIBS_2Syst_F32 *const pOut input, output Pointer to the structure containing data of the two-phase stationary orthogonal system ( α- β). const SWLIBS_2Syst_F32 *const pInAngle input Pointer to the structure where the values of the sine and cosine of the rotor position are stored. const SWLIBS_2Syst_F32 *const pIn input Pointer to the structure containing data of the two-phase rotational orthogonal system (d-q). 5.75.3 Return void 5.75.4 Description The GMCLIB_ParkInv_F32 function calculates the Inverse Park Transformation, which transforms quantities (flux, voltage, current) from the two-phase (d-q) rotational orthogonal coordinate system to the two-phase ( α- β) stationary orthogonal coordinate system, according to these equations: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 372 NXP Semiconductors Chapter 5 API References Equation GMCLIB_ParkInv_Eq1 Equation GMCLIB_ParkInv_Eq2 Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). The inputs and the outputs are normalized to fit in the range [-1, 1). 5.75.5 Re-entrancy The function is re-entrant. 5.75.6 Code Example #include "gmclib.h" SWLIBS_2Syst_F32 tr32Angle; SWLIBS_2Syst_F32 tr32Dq; SWLIBS_2Syst_F32 tr32AlBe; void main(void) { // input angle sin(60) = 0.866025403 // input angle cos(60) = 0.5 tr32Angle.f32Arg1 = FRAC32 (0.866025403); tr32Angle.f32Arg2 = FRAC32 (0.5); // input d = 0.123 // input q = 0.654 tr32Dq.f32Arg1 = FRAC32 (0.123); tr32Dq.f32Arg2 = FRAC32 (0.654); // output should be // tr32AlBe.f32Arg1 ~ alpha = 0xBF601273 // tr32AlBe.f32Arg2 ~ beta = 0x377D9EE4 GMCLIB_ParkInv_F32 (&tr32AlBe,&tr32Angle,&tr32Dq); // output should be // tr32AlBe.f32Arg1 ~ alpha = 0xBF601273 // tr32AlBe.f32Arg2 ~ beta = 0x377D9EE4 GMCLIB_ParkInv (&tr32AlBe,&tr32Angle,&tr32Dq,F32); // ############################################################## // Available only if 32-bit fractional implementation selected // as default Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 373 Function GMCLIB_ParkInv_F16 // ############################################################## } // output should be // tr32AlBe.f32Arg1 ~ alpha = 0xBF601273 // tr32AlBe.f32Arg2 ~ beta = 0x377D9EE4 GMCLIB_ParkInv (&tr32AlBe,&tr32Angle,&tr32Dq); 5.76 Function GMCLIB_ParkInv_F16 This function implements the inverse Park transformation. 5.76.1 Declaration void GMCLIB_ParkInv_F16(SWLIBS_2Syst_F16 *const pOut, const SWLIBS_2Syst_F16 *const pInAngle, const SWLIBS_2Syst_F16 *const pIn); 5.76.2 Arguments Table 5-92. GMCLIB_ParkInv_F16 arguments Type Name Direction Description SWLIBS_2Syst_F16 *const pOut input, output Pointer to the structure containing data of the two-phase stationary orthogonal system ( α- β). const SWLIBS_2Syst_F16 *const pInAngle input Pointer to the structure where the values of the sine and cosine of the rotor position are stored. const SWLIBS_2Syst_F16 *const pIn input Pointer to the structure containing data of the two-phase rotational orthogonal system (d-q). 5.76.3 Return void 5.76.4 Description The GMCLIB_ParkInv_F16 function calculates the Inverse Park Transformation, which transforms quantities (flux, voltage, current) from the two-phase (d-q) rotational orthogonal coordinate system to the two-phase ( α- β) stationary orthogonal coordinate system, according to these equations: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 374 NXP Semiconductors Chapter 5 API References Equation GMCLIB_ParkInv_Eq1 Equation GMCLIB_ParkInv_Eq2 Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). The inputs and the outputs are normalized to fit in the range [-1, 1). 5.76.5 Re-entrancy The function is re-entrant. 5.76.6 Code Example #include "gmclib.h" SWLIBS_2Syst_F16 tr16Angle; SWLIBS_2Syst_F16 tr16Dq; SWLIBS_2Syst_F16 tr16AlBe; void main(void) { // input angle sin(60) = 0.866025403 // input angle cos(60) = 0.5 tr16Angle.f16Arg1 = FRAC16 (0.866025403); tr16Angle.f16Arg2 = FRAC16 (0.5); // input d = 0.123 // input q = 0.654 tr16Dq.f16Arg1 = FRAC16 (0.123); tr16Dq.f16Arg2 = FRAC16 (0.654); // output should be // tr16AlBe.f16Arg1 ~ alpha = 0xBF61 // tr16AlBe.f16Arg2 ~ beta = 0x377C GMCLIB_ParkInv_F16 (&tr16AlBe,&tr16Angle,&tr16Dq); // output should be // tr16AlBe.f16Arg1 ~ alpha = 0xBF61 // tr16AlBe.f16Arg2 ~ beta = 0x377C GMCLIB_ParkInv (&tr16AlBe,&tr16Angle,&tr16Dq,F16); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 375 Function GMCLIB_SvmStd_F32 // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be // tr16AlBe.f16Arg1 ~ alpha = 0xBF61 // tr16AlBe.f16Arg2 ~ beta = 0x377C GMCLIB_ParkInv (&tr16AlBe,&tr16Angle,&tr16Dq); 5.77 Function GMCLIB_SvmStd_F32 This function calculates the duty-cycle ratios using the Standard Space Vector Modulation technique. 5.77.1 Declaration tU32 GMCLIB_SvmStd_F32(SWLIBS_3Syst_F32 *pOut, const SWLIBS_2Syst_F32 *const pIn); 5.77.2 Arguments Table 5-93. GMCLIB_SvmStd_F32 arguments Type Name Direction Description SWLIBS_3Syst_F32 * pOut input, output Pointer to the structure containing calculated duty-cycle ratios of the 3-Phase system. const SWLIBS_2Syst_F32 *const pIn input Pointer to the structure containing direct U α and quadrature U β components of the stator voltage vector. 5.77.3 Return The function returns a 32-bit value in format INT, representing the actual space sector which contains the stator reference vector U s. 5.77.4 Description The GMCLIB_SvmStd_F32 function for calculating duty-cycle ratios is widely-used in the modern electric drive. This, function calculates appropriate duty-cycle ratios, which are needed for generating the given stator reference voltage vector using a special Space Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 376 NXP Semiconductors Chapter 5 API References Vector Modulation technique, termed Standard Space Vector Modulation. The basic principle of the Standard Space Vector Modulation Technique can be explained with the help of the power stage diagram in Figure 5-37. Figure 5-37. Power stage schematic diagram Top and bottom switches work in a complementary mode; i.e., if the top switch, S At, is ON, then the corresponding bottom switch, S Ab, is OFF, and vice versa. Considering that value 1 is assigned to the ON state of the top switch, and value 0 is assigned to the ON state of the bottom switch, the switching vector, [a, b, c] T can be defined. Creating such a vector allows a numerical definition of all possible switching states. In a three-phase power stage configuration (as shown in Figure 5-37), eight possible switching states (detailed in Figure 5-38) are feasible. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 377 Function GMCLIB_SvmStd_F32 Figure 5-38. Basic space vectors These states, together with the resulting instantaneous output line-to-line and phase voltages, are listed in Table 5-94. Table 5-94. Switching patterns a b c Ua Ub Uc U AB U BC U CA Vector 0 0 0 0 0 0 0 0 0 O 000 1 0 0 U DCBus 0 -U DCBus U0 0 U DCBus -U DCBus U 60 -U DCBus U DCBus 0 U 120 -U DCBus 0 U DCBus U 180 0 -U DCBus U DCBus U 240 U DCBus -U DCBus 0 U 300 0 0 0 O 111 1 0 1 1 0 0 0 1 1 0 0 1 1 1 0 1 1 1 2/3*U -1/3*U -1/3*U DCBus DCBus DCBus 1/3*U 1/3*U -2/3*U DCBus DCBus DCBus -1/3*U 2/3*U -1/3*U DCBus DCBus DCBus -2/3*U 1/3*U 1/3*U DCBus DCBus DCBus -1/3*U -1/3*U 2/3*U DCBus DCBus DCBus 1/3*U -2/3*U 1/3*U DCBus DCBus DCBus 0 0 0 The quantities of the direct-u α and the quadrature-u β components of the two-phase orthogonal coordinate system, describing the three-phase stator voltages, are expressed by the Clarke Transformation. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 378 NXP Semiconductors Chapter 5 API References Equation GMCLIB_SvmStd_Eq1 Equation GMCLIB_SvmStd_Eq2 The three-phase stator voltages, U a, U b, and U c, are transformed using the Clarke Transformation into the U α and the U β components of the two-phase orthogonal coordinate system. The transformation results are listed in Table 5-95. Table 5-95. Switching patterns and space vectors a b c uα uβ Vector 0 0 0 0 0 O 000 1 0 0 2/3*U DCBus 0 U0 1 1 0 1/3*U DCBus 1/ √(3)*U DCBus U 60 0 1 0 -1/3*U DCBus 1/ √(3)*U DCBus U 120 0 1 1 -2/3*U DCBus 0 U 180 0 0 1 -1/3*U DCBus -1/ √(3)*U DCBus U 240 1 0 1 1/3*U DCBus -1/ √(3)*U DCBus U 300 1 1 1 0 0 O 111 Figure 5-38 graphically depicts some feasible basic switching states (vectors). It is clear that there are six non-zero vectors U 0, U 60, U 120, U 180, U 240, U 300, and two zero vectors O 111, O 000, usable for switching. Therefore, the principle of the Standard Space Vector Modulation resides in applying appropriate switching states for a certain time and thus generating a voltage vector identical to the reference one. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 379 Function GMCLIB_SvmStd_F32 Figure 5-39. Projection of reference voltage vector in sector I Referring to that principle, an objective of the Standard Space Vector Modulation is an approximation of the reference stator voltage vector U S with an appropriate combination of the switching patterns composed of basic space vectors. The graphical explanation of this objective is shown in Figure 5-39 and Figure 5-40. Figure 5-40. Detail of the voltage vector projection in sector I The stator reference voltage vector U S is phase-advanced by 30 ° from the axis- α and thus might be generated with an appropriate combination of the adjacent basic switching states U 0 and U60. These figures also indicate the resultant U α and U β components for space vectors U 0 and U 60 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 380 NXP Semiconductors Chapter 5 API References In this case, the reference stator voltage vector U S is located in Sector I and, as previously mentioned, can be generated with the appropriate duty-cycle ratios of the basic switching states U 60 and U 0. The principal equations concerning this vector location are: Equation GMCLIB_SvmStd_Eq3 Equation GMCLIB_SvmStd_Eq4 where T 60 and T 0 are the respective duty-cycle ratios for which the basic space vectors U 60 and U 0 should be applied within the time period T. T null is the course of time for which the null vectors O 000 and O 111 are applied. Those duty-cycle ratios can be calculated using equations: Equation GMCLIB_SvmStd_Eq5 Equation GMCLIB_SvmStd_Eq6 Considering that the normalized magnitudes of the basic space vectors are |U 60| = |U 0| = 2/ √(3) and by substitution of the trigonometric expressions sin(60 °) and tan(60 °) by their quantities 2/ √(3) and √(3), respectively, equation GMCLIB_SvmStd_Eq5 and equation GMCLIB_SvmStd_Eq6 can be rearranged for the unknown duty-cycle ratios T 60/T and T 0/T: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 381 Function GMCLIB_SvmStd_F32 Equation GMCLIB_SvmStd_Eq7 Equation GMCLIB_SvmStd_Eq8 Equation GMCLIB_SvmStd_Eq7 Equation GMCLIB_SvmStd_Eq8 Figure 5-41. Projection of the reference voltage vector in sector II Sector II is depicted in Figure 5-41. In this particular case, the reference stator voltage vector U S is generated by the appropriate duty-cycle ratios of the basic switching states U 60 and U120 . The basic equations describing this sector are: Equation GMCLIB_SvmStd_Eq9 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 382 NXP Semiconductors Chapter 5 API References Equation GMCLIB_SvmStd_Eq10 where T 120 and T 60 are the respective duty-cycle ratios for which the basic space vectors U 120 and U 60 should be applied within the time period T. These resultant duty-cycle ratios are formed from the auxiliary components termed A and B. The graphical representation of the auxiliary components is shown in Figure 5-42. Figure 5-42. Detail of the voltage vector projection in sector II The equations describing those auxiliary time-duration components are: Equation GMCLIB_SvmStd_Eq11 Equation GMCLIB_SvmStd_Eq12 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 383 Function GMCLIB_SvmStd_F32 Equation GMCLIB_SvmStd_Eq11 and equation GMCLIB_SvmStd_Eq12 have been formed using the sine rule. These equations can be rearranged for the calculation of the auxiliary time-duration components A and B. This is done simply by substitution of the trigonometric terms sin(30 °), sin(120 °) and sin(60 °) by their numerical representations 1/2, √(3)/2 and 1/ √(3), respectively. Equation GMCLIB_SvmStd_Eq13 Equation GMCLIB_SvmStd_Eq14 The resultant duty-cycle ratios, T 120/T and T 60/T, are then expressed in terms of the auxiliary time-duration components defined by equation GMCLIB_SvmStd_Eq13 and equation GMCLIB_SvmStd_Eq14, as follows: Equation GMCLIB_SvmStd_Eq15 Equation GMCLIB_SvmStd_Eq16 With the help of these equations, and also considering the normalized magnitudes of the basic space vectors to be |U 120| = |U 60| = 2/ √(3), the equations expressed for the unknown duty-cycle ratios of basic space vectors T 120/T and T 60/T can be written: Equation GMCLIB_SvmStd_Eq17 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 384 NXP Semiconductors Chapter 5 API References Equation GMCLIB_SvmStd_Eq18 The duty-cycle ratios in remaining sectors can be derived using the same approach. The resulting equations will be similar to those derived for Sector I and Sector II. To depict duty-cycle ratios of the basic space vectors for all sectors, we define: • Three auxiliary variables: Equation GMCLIB_SvmStd_Eq19 Equation GMCLIB_SvmStd_Eq20 Equation GMCLIB_SvmStd_Eq21 Two expressions t_1 and t_2 generally represent duty-cycle ratios of the basic space vectors in the respective sector; e.g., for the first sector, t_1 and t_2 represent duty-cycle ratios of the basic space vectors U 60 and U 0; for the second sector, t_1 and t_2 represent duty-cycle ratios of the basic space vectors U 120 and U 60, etc. For each sector, the expressions t_1 and t_2, in terms of auxiliary variables X, Y and Z, are listed in Table 5-96. Table 5-96. Determination of t_1 and t_2 expressions Sector U 0, U 60 U 60, U 120 U 120, U 180 U 180, U 240 U 240, U 300 U 300, U 0 t_1 X Y -Y Z -Z -X t_2 -Z Z X -X -Y Y Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 385 Function GMCLIB_SvmStd_F32 For the determination of auxiliary variables X equation GMCLIB_SvmStd_Eq19, Y equation GMCLIB_SvmStd_Eq20 and Z equation GMCLIB_SvmStd_Eq21, the sector number is required. This information can be obtained by several approaches. One approach discussed here requires the use of a modified Inverse Clark Transformation to transform the direct- α and quadrature- β components into a balanced three-phase quantity u ref1, u ref2 and u ref3, used for a straightforward calculation of the sector number, to be shown later. Equation GMCLIB_SvmStd_Eq22 Equation GMCLIB_SvmStd_Eq23 Equation GMCLIB_SvmStd_Eq24 The modified Inverse Clark Transformation projects the quadrature-u β component into u ref1, as shown in Figure 5-43 and Figure 5-44, whereas voltages generated by the conventional Inverse Clark Transformation project the u α component into u ref1. Figure 5-43. Direct-ua and quadrature-ub components of stator reference voltage Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 386 NXP Semiconductors Chapter 5 API References Figure 5-43 depicts the u α and u β components of the stator reference voltage vector U S that were calculated by the equations u α = cos( θ) and u β = sin( θ), respectively. Figure 5-44. Reference Voltages u_ref1, u_ref2 and u_ref3 The Sector Identification Tree, shown in Figure 5-45, can be a numerical solution of the approach shown in Figure 5-44. Figure 5-45. Identification of the sector number It should be pointed out that, in the worst case, three simple comparisons are required to precisely identify the sector of the stator reference voltage vector. For example, if the stator reference voltage vector resides according to the one shown in Figure 5-39, the stator reference voltage vector is phase-advanced by 30 ° from the α-axis, which results in the positive quantities of u ref1 and u ref2 and the negative quantity of u ref3; refer to Figure 5-44. If these quantities are used as the inputs to the Sector Identification Tree, the product of those comparisons will be Sector I. Using the same approach identifies Sector II, if the stator reference voltage vector is located according to the one shown in Figure 5-42. The variables t 1, t 2 and t 3, representing the switching duty-cycle ratios of the respective three-phase system, are given by the following equations: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 387 Function GMCLIB_SvmStd_F32 Equation GMCLIB_SvmStd_Eq25 Equation GMCLIB_SvmStd_Eq26 Equation GMCLIB_SvmStd_Eq27 where T is the switching period, t_1 and t_2 are the duty-cycle ratios (see Table 5-96) of the basic space vectors, given for the respective sector. Equation GMCLIB_SvmStd_Eq25, equation GMCLIB_SvmStd_Eq26 and equation GMCLIB_SvmStd_Eq27 are specific solely to the Standard Space Vector Modulation technique; consequently, other Space Vector Modulation techniques discussed later will require deriving different equations. The next step is to assign the correct duty-cycle ratios, t 1, t 2 and t 3, to the respective motor phases. This is a simple task, accomplished in view of the position of the stator reference voltage vector as shown in Table 5-97. Table 5-97. Assignment of the duty-cycle ratios to motor phases Sector U 0, U 60 U 60, U 120 U 120, U 180 U 180, U 240 U 240, U 300 U 300, U 0 pwm a t3 t2 t1 t1 t2 t3 pwm b t2 t3 t3 t2 t1 t1 pwm c t1 t1 t2 t3 t3 t2 The principle of the Space Vector Modulation technique consists in applying the basic voltage vectors U XXX and O XXX for the certain time in such a way that the mean vector, generated by the Pulse Width Modulation approach for the period T, is equal to the original stator reference voltage vector U S. This provides a great variability of the arrangement of the basic vectors during the PWM period T. Those vectors might be arranged either to lower switching losses or to achieve diverse results, such as centrealigned PWM, edge-aligned PWM or a minimal number of switching states. A brief discussion of the widely-used centre-aligned PWM follows. Generating the centrealigned PWM pattern is accomplished practically by comparing the threshold levels, Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 388 NXP Semiconductors Chapter 5 API References pwm a, pwm b and pwm c with a free-running up-down counter. The timer counts to 1 (0x7FFF) and then down to 0 (0x0000). It is supposed that when a threshold level is larger than the timer value, the respective PWM output is active. Otherwise, it is inactive; see Figure 5-46 Figure 5-46. Standard space vector modulation technique - centre-aligned PWM Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). 5.77.5 Re-entrancy The function is re-entrant. 5.77.6 Code Example #include "gmclib.h" #define U_MAX 15 SWLIBS_2Syst_F32 tr32InVoltage; SWLIBS_3Syst_F32 tr32PwmABC; tU32 u32SvmSector; void main(void) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 389 Function GMCLIB_SvmStd_F16 { // Input voltage vector 15V @ angle 30deg // alpha component of input voltage vector = 12.99[V] // beta component of input voltage vector = 7.5[V] tr32InVoltage.f32Arg1 = FRAC32 (12.99/U_MAX); tr32InVoltage.f32Arg2 = FRAC32 (7.5/U_MAX); // output pwm dutycycles stored in structure referenced by tr32PwmABC // pwmA dutycycle = 0x7FFF A2C9 = FRAC32(0.9999888... ) // pwmb dutycycle = 0x4000 5D35 = FRAC32(0.5000111... ) // pwmc dutycycle = 0x0000 5D35 = FRAC32(0.0000111... ) // svmSector = 0x1 [sector] u32SvmSector = GMCLIB_SvmStd_F32 (&tr32PwmABC,&tr32InVoltage); // output pwm dutycycles stored in structure referenced by tr32PwmABC // pwmA dutycycle = 0x7FFF A2C9 = FRAC32(0.9999888... ) // pwmb dutycycle = 0x4000 5D35 = FRAC32(0.5000111... ) // pwmc dutycycle = 0x0000 5D35 = FRAC32(0.0000111... ) // svmSector = 0x1 [sector] u32SvmSector = GMCLIB_SvmStd (&tr32PwmABC,&tr32InVoltage,F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output pwm dutycycles stored in structure referenced by tr32PwmABC // pwmA dutycycle = 0x7FFF A2C9 = FRAC32(0.9999888... ) // pwmb dutycycle = 0x4000 5D35 = FRAC32(0.5000111... ) // pwmc dutycycle = 0x0000 5D35 = FRAC32(0.0000111... ) // svmSector = 0x1 [sector] u32SvmSector = GMCLIB_SvmStd (&tr32PwmABC,&tr32InVoltage); 5.78 Function GMCLIB_SvmStd_F16 This function calculates the duty-cycle ratios using the Standard Space Vector Modulation technique. 5.78.1 Declaration tU16 GMCLIB_SvmStd_F16(SWLIBS_3Syst_F16 *pOut, const SWLIBS_2Syst_F16 *const pIn); 5.78.2 Arguments Table 5-98. GMCLIB_SvmStd_F16 arguments Type Name Direction Description SWLIBS_3Syst_F16 * pOut input, output Pointer to the structure containing calculated duty-cycle ratios of the 3-Phase system. const SWLIBS_2Syst_F16 *const pIn input Pointer to the structure containing direct U α and quadrature U β components of the stator voltage vector. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 390 NXP Semiconductors Chapter 5 API References 5.78.3 Return The function returns a 16-bit value in format INT, representing the actual space sector which contains the stator reference vector U s. 5.78.4 Description The GMCLIB_SvmStd_F16 function for calculating duty-cycle ratios is widely-used in the modern electric drive. This, function calculates appropriate duty-cycle ratios, which are needed for generating the given stator reference voltage vector using a special Space Vector Modulation technique, termed Standard Space Vector Modulation. The basic principle of the Standard Space Vector Modulation Technique can be explained with the help of the power stage diagram in Figure 5-47. Figure 5-47. Power stage schematic diagram Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 391 Function GMCLIB_SvmStd_F16 Top and bottom switches work in a complementary mode; i.e., if the top switch, S At, is ON, then the corresponding bottom switch, S Ab, is OFF, and vice versa. Considering that value 1 is assigned to the ON state of the top switch, and value 0 is assigned to the ON state of the bottom switch, the switching vector, [a, b, c] T can be defined. Creating such a vector allows a numerical definition of all possible switching states. In a three-phase power stage configuration (as shown in Figure 5-47), eight possible switching states (detailed in Figure 5-48) are feasible. Figure 5-48. Basic space vectors These states, together with the resulting instantaneous output line-to-line and phase voltages, are listed in Table 5-99. Table 5-99. Switching patterns a b c Ua Ub Uc U AB U BC U CA Vector 0 0 0 0 0 0 0 0 0 O 000 1 0 0 2/3*U -1/3*U -1/3*U U DCBus 0 -U DCBus U0 DCBus DCBus DCBus 1 1 0 1/3*U 1/3*U -2/3*U 0 U DCBus -U DCBus U 60 DCBus DCBus DCBus -U DCBus U DCBus 0 U 120 -U DCBus 0 U DCBus U 180 0 -U DCBus U DCBus U 240 U DCBus -U DCBus 0 U 300 0 0 0 O 111 0 1 0 0 1 1 0 0 1 1 1 0 1 1 1 -1/3*U 2/3*U -1/3*U DCBus DCBus DCBus -2/3*U 1/3*U 1/3*U DCBus DCBus DCBus -1/3*U -1/3*U 2/3*U DCBus DCBus DCBus 1/3*U -2/3*U 1/3*U DCBus DCBus DCBus 0 0 0 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 392 NXP Semiconductors Chapter 5 API References The quantities of the direct-u α and the quadrature-u β components of the two-phase orthogonal coordinate system, describing the three-phase stator voltages, are expressed by the Clarke Transformation. Equation GMCLIB_SvmStd_Eq1 Equation GMCLIB_SvmStd_Eq2 The three-phase stator voltages,U a, U b, and U c, are transformed using the Clarke Transformation into the U α and the U β components of the two-phase orthogonal coordinate system. The transformation results are listed in Table 5-100. Table 5-100. Switching patterns and space vectors a b c uα uβ Vector 0 0 0 0 0 O 000 1 0 0 2/3*U DCBus 0 U0 1 1 0 1/3*U DCBus 1/ √(3)*U DCBus U 60 0 1 0 -1/3*U DCBus 1/ √(3)*U DCBus U 120 0 1 1 -2/3*U DCBus 0 U 180 0 0 1 -1/3*U DCBus -1/ √(3)*U DCBus U 240 1 0 1 1/3*U DCBus -1/ √(3)*U DCBus U 300 1 1 1 0 0 O 111 Figure 5-48 graphically depicts some feasible basic switching states (vectors). It is clear that there are six non-zero vectors U 0, U 60, U 120, U 180, U 240, U 300, and two zero vectors O 111, O 000, usable for switching. Therefore, the principle of the Standard Space Vector Modulation resides in applying appropriate switching states for a certain time and thus generating a voltage vector identical to the reference one. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 393 Function GMCLIB_SvmStd_F16 Figure 5-49. Projection of reference voltage vector in sector I Referring to that principle, an objective of the Standard Space Vector Modulation is an approximation of the reference stator voltage vector U S with an appropriate combination of the switching patterns composed of basic space vectors. The graphical explanation of this objective is shown in Figure 5-49 and Figure 5-50. Figure 5-50. Detail of the voltage vector projection in sector I The stator reference voltage vector U S is phase-advanced by 30 ° from the axis- α and thus might be generated with an appropriate combination of the adjacent basic switching states U 0 and U60. These figures also indicate the resultant U α and U β components for space vectors U 0 and U 60 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 394 NXP Semiconductors Chapter 5 API References In this case, the reference stator voltage vector U S is located in Sector I and, as previously mentioned, can be generated with the appropriate duty-cycle ratios of the basic switching states U 60 and U 0. The principal equations concerning this vector location are: Equation GMCLIB_SvmStd_Eq3 Equation GMCLIB_SvmStd_Eq4 where T 60 and T 0 are the respective duty-cycle ratios for which the basic space vectors U 60 and U 0 should be applied within the time period T. T null is the course of time for which the null vectors O 000 and O 111 are applied. Those duty-cycle ratios can be calculated using equations: Equation GMCLIB_SvmStd_Eq5 Equation GMCLIB_SvmStd_Eq6 Considering that the normalized magnitudes of the basic space vectors are |U 60| = |U 0| = 2/ √(3) and by substitution of the trigonometric expressions sin(60 °) and tan(60 °) by their quantities 2/ √(3) and √(3), respectively, equation GMCLIB_SvmStd_Eq5 and equation GMCLIB_SvmStd_Eq6 can be rearranged for the unknown duty-cycle ratios T 60/T and T 0/T: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 395 Function GMCLIB_SvmStd_F16 Equation GMCLIB_SvmStd_Eq7 Equation GMCLIB_SvmStd_Eq8 Equation GMCLIB_SvmStd_Eq7 Equation GMCLIB_SvmStd_Eq8 Figure 5-51. Projection of the reference voltage vector in sector II Sector II is depicted in Figure 5-51. In this particular case, the reference stator voltage vector U S is generated by the appropriate duty-cycle ratios of the basic switching states U 60 and U 120. The basic equations describing this sector are: Equation GMCLIB_SvmStd_Eq9 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 396 NXP Semiconductors Chapter 5 API References Equation GMCLIB_SvmStd_Eq10 where T 120 and T 60 are the respective duty-cycle ratios for which the basic space vectors U 120 and U 60 should be applied within the time period T. These resultant duty-cycle ratios are formed from the auxiliary components termed A and B. The graphical representation of the auxiliary components is shown in Figure 5-52. Figure 5-52. Detail of the voltage vector projection in sector II The equations describing those auxiliary time-duration components are: Equation GMCLIB_SvmStd_Eq11 Equation GMCLIB_SvmStd_Eq12 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 397 Function GMCLIB_SvmStd_F16 Equation GMCLIB_SvmStd_Eq11 and equation GMCLIB_SvmStd_Eq12 have been formed using the sine rule. These equations can be rearranged for the calculation of the auxiliary time-duration components A and B. This is done simply by substitution of the trigonometric terms sin(30 °), sin(120 °) and sin(60 °) by their numerical representations 1/2, √(3)/2 and 1/ √(3), respectively. Equation GMCLIB_SvmStd_Eq13 Equation GMCLIB_SvmStd_Eq14 The resultant duty-cycle ratios, T 120/T and T 60/T, are then expressed in terms of the auxiliary time-duration components defined by equation GMCLIB_SvmStd_Eq13 and equation GMCLIB_SvmStd_Eq14, as follows: Equation GMCLIB_SvmStd_Eq15 Equation GMCLIB_SvmStd_Eq16 With the help of these equations, and also considering the normalized magnitudes of the basic space vectors to be |U 120| = |U 60| = 2/ √(3), the equations expressed for the unknown duty-cycle ratios of basic space vectors T 120/T and T 60/T can be written: Equation GMCLIB_SvmStd_Eq17 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 398 NXP Semiconductors Chapter 5 API References Equation GMCLIB_SvmStd_Eq18 The duty-cycle ratios in remaining sectors can be derived using the same approach. The resulting equations will be similar to those derived for Sector I and Sector II. To depict duty-cycle ratios of the basic space vectors for all sectors, we define: • Three auxiliary variables: Equation GMCLIB_SvmStd_Eq19 Equation GMCLIB_SvmStd_Eq20 Equation GMCLIB_SvmStd_Eq21 Two expressions t_1 and t_2 generally represent duty-cycle ratios of the basic space vectors in the respective sector; e.g., for the first sector, t_1 and t_2 represent duty-cycle ratios of the basic space vectors U 60 and U 0; for the second sector, t_1 and t_2 represent duty-cycle ratios of the basic space vectors U 120 and U 60, etc. For each sector, the expressions t_1 and t_2, in terms of auxiliary variables X, Y and Z, are listed in Table 5-101. Table 5-101. Determination of t_1 and t_2 expressions Sector U 0, U 60 U 60, U 120 U 120, U 180 U 180, U 240 U 240, U 300 U 300, U 0 t_1 X Y -Y Z -Z -X t_2 -Z Z X -X -Y Y Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 399 Function GMCLIB_SvmStd_F16 For the determination of auxiliary variables X equation GMCLIB_SvmStd_Eq19, Y equation GMCLIB_SvmStd_Eq20 and Z equation GMCLIB_SvmStd_Eq21, the sector number is required. This information can be obtained by several approaches. One approach discussed here requires the use of a modified Inverse Clark Transformation to transform the direct- α and quadrature- β components into a balanced three-phase quantity u ref1, u ref2 and u ref3, used for a straightforward calculation of the sector number, to be shown later. Equation GMCLIB_SvmStd_Eq22 Equation GMCLIB_SvmStd_Eq23 Equation GMCLIB_SvmStd_Eq24 The modified Inverse Clark Transformation projects the quadrature-u β component into u ref1, as shown in Figure 5-53 and Figure 5-54, whereas voltages generated by the conventional Inverse Clark Transformation project the u α component into u ref1. Figure 5-53. Direct-ua and quadrature-ub components of stator reference voltage Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 400 NXP Semiconductors Chapter 5 API References Figure 5-53 depicts the u α and u β components of the stator reference voltage vector U S that were calculated by the equations u α = cos( θ) and u β = sin( θ), respectively. Figure 5-54. Reference voltages u_ref1, u_ref2 and u_ref3 The Sector Identification Tree, shown in Figure 5-55, can be a numerical solution of the approach shown in Figure 5-54. Figure 5-55. Identification of the sector number It should be pointed out that, in the worst case, three simple comparisons are required to precisely identify the sector of the stator reference voltage vector. For example, if the stator reference voltage vector resides according to the one shown in Figure 5-49, the stator reference voltage vector is phase-advanced by 30 ° from the α-axis, which results in the positive quantities of u ref1 and u ref2 and the negative quantity of u ref3; refer to Figure 5-54. If these quantities are used as the inputs to the Sector Identification Tree, the product of those comparisons will be Sector I. Using the same approach identifies Sector II, if the stator reference voltage vector is located according to the one shown in Figure 5-52. The variables t 1, t 2 and t 3, representing the switching duty-cycle ratios of the respective three-phase system, are given by the following equations: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 401 Function GMCLIB_SvmStd_F16 Equation GMCLIB_SvmStd_Eq25 Equation GMCLIB_SvmStd_Eq26 Equation GMCLIB_SvmStd_Eq27 where T is the switching period, t_1 and t_2 are the duty-cycle ratios (see Table 5-101) of the basic space vectors, given for the respective sector. Equation GMCLIB_SvmStd_Eq25, equation GMCLIB_SvmStd_Eq26 and equation GMCLIB_SvmStd_Eq27 are specific solely to the Standard Space Vector Modulation technique; consequently, other Space Vector Modulation techniques discussed later will require deriving different equations. The next step is to assign the correct duty-cycle ratios, t 1, t 2 and t 3, to the respective motor phases. This is a simple task, accomplished in view of the position of the stator reference voltage vector as shown in Table 5-102. Table 5-102. Assignment of the duty-cycle ratios to motor phases Sector U 0, U 60 U 60, U 120 U 120, U 180 U 180, U 240 U 240, U 300 U 300, U 0 pwm a t3 t2 t1 t1 t2 t3 pwm b t2 t3 t3 t2 t1 t1 pwm c t1 t1 t2 t3 t3 t2 The principle of the Space Vector Modulation technique consists in applying the basic voltage vectors U XXX and O XXX for the certain time in such a way that the mean vector, generated by the Pulse Width Modulation approach for the period T, is equal to the original stator reference voltage vector U S. This provides a great variability of the arrangement of the basic vectors during the PWM period T. Those vectors might be arranged either to lower switching losses or to achieve diverse results, such as centrealigned PWM, edge-aligned PWM or a minimal number of switching states. A brief discussion of the widely-used centre-aligned PWM follows. Generating the centrealigned PWM pattern is accomplished practically by comparing the threshold levels, Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 402 NXP Semiconductors Chapter 5 API References pwm a, pwm b and pwm c with a free-running up-down counter. The timer counts to 1 (0x7FFF) and then down to 0 (0x0000). It is supposed that when a threshold level is larger than the timer value, the respective PWM output is active. Otherwise, it is inactive; see Figure 5-56 Figure 5-56. Standard space vector modulation technique - centre-aligned PWM Note The input/output pointers must contain valid addresses otherwise a fault may occur (HardFault). 5.78.5 Re-entrancy The function is re-entrant. 5.78.6 Code Example #include "gmclib.h" #define U_MAX 15 SWLIBS_2Syst_F16 tr16InVoltage; SWLIBS_3Syst_F16 tr16PwmABC; tU16 u16SvmSector; void main(void) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 403 Function MLIB_Abs_F32 { // Input voltage vector 15V @ angle 30deg // alpha component of input voltage vector = 12.99[V] // beta component of input voltage vector = 7.5[V] tr16InVoltage.f16Arg1 = FRAC16 (12.99/U_MAX); tr16InVoltage.f16Arg2 = FRAC16 (7.5/U_MAX); // output pwm dutycycles stored in structure referenced by tr16PwmABC // pwmA dutycycle = 0x7FFF = FRAC16(0.9999... ) // pwmb dutycycle = 0x4000 = FRAC16(0.5000... ) // pwmc dutycycle = 0x0000 = FRAC16(0.0000... ) // svmSector = 0x1 [sector] u16SvmSector = GMCLIB_SvmStd_F16 (&tr16PwmABC,&tr16InVoltage); // output pwm dutycycles stored in structure referenced by tr16PwmABC // pwmA dutycycle = 0x7FFF = FRAC16(0.9999... ) // pwmb dutycycle = 0x4000 = FRAC16(0.5000... ) // pwmc dutycycle = 0x0000 = FRAC16(0.0000... ) // svmSector = 0x1 [sector] u16SvmSector = GMCLIB_SvmStd (&tr16PwmABC,&tr16InVoltage,F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output pwm dutycycles stored in structure referenced by tr16PwmABC // pwmA dutycycle = 0x7FFF = FRAC16(0.9999... ) // pwmb dutycycle = 0x4000 = FRAC16(0.5000... ) // pwmc dutycycle = 0x0000 = FRAC16(0.0000... ) // svmSector = 0x1 [sector] u16SvmSector = GMCLIB_SvmStd (&tr16PwmABC,&tr16InVoltage); 5.79 Function MLIB_Abs_F32 This function returns absolute value of input parameter. 5.79.1 Declaration tFrac32 MLIB_Abs_F32(register tFrac32 f32In); 5.79.2 Arguments Table 5-103. MLIB_Abs_F32 arguments Type register tFrac32 Name f32In Direction input Description Input value. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 404 NXP Semiconductors Chapter 5 API References 5.79.3 Return Absolute value of input parameter. 5.79.4 Description This inline function returns the absolute value of input parameter. The input value as well as output value is considered as 32-bit fractional data type. The output saturation is not implemented in this function, thus in case the absolute value of input parameter is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Abs_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. 5.79.5 Re-entrancy The function is re-entrant. 5.79.6 Code Example #include "mlib.h" tFrac32 f32In; tFrac32 f32Out; void main(void) { // input value = -0.25 f32In = FRAC32 (-0.25); // output should be FRAC32(0.25) f32Out = MLIB_Abs_F32(f32In); // output should be FRAC32(0.25) f32Out = MLIB_Abs (f32In, F32); // ############################################################## // Available only if 32-bit fractional implementation selected Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 405 Function MLIB_Abs_F16 // as default // ############################################################## } // output should be FRAC32(0.25) f32Out = MLIB_Abs (f32In); 5.80 Function MLIB_Abs_F16 This function returns absolute value of input parameter. 5.80.1 Declaration tFrac16 MLIB_Abs_F16(register tFrac16 f16In); 5.80.2 Arguments Table 5-104. MLIB_Abs_F16 arguments Type register tFrac16 Name Direction input f16In Description Input value. 5.80.3 Return Absolute value of input parameter. 5.80.4 Description This inline function returns the absolute value of input parameter. The input value as well as output value is considered as 16-bit fractional data type. The output saturation is not implemented in this function, thus in case the absolute value of input parameter is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Abs_Eq1 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 406 NXP Semiconductors Chapter 5 API References Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. 5.80.5 Re-entrancy The function is re-entrant. 5.80.6 Code Example #include "mlib.h" tFrac16 f16In; tFrac16 f16Out; void main(void) { // input value = -0.25 f16In = FRAC16 (-0.25); // output should be FRAC16(0.25) f16Out = MLIB_Abs_F16(f16In); // output should be FRAC16(0.25) f16Out = MLIB_Abs (f16In, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be FRAC16(0.25) f16Out = MLIB_Abs (f16In); 5.81 Function MLIB_AbsSat_F32 This function returns absolute value of input parameter and saturate if necessary. 5.81.1 Declaration tFrac32 MLIB_AbsSat_F32(register tFrac32 f32In); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 407 Function MLIB_AbsSat_F32 5.81.2 Arguments Table 5-105. MLIB_AbsSat_F32 arguments Type register tFrac32 Name Direction input f32In Description Input value. 5.81.3 Return Absolute value of input parameter, saturated if necessary. 5.81.4 Description This inline function returns the absolute value of input parameter. The input values as well as output value is considered as 32-bit fractional data type. The output saturation is implemented in this function, thus in case the absolute value of input parameter is outside the (-1, 1) interval, the output value is limited to the boundary value. The output of the function is defined by the following simple equation: Equation MLIB_AbsSat_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is detected in this function. The functions saturates the return value if it cannot fit into the return type. 5.81.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 408 NXP Semiconductors Chapter 5 API References 5.81.6 Code Example #include "mlib.h" tFrac32 f32In; tFrac32 f32Out; void main(void) { // input value = -0.25 f32In = FRAC32 (-0.25); // output should be FRAC32(0.25) f32Out = MLIB_AbsSat_F32(f32In); // output should be FRAC32(0.25) f32Out = MLIB_AbsSat (f32In, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be FRAC32(0.25) f32Out = MLIB_AbsSat (f32In); 5.82 Function MLIB_AbsSat_F16 This function returns absolute value of input parameter and saturate if necessary. 5.82.1 Declaration tFrac16 MLIB_AbsSat_F16(register tFrac16 f16In); 5.82.2 Arguments Table 5-106. MLIB_AbsSat_F16 arguments Type Name register tFrac16 f16In Direction input Description Input value. 5.82.3 Return Absolute value of input parameter, saturated if necessary. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 409 Function MLIB_AbsSat_F16 5.82.4 Description This inline function returns the absolute value of input parameter. The input values as well as output value is considered as 16-bit fractional data type. The output saturation is implemented in this function, thus in case the absolute value of input parameter is outside the (-1, 1) interval, the output value is limited to the boundary value. The output of the function is defined by the following simple equation: Equation MLIB_AbsSat_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is detected in this function. The functions saturates the return value if it cannot fit into the return type. 5.82.5 Re-entrancy The function is re-entrant. 5.82.6 Code Example #include "mlib.h" tFrac16 f16In; tFrac16 f16Out; void main(void) { // input value = -0.25 f16In = FRAC16 (-0.25); // output should be FRAC16(0.25) f16Out = MLIB_AbsSat_F16(f16In); // output should be FRAC16(0.25) f16Out = MLIB_AbsSat (f16In, F16); // ############################################################## // Available only if 16-bit fractional implementation selected // as default Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 410 NXP Semiconductors Chapter 5 API References // ############################################################## } // output should be FRAC16(0.25) f16Out = MLIB_AbsSat (f16In); 5.83 Function MLIB_Add_F32 This function returns sum of two input parameters. 5.83.1 Declaration tFrac32 MLIB_Add_F32(register tFrac32 f32In1, register tFrac32 f32In2); 5.83.2 Arguments Table 5-107. MLIB_Add_F32 arguments Type Name Direction Description register tFrac32 f32In1 input First value to be add. register tFrac32 f32In2 input Second value to be add. 5.83.3 Return Sum of two input values. 5.83.4 Description This inline function returns the sum of two input values. The input values as well as output value is considered as 32-bit fractional data type. The output saturation is not implemented in this function, thus in case the sum of input values is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Add_Eq1 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 411 Function MLIB_Add_F16 Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. 5.83.5 Re-entrancy: The function is re-entrant. 5.83.6 Code Example: #include "mlib.h" tFrac32 f32In1, f32In2; tFrac32 f32Out; void main(void) { // input value 1 = 0.25 f32In1 = FRAC32 (0.25); // input value 2 = 0.25 f32In2 = FRAC32 (0.25); // output should be FRAC32(0.5) = 0x40000000 f32Out = MLIB_Add_F32(f32In1, f32In2); // output should be FRAC32(0.5) = 0x40000000 f32Out = MLIB_Add (f32In1, f32In2, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be FRAC32(0.5) = 0x40000000 f32Out = MLIB_Add (f32In1, f32In2); 5.84 Function MLIB_Add_F16 This function returns sum of two input parameters. 5.84.1 Declaration tFrac16 MLIB_Add_F16(register tFrac16 f16In1, register tFrac16 f16In2); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 412 NXP Semiconductors Chapter 5 API References 5.84.2 Arguments Table 5-108. MLIB_Add_F16 arguments Type Name Direction Description register tFrac16 f16In1 input First value to be add. register tFrac16 f16In2 input Second value to be add. 5.84.3 Return Sum of two input values. 5.84.4 Description This inline function returns the sum of two input values. The input values as well as output value is considered as 16-bit fractional values. The output saturation is not implemented in this function, thus in case the sum of input values is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Add_Eq1 Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. 5.84.5 Re-entrancy The function is re-entrant. 5.84.6 Code Example #include "mlib.h" tFrac16 f16In1, f16In2; tFrac16 f16Out; Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 413 Function MLIB_AddSat_F32 void main(void) { // input value 1 = 0.25 f16In1 = FRAC16 (0.25); // input value 2 = 0.25 f16In2 = FRAC16 (0.25); // output should be FRAC16(0.5) = 0x4000 f16Out = MLIB_Add_F16(f16In1, f16In2); // output should be FRAC16(0.5) = 0x4000 f16Out = MLIB_Add (f16In1, f16In2, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be FRAC16(0.5) = 0x4000 f16Out = MLIB_Add (f16In1, f16In2); 5.85 Function MLIB_AddSat_F32 This function returns sum of two input parameters and saturate if necessary. 5.85.1 Declaration tFrac32 MLIB_AddSat_F32(register tFrac32 f32In1, register tFrac32 f32In2); 5.85.2 Arguments Table 5-109. MLIB_AddSat_F32 arguments Type Name Direction Description register tFrac32 f32In1 input First value to be add. register tFrac32 f32In2 input Second value to be add. 5.85.3 Return Sum of two input values, saturated if necessary. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 414 NXP Semiconductors Chapter 5 API References 5.85.4 Description This inline function returns the sum of two input values. The input values as well as output value is considered as 32-bit fractional data type. The output saturation is implemented in this function, thus in case the sum of input values is outside the (-1, 1) interval, the output value is limited to the boundary value. The output of the function is defined by the following simple equation: Equation MLIB_AddSat_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is detected in this function. The functions saturates the return value if it cannot fit into the return type. 5.85.5 Re-entrancy The function is re-entrant. 5.85.6 Code Example #include "mlib.h" tFrac32 f32In1, f32In2; tFrac32 f32Out; void main(void) { // input value 1 = 0.25 f32In1 = FRAC32 (0.25); // input value 2 = 0.25 f32In2 = FRAC32 (0.25); // output should be FRAC32(0.5) = 0x40000000 f32Out = MLIB_AddSat_F32(f32In1, f32In2); // output should be FRAC32(0.5) = 0x40000000 f32Out = MLIB_AddSat (f32In1, f32In2, F32); // ############################################################## // Available only if 32-bit fractional implementation selected Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 415 Function MLIB_AddSat_F16 // as default // ############################################################## } // output should be FRAC32(0.5) = 0x40000000 f32Out = MLIB_AddSat (f32In1, f32In2); 5.86 Function MLIB_AddSat_F16 This function returns sum of two input parameters and saturate if necessary. 5.86.1 Declaration tFrac16 MLIB_AddSat_F16(register tFrac16 f16In1, register tFrac16 f16In2); 5.86.2 Arguments Table 5-110. MLIB_AddSat_F16 arguments Type Name Direction Description register tFrac16 f16In1 input First value to be add. register tFrac16 f16In2 input Second value to be add. 5.86.3 Return Sum of two input values, saturated if necessary. 5.86.4 Description This inline function returns the sum of two input values. The input values as well as output value is considered as 16-bit fractional data type. The output saturation is implemented in this function, thus in case the sum of input values is outside the (-1, 1) interval, the output value is limited to the boundary value. The output of the function is defined by the following simple equation: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 416 NXP Semiconductors Chapter 5 API References Equation MLIB_AddSat_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is detected in this function. The functions saturates the return value if it cannot fit into the return type. 5.86.5 Re-entrancy The function is re-entrant. 5.86.6 Code Example #include "mlib.h" tFrac16 f16In1, f16In2; tFrac16 f16Out; void main(void) { // input value 1 = 0.25 f16In1 = FRAC16 (0.25); // input value 2 = 0.25 f16In2 = FRAC16 (0.25); // output should be FRAC16(0.5) = 0x4000 f16Out = MLIB_AddSat_F16(f16In1, f16In2); // output should be FRAC16(0.5) = 0x4000 f16Out = MLIB_AddSat (f16In1, f16In2, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be FRAC16(0.5) = 0x4000 f16Out = MLIB_AddSat (f16In1, f16In2); 5.87 Function MLIB_Convert_F32F16 This function converts the input value to different representation with scale. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 417 Function MLIB_Convert_F32F16 5.87.1 Declaration tFrac32 MLIB_Convert_F32F16(register tFrac16 f16In1, register tFrac16 f16In2); 5.87.2 Arguments Table 5-111. MLIB_Convert_F32F16 arguments Type Name Direction Description register tFrac16 f16In1 input Input value in 16-bit fractional format to be converted. register tFrac16 f16In2 input Scale factor in 16-bit fractional format. 5.87.3 Return Converted input value in 32-bit fractional format. 5.87.4 Description This inline function returns converted input value. The input value is considered as 16-bit fractional data type and output value is considered as 32-bit fractional data type thus both values represent the values in unity model. The second value represents the scale factor and is considered as 16-bit fractional data type. The sign of the second value represents the scale mechanism. In case the second value is positive the first input value is multiplied with the second one and converted to the output format. In case the second value is negative, the first input value is divided by absolute value of second input value and converted to the output format. The output saturation is not implemented in this function, thus in case the input value is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Convert_Eq1 Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 418 NXP Semiconductors Chapter 5 API References 5.87.5 Re-entrancy The function is re-entrant. 5.87.6 Code Example #include "mlib.h" tFrac16 f16In1, f16In2; tFrac32 f32Out; void main(void) { // input value = 0.25 = 0x2000 f16In1 = FRAC16 (0.25); // scale value = 0.5 = 0x4000 f16In2 = FRAC16 (0.5); // output should be FRAC32(0.125) = 0x10000000 f32Out = MLIB_Convert_F32F16(f16In1, f16In2); // output should be FRAC32(0.125) = 0x10000000 f32Out = MLIB_Convert (f16In1, f16In2, F32F16); // scale value = -0.5 = 0xC000 f16In2 = FRAC16 (-0.5); // output should be FRAC32(0.5) = 0x40000000 f32Out = MLIB_Convert_F32F16(f16In1, f16In2); } // output should be FRAC32(0.5) = 0x40000000 f32Out = MLIB_Convert (f16In1, f16In2, F32F16); 5.88 Function MLIB_Convert_F16F32 This function converts the input value to different representation with scale. 5.88.1 Declaration tFrac16 MLIB_Convert_F16F32(register tFrac32 f32In1, register tFrac32 f32In2); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 419 Function MLIB_Convert_F16F32 5.88.2 Arguments Table 5-112. MLIB_Convert_F16F32 arguments Type Name Direction Description register tFrac32 f32In1 input Input value in 32-bit fractional format to be converted. register tFrac32 f32In2 input Scale factor in 32-bit fractional format. 5.88.3 Return Converted input value in 16-bit fractional format. 5.88.4 Description This inline function returns converted input value. The input value is considered as 32-bit fractional data type and output value is considered as 16-bit fractional data type thus both values represent the values in unity model. The second value represents the scale factor and is considered as 32-bit fractional data type. The sign of the second value represents the scale mechanism. In case the second value is positive the first input value is multiplied with the second one and converted to the output format. In case the second value is negative, the first input value is divided by absolute value of second input value and converted to the output format. The output saturation is not implemented in this function, thus in case the input value is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Convert_Eq1 Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. 5.88.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 420 NXP Semiconductors Chapter 5 API References 5.88.6 Code Example #include "mlib.h" tFrac32 f32In1, f32In2; tFrac16 f16Out; void main(void) { // input value = 0.25 = 0x20000000 f32In1 = FRAC32 (0.25); // scale value = 0.5 = 0x40000000 f32In2 = FRAC32 (0.5); // output should be FRAC16(0.125) = 0x1000 f16Out = MLIB_Convert_F16F32(f32In1, f32In2); // output should be FRAC16(0.125) = 0x1000 f16Out = MLIB_Convert (f32In1, f32In2, F16F32); // scale value = -0.5 = 0xC0000000 f32In2 = FRAC32 (-0.5); // output should be FRAC16(0.5) = 0x4000 f16Out = MLIB_Convert_F16F32(f32In1, f32In2); } // output should be FRAC16(0.5) = 0x4000 f16Out = MLIB_Convert (f32In1, f32In2, F16F32); 5.89 Function MLIB_ConvertPU_F32F16 This function converts the input value to different representation without scale. 5.89.1 Declaration tFrac32 MLIB_ConvertPU_F32F16(register tFrac16 f16In); 5.89.2 Arguments Table 5-113. MLIB_ConvertPU_F32F16 arguments Type Name register tFrac16 f16In Direction input Description Input value in 16-bit fractional format to be converted. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 421 Function MLIB_ConvertPU_F32F16 5.89.3 Return Converted input value in 32-bit fractional format. 5.89.4 Description This inline function returns converted input value. The input value is considered as 16-bit fractional data type and output value is considered as 32-bit fractional data type thus both values represent the values in unity model. The output saturation is not implemented in this function, thus in case the input value is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_ConvertPU_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. 5.89.5 Re-entrancy The function is re-entrant. 5.89.6 Code Example #include "mlib.h" tFrac16 f16In; tFrac32 f32Out; void main(void) { // input value = 0.25 = 0x2000 f16In = FRAC16 (0.25); // output should be FRAC32(0.25) = 0x20000000 f32Out = MLIB_ConvertPU_F32F16(f16In); } // output should be FRAC32(0.25) = 0x20000000 f32Out = MLIB_ConvertPU (f16In, F32F16); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 422 NXP Semiconductors Chapter 5 API References 5.90 Function MLIB_ConvertPU_F16F32 This function converts the input value to different representation without scale. 5.90.1 Declaration tFrac16 MLIB_ConvertPU_F16F32(register tFrac32 f32In); 5.90.2 Arguments Table 5-114. MLIB_ConvertPU_F16F32 arguments Type Name register tFrac32 Direction input f32In Description Input value in 32-bit fractional format to be converted. 5.90.3 Return Converted input value in 16-bit fractional format. 5.90.4 Description This inline function returns converted input value. The input value is considered as 32-bit fractional data type and output value is considered as 16-bit fractional data type thus both values represent the values in unity model. The output saturation is not implemented in this function, thus in case the input value is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_ConvertPU_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 423 Function MLIB_Div_F32 5.90.5 Re-entrancy The function is re-entrant. 5.90.6 Code Example #include "mlib.h" tFrac32 f32In; tFrac16 f16Out; void main(void) { // input value = 0.25 = 0x2000 0000 f32In = FRAC32 (0.25); // output should be FRAC16(0.25) = 0x2000 f16Out = MLIB_ConvertPU_F16F32(f32In); } // output should be FRAC16(0.25) = 0x2000 f16Out = MLIB_ConvertPU (f32In, F16F32); 5.91 Function MLIB_Div_F32 This function divides the first parameter by the second one. 5.91.1 Declaration tFrac32 MLIB_Div_F32(register tFrac32 f32In1, register tFrac32 f32In2); 5.91.2 Arguments Table 5-115. MLIB_Div_F32 arguments Type Name Direction Description register tFrac32 f32In1 input Numerator of division. register tFrac32 f32In2 input Denominator of division. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 424 NXP Semiconductors Chapter 5 API References 5.91.3 Return Division of two input values. 5.91.4 Description This inline function returns the division of two input values. The first input value is numerator and the second input value is denominator. The input values as well as output value is considered as 32-bit fractional data type. The output saturation is not implemented in this function, thus in case the numerator is greater or equal to denominator, the output value is undefined. The function will never cause division by zero exception. The output of the function is defined by the following simple equation: Equation MLIB_Div_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is not detected in this function. CAUTION Due to effectivity reason the division is held in 16-bit precision. 5.91.5 Re-entrancy The function is re-entrant. 5.91.6 Code Example #include "mlib.h" tFrac32 f32In1,f32In2; tFrac32 f32Out; Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 425 Function MLIB_Div_F16 void main(void) { // input value 1 = 0.25 f32In1 = FRAC32 (0.25); // input value 2 = 0.5 f32In2 = FRAC32 (0.5); // output should be FRAC32(0.5) = 0x40000000 f32Out = MLIB_Div_F32(f32In1,f32In2); // output should be FRAC32(0.5) = 0x40000000 f32Out = MLIB_Div (f32In1,f32In2,F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be FRAC32(0.5) = 0x40000000 f32Out = MLIB_Div (f32In1,f32In2); 5.92 Function MLIB_Div_F16 This function divides the first parameter by the second one. 5.92.1 Declaration tFrac16 MLIB_Div_F16(register tFrac16 f16In1, register tFrac16 f16In2); 5.92.2 Arguments Table 5-116. MLIB_Div_F16 arguments Type Name Direction Description register tFrac16 f16In1 input Numerator of division. register tFrac16 f16In2 input Denominator of division. 5.92.3 Return Division of two input values. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 426 NXP Semiconductors Chapter 5 API References 5.92.4 Description This inline function returns the division of two input values. The first input value is numerator and the second input value is denominator. The input values as well as output value is considered as 16-bit fractional data type. The output saturation is not implemented in this function, thus in case the numerator is greater or equal to denominator, the output value is undefined. The function will never cause division by zero exception. The output of the function is defined by the following simple equation: Equation MLIB_Div_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is not detected in this function. 5.92.5 Re-entrancy The function is re-entrant. 5.92.6 Code Example #include "mlib.h" tFrac16 f16In1,f16In2; tFrac16 f16Out; void main(void) { // input value 1 = 0.25 f16In1 = FRAC16 (0.25); // input value 2 = 0.5 f16In2 = FRAC16 (0.5); // output should be FRAC16(0.5) = 0x4000 f16Out = MLIB_Div_F16(f16In1,f16In2); // output should be FRAC16(0.5) = 0x4000 f16Out = MLIB_Div (f16In1,f16In2,F16); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 427 Function MLIB_DivSat_F32 // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be FRAC16(0.5) = 0x4000 f16Out = MLIB_Div (f16In1,f16In2); 5.93 Function MLIB_DivSat_F32 This function divides the first parameter by the second one as saturate. 5.93.1 Declaration tFrac32 MLIB_DivSat_F32(register tFrac32 f32In1, register tFrac32 f32In2); 5.93.2 Arguments Table 5-117. MLIB_DivSat_F32 arguments Type Name Direction Description register tFrac32 f32In1 input Numerator of division. register tFrac32 f32In2 input Denominator of division. 5.93.3 Return Division of two input values, saturated if necessary. 5.93.4 Description This inline function returns the division of two input values. The first input value is numerator and the second input value is denominator. The input values as well as output value is considered as 32-bit fractional data type. The output saturation is implemented in this function, thus in case the sum of input values is outside the (-1, 1) interval, the output value is limited to the boundary value. The output of the function is defined by the following simple equation: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 428 NXP Semiconductors Chapter 5 API References Equation MLIB_DivSat_Eq1 Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. 5.93.5 Re-entrancy The function is re-entrant. 5.93.6 Code Example #include "mlib.h" tFrac32 f32In1, f32In2; tFrac32 f32Out; void main(void) { // input value 1 = 0.25 f32In1 = FRAC32 (0.25); // input value 2 = 0.5 f32In2 = FRAC32 (0.5); // output should be FRAC32(0.5) = 0x40000000 f32Out = MLIB_DivSat_F32(f32In1, f32In2); // output should be FRAC32(0.5) = 0x40000000 f32Out = MLIB_DivSat (f32In1, f32In2, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be FRAC32(0.5) = 0x40000000 f32Out = MLIB_DivSat (f32In1, f32In2); 5.94 Function MLIB_DivSat_F16 This function divides the first parameter by the second one as saturate. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 429 Function MLIB_DivSat_F16 5.94.1 Declaration tFrac16 MLIB_DivSat_F16(register tFrac16 f16In1, register tFrac16 f16In2); 5.94.2 Arguments Table 5-118. MLIB_DivSat_F16 arguments Type Name Direction Description register tFrac16 f16In1 input Numerator of division. register tFrac16 f16In2 input Denominator of division. 5.94.3 Return Division of two input values, saturated if necessary. 5.94.4 Description This inline function returns the division of two input values. The first input value is numerator and the second input value is denominator. The input values as well as output value is considered as 16-bit fractional data type. The output saturation is implemented in this function, thus in case the sum of input values is outside the (-1, 1) interval, the output value is limited to the boundary value. The output of the function is defined by the following simple equation: Equation MLIB_DivSat_Eq1 Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 430 NXP Semiconductors Chapter 5 API References 5.94.5 Re-entrancy The function is re-entrant. 5.94.6 Code Example #include "mlib.h" tFrac16 f16In1, f16In2; tFrac16 f16Out; void main(void) { // input value 1 = 0.25 f16In1 = FRAC16 (0.25); // input value 2 = 0.5 f16In2 = FRAC16 (0.5); // output should be FRAC16(0.5) = 0x4000 f16Out = MLIB_DivSat_F16(f16In1, f16In2); // output should be FRAC16(0.5) = 0x4000 f16Out = MLIB_DivSat (f16In1, f16In2, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be FRAC16(0.5) = 0x4000 f16Out = MLIB_DivSat (f16In1, f16In2); 5.95 Function MLIB_Mac_F32 This function implements the multiply accumulate function. 5.95.1 Declaration tFrac32 MLIB_Mac_F32(register tFrac32 f32In1, register tFrac32 f32In2, register tFrac32 f32In3); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 431 Function MLIB_Mac_F32 5.95.2 Arguments Table 5-119. MLIB_Mac_F32 arguments Type Name Direction Description register tFrac32 f32In1 input Input value to be add. register tFrac32 f32In2 input First value to be multiplied. register tFrac32 f32In3 input Second value to be multiplied. 5.95.3 Return Multiplied second and third input value with adding of first input value. 5.95.4 Description This inline function returns the multiplied second and third input value with adding of first input value. The input values as well as output value is considered as 32-bit fractional values. The output saturation is not implemented in this function, thus in case the output value is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Mac_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is not detected in this function. 5.95.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 432 NXP Semiconductors Chapter 5 API References 5.95.6 Code Example #include "mlib.h" tFrac32 tFrac32 tFrac32 tFrac32 f32In1; f32In2; f32In3; f32Out; void main(void) { // input1 value = 0.25 f32In1 = FRAC32 (0.25); // input2 value = 0.15 f32In2 = FRAC32 (0.15); // input3 value = 0.35 f32In3 = FRAC32 (0.35); // output should be FRAC32(0.3025) = 0x26B851EB f32Out = MLIB_Mac_F32(f32In1, f32In2, f32In3); // output should be FRAC32(0.3025) = 0x26B851EB f32Out = MLIB_Mac (f32In1, f32In2, f32In3, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be FRAC32(0.3025) = 0x26B851EB f32Out = MLIB_Mac (f32In1, f32In2, f32In3); 5.96 Function MLIB_Mac_F32F16F16 This function implements the multiply accumulate function. 5.96.1 Declaration tFrac32 MLIB_Mac_F32F16F16(register tFrac32 f32In1, register tFrac16 f16In2, register tFrac16 f16In3); 5.96.2 Arguments Table 5-120. MLIB_Mac_F32F16F16 arguments Type Name register tFrac32 f32In1 Direction input Description Input value to be add. Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 433 Function MLIB_Mac_F32F16F16 Table 5-120. MLIB_Mac_F32F16F16 arguments (continued) Type Name Direction Description register tFrac16 f16In2 input First value to be multiplied. register tFrac16 f16In3 input Second value to be multiplied. 5.96.3 Return Multiplied second and third input value with adding of first input value. 5.96.4 Description This inline function returns the multiplied second and third input value with adding of first input value. The first input value as well as output value is considered as 32-bit fractional values. The second and third input values are considered as 16-bit fractional values. The output saturation is not implemented in this function, thus in case the output value is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Mac_Eq1 This implementation is available if 32-bit fractional implementations are enabled. However it is not possible to use the default implementation based function call, thus the implementation post-fix or additional parameter function call shall be used. Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is not detected in this function. 5.96.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 434 NXP Semiconductors Chapter 5 API References 5.96.6 Code Example #include "mlib.h" tFrac32 tFrac16 tFrac16 tFrac32 f32In1; f16In2; f16In3; f32Out; void main(void) { // input1 value = 0.25 f32In1 = FRAC32 (0.25); // input2 value = 0.15 f16In2 = FRAC16 (0.15); // input3 value = 0.35 f16In3 = FRAC16 (0.35); // output should be FRAC32(0.3025) = 0x26B851EB f32Out = MLIB_Mac_F32F16F16(f32In1, f16In2, f16In3); // output should be FRAC32(0.3025) = 0x26B851EB f32Out = MLIB_Mac (f32In1, f32In2, f32In3, F32F16F16); } 5.97 Function MLIB_Mac_F16 This function implements the multiply accumulate function. 5.97.1 Declaration tFrac16 MLIB_Mac_F16(register tFrac16 f16In1, register tFrac16 f16In2, register tFrac16 f16In3); 5.97.2 Arguments Table 5-121. MLIB_Mac_F16 arguments Type Name Direction Description register tFrac16 f16In1 input Input value to be add. register tFrac16 f16In2 input First value to be multiplied. register tFrac16 f16In3 input Second value to be multiplied. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 435 Function MLIB_Mac_F16 5.97.3 Return Multiplied second and third input value with adding of first input value. 5.97.4 Description This inline function returns the multiplied second and third input value with adding of first input value. The input values as well as output value is considered as 16-bit fractional values. The output saturation is not implemented in this function, thus in case the output value is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Mac_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is not detected in this function. 5.97.5 Re-entrancy The function is re-entrant. 5.97.6 Code Example #include "mlib.h" tFrac16 tFrac16 tFrac16 tFrac16 f16In1; f16In2; f16In3; f16Out; void main(void) { // input1 value = 0.25 f16In1 = FRAC16 (0.25); // input2 value = 0.15 f16In2 = FRAC16 (0.15); // input3 value = 0.35 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 436 NXP Semiconductors Chapter 5 API References f16In3 = FRAC16 (0.35); // output should be FRAC16(0.3025) = 0x26B8 f16Out = MLIB_Mac_F16(f16In1, f16In2, f16In3); // output should be FRAC16(0.3025) = 0x26B8 f16Out = MLIB_Mac (f16In1, f16In2, f16In3, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be FRAC16(0.3025) = 0x26B8 f16Out = MLIB_Mac (f16In1, f16In2, f16In3); 5.98 Function MLIB_MacSat_F32 This function implements the multiply accumulate function saturated if necessary. 5.98.1 Declaration tFrac32 MLIB_MacSat_F32(register tFrac32 f32In1, register tFrac32 f32In2, register tFrac32 f32In3); 5.98.2 Arguments Table 5-122. MLIB_MacSat_F32 arguments Type Name Direction Description register tFrac32 f32In1 input Input value to be add. register tFrac32 f32In2 input First value to be multiplied. register tFrac32 f32In3 input Second value to be multiplied. 5.98.3 Return Multiplied second and third input value with adding of first input value. The output value is saturated if necessary. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 437 Function MLIB_MacSat_F32 5.98.4 Description This inline function returns the multiplied second and third input value with adding of first input value. The input values as well as output value is considered as 32-bit fractional values. The output saturation is implemented in this function, thus in case the output value is outside the (-1, 1) interval, the output value is limited to the boundary value. The output of the function is defined by the following simple equation: Equation MLIB_MacSat_Eq1 Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. The overflow is detected in this function. The functions saturates the return value if it cannot fit into the return type. 5.98.5 Re-entrancy The function is re-entrant. 5.98.6 Code Example #include "mlib.h" tFrac32 tFrac32 tFrac32 tFrac32 f32In1; f32In2; f32In3; f32Out; void main(void) { // input1 value = 0.25 f32In1 = FRAC32 (0.25); // input2 value = 0.15 f32In2 = FRAC32 (0.15); // input3 value = 0.35 f32In3 = FRAC32 (0.35); // output should be FRAC32(0.3025) = 0x26B851EB Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 438 NXP Semiconductors Chapter 5 API References f32Out = MLIB_MacSat_F32(f32In1, f32In2, f32In3); // output should be FRAC32(0.3025) = 0x26B851EB f32Out = MLIB_MacSat (f32In1, f32In2, f32In3, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be FRAC32(0.3025) = 0x26B851EB f32Out = MLIB_MacSat (f32In1, f32In2, f32In3); 5.99 Function MLIB_MacSat_F32F16F16 This function implements the multiply accumulate function saturated if necessary. 5.99.1 Declaration tFrac32 MLIB_MacSat_F32F16F16(register tFrac32 f32In1, register tFrac16 f16In2, register tFrac16 f16In3); 5.99.2 Arguments Table 5-123. MLIB_MacSat_F32F16F16 arguments Type Name Direction Description register tFrac32 f32In1 input Input value to be add. register tFrac16 f16In2 input First value to be multiplied. register tFrac16 f16In3 input Second value to be multiplied. 5.99.3 Return Multiplied second and third input value with adding of first input value. The output value is saturated if necessary. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 439 Function MLIB_MacSat_F32F16F16 5.99.4 Description This inline function returns the multiplied second and third input value with adding of first input value. The first input values as well as output value is considered as 32-bit fractional values, second and third input values are considered as 16-bit fractional values. The output saturation is implemented in this function, thus in case the output value is outside the (-1, 1) interval, the output value is limited to the boundary value. The output of the function is defined by the following simple equation: Equation MLIB_MacSat_Eq1 Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. The overflow is detected in this function. The functions saturates the return value if it cannot fit into the return type. 5.99.5 Re-entrancy The function is re-entrant. 5.99.6 Code Example #include "mlib.h" tFrac32 tFrac16 tFrac16 tFrac32 f32In1; f16In2; f16In3; f32Out; void main(void) { // input1 value = 0.25 f32In1 = FRAC32 (0.25); // input2 value = 0.15 f16In2 = FRAC16 (0.15); // input3 value = 0.35 f16In3 = FRAC16 (0.35); // output should be FRAC32(0.3025) = 0x26B851EB Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 440 NXP Semiconductors Chapter 5 API References f32Out = MLIB_MacSat_F32F16F16(f32In1, f16In2, f16In3); } // output should be FRAC32(0.3025) = 0x26B851EB f32Out = MLIB_MacSat (f32In1, f16In2, f16In3, F32F16F16); 5.100 Function MLIB_MacSat_F16 This function implements the multiply accumulate function saturated if necessary. 5.100.1 Declaration tFrac16 MLIB_MacSat_F16(register tFrac16 f16In1, register tFrac16 f16In2, register tFrac16 f16In3); 5.100.2 Arguments Table 5-124. MLIB_MacSat_F16 arguments Type Name Direction Description register tFrac16 f16In1 input Input value to be add. register tFrac16 f16In2 input First value to be multiplied. register tFrac16 f16In3 input Second value to be multiplied. 5.100.3 Return Multiplied second and third input value with adding of first input value. The output value is saturated if necessary. 5.100.4 Description This inline function returns the multiplied second and third input value with adding of first input value. The input values as well as output value is considered as 16-bit fractional values. The output saturation is implemented in this function, thus in case the output value is outside the (-1, 1) interval, the output value is limited to the boundary value. The output of the function is defined by the following simple equation: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 441 Function MLIB_MacSat_F16 Equation MLIB_MacSat_Eq1 Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. The overflow is detected in this function. The functions saturates the return value if it cannot fit into the return type. 5.100.5 Re-entrancy The function is re-entrant. 5.100.6 Code Example #include "mlib.h" tFrac16 tFrac16 tFrac16 tFrac16 f16In1; f16In2; f16In3; f16Out; void main(void) { // input1 value = 0.25 f16In1 = FRAC16 (0.25); // input2 value = 0.15 f16In2 = FRAC16 (0.15); // input3 value = 0.35 f16In3 = FRAC16 (0.35); // output should be FRAC16(0.3025) = 0x26B8 f16Out = MLIB_MacSat_F16(f16In1, f16In2, f16In3); // output should be FRAC16(0.3025) = 0x26B8 f16Out = MLIB_MacSat (f16In1, f16In2, f16In3, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be FRAC16(0.3025) = 0x26B8 f16Out = MLIB_MacSat (f16In1, f16In2, f16In3); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 442 NXP Semiconductors Chapter 5 API References 5.101 Function MLIB_Mnac_F32 This function implements the multiply-subtract function. 5.101.1 Declaration tFrac32 MLIB_Mnac_F32(register tFrac32 f32In1, register tFrac32 f32In2, register tFrac32 f32In3); 5.101.2 Arguments Table 5-125. MLIB_Mnac_F32 arguments Type Name Direction Description register tFrac32 f32In1 input Input value to be subtracted. register tFrac32 f32In2 input First value to be multiplied. register tFrac32 f32In3 input Second value to be multiplied. 5.101.3 Return Multiplied second and third input value with subtracted first input value. 5.101.4 Description This inline function returns the multiplied second and third input value with subtracted first input value. The input values as well as output value is considered as 32-bit fractional values. The output saturation is not implemented in this function, thus in case the output value is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Mnac_Eq1 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 443 Function MLIB_Mnac_F32F16F16 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is not detected in this function. 5.101.5 Re-entrancy The function is re-entrant. 5.101.6 Code Example #include "mlib.h" tFrac32 tFrac32 tFrac32 tFrac32 f32In1; f32In2; f32In3; f32Out; void main(void) { // input1 value = 0.0625 f32In1 = FRAC32 (0.0625); // input2 value = 0.5 f32In2 = FRAC32 (0.5); // input3 value = 0.25 f32In3 = FRAC32 (0.25); // output should be FRAC32(0.0625) = 0x08000000 f32Out = MLIB_Mnac_F32(f32In1, f32In2, f32In3); // output should be FRAC32(0.0625) = 0x08000000 f32Out = MLIB_Mnac (f32In1, f32In2, f32In3, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be FRAC32(0.0625) = 0x08000000 f32Out = MLIB_Mnac (f32In1, f32In2, f32In3); 5.102 Function MLIB_Mnac_F32F16F16 This function implements the multiply-subtract function. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 444 NXP Semiconductors Chapter 5 API References 5.102.1 Declaration tFrac32 MLIB_Mnac_F32F16F16(register tFrac32 f32In1, register tFrac16 f16In2, register tFrac16 f16In3); 5.102.2 Arguments Table 5-126. MLIB_Mnac_F32F16F16 arguments Type Name Direction Description register tFrac32 f32In1 input Input value to be subtracted. register tFrac16 f16In2 input First value to be multiplied. register tFrac16 f16In3 input Second value to be multiplied. 5.102.3 Return Multiplied second and third input value with subtracted first input value. 5.102.4 Description This inline function returns the multiplied second and third input value with subtracted first input value. The first input value as well as output value is considered as 32-bit fractional values. The second and third input values are considered as 16-bit fractional values. The output saturation is not implemented in this function, thus in case the output value is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Mnac_Eq1 This implementation is available if 32-bit fractional implementations are enabled. However it is not possible to use the default implementation based function call, thus the implementation post-fix or additional parameter function call shall be used. Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is not detected in this function. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 445 Function MLIB_Mnac_F16 5.102.5 Re-entrancy The function is re-entrant. 5.102.6 Code Example #include "mlib.h" tFrac32 tFrac16 tFrac16 tFrac32 f32In1; f16In2; f16In3; f32Out; void main(void) { // input1 value = 0.0625 f32In1 = FRAC32 (0.0625); // input2 value = 0.5 f16In2 = FRAC16 (0.5); // input3 value = 0.25 f16In3 = FRAC16 (0.25); // output should be FRAC32(0.0625) = 0x08000000 f32Out = MLIB_Mnac_F32F16F16(f32In1, f16In2, f16In3); // output should be FRAC32(0.0625) = 0x08000000 f32Out = MLIB_Mnac (f32In1, f32In2, f32In3, F32F16F16); } 5.103 Function MLIB_Mnac_F16 This function implements the multiply-subtract function. 5.103.1 Declaration tFrac16 MLIB_Mnac_F16(register tFrac16 f16In1, register tFrac16 f16In2, register tFrac16 f16In3); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 446 NXP Semiconductors Chapter 5 API References 5.103.2 Arguments Table 5-127. MLIB_Mnac_F16 arguments Type Name Direction Description register tFrac16 f16In1 input Input value to be subtracted. register tFrac16 f16In2 input First value to be multiplied. register tFrac16 f16In3 input Second value to be multiplied. 5.103.3 Return Multiplied second and third input value with subtracted first input value. 5.103.4 Description This inline function returns the multiplied second and third input value with subtracted first input value. The input values as well as output value is considered as 16-bit fractional values. The output saturation is not implemented in this function, thus in case the output value is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Mnac_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is not detected in this function. 5.103.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 447 Function MLIB_Msu_F32 5.103.6 Code Example #include "mlib.h" tFrac16 tFrac16 tFrac16 tFrac16 f16In1; f16In2; f16In3; f16Out; void main(void) { // input1 value = 0.0625 f16In1 = FRAC16 (0.0625); // input2 value = 0.5 f16In2 = FRAC16 (0.5); // input3 value = 0.25 f16In3 = FRAC16 (0.25); // output should be FRAC16(0.0625) = 0x0800 f16Out = MLIB_Mnac_F16(f16In1, f16In2, f16In3); // output should be FRAC16(0.0625) = 0x0800 f16Out = MLIB_Mnac (f16In1, f16In2, f16In3, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be FRAC16(0.0625) = 0x0800 f16Out = MLIB_Mnac (f16In1, f16In2, f16In3); 5.104 Function MLIB_Msu_F32 This function implements the multiply-subtract-from function. 5.104.1 Declaration tFrac32 MLIB_Msu_F32(register tFrac32 f32In1, register tFrac32 f32In2, register tFrac32 f32In3); 5.104.2 Arguments Table 5-128. MLIB_Msu_F32 arguments Type register tFrac32 Name f32In1 Direction input Description Input value from which to subtract. Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 448 NXP Semiconductors Chapter 5 API References Table 5-128. MLIB_Msu_F32 arguments (continued) Type Name Direction Description register tFrac32 f32In2 input First value to be multiplied. register tFrac32 f32In3 input Second value to be multiplied. 5.104.3 Return First input value from which the multiplication result of the second and third input values is subtracted. 5.104.4 Description This inline function returns the first input value from which the multiplication result of the second and third input values is subtracted. The input values as well as output value is considered as 32-bit fractional values. The output saturation is not implemented in this function, thus in case the output value is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Msu_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is not detected in this function. 5.104.5 Re-entrancy The function is re-entrant. 5.104.6 Code Example #include "mlib.h" tFrac32 f32In1; Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 449 Function MLIB_Msu_F32F16F16 tFrac32 f32In2; tFrac32 f32In3; tFrac32 f32Out; void main(void) { // input1 value = 0.25 f32In1 = FRAC32 (0.25); // input2 value = 0.5 f32In2 = FRAC32 (0.5); // input3 value = 0.125 f32In3 = FRAC32 (0.125); // output should be FRAC32(0.1875) = 0x18000000 f32Out = MLIB_Msu_F32(f32In1, f32In2, f32In3); // output should be FRAC32(0.1875) = 0x18000000 f32Out = MLIB_Msu (f32In1, f32In2, f32In3, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be FRAC32(0.1875) = 0x18000000 f32Out = MLIB_Msu (f32In1, f32In2, f32In3); 5.105 Function MLIB_Msu_F32F16F16 This function implements the multiply-subtract-from function. 5.105.1 Declaration tFrac32 MLIB_Msu_F32F16F16(register tFrac32 f32In1, register tFrac16 f16In2, register tFrac16 f16In3); 5.105.2 Arguments Table 5-129. MLIB_Msu_F32F16F16 arguments Type Name Direction Description register tFrac32 f32In1 input Input value from which to subtract. register tFrac16 f16In2 input First value to be multiplied. register tFrac16 f16In3 input Second value to be multiplied. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 450 NXP Semiconductors Chapter 5 API References 5.105.3 Return First input value from which the multiplication result of the second and third input values is subtracted. 5.105.4 Description This inline function returns the first input value from which the multiplication result of the second and third input values is subtracted. The first input value as well as output value is considered as 32-bit fractional values. The second and third input values are considered as 16-bit fractional values. The output saturation is not implemented in this function, thus in case the output value is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Msu_Eq1 This implementation is available if 32-bit fractional implementations are enabled. However it is not possible to use the default implementation based function call, thus the implementation post-fix or additional parameter function call shall be used. Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is not detected in this function. 5.105.5 Re-entrancy The function is re-entrant. 5.105.6 Code Example #include "mlib.h" tFrac32 tFrac16 tFrac16 tFrac32 f32In1; f16In2; f16In3; f32Out; Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 451 Function MLIB_Msu_F16 void main(void) { // input1 value = 0.25 f32In1 = FRAC32 (0.25); // input2 value = 0.5 f16In2 = FRAC16 (0.5); // input3 value = 0.125 f16In3 = FRAC16 (0.125); // output should be FRAC32(0.1875) = 0x18000000 f32Out = MLIB_Msu_F32F16F16(f32In1, f16In2, f16In3); // output should be FRAC32(0.1875) = 0x18000000 f32Out = MLIB_Msu (f32In1, f32In2, f32In3, F32F16F16); } 5.106 Function MLIB_Msu_F16 This function implements the multiply-subtract-from function. 5.106.1 Declaration tFrac16 MLIB_Msu_F16(register tFrac16 f16In1, register tFrac16 f16In2, register tFrac16 f16In3); 5.106.2 Arguments Table 5-130. MLIB_Msu_F16 arguments Type Name Direction Description register tFrac16 f16In1 input Input value from which to subtract. register tFrac16 f16In2 input First value to be multiplied. register tFrac16 f16In3 input Second value to be multiplied. 5.106.3 Return First input value from which the multiplication result of the second and third input values is subtracted. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 452 NXP Semiconductors Chapter 5 API References 5.106.4 Description This inline function returns the first input value from which the multiplication result of the second and third input values is subtracted. The input values as well as output value is considered as 16-bit fractional values. The output saturation is not implemented in this function, thus in case the output value is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Msu_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is not detected in this function. 5.106.5 Re-entrancy The function is re-entrant. 5.106.6 Code Example #include "mlib.h" tFrac16 tFrac16 tFrac16 tFrac16 f16In1; f16In2; f16In3; f16Out; void main(void) { // input1 value = 0.25 f16In1 = FRAC16 (0.25); // input2 value = 0.5 f16In2 = FRAC16 (0.5); // input3 value = 0.125 f16In3 = FRAC16 (0.125); // output should be FRAC16(0.1875) = 0x1800 f16Out = MLIB_Msu_F16(f16In1, f16In2, f16In3); // output should be FRAC16(0.1875) = 0x1800 f16Out = MLIB_Msu (f16In1, f16In2, f16In3, F16); // ############################################################## Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 453 Function MLIB_Mul_F32 // Available only if 16-bit fractional implementation selected // as default // ############################################################## } // output should be FRAC16(0.1875) = 0x1800 f16Out = MLIB_Msu (f16In1, f16In2, f16In3); 5.107 Function MLIB_Mul_F32 This function multiplies two input parameters. 5.107.1 Declaration tFrac32 MLIB_Mul_F32(register tFrac32 f32In1, register tFrac32 f32In2); 5.107.2 Arguments Table 5-131. MLIB_Mul_F32 arguments Type Name Direction Description register tFrac32 f32In1 input Operand is a 32-bit number normalized between [-1,1). register tFrac32 f32In2 input Operand is a 32-bit number normalized between [-1,1). 5.107.3 Return Fractional multiplication of the input arguments. 5.107.4 Description Fractional multiplication of two fractional 32-bit values. The input values as well as output value is considered as 32-bit fractional values. The output saturation is not implemented in this function, thus in case the multiplication of input values is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Mul_Eq1 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 454 NXP Semiconductors Chapter 5 API References Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. 5.107.5 Re-entrancy The function is re-entrant. 5.107.6 Code Example #include "mlib.h" tFrac32 f32In1; tFrac32 f32In2; tFrac32 f32Out; void main(void) { // first input = 0.5 f32In1 = FRAC32 (0.5); // second input = 0.25 f32In2 = FRAC32 (0.25); // output should be 0x10000000 = FRAC32(0.125) f32Out = MLIB_Mul_F32(f32In1,f32In2); // output should be 0x10000000 = FRAC32(0.125) f32Out = MLIB_Mul (f32In1,f32In2,F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x10000000 = FRAC32(0.125) f32Out = MLIB_Mul (f32In1,f32In2); 5.108 Function MLIB_Mul_F32F16F16 This function multiplies two input parameters. 5.108.1 Declaration tFrac32 MLIB_Mul_F32F16F16(register tFrac16 f16In1, register tFrac16 f16In2); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 455 Function MLIB_Mul_F32F16F16 5.108.2 Arguments Table 5-132. MLIB_Mul_F32F16F16 arguments Type Name Direction Description register tFrac16 f16In1 input Operand is a 16-bit number normalized between [-1,1). register tFrac16 f16In2 input Operand is a 16-bit number normalized between [-1,1). 5.108.3 Return Fractional multiplication of the input arguments. 5.108.4 Description Fractional multiplication of two fractional 16-bit values. The input values are considered as 16-bit fractional values and the output value is considered as 32-bit fractional value. The output saturation is not implemented in this function, thus in case the multiplication of input values is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Mul_Eq1 Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. 5.108.5 Re-entrancy The function is re-entrant. 5.108.6 Code Example #include "mlib.h" tFrac16 f16In1; Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 456 NXP Semiconductors Chapter 5 API References tFrac16 f16In2; tFrac32 f32Out; void main(void) { // first input = 0.5 f16In1 = FRAC16 (0.5); // second input = 0.25 f16In2 = FRAC16 (0.25); // output should be 0x10000000 = FRAC32(0.125) f32Out = MLIB_Mul_F32F16F16(f16In1, f16In2); } // output should be 0x10000000 = FRAC32(0.125) f32Out = MLIB_Mul (f16In1, f16In2, F32F16F16); 5.109 Function MLIB_Mul_F16 This function multiplies two input parameters. 5.109.1 Declaration tFrac16 MLIB_Mul_F16(register tFrac16 f16In1, register tFrac16 f16In2); 5.109.2 Arguments Table 5-133. MLIB_Mul_F16 arguments Type Name Direction Description register tFrac16 f16In1 input Operand is a 16-bit number normalized between [-1,1). register tFrac16 f16In2 input Operand is a 16-bit number normalized between [-1,1). 5.109.3 Return Fractional multiplication of the input arguments. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 457 Function MLIB_Mul_F16 5.109.4 Description Fractional multiplication of two fractional 16-bit values. The input values as well as output value is considered as 16-bit fractional values. The output saturation is not implemented in this function, thus in case the multiplication of input values is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Mul_Eq1 Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. 5.109.5 Re-entrancy The function is re-entrant. 5.109.6 Code Example #include "mlib.h" tFrac16 f16In1; tFrac16 f16In2; tFrac16 f16Out; void main(void) { // first input = 0.5 f16In1 = FRAC16 (0.5); // second input = 0.25 f16In2 = FRAC16 (0.25); // output should be 0x1000 = FRAC16(0.125) f16Out = MLIB_Mul_F16(f16In1,f16In2); // output should be 0x1000 = FRAC16(0.125) f16Out = MLIB_Mul (f16In1,f16In2,F16); // // // // ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 458 NXP Semiconductors Chapter 5 API References } // output should be 0x1000 = FRAC16(0.125) f16Out = MLIB_Mul (f16In1,f16In2); 5.110 Function MLIB_MulSat_F32 This function multiplies two input parameters and saturate if necessary. 5.110.1 Declaration tFrac32 MLIB_MulSat_F32(register tFrac32 f32In1, register tFrac32 f32In2); 5.110.2 Arguments Table 5-134. MLIB_MulSat_F32 arguments Type Name Direction Description register tFrac32 f32In1 input Operand is a 32-bit number normalized between [-1,1). register tFrac32 f32In2 input Operand is a 32-bit number normalized between [-1,1). 5.110.3 Return Fractional multiplication of the input arguments. 5.110.4 Description Fractional multiplication of two fractional 32-bit values. The input values as well as output value are considered as 32-bit fractional data type. The output saturation is implemented in this function, thus in case the multiplication of input values is outside the (-1, 1) interval, the output value is limited to the boundary value. The output of the function is defined by the following simple equation: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 459 Function MLIB_MulSat_F32F16F16 Equation MLIB_MulSat_Eq1 Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. The overflow is detected in this function. The functions saturates the return value if it cannot fit into the return type. 5.110.5 Re-entrancy The function is re-entrant. 5.110.6 Code Example #include "mlib.h" tFrac32 f32In1; tFrac32 f32In2; tFrac32 f32Out; void main(void) { // first input = 0.8 f32In1 = FRAC32 (0.8); // second input = 0.75 f32In2 = FRAC32 (0.75); // output should be 0x4ccccccc = FRAC32(0.6) f32Out = MLIB_MulSat_F32(f32In1,f32In2); // output should be 0x4ccccccc = FRAC32(0.6) f32Out = MLIB_MulSat (f32In1,f32In2,F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x4ccccccc = FRAC32(0.6) f32Out = MLIB_MulSat (f32In1,f32In2); 5.111 Function MLIB_MulSat_F32F16F16 This function multiplies two input parameters and saturate if necessary. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 460 NXP Semiconductors Chapter 5 API References 5.111.1 Declaration tFrac32 MLIB_MulSat_F32F16F16(register tFrac16 f16In1, register tFrac16 f16In2); 5.111.2 Arguments Table 5-135. MLIB_MulSat_F32F16F16 arguments Type Name Direction Description register tFrac16 f16In1 input Operand is a 16-bit number normalized between [-1,1). register tFrac16 f16In2 input Operand is a 16-bit number normalized between [-1,1). 5.111.3 Return Fractional multiplication of the input arguments. 5.111.4 Description Fractional multiplication of two fractional 16-bit values. The input values are considered as 16-bit fractional data type and the output value is considered as 32-bit fractional data type. The output saturation is implemented in this function, thus in case the multiplication of input values is outside the (-1, 1) interval, the output value is limited to the boundary value. The output of the function is defined by the following simple equation: Equation MLIB_MulSat_Eq1 Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. The overflow is detected in this function. The functions saturates the return value if it cannot fit into the return type. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 461 Function MLIB_MulSat_F16 5.111.5 Re-entrancy The function is re-entrant. 5.111.6 Code Example #include "mlib.h" tFrac16 f16In1; tFrac16 f16In2; tFrac32 f32Out; void main(void) { // first input = 0.8 f16In1 = FRAC16 (0.8); // second input = 0.75 f16In2 = FRAC16 (0.75); // output should be 0x4ccccccc = FRAC32(0.6) f32Out = MLIB_MulSat_F32F16F16(f16In1,f16In2); } // output should be 0x4ccccccc = FRAC32(0.6) f32Out = MLIB_MulSat (f32In1,f32In2,F32F16f16); 5.112 Function MLIB_MulSat_F16 This function multiplies two input parameters and saturate if necessary. 5.112.1 Declaration tFrac16 MLIB_MulSat_F16(register tFrac16 f16In1, register tFrac16 f16In2); 5.112.2 Arguments Table 5-136. MLIB_MulSat_F16 arguments Type Name Direction Description register tFrac16 f16In1 input Operand is a 16-bit number normalized between [-1,1). register tFrac16 f16In2 input Operand is a 16-bit number normalized between [-1,1). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 462 NXP Semiconductors Chapter 5 API References 5.112.3 Return Fractional multiplication of the input arguments. 5.112.4 Description Fractional multiplication of two fractional 16-bit values. The input values as well as output value are considered as 16-bit fractional data type. The output saturation is implemented in this function, thus in case the multiplication of input values is outside the (-1, 1) interval, the output value is limited to the boundary value. The output of the function is defined by the following simple equation: Equation MLIB_MulSat_Eq1 Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. The overflow is detected in this function. The functions saturates the return value if it cannot fit into the return type. 5.112.5 Re-entrancy The function is re-entrant. 5.112.6 Code Example #include "mlib.h" tFrac16 f16In1; tFrac16 f16In2; tFrac16 f16Out; void main(void) { // first input = 0.8 f16In1 = FRAC16 (0.8); // second input = 0.75 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 463 Function MLIB_Neg_F32 f16In2 = FRAC16 (0.75); // output should be 0x4ccc = FRAC16(0.6) f16Out = MLIB_MulSat_F16(f16In1,f16In2); // output should be 0x4ccc = FRAC16(0.6) f16Out = MLIB_MulSat (f16In1,f16In2,F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x4ccc = FRAC32(0.6) f16Out = MLIB_MulSat (f16In1,f16In2); 5.113 Function MLIB_Neg_F32 This function returns negative value of input parameter. 5.113.1 Declaration tFrac32 MLIB_Neg_F32(register tFrac32 f32In); 5.113.2 Arguments Table 5-137. MLIB_Neg_F32 arguments Type register tFrac32 Name f32In Direction input Description Input value which negative value should be returned. 5.113.3 Return Negative value of input parameter. 5.113.4 Description This inline function returns the negative value of input parameter. The input values as well as output value is considered as 32-bit fractional values. The output saturation is not implemented in this function, thus in case the negation of input values is outside the (-1, 1) interval, the output value will overflow without any detection. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 464 NXP Semiconductors Chapter 5 API References The output of the function is defined by the following simple equation: Equation MLIB_Neg_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is not detected in this function. 5.113.5 Re-entrancy The function is re-entrant. 5.113.6 Code Example #include "mlib.h" tFrac32 f32In; tFrac32 f32Out; void main(void) { // input value = 0.25 f32In = FRAC32 (0.25); // output should be FRAC32(-0.25) = 0xA0000000 f32Out = MLIB_Neg_F32(f32In); // output should be FRAC32(-0.25) = 0xA0000000 f32Out = MLIB_Neg (f32In, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be FRAC32(-0.25) = 0xA0000000 f32Out = MLIB_Neg (f32In); 5.114 Function MLIB_Neg_F16 This function returns negative value of input parameter. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 465 Function MLIB_Neg_F16 5.114.1 Declaration tFrac16 MLIB_Neg_F16(register tFrac16 f16In); 5.114.2 Arguments Table 5-138. MLIB_Neg_F16 arguments Type register tFrac16 Name Direction input f16In Description Input value which negative value should be returned. 5.114.3 Return Negative value of input parameter. 5.114.4 Description This inline function returns the negative value of input parameter. The input values as well as output value is considered as 16-bit fractional values. The output saturation is not implemented in this function, thus in case the negation of input values is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Neg_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is not detected in this function. 5.114.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 466 NXP Semiconductors Chapter 5 API References 5.114.6 Code Example #include "mlib.h" tFrac16 f16In; tFrac16 f16Out; void main(void) { // input value = 0.25 f16In = FRAC16 (0.25); // output should be FRAC16(-0.25) = 0xA000 f16Out = MLIB_Neg_F16(f16In); // output should be FRAC16(-0.25) = 0xA000 f16Out = MLIB_Neg (f16In, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be FRAC16(-0.25) = 0xA000 f16Out = MLIB_Neg (f16In); 5.115 Function MLIB_NegSat_F32 This function returns negative value of input parameter and saturate if necessary. 5.115.1 Declaration tFrac32 MLIB_NegSat_F32(register tFrac32 f32In); 5.115.2 Arguments Table 5-139. MLIB_NegSat_F32 arguments Type Name register tFrac32 f32In Direction input Description Input value which negative value should be returned. 5.115.3 Return Negative value of input parameter. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 467 Function MLIB_NegSat_F32 5.115.4 Description This inline function returns the negative value of input parameter. The input values as well as output value is considered as 32-bit fractional data type. The output saturation is implemented in this function, thus in case the negation of input values is outside the (-1, 1) interval, the output value is limited to the boundary value. The output of the function is defined by the following simple equation: Equation MLIB_NegSat_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is detected in this function. The functions saturates the return value if it cannot fit into the return type. 5.115.5 Re-entrancy The function is re-entrant. 5.115.6 Code Example #include "mlib.h" tFrac32 f32In; tFrac32 f32Out; void main(void) { // input value = 0.25 f32In = FRAC32 (0.25); // output should be FRAC32(-0.25) = 0xA0000000 f32Out = MLIB_NegSat_F32(f32In); // output should be FRAC32(-0.25) = 0xA0000000 f32Out = MLIB_NegSat (f32In, F32); // ############################################################## // Available only if 32-bit fractional implementation selected Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 468 NXP Semiconductors Chapter 5 API References // as default // ############################################################## } // output should be FRAC32(-0.25) = 0xA0000000 f32Out = MLIB_NegSat (f32In); 5.116 Function MLIB_NegSat_F16 This function returns negative value of input parameter and saturate if necessary. 5.116.1 Declaration tFrac16 MLIB_NegSat_F16(register tFrac16 f16In); 5.116.2 Arguments Table 5-140. MLIB_NegSat_F16 arguments Type Name register tFrac16 f16In Direction input Description Input value which negative value should be returned. 5.116.3 Return Negative value of input parameter. 5.116.4 Description This inline function returns the negative value of input parameter. The input values as well as output value is considered as 16-bit fractional data type. The output saturation is implemented in this function, thus in case the negation of input values is outside the (-1, 1) interval, the output value is limited to the boundary value. The output of the function is defined by the following simple equation: Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 469 Function MLIB_Norm_F32 Equation MLIB_NegSat_Eq1 Note Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. The overflow is detected in this function. The functions saturates the return value if it cannot fit into the return type. 5.116.5 Re-entrancy The function is re-entrant. 5.116.6 Code Example #include "mlib.h" tFrac16 f16In; tFrac16 f16Out; void main(void) { // input value = 0.25 f16In = FRAC16 (0.25); // output should be FRAC16(-0.25) = 0xA000 f16Out = MLIB_NegSat_F16(f16In); // output should be FRAC16(-0.25) = 0xA000 f16Out = MLIB_NegSat (f16In, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be FRAC16(-0.25) = 0xA000 f16Out = MLIB_NegSat (f16In); 5.117 Function MLIB_Norm_F32 This function returns the number of left shifts needed to normalize the input parameter. 5.117.1 Declaration tU16 MLIB_Norm_F32(register tFrac32 f32In); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 470 NXP Semiconductors Chapter 5 API References 5.117.2 Arguments Table 5-141. MLIB_Norm_F32 arguments Type Name register tFrac32 f32In Direction input Description The first value to be normalized. 5.117.3 Return The number of left shift needed to normalize the argument. For the input "0" returns "0". 5.117.4 Description Depending on the sign of the input value the function counts and returns the number of the left shift needed to get an equality between input value and the maximum fractional values "1" or "-1". Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. 5.117.5 Re-entrancy The function is re-entrant. 5.117.6 Code Example #include "mlib.h" tFrac32 f32In; tU16 u16Out; void main(void) { // first input = 0.00005 f32In = FRAC32 (0.00005); // output should be 14 u16Out = MLIB_Norm_F32(f32In); // output should be 14 u16Out = MLIB_Norm (f32In,F32); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 471 Function MLIB_Norm_F16 // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 14 u16Out = MLIB_Norm (f32In); 5.118 Function MLIB_Norm_F16 This function returns the number of left shifts needed to normalize the input parameter. 5.118.1 Declaration tU16 MLIB_Norm_F16(register tFrac16 f16In); 5.118.2 Arguments Table 5-142. MLIB_Norm_F16 arguments Type register tFrac16 Name f16In Direction input Description The first value to be normalized. 5.118.3 Return The number of left shift needed to normalize the argument. For the input "0" returns "0". 5.118.4 Description Depending on the sign of the input value the function counts and returns the number of the left shift needed to get an equality between input value and the maximum fractional values "1" or "-1". Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 472 NXP Semiconductors Chapter 5 API References 5.118.5 Re-entrancy The function is re-entrant. 5.118.6 Code Example #include "mlib.h" tFrac16 f16In; tU16 u16Out; void main(void) { // first input = 0.00005 f16In = FRAC16 (0.00005); // output should be 14 u16Out = MLIB_Norm_F16(f16In); // output should be 14 u16Out = MLIB_Norm (f16In,F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 14 u16Out = MLIB_Norm (f16In); 5.119 Function MLIB_RndSat_F16F32 This function rounds the input value to the nearest saturated value in the output format. 5.119.1 Declaration tFrac16 MLIB_RndSat_F16F32(register tFrac32 f32In); 5.119.2 Arguments Table 5-143. MLIB_RndSat_F16F32 arguments Type Name register tFrac32 f32In Direction input Description Input value. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 473 Function MLIB_Round_F32 5.119.3 Return Rounded saturated value. 5.119.4 Description This inline function rounds the input value to the nearest saturated value in the output format. The input value is considered as 32-bit fractional data type and output value is considered as 16-bit fractional data type. 5.119.5 Re-entrancy The function is re-entrant. 5.119.6 Code Example #include "mlib.h" tFrac32 f32In; tFrac16 f16Out; void main(void) { // input value = 0.25 = 0x2000 0000 f32In = FRAC32 (0.25); } // output should be FRAC16(0.25) = 0x2000 f16Out = MLIB_RndSat_F16F32(f32In); 5.120 Function MLIB_Round_F32 The function rounds the input and saturates. 5.120.1 Declaration tFrac32 MLIB_Round_F32(register tFrac32 f32In1, register tU16 u16In2); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 474 NXP Semiconductors Chapter 5 API References 5.120.2 Arguments Table 5-144. MLIB_Round_F32 arguments Type Name Direction Description register tFrac32 f32In1 input The value to be rounded. register tU16 u16In2 input The number of trailing zeros in the rounded result. 5.120.3 Return Rounded 32-bit fractional value. 5.120.4 Description The function rounds the first input argument to the nearest value (round half up). The number of trailing zeros in the rounded result is equal to the second input argument, i.e., the number of significant digits is 32 - u16In2. The result is saturated to the fractional range. Note The second input argument must not exceed 30 for positive and 31 for negative f32In1, respectively, otherwise the result is undefined. Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. 5.120.5 Re-entrancy The function is re-entrant. 5.120.6 Code Example #include "mlib.h" tFrac32 f32In1; tFrac32 f32Out; tU16 u16In2; void main(void) { // Example no. 1 // first input = 0.25 f32In1 = FRAC32 (0.25); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 475 Function MLIB_Round_F16 // second input = 29 u16In2 = (tU16)29; // output should be 0x20000000 ~ FRAC32(0.25) f32Out = MLIB_Round_F32(f32In1,u16In2); // output should be 0x20000000 ~ FRAC32(0.25) f32Out = MLIB_Round (f32In1,u16In2,F32); // // // // ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x20000000 ~ FRAC32(0.25) f32Out = MLIB_Round (f32In1,u16In2); // Example no. 2 // first input = 0.375 f32In1 = FRAC32 (0.375); // second input = 29 u16In2 = (tU16)29; // output should be 0x40000000 ~ FRAC32(0.5) f32Out = MLIB_Round_F32(f32In1,u16In2); // Example no. 3 // first input = -0.375 f32In1 = FRAC32 (-0.375); // second input = 29 u16In2 = (tU16)29; } // output should be 0xE0000000 ~ FRAC32(-0.25) f32Out = MLIB_Round_F32(f32In1,u16In2); 5.121 Function MLIB_Round_F16 The function rounds the input and saturates. 5.121.1 Declaration tFrac16 MLIB_Round_F16(register tFrac16 f16In1, register tU16 u16In2); 5.121.2 Arguments Table 5-145. MLIB_Round_F16 arguments Type Name Direction Description register tFrac16 f16In1 input The value to be rounded. register tU16 u16In2 input The number of trailing zeros in the rounded result. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 476 NXP Semiconductors Chapter 5 API References 5.121.3 Return Rounded 16-bit fractional value. 5.121.4 Description The function rounds the first input argument to the nearest value (round half up). The number of trailing zeros in the rounded result is equal to the second input argument, i.e., the number of significant digits is 16 - u16In2. The result is saturated to the fractional range. Note The second input argument must not exceed 14 for positive and 15 for negative f16In1, respectively, otherwise the result is undefined. Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. 5.121.5 Re-entrancy The function is re-entrant. 5.121.6 Code Example #include "mlib.h" tFrac16 f16In1; tFrac16 f16Out; tU16 u16In2; void main(void) { // Example no. 1 // first input = 0.25 f16In1 = FRAC16 (0.25); // second input = 13 u16In2 = (tU16)13; // output should be 0x2000 ~ FRAC16(0.25) f16Out = MLIB_Round_F16(f16In1,u16In2); // output should be 0x2000 ~ FRAC16(0.25) f16Out = MLIB_Round (f16In1,u16In2,F16); // // // // ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 477 Function MLIB_ShBi_F32 // output should be 0x2000 ~ FRAC16(0.25) f16Out = MLIB_Round (f16In1,u16In2); // Example no. 2 // first input = 0.375 f16In1 = FRAC16 (0.375); // second input = 13 u16In2 = (tU16)13; // output should be 0x4000 ~ FRAC16(0.5) f16Out = MLIB_Round_F16(f16In1,u16In2); // Example no. 3 // first input = -0.375 f16In1 = FRAC16 (-0.375); // second input = 13 u16In2 = (tU16)13; } // output should be 0xE000 ~ FRAC16(-0.25) f16Out = MLIB_Round_F16(f16In1,u16In2); 5.122 Function MLIB_ShBi_F32 This function shifts the first argument to left or right by number defined by second argument. 5.122.1 Declaration tFrac32 MLIB_ShBi_F32(register tFrac32 f32In1, register tS16 s16In2); 5.122.2 Arguments Table 5-146. MLIB_ShBi_F32 arguments Type Name Direction Description register tFrac32 f32In1 input First value to be shift. register tS16 s16In2 input The shift amount value. 5.122.3 Return 32-bit fractional value shifted to left or right by the shift amount. The bits beyond the 32bit boundary are discarded. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 478 NXP Semiconductors Chapter 5 API References 5.122.4 Description Based on sign of second parameter this function shifts the first parameter to right or left. If the sign of second parameter is negative, shift to right. Overflow is not detected. Note The shift amount cannot exceed in magnitude the bit-width of the shift value, that means must be within the range -31...31. Otherwise the result of the function is undefined. Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. 5.122.5 Re-entrancy The function is re-entrant. 5.122.6 Code Example #include "mlib.h" tFrac32 f32In1; tFrac32 f32Out; tS16 s16In2; void main(void) { // first input = 0.25 f32In1 = FRAC32 (0.25); // second input = -1 s16In2 = (tS16)-1; // output should be 0x10000000 ~ FRAC32(0.125) f32Out = MLIB_ShBi_F32(f32In1, s16In2); // output should be 0x10000000 ~ FRAC32(0.125) f32Out = MLIB_ShBi (f32In1, s16In2, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x10000000 ~ FRAC32(0.125) f32Out = MLIB_ShBi (f32In1, s16In2); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 479 Function MLIB_ShBi_F16 5.123 Function MLIB_ShBi_F16 This function shifts the first argument to left or right by number defined by second argument. 5.123.1 Declaration tFrac16 MLIB_ShBi_F16(register tFrac16 f16In1, register tS16 s16In2); 5.123.2 Arguments Table 5-147. MLIB_ShBi_F16 arguments Type Name Direction Description register tFrac16 f16In1 input First value to be left shift. register tS16 s16In2 input The shift amount value. 5.123.3 Return 16-bit fractional value shifted to left or right by the shift amount. The bits beyond the 16bit boundary are discarded. 5.123.4 Description Based on sign of second parameter this function shifts the first parameter to right or left. If the sign of second parameter is negative, shift to right. Overflow is not detected. Note The shift amount cannot exceed in magnitude the bit-width of the shift value, that means must be within the range -15...15. Otherwise the result of the function is undefined. Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. 5.123.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 480 NXP Semiconductors Chapter 5 API References 5.123.6 Code Example #include "mlib.h" tFrac16 f16In1; tFrac16 f16Out; tS16 s16In2; void main(void) { // first input = 0.25 f16In1 = FRAC16 (0.25); // second input = -1 s16In2 = (tS16)-1; // output should be 0x1000 ~ FRAC16(0.125) f16Out = MLIB_ShBi_F16(f16In1, s16In2); // output should be 0x1000 ~ FRAC16(0.125) f16Out = MLIB_ShBi (f16In1, s16In2, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x1000 ~ FRAC16(0.125) f16Out = MLIB_ShBi (f16In1, s16In2); 5.124 Function MLIB_ShBiSat_F32 This function shifts the first argument to left or right by number defined by second argument and saturate if necessary. 5.124.1 Declaration tFrac32 MLIB_ShBiSat_F32(register tFrac32 f32In1, register tS16 s16In2); 5.124.2 Arguments Table 5-148. MLIB_ShBiSat_F32 arguments Type Name Direction Description register tFrac32 f32In1 input First value to be shift. register tS16 s16In2 input The shift amount value. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 481 Function MLIB_ShBiSat_F32 5.124.3 Return 32-bit fractional value shifted to left or right by the shift amount. The bits beyond the 32bit boundary are discarded. 5.124.4 Description Based on sign of second parameter this function shifts the first parameter to right or left and saturate if an overflow is detected. If the sign of second parameter is negative, shift to right. Note The shift amount cannot exceed in magnitude the bit-width of the shift value, that means must be within the range -31...31. Otherwise the result of the function is undefined. Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. 5.124.5 Re-entrancy The function is re-entrant. 5.124.6 Code Example #include "mlib.h" tFrac32 f32In1; tFrac32 f32Out; tS16 s16In2; void main(void) { // first input = 0.25 f32In1 = FRAC32 (0.25); // second input = -1 s16In2 = (tS16)-1; // output should be 0x10000000 ~ FRAC32(0.125) f32Out = MLIB_ShBiSat_F32(f32In1, s16In2); // output should be 0x10000000 ~ FRAC32(0.125) f32Out = MLIB_ShBiSat (f32In1, s16In2, F32); // ############################################################## // Available only if 32-bit fractional implementation selected // as default Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 482 NXP Semiconductors Chapter 5 API References // ############################################################## } // output should be 0x10000000 ~ FRAC32(0.125) f32Out = MLIB_ShBiSat (f32In1, s16In2); 5.125 Function MLIB_ShBiSat_F16 This function shifts the first argument to left or right by number defined by second argument and saturate if necessary. 5.125.1 Declaration tFrac16 MLIB_ShBiSat_F16(register tFrac16 f16In1, register tS16 s16In2); 5.125.2 Arguments Table 5-149. MLIB_ShBiSat_F16 arguments Type Name Direction Description register tFrac16 f16In1 input First value to be left shift. register tS16 s16In2 input The shift amount value. 5.125.3 Return 16-bit fractional value shifted to left or right by the shift amount. The bits beyond the 16bit boundary are discarded. 5.125.4 Description Based on sign of second parameter this function shifts the first parameter to right or left and saturate if an overflow is detected. If the sign of second parameter is negative, shift to right. Note The shift amount cannot exceed in magnitude the bit-width of the shift value, that means must be within the range -15...15. Otherwise the result of the function is undefined. Due to Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 483 Function MLIB_ShL_F32 effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. 5.125.5 Re-entrancy The function is re-entrant. 5.125.6 Code Example #include "mlib.h" tFrac16 f16In1; tFrac16 f16Out; tS16 s16In2; void main(void) { // first input = 0.25 f16In1 = FRAC16 (0.25); // second input = -1 s16In2 = (tS16)-1; // output should be 0x1000 ~ FRAC16(0.125) f16Out = MLIB_ShBiSat_F16(f16In1, s16In2); // output should be 0x1000 ~ FRAC16(0.125) f16Out = MLIB_ShBiSat (f16In1, s16In2, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x1000 ~ FRAC16(0.125) f16Out = MLIB_ShBiSat (f16In1, s16In2); 5.126 Function MLIB_ShL_F32 This function shifts the first parameter to left by number defined by second parameter. 5.126.1 Declaration tFrac32 MLIB_ShL_F32(register tFrac32 f32In1, register tU16 u16In2); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 484 NXP Semiconductors Chapter 5 API References 5.126.2 Arguments Table 5-150. MLIB_ShL_F32 arguments Type Name Direction Description register tFrac32 f32In1 input First value to be left shift. register tU16 u16In2 input The shift amount value. 5.126.3 Return 32-bit fractional value shifted to left by the shift amount. The bits beyond the 32-bit boundary are discarded. 5.126.4 Description This function shifts the first argument to left by number defined by second argument. Overflow is not detected. Note The shift amount cannot exceed in magnitude the bit-width of the shift value, that means must be within the range 0...31. Otherwise the result of the function is undefined. Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. 5.126.5 Re-entrancy The function is re-entrant. 5.126.6 Code Example #include "mlib.h" tFrac32 f32In1; tFrac32 f32Out; tU16 u16In2; void main(void) { // first input = 0.25 f32In1 = FRAC32 (0.25); // second input = 1 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 485 Function MLIB_ShL_F16 u16In2 = (tU16)1; // output should be 0x40000000 ~ FRAC32(0.5) f32Out = MLIB_ShL_F32(f32In1, u16In2); // output should be 0x40000000 ~ FRAC32(0.5) f32Out = MLIB_ShL (f32In1, u16In2, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x40000000 ~ FRAC32(0.5) f32Out = MLIB_ShL (f32In1, u16In2); 5.127 Function MLIB_ShL_F16 This function shifts the first parameter to left by number defined by second parameter. 5.127.1 Declaration tFrac16 MLIB_ShL_F16(register tFrac16 f16In1, register tU16 u16In2); 5.127.2 Arguments Table 5-151. MLIB_ShL_F16 arguments Type Name Direction Description register tFrac16 f16In1 input First value to be left shift. register tU16 u16In2 input The shift amount value. 5.127.3 Return 16-bit fractional value shifted to left by the shift amount. The bits beyond the 16-bit boundary are discarded. 5.127.4 Description This function shifts the first argument to left by number defined by second argument. Overflow is not detected. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 486 NXP Semiconductors Chapter 5 API References Note The shift amount cannot exceed in magnitude the bit-width of the shift value, that means must be within the range 0...15. Otherwise the result of the function is undefined. Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. 5.127.5 Re-entrancy The function is re-entrant. 5.127.6 Code Example #include "mlib.h" tFrac16 f16In1; tFrac16 f16Out; tU16 u16In2; void main(void) { // first input = 0.25 f16In1 = FRAC16 (0.25); // second input = 1 u16In2 = (tU16)1; // output should be 0x4000 ~ FRAC16(0.5) f16Out = MLIB_ShL_F16(f16In1, u16In2); // output should be 0x4000 ~ FRAC16(0.5) f16Out = MLIB_ShL (f16In1, u16In2, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x4000 ~ FRAC16(0.5) f16Out = MLIB_ShL (f16In1, u16In2); 5.128 Function MLIB_ShLSat_F32 This function shifts the first parameter to left by number defined by second parameter and saturate if necessary. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 487 Function MLIB_ShLSat_F32 5.128.1 Declaration tFrac32 MLIB_ShLSat_F32(register tFrac32 f32In1, register tU16 u16In2); 5.128.2 Arguments Table 5-152. MLIB_ShLSat_F32 arguments Type Name Direction Description register tFrac32 f32In1 input First value to be left shift. register tU16 u16In2 input The shift amount value. 5.128.3 Return 32-bit fractional value shifted to left by the shift amount. The bits beyond the 32-bit boundary are discarded. 5.128.4 Description This function shifts the first argument to left by number defined by second argument and saturate if an overflow is detected. The function returns a saturated fractional value if the return value cannot fit into the return type. Note The shift amount cannot exceed in magnitude the bit-width of the shift value, that means must be within the range 0...31. Otherwise the result of the function is undefined. Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. 5.128.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 488 NXP Semiconductors Chapter 5 API References 5.128.6 Code Example #include "mlib.h" tFrac32 f32In1; tFrac32 f32Out; tU16 u16In2; void main(void) { // first input = 0.25 f32In1 = FRAC32 (0.25); // second input = 1 u16In2 = (tU16)1; // output should be 0x40000000 ~ FRAC32(0.5) f32Out = MLIB_ShLSat_F32(f32In1, u16In2); // output should be 0x40000000 ~ FRAC32(0.5) f32Out = MLIB_ShLSat (f32In1, u16In2, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x40000000 ~ FRAC32(0.5) f32Out = MLIB_ShLSat (f32In1, u16In2); 5.129 Function MLIB_ShLSat_F16 This function shifts the first parameter to left by number defined by second parameter and saturate if necessary. 5.129.1 Declaration tFrac16 MLIB_ShLSat_F16(register tFrac16 f16In1, register tU16 u16In2); 5.129.2 Arguments Table 5-153. MLIB_ShLSat_F16 arguments Type Name Direction Description register tFrac16 f16In1 input First value to be left shift. register tU16 u16In2 input The shift amount value. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 489 Function MLIB_ShLSat_F16 5.129.3 Return 16-bit fractional value shifted to left by the shift amount. The bits beyond the 16-bit boundary are discarded. 5.129.4 Description This function shifts the first argument to left by number defined by second argument and saturate if an overflow is detected. The function returns a saturated fractional value if the return value cannot fit into the return type. Note The shift amount cannot exceed in magnitude the bit-width of the shift value, that means must be within the range 0...15. Otherwise the result of the function is undefined. Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. 5.129.5 Re-entrancy The function is re-entrant. 5.129.6 Code Example #include "mlib.h" tFrac16 f16In1; tFrac16 f16Out; tU16 u16In2; void main(void) { // first input = 0.25 f16In1 = FRAC16 (0.25); // second input = 1 u16In2 = (tU16)1; // output should be 0x4000 ~ FRAC16(0.5) f16Out = MLIB_ShLSat_F16(f16In1, u16In2); // output should be 0x4000 ~ FRAC16(0.5) f16Out = MLIB_ShLSat (f16In1, u16In2, F16); // // // // ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 490 NXP Semiconductors Chapter 5 API References } // output should be 0x4000 ~ FRAC16(0.5) f16Out = MLIB_ShLSat (f16In1, u16In2); 5.130 Function MLIB_ShR_F32 This function shifts the first parameter to right by number defined by second parameter. 5.130.1 Declaration tFrac32 MLIB_ShR_F32(register tFrac32 f32In1, register tU16 u16In2); 5.130.2 Arguments Table 5-154. MLIB_ShR_F32 arguments Type Name Direction Description register tFrac32 f32In1 input First value to be right shift. register tU16 u16In2 input The shift amount value. 5.130.3 Return 32-bit fractional value shifted right by the shift amount. The bits beyond the 32-bit boundary of the result are discarded. 5.130.4 Description This function shifts the first argument to right by number defined by second argument. Note The shift amount cannot exceed in magnitude the bit-width of the shifted value, that means it must be within the range 0...31. Otherwise the result of the function is undefined. Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 491 Function MLIB_ShR_F16 5.130.5 Re-entrancy The function is re-entrant. 5.130.6 Code Example #include "mlib.h" tFrac32 f32In1; tFrac32 f32Out; tU16 u16In2; void main(void) { // first input = 0.25 f32In1 = FRAC32 (0.25); // second input = 1 u16In2 = (tU16)1; // output should be 0x10000000 ~ FRAC32(0.125) f32Out = MLIB_ShR_F32(f32In1, u16In2); // output should be 0x10000000 ~ FRAC32(0.125) f32Out = MLIB_ShR (f32In1, u16In2, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x10000000 ~ FRAC32(0.125) f32Out = MLIB_ShR (f32In1, u16In2); 5.131 Function MLIB_ShR_F16 This function shifts the first parameter to right by number defined by second parameter. 5.131.1 Declaration tFrac16 MLIB_ShR_F16(register tFrac16 f16In1, register tU16 u16In2); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 492 NXP Semiconductors Chapter 5 API References 5.131.2 Arguments Table 5-155. MLIB_ShR_F16 arguments Type Name Direction Description register tFrac16 f16In1 input First value to be right shift. register tU16 u16In2 input The shift amount value. 5.131.3 Return 16-bit fractional value shifted right by the shift amount. The bits beyond the 16-bit boundary of the result are discarded. 5.131.4 Description This function shifts the first argument to right by number defined by second argument. Note The shift amount cannot exceed in magnitude the bit-width of the shifted value, that means it must be within the range 0...15. Otherwise the result of the function is undefined. Due to effectivity reason this function is implemented as inline, and thus is not ANSI-C compliant. 5.131.5 Re-entrancy The function is re-entrant. 5.131.6 Code Example #include "mlib.h" tFrac16 f16In1; tFrac16 f16Out; tU16 u16In2; void main(void) { // first input = 0.25 f16In1 = FRAC16 (0.25); // second input = 1 u16In2 = (tU16)1; Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 493 Function MLIB_Sub_F32 // output should be 0x1000 ~ FRAC16(0.125) f16Out = MLIB_ShR_F16(f16In1, u16In2); // output should be 0x1000 ~ FRAC16(0.125) f16Out = MLIB_ShR (f16In1, u16In2, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x1000 ~ FRAC16(0.125) f16Out = MLIB_ShR (f16In1, u16In2); 5.132 Function MLIB_Sub_F32 This function subtracts the second parameter from the first one. 5.132.1 Declaration tFrac32 MLIB_Sub_F32(register tFrac32 f32In1, register tFrac32 f32In2); 5.132.2 Arguments Table 5-156. MLIB_Sub_F32 arguments Type Name Direction Description register tFrac32 f32In1 input Operand is a 32-bit number normalized between[-1,1). register tFrac32 f32In2 input Operand is a 32-bit number normalized between[-1,1). 5.132.3 Return The subtraction of the second argument from the first argument. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 494 NXP Semiconductors Chapter 5 API References 5.132.4 Description Subtraction of two fractional 32-bit values. The second argument is subtracted from the first one. The input values as well as output value are considered as 32-bit fractional data type. The output saturation is not implemented in this function, thus in case the subtraction of input parameters is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Sub_Eq1 Note Overflow is not detected. Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. 5.132.5 Re-entrancy The function is re-entrant. 5.132.6 Code Example #include "mlib.h" tFrac32 f32In1; tFrac32 f32In2; tFrac32 f32Out; void main(void) { // first input = 0.5 f32In1 = FRAC32 (0.5); // second input = 0.25 f32In2 = FRAC32 (0.25); // output should be 0x20000000 f32Out = MLIB_Sub_F32(f32In1,f32In2); // output should be 0x20000000 f32Out = MLIB_Sub (f32In1,f32In2,F32); // // // // ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 495 Function MLIB_Sub_F16 } // output should be 0x20000000 f32Out = MLIB_Sub (f32In1,f32In2); 5.133 Function MLIB_Sub_F16 This function subtracts the second parameter from the first one. 5.133.1 Declaration tFrac16 MLIB_Sub_F16(register tFrac16 f16In1, register tFrac16 f16In2); 5.133.2 Arguments Table 5-157. MLIB_Sub_F16 arguments Type Name Direction Description register tFrac16 f16In1 input Operand is a 16-bit number normalized between [-1,1). register tFrac16 f16In2 input Operand is a 16-bit number normalized between [-1,1). 5.133.3 Return The subtraction of the second argument from the first argument. 5.133.4 Description Subtraction of two fractional 16-bit values. The second argument is subtracted from the first one. The input values as well as output value are considered as 16-bit fractional data type. The output saturation is not implemented in this function, thus in case the subtraction of input parameters is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_Sub_Eq1 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 496 NXP Semiconductors Chapter 5 API References Note Overflow is not detected. Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. 5.133.5 Re-entrancy The function is re-entrant. 5.133.6 Code Example #include "mlib.h" tFrac16 f16In1; tFrac16 f16In2; tFrac16 f16Out; void main(void) { // first input = 0.5 f16In1 = FRAC16 (0.5); // second input = 0.25 f16In2 = FRAC16 (0.25); // output should be 0x2000 f16Out = MLIB_Sub_F16(f16In1,f16In2); // output should be 0x2000 f16Out = MLIB_Sub (f16In1,f16In2,F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x20000000 f16Out = MLIB_Sub (f16In1,f16In2); 5.134 Function MLIB_SubSat_F32 This function subtracts the second parameter from the first one and saturate if necessary. 5.134.1 Declaration tFrac32 MLIB_SubSat_F32(register tFrac32 f32In1, register tFrac32 f32In2); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 497 Function MLIB_SubSat_F32 5.134.2 Arguments Table 5-158. MLIB_SubSat_F32 arguments Type Name Direction Description register tFrac32 f32In1 input Operand is a 32-bit number normalized between [-1,1). register tFrac32 f32In2 input Operand is a 32-bit number normalized between [-1,1). 5.134.3 Return The subtraction of the second argument from the first argument. 5.134.4 Description Subtraction with overflow control of two fractional 32-bit numbers. The second argument is subtracted from the first one. The input values as well as output value are considered as 32-bit fractional data type. The output saturation is implemented in this function, thus in case the subtraction of input parameters is outside the (-1, 1) interval, the output value is limited to the boundary value. The output of the function is defined by the following simple equation: Equation MLIB_SubSat_Eq1 Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. 5.134.5 Re-entrancy The function is re-entrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 498 NXP Semiconductors Chapter 5 API References 5.134.6 Code Example #include "mlib.h" tFrac32 f32In1; tFrac32 f32In2; tFrac32 f32Out; void main(void) { // first input = 0.5 f32In1 = FRAC32 (0.5); // second input = 0.25 f32In2 = FRAC32 (0.25); // output should be 0x20000000 f32Out = MLIB_SubSat_F32(f32In1,f32In2); // output should be 0x20000000 f32Out = MLIB_SubSat (f32In1,f32In2,F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be 0x20000000 f32Out = MLIB_SubSat (f32In1,f32In2); 5.135 Function MLIB_SubSat_F16 This function subtracts the second parameter from the first one and saturate if necessary. 5.135.1 Declaration tFrac16 MLIB_SubSat_F16(register tFrac16 f16In1, register tFrac16 f16In2); 5.135.2 Arguments Table 5-159. MLIB_SubSat_F16 arguments Type Name Direction Description register tFrac16 f16In1 input Operand is a 16-bit number normalized between [-1,1). register tFrac16 f16In2 input Operand is a 16-bit number normalized between [-1,1). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 499 Function MLIB_SubSat_F16 5.135.3 Return The subtraction of the second argument from the first argument. 5.135.4 Description Subtraction with overflow control of two fractional 16-bit numbers. The second argument is subtracted from the first one. The input values as well as output value are considered as 16-bit fractional data type. The output saturation is implemented in this function, thus in case the subtraction of input parameters is outside the (-1, 1) interval, the output value is limited to the boundary value. The output of the function is defined by the following simple equation: Equation MLIB_SubSat_Eq1 Note Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. 5.135.5 Re-entrancy The function is re-entrant. 5.135.6 Code Example #include "mlib.h" tFrac16 f16In1; tFrac16 f16In2; tFrac16 f16Out; void main(void) { // first input = 0.5 f16In1 = FRAC16 (0.5); // second input = 0.25 f16In2 = FRAC16 (0.25); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 500 NXP Semiconductors Chapter 5 API References // output should be 0x2000 f16Out = MLIB_SubSat_F16(f16In1,f16In2); // output should be 0x2000 f16Out = MLIB_SubSat (f16In1,f16In2,F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be 0x2000 f16Out = MLIB_SubSat (f16In1,f16In2); 5.136 Function MLIB_VMac_F32 This function implements the vector multiply accumulate function. 5.136.1 Declaration tFrac32 MLIB_VMac_F32(register tFrac32 f32In1, register tFrac32 f32In2, register tFrac32 f32In3, register tFrac32 f32In4); 5.136.2 Arguments Table 5-160. MLIB_VMac_F32 arguments Type Name Direction Description register tFrac32 f32In1 input First input value to first multiplication. register tFrac32 f32In2 input Second input value to first multiplication. register tFrac32 f32In3 input First input value to second multiplication. register tFrac32 f32In4 input Second input value to second multiplication. 5.136.3 Return Vector multiplied input values with addition. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 501 Function MLIB_VMac_F32 5.136.4 Description This inline function returns the vector multiply accumulate of input values. The input values as well as output value is considered as 32-bit fractional values. The output saturation is not implemented in this function, thus in case the vector multiply-add of input values is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_VMac_Eq1 Note Overflow is not detected. Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. 5.136.5 Re-entrancy The function is re-entrant. 5.136.6 Code Example #include "mlib.h" tFrac32 tFrac32 tFrac32 tFrac32 tFrac32 f32In1; f32In2; f32In3; f32In4; f32Out; void main(void) { // input1 value = 0.25 f32In1 = FRAC32 (0.25); // input2 value = 0.15 f32In2 = FRAC32 (0.15); // input3 value = 0.35 f32In3 = FRAC32 (0.35); // input4 value = 0.45 f32In4 = FRAC32 (0.45); // output should be FRAC32(0.195) = 0x18F5C28F f32Out = MLIB_VMac_F32(f32In1,f32In2,f32In3,f32In4); // output should be FRAC32(0.195) = 0x18F5C28F Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 502 NXP Semiconductors Chapter 5 API References f32Out = MLIB_VMac (f32In1,f32In2,f32In3,f32In4, F32); // // // // } ############################################################## Available only if 32-bit fractional implementation selected as default ############################################################## // output should be FRAC32(0.195) = 0x18F5C28F f32Out = MLIB_VMac (f32In1,f32In2,f32In3,f32In4); 5.137 Function MLIB_VMac_F32F16F16 This function implements the vector multiply accumulate function. 5.137.1 Declaration tFrac32 MLIB_VMac_F32F16F16(register tFrac16 f16In1, register tFrac16 f16In2, register tFrac16 f16In3, register tFrac16 f16In4); 5.137.2 Arguments Table 5-161. MLIB_VMac_F32F16F16 arguments Type Name Direction Description register tFrac16 f16In1 input First input value to first multiplication. register tFrac16 f16In2 input Second input value to first multiplication. register tFrac16 f16In3 input First input value to second multiplication. register tFrac16 f16In4 input Second input value to second multiplication. 5.137.3 Return Vector multiplied input values with addition. 5.137.4 Description This inline function returns the vector multiply accumulate of input values. The input values are considered as 16-bit fractional values and the output value is considered as 32bit fractional value. The output saturation is not implemented in this function, thus in case the vector multiply-add of input values is outside the (-1, 1) interval, the output value will overflow without any detection. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 503 Function MLIB_VMac_F16 The output of the function is defined by the following simple equation: Equation MLIB_VMac_Eq1 Note Overflow is not detected. Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. 5.137.5 Re-entrancy The function is re-entrant. 5.137.6 Code Example #include "mlib.h" tFrac16 tFrac16 tFrac16 tFrac16 tFrac32 f16In1; f16In2; f16In3; f16In4; f32Out; void main(void) { // input1 value = 0.25 f16In1 = FRAC16 (0.25); // input2 value = 0.15 f16In2 = FRAC16 (0.15); // input3 value = 0.35 f16In3 = FRAC16 (0.35); // input4 value = 0.45 f16In4 = FRAC16 (0.45); // output should be FRAC32(0.195) = 0x18F5C28F f32Out = MLIB_VMac_F32F16F16(f16In1,f16In2,f16In3,f16In4); } // output should be FRAC32(0.195) = 0x18F5C28F f32Out = MLIB_VMac (f16In1,f16In2,f16In3,f16In4, F32F16F16); 5.138 Function MLIB_VMac_F16 This function implements the vector multiply accumulate function. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 504 NXP Semiconductors Chapter 5 API References 5.138.1 Declaration tFrac16 MLIB_VMac_F16(register tFrac16 f16In1, register tFrac16 f16In2, register tFrac16 f16In3, register tFrac16 f16In4); 5.138.2 Arguments Table 5-162. MLIB_VMac_F16 arguments Type Name Direction Description register tFrac16 f16In1 input First input value to first multiplication. register tFrac16 f16In2 input Second input value to first multiplication. register tFrac16 f16In3 input First input value to second multiplication. register tFrac16 f16In4 input Second input value to second multiplication. 5.138.3 Return Vector multiplied input values with addition. 5.138.4 Description This inline function returns the vector multiply accumulate of input values. The input values as well as output value is considered as 16-bit fractional values. The output saturation is not implemented in this function, thus in case the vector multiply-add of input values is outside the (-1, 1) interval, the output value will overflow without any detection. The output of the function is defined by the following simple equation: Equation MLIB_VMac_Eq1 Note Overflow is not detected. Due to effectivity reason this function is implemented as inline and thus is not ANSI-C compliant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 505 Function SWLIBS_GetVersion 5.138.5 Re-entrancy The function is re-entrant. 5.138.6 Code Example #include "mlib.h" tFrac16 tFrac16 tFrac16 tFrac16 tFrac16 f16In1; f16In2; f16In3; f16In4; f16Out; void main(void) { // input1 value = 0.25 f16In1 = FRAC16 (0.25); // input2 value = 0.15 f16In2 = FRAC16 (0.15); // input3 value = 0.35 f16In3 = FRAC16 (0.35); // input4 value = 0.45 f16In4 = FRAC16 (0.45); // output should be FRAC16(0.195) = 0x18F5 f16Out = MLIB_VMac_F16(f16In1,f16In2,f16In3,f16In4); // output should be FRAC16(0.195) = 0x18F5 f16Out = MLIB_VMac (f16In1,f16In2,f16In3,f16In4, F16); // // // // } ############################################################## Available only if 16-bit fractional implementation selected as default ############################################################## // output should be FRAC16(0.195) = 0x18F5 f16Out = MLIB_VMac (f16In1,f16In2,f16In3,f16In4); 5.139 Function SWLIBS_GetVersion This function returns the information about AMMCLIB version. 5.139.1 Declaration const SWLIBS_VERSION_T * SWLIBS_GetVersion(); Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 506 NXP Semiconductors Chapter 5 API References 5.139.2 Return The function returns the information about the version of Motor Control Library Set. 5.139.3 Description The function returns the information about the version of Motor Control Library Set. The information are structured as follows: • Motor Control Library Set identification code • Motor Control Library Set version code • Motor Control Library Set supported implementation code 5.139.4 Reentrancy The function is reentrant. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 507 Function SWLIBS_GetVersion Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 508 NXP Semiconductors Chapter 6 6.1 Typedefs Index Table 6-1. Quick typedefs reference Type Name Description typedef unsigned char tBool basic boolean type typedef double tDouble double precision float type typedef float tFloat single precision float type typedef tS16 tFrac16 16-bit signed fractional Q1.15 type typedef tS32 tFrac32 32-bit Q1.31 type typedef signed short tS16 signed 16-bit integer type typedef signed long tS32 signed 32-bit integer type typedef signed long long tS64 signed 64-bit integer type typedef signed char tS8 signed 8-bit integer type typedef unsigned short tU16 unsigned 16-bit integer type typedef unsigned long tU32 unsigned 32-bit integer type typedef unsigned char tU8 unsigned 8-bit integer type Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 509 Typedefs Index Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 510 NXP Semiconductors Chapter 7 Compound Data Types Table 7-1. Compound data types overview Name Description GDFLIB_FILTER_IIR1_COEFF_T_F16 Sub-structure containing filter coefficients. GDFLIB_FILTER_IIR1_COEFF_T_F32 Sub-structure containing filter coefficients. GDFLIB_FILTER_IIR1_T_F16 Structure containing filter buffer and coefficients. GDFLIB_FILTER_IIR1_T_F32 Structure containing filter buffer and coefficients. GDFLIB_FILTER_IIR2_COEFF_T_F16 Sub-structure containing filter coefficients. GDFLIB_FILTER_IIR2_COEFF_T_F32 Sub-structure containing filter coefficients. GDFLIB_FILTER_IIR2_T_F16 Structure containing filter buffer and coefficients. GDFLIB_FILTER_IIR2_T_F32 Structure containing filter buffer and coefficients. GDFLIB_FILTER_MA_T_F16 Structure containing filter buffer and coefficients. GDFLIB_FILTER_MA_T_F32 Structure containing filter buffer and coefficients. GDFLIB_FILTERFIR_PARAM_T_F16 Structure containing parameters of the filter. GDFLIB_FILTERFIR_PARAM_T_F32 Structure containing parameters of the filter. GDFLIB_FILTERFIR_STATE_T_F16 Structure containing the current state of the filter. GDFLIB_FILTERFIR_STATE_T_F32 Structure containing the current state of the filter. GFLIB_ACOS_T_F16 Default approximation coefficients datatype for arccosine approximation. GFLIB_ACOS_T_F32 Default approximation coefficients datatype for arccosine approximation. GFLIB_ACOS_TAYLOR_COEF_T_F16 Array of approximation coefficients for piece-wise polynomial. GFLIB_ACOS_TAYLOR_COEF_T_F32 Array of approximation coefficients for piece-wise polynomial. GFLIB_ASIN_T_F16 Default approximation coefficients datatype for arcsine approximation. GFLIB_ASIN_T_F32 Default approximation coefficients datatype for arcsine approximation. GFLIB_ASIN_TAYLOR_COEF_T_F16 Array of approximation coefficients for piece-wise polynomial. GFLIB_ASIN_TAYLOR_COEF_T_F32 Array of approximation coefficients for piece-wise polynomial. GFLIB_ATAN_T_F16 Structure containing eight sub-structures with polynomial coefficients to cover all sub-intervals. GFLIB_ATAN_T_F32 Structure containing eight sub-structures with polynomial coefficients to cover all sub-intervals. GFLIB_ATAN_TAYLOR_COEF_T_F16 Array of polynomial approximation coefficients for one sub-interval. GFLIB_ATAN_TAYLOR_COEF_T_F32 Array of minimax polynomial approximation coefficients for one sub-interval. GFLIB_ATANYXSHIFTED_T_F16 Structure containing the parameter for the AtanYXShifted function. GFLIB_ATANYXSHIFTED_T_F32 Structure containing the parameter for the AtanYXShifted function. Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 511 Table 7-1. Compound data types overview (continued) Name Description GFLIB_CONTROLLER_PI_P_T_F16 Structure containing parameters and states of the parallel form PI controller. GFLIB_CONTROLLER_PI_P_T_F32 Structure containing parameters and states of the parallel form PI controller. GFLIB_CONTROLLER_PI_R_T_F16 Structure containing parameters and states of the recurrent form PI controller. GFLIB_CONTROLLER_PI_R_T_F32 Structure containing parameters and states of the recurrent form PI controller. GFLIB_CONTROLLER_PIAW_P_T_F16 Structure containing parameters and states of the parallel form PI controller with anti-windup. GFLIB_CONTROLLER_PIAW_P_T_F32 Structure containing parameters and states of the parallel form PI controller with anti-windup. GFLIB_CONTROLLER_PIAW_R_T_F16 Structure containing parameters and states of the recurrent form PI controller with anti-windup. GFLIB_CONTROLLER_PIAW_R_T_F32 Structure containing parameters and states of the recurrent form PI controller with anti-windup. GFLIB_COS_T_F16 Array of four 16-bit elements for storing coefficients of the Taylor polynomial. GFLIB_COS_T_F32 Array of five 32-bit elements for storing coefficients of the Taylor polynomial. GFLIB_HYST_T_F16 Structure containing parameters and states for the hysteresis function. GFLIB_HYST_T_F32 Structure containing parameters and states for the hysteresis function. GFLIB_INTEGRATOR_TR_T_F16 Structure containing integrator parameters and coefficients. GFLIB_INTEGRATOR_TR_T_F32 Structure containing integrator parameters and coefficients. GFLIB_LIMIT_T_F16 Structure containing the limits. GFLIB_LIMIT_T_F32 Structure containing the limits. GFLIB_LOWERLIMIT_T_F16 Structure containing the lower limit. GFLIB_LOWERLIMIT_T_F32 Structure containing the lower limit. GFLIB_LUT1D_T_F16 Structure containing 1D look-up table parameters. GFLIB_LUT1D_T_F32 Structure containing 1D look-up table parameters. GFLIB_LUT2D_T_F16 Structure containing 2D look-up table parameters. GFLIB_LUT2D_T_F32 Structure containing 2D look-up table parameters. GFLIB_RAMP_T_F16 Structure containing increment/decrement coefficients and state value for the ramp function implemented in GFLIB_Ramp. GFLIB_RAMP_T_F32 Structure containing increment/decrement coefficients and state value for the ramp function implemented in GFLIB_Ramp. GFLIB_SIN_T_F16 Array of four 16-bit elements for storing coefficients of the Taylor polynomial. GFLIB_SIN_T_F32 Array of five 32-bit elements for storing coefficients of the Taylor polynomial. GFLIB_SINCOS_T_F16 Array of four 16-bit elements for storing coefficients of the Taylor polynomial. GFLIB_SINCOS_T_F32 Array of five 32-bit elements for storing coefficients of the Taylor polynomial. GFLIB_TAN_T_F16 Output of tan(PI * f16In) for interval [0, PI/4) of the input angles is divided into eight sub-sectors. Polynomial approximation is done using a 4th order polynomial, for each sub-sector respectively. Eight arrays, each including four polynomial coefficients for each sub-interval, are stored in this (GFLIB_TAN_T_F16) structure. Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 512 NXP Semiconductors Chapter 7 Compound Data Types Table 7-1. Compound data types overview (continued) Name Description GFLIB_TAN_T_F32 Output of tan(PI * f32In) for interval [0, PI/4) of the input angles is divided into eight sub-sectors. Polynomial approximation is done using a 4th order polynomial, for each sub-sector respectively. Eight arrays, each including four polynomial coefficients for each sub-interval, are stored in this (GFLIB_TAN_T_F32) structure. GFLIB_TAN_TAYLOR_COEF_T_F16 Structure containing four polynomial coefficients for one sub-interval. GFLIB_TAN_TAYLOR_COEF_T_F32 Structure containing four polynomial coefficients for one sub-interval. GFLIB_UPPERLIMIT_T_F16 Structure containing the upper limit. GFLIB_UPPERLIMIT_T_F32 Structure containing the upper limit. GFLIB_VECTORLIMIT_T_F16 Structure containing the limit. GFLIB_VECTORLIMIT_T_F32 Structure containing the limit. GMCLIB_DECOUPLINGPMSM_T_F16 Structure containing coefficients for calculation of the decoupling. GMCLIB_DECOUPLINGPMSM_T_F32 Structure containing coefficients for calculation of the decoupling. GMCLIB_ELIMDCBUSRIP_T_F16 Structure containing the PWM modulation index and the measured value of the DC bus voltage. GMCLIB_ELIMDCBUSRIP_T_F32 Structure containing the PWM modulation index and the measured value of the DC bus voltage. SWLIBS_2Syst_F16 Array of two standard 16-bit fractional arguments. SWLIBS_2Syst_F32 Array of two standard 32-bit fractional arguments. SWLIBS_3Syst_F16 Array of three standard 16-bit fractional arguments. SWLIBS_3Syst_F32 Array of three standard 32-bit fractional arguments. SWLIBS_VERSION_T Motor Control Library Set identification structure. 7.1 GDFLIB_FILTER_IIR1_COEFF_T_F16 #include <GDFLIB_FilterIIR1.h> 7.1.1 Description Sub-structure containing filter coefficients. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 513 GDFLIB_FILTER_IIR1_COEFF_T_F32 7.1.2 Compound Type Members Table 7-2. GDFLIB_FILTER_IIR1_COEFF_T_F16 members description Type Name Description tFrac16 f16B0 B0 coefficient of an IIR1 filter, fractional format normalized to fit into (-2 15, 2 15-1). tFrac16 f16B1 B1 coefficient of an IIR1 filter, fractional format normalized to fit into (-2 15, 2 15-1). tFrac16 f16A1 A1 coefficient of an IIR1 filter, fractional format normalized to fit into (-2 15, 2 15-1). 7.2 GDFLIB_FILTER_IIR1_COEFF_T_F32 #include <GDFLIB_FilterIIR1.h> 7.2.1 Description Sub-structure containing filter coefficients. 7.2.2 Compound Type Members Table 7-3. GDFLIB_FILTER_IIR1_COEFF_T_F32 members description Type Name Description tFrac32 f32B0 B0 coefficient of an IIR1 filter, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32B1 B1 coefficient of an IIR1 filter, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32A1 A1 coefficient of an IIR1 filter, fractional format normalized to fit into (-2 31, 2 31-1). 7.3 GDFLIB_FILTER_IIR1_T_F16 #include <GDFLIB_FilterIIR1.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 514 NXP Semiconductors Chapter 7 Compound Data Types 7.3.1 Description Structure containing filter buffer and coefficients. 7.3.2 Compound Type Members Table 7-4. GDFLIB_FILTER_IIR1_T_F16 members description Type Name Description GDFLIB_FILTER_IIR1_COEF trFiltCoeff F_T_F16 Sub-structure containing filter coefficients. tFrac16 f16FiltBufferX Input buffer of an IIR1 filter, fractional format normalized to fit into (-2 15, 2 15-1). tFrac32 f32FiltBufferY Internal accumulator buffer, fractional format normalized to fit into (-2 15, 2 15-1). 7.4 GDFLIB_FILTER_IIR1_T_F32 #include <GDFLIB_FilterIIR1.h> 7.4.1 Description Structure containing filter buffer and coefficients. 7.4.2 Compound Type Members Table 7-5. GDFLIB_FILTER_IIR1_T_F32 members description Type Name Description GDFLIB_FILTER_IIR1_COEF trFiltCoeff F_T_F32 Sub-structure containing filter coefficients. tFrac32 f32FiltBufferX Input buffer of an IIR1 filter, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32FiltBufferY Internal accumulator buffer, fractional format normalized to fit into (-2 31, 2 31-1). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 515 GDFLIB_FILTER_IIR2_COEFF_T_F32 7.5 GDFLIB_FILTER_IIR2_COEFF_T_F16 #include <GDFLIB_FilterIIR2.h> 7.5.1 Description Sub-structure containing filter coefficients. 7.5.2 Compound Type Members Table 7-6. GDFLIB_FILTER_IIR2_COEFF_T_F16 members description Type Name Description tFrac16 f16B0 B0 coefficient of an IIR2 filter, fractional format normalized to fit into (-2 15, 2 15-1). tFrac16 f16B1 B1 coefficient of an IIR2 filter, fractional format normalized to fit into (-2 15, 2 15-1). tFrac16 f16B2 B2 coefficient of an IIR2 filter, fractional format normalized to fit into (-2 15, 2 15-1). tFrac16 f16A1 A1 coefficient of an IIR2 filter, fractional format normalized to fit into (-2 15, 2 15-1). tFrac16 f16A2 A2 coefficient of an IIR2 filter, fractional format normalized to fit into (-2 15, 2 15-1). 7.6 GDFLIB_FILTER_IIR2_COEFF_T_F32 #include <GDFLIB_FilterIIR2.h> 7.6.1 Description Sub-structure containing filter coefficients. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 516 NXP Semiconductors Chapter 7 Compound Data Types 7.6.2 Compound Type Members Table 7-7. GDFLIB_FILTER_IIR2_COEFF_T_F32 members description Type Name Description tFrac32 f32B0 B0 coefficient of an IIR2 filter, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32B1 B1 coefficient of an IIR2 filter, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32B2 B2 coefficient of an IIR2 filter, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32A1 A1 coefficient of an IIR2 filter, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32A2 A2 coefficient of an IIR2 filter, fractional format normalized to fit into (-2 31, 2 31-1). 7.7 GDFLIB_FILTER_IIR2_T_F16 #include <GDFLIB_FilterIIR2.h> 7.7.1 Description Structure containing filter buffer and coefficients. 7.7.2 Compound Type Members Table 7-8. GDFLIB_FILTER_IIR2_T_F16 members description Type Name Description GDFLIB_FILTER_IIR2_COEF trFiltCoeff F_T_F16 Sub-structure containing filter coefficients. tFrac16 f16FiltBufferX Input buffer of an IIR2 filter, fractional format normalized to fit into (-2 15, 2 15-1). tFrac32 f32FiltBufferY Internal accumulator buffer, fractional format normalized to fit into (-2 15, 2 15-1). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 517 GDFLIB_FILTER_MA_T_F16 7.8 GDFLIB_FILTER_IIR2_T_F32 #include <GDFLIB_FilterIIR2.h> 7.8.1 Description Structure containing filter buffer and coefficients. 7.8.2 Compound Type Members Table 7-9. GDFLIB_FILTER_IIR2_T_F32 members description Type Name Description GDFLIB_FILTER_IIR2_COEF trFiltCoeff F_T_F32 Sub-structure containing filter coefficients. tFrac32 f32FiltBufferX Input buffer of an IIR2 filter, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32FiltBufferY Internal accumulator buffer, fractional format normalized to fit into (-2 31, 2 31-1). 7.9 GDFLIB_FILTER_MA_T_F16 #include <GDFLIB_FilterMA.h> 7.9.1 Description Structure containing filter buffer and coefficients. 7.9.2 Compound Type Members Table 7-10. GDFLIB_FILTER_MA_T_F16 members description Type Name Description tFrac32 f32Acc Filter accumulator. tU16 u16NSamples Recalculated smoothing factor [0, 15]. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 518 NXP Semiconductors Chapter 7 Compound Data Types 7.10 GDFLIB_FILTER_MA_T_F32 #include <GDFLIB_FilterMA.h> 7.10.1 Description Structure containing filter buffer and coefficients. 7.10.2 Compound Type Members Table 7-11. GDFLIB_FILTER_MA_T_F32 members description Type Name Description tFrac32 f32Acc Filter accumulator. tU16 u16NSamples Recalculated smoothing factor [0, 31]. 7.11 GDFLIB_FILTERFIR_PARAM_T_F16 #include <GDFLIB_FilterFIR.h> 7.11.1 Description Structure containing parameters of the filter. 7.11.2 Compound Type Members Table 7-12. GDFLIB_FILTERFIR_PARAM_T_F16 members description Type Name Description tU16 u16Order FIR filter order, must be 1 or more. const tFrac16 * pCoefBuf FIR filter coefficients buffer. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 519 GDFLIB_FILTERFIR_STATE_T_F16 7.12 GDFLIB_FILTERFIR_PARAM_T_F32 #include <GDFLIB_FilterFIR.h> 7.12.1 Description Structure containing parameters of the filter. 7.12.2 Compound Type Members Table 7-13. GDFLIB_FILTERFIR_PARAM_T_F32 members description Type Name Description tU32 u32Order FIR filter order, must be 1 or more. const tFrac32 * pCoefBuf FIR filter coefficients buffer. 7.13 GDFLIB_FILTERFIR_STATE_T_F16 #include <GDFLIB_FilterFIR.h> 7.13.1 Description Structure containing the current state of the filter. 7.13.2 Compound Type Members Table 7-14. GDFLIB_FILTERFIR_STATE_T_F16 members description Type Name Description tU16 u16Idx Input buffer index. tFrac16 * pInBuf Pointer to the input buffer. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 520 NXP Semiconductors Chapter 7 Compound Data Types 7.14 GDFLIB_FILTERFIR_STATE_T_F32 #include <GDFLIB_FilterFIR.h> 7.14.1 Description Structure containing the current state of the filter. 7.14.2 Compound Type Members Table 7-15. GDFLIB_FILTERFIR_STATE_T_F32 members description Type Name Description tU32 u32Idx Input buffer index. tFrac32 * pInBuf Pointer to the input buffer. 7.15 GFLIB_ACOS_T_F16 #include <GFLIB_Acos.h> 7.15.1 Description Default approximation coefficients datatype for arccosine approximation. 7.15.2 Compound Type Members Table 7-16. GFLIB_ACOS_T_F16 members description Type Name GFLIB_ACOS_TAYLOR_CO EF_T_F16 GFLIB_ACOS_SECTOR Description Array of two elements for storing two subarrays (each sub-array contains five 16-bit coefficients) for all sub-intervals. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 521 GFLIB_ACOS_TAYLOR_COEF_T_F16 7.16 GFLIB_ACOS_T_F32 #include <GFLIB_Acos.h> 7.16.1 Description Default approximation coefficients datatype for arccosine approximation. 7.16.2 Compound Type Members Table 7-17. GFLIB_ACOS_T_F32 members description Type Name GFLIB_ACOS_TAYLOR_CO EF_T_F32 GFLIB_ACOS_SECTOR Description Array of two elements for storing three subarrays (each sub-array contains five 32-bit coefficients) for all sub-intervals. 7.17 GFLIB_ACOS_TAYLOR_COEF_T_F16 #include <GFLIB_Acos.h> 7.17.1 Description Array of approximation coefficients for piece-wise polynomial. 7.17.2 Compound Type Members Table 7-18. GFLIB_ACOS_TAYLOR_COEF_T_F16 members description Type const tFrac16 Name f16A Description Array of five 16-bit elements for storing coefficients of the piece-wise polynomial. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 522 NXP Semiconductors Chapter 7 Compound Data Types 7.18 GFLIB_ACOS_TAYLOR_COEF_T_F32 #include <GFLIB_Acos.h> 7.18.1 Description Array of approximation coefficients for piece-wise polynomial. 7.18.2 Compound Type Members Table 7-19. GFLIB_ACOS_TAYLOR_COEF_T_F32 members description Type Name const tFrac32 f32A Description Array of five 32-bit elements for storing coefficients of the piece-wise polynomial. 7.19 GFLIB_ASIN_T_F16 #include <GFLIB_Asin.h> 7.19.1 Description Default approximation coefficients datatype for arcsine approximation. 7.19.2 Compound Type Members Table 7-20. GFLIB_ASIN_T_F16 members description Type Name GFLIB_ASIN_TAYLOR_COE GFLIB_ASIN_SECTOR F_T_F16 Description Default approximation coefficients datatype for arcsine approximation. 7.20 GFLIB_ASIN_T_F32 #include <GFLIB_Asin.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 523 GFLIB_ASIN_TAYLOR_COEF_T_F16 7.20.1 Description Default approximation coefficients datatype for arcsine approximation. 7.20.2 Compound Type Members Table 7-21. GFLIB_ASIN_T_F32 members description Type Name GFLIB_ASIN_TAYLOR_COE GFLIB_ASIN_SECTOR F_T_F32 Description Default approximation coefficients datatype for arcsine approximation. 7.21 GFLIB_ASIN_TAYLOR_COEF_T_F16 #include <GFLIB_Asin.h> 7.21.1 Description Array of approximation coefficients for piece-wise polynomial. 7.21.2 Compound Type Members Table 7-22. GFLIB_ASIN_TAYLOR_COEF_T_F16 members description Type Name const tFrac16 f16A Description Array of approximation coefficients for piecewise polynomial. 7.22 GFLIB_ASIN_TAYLOR_COEF_T_F32 #include <GFLIB_Asin.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 524 NXP Semiconductors Chapter 7 Compound Data Types 7.22.1 Description Array of approximation coefficients for piece-wise polynomial. 7.22.2 Compound Type Members Table 7-23. GFLIB_ASIN_TAYLOR_COEF_T_F32 members description Type Name const tFrac32 f32A Description Array of five 32-bit elements for storing coefficients of the piece-wise polynomial. 7.23 GFLIB_ATAN_T_F16 #include <GFLIB_Atan.h> 7.23.1 Description Structure containing eight sub-structures with polynomial coefficients to cover all subintervals. 7.23.2 Compound Type Members Table 7-24. GFLIB_ATAN_T_F16 members description Type Name const GFLIB_ATAN_SECTOR GFLIB_ATAN_TAYLOR_COE F_T_F16 Description Structure containing eight sub-structures with polynomial coefficients to cover all subintervals. 7.24 GFLIB_ATAN_T_F32 #include <GFLIB_Atan.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 525 GFLIB_ATAN_TAYLOR_COEF_T_F16 7.24.1 Description Structure containing eight sub-structures with polynomial coefficients to cover all subintervals. 7.24.2 Compound Type Members Table 7-25. GFLIB_ATAN_T_F32 members description Type Name const GFLIB_ATAN_SECTOR GFLIB_ATAN_TAYLOR_COE F_T_F32 Description Structure containing eight sub-structures with polynomial coefficients to cover all subintervals. 7.25 GFLIB_ATAN_TAYLOR_COEF_T_F16 #include <GFLIB_Atan.h> 7.25.1 Description Array of polynomial approximation coefficients for one sub-interval. 7.25.2 Compound Type Members Table 7-26. GFLIB_ATAN_TAYLOR_COEF_T_F16 members description Type Name const tFrac16 f16A Description Array of polynomial approximation coefficients for one sub-interval. 7.26 GFLIB_ATAN_TAYLOR_COEF_T_F32 #include <GFLIB_Atan.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 526 NXP Semiconductors Chapter 7 Compound Data Types 7.26.1 Description Array of minimax polynomial approximation coefficients for one sub-interval. 7.26.2 Compound Type Members Table 7-27. GFLIB_ATAN_TAYLOR_COEF_T_F32 members description Type Name const tFrac32 f32A Description Array of minimax polynomial approximation coefficients for one sub-interval. 7.27 GFLIB_ATANYXSHIFTED_T_F16 #include <GFLIB_AtanYXShifted.h> 7.27.1 Description Structure containing the parameter for the AtanYXShifted function. 7.27.2 Compound Type Members Table 7-28. GFLIB_ATANYXSHIFTED_T_F16 members description Type Name Description tFrac16 f16Ky Multiplication coefficient for the y-signal. tFrac16 f16Kx Multiplication coefficient for the x-signal. tS16 s16Ny Scaling coefficient for the y-signal. tS16 s16Nx Scaling coefficient for the x-signal. tFrac16 f16ThetaAdj Adjusting angle. 7.28 GFLIB_ATANYXSHIFTED_T_F32 #include <GFLIB_AtanYXShifted.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 527 GFLIB_CONTROLLER_PI_P_T_F16 7.28.1 Description Structure containing the parameter for the AtanYXShifted function. 7.28.2 Compound Type Members Table 7-29. GFLIB_ATANYXSHIFTED_T_F32 members description Type Name Description tFrac32 f32Ky Multiplication coefficient for the y-signal. tFrac32 f32Kx Multiplication coefficient for the x-signal. tS32 s32Ny Scaling coefficient for the y-signal. tS32 s32Nx Scaling coefficient for the x-signal. tFrac32 f32ThetaAdj Adjusting angle. 7.29 GFLIB_CONTROLLER_PI_P_T_F16 #include <GFLIB_ControllerPIp.h> 7.29.1 Description Structure containing parameters and states of the parallel form PI controller. 7.29.2 Compound Type Members Table 7-30. GFLIB_CONTROLLER_PI_P_T_F16 members description Type Name Description tFrac16 f16PropGain Proportional Gain, fractional format normalized to fit into (-2 15, 2 15-1). tFrac16 f16IntegGain Integral Gain, fractional format normalized to fit into (-2 15, 2 15-1). tS16 s16PropGainShift Proportional Gain Shift, integer format [-15, 15]. tS16 s16IntegGainShift Integral Gain Shift, integer format [-15, 15]. tFrac32 f32IntegPartK_1 State variable integral part at step k-1. tFrac16 f16InK_1 State variable input error at step k-1. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 528 NXP Semiconductors Chapter 7 Compound Data Types 7.30 GFLIB_CONTROLLER_PI_P_T_F32 #include <GFLIB_ControllerPIp.h> 7.30.1 Description Structure containing parameters and states of the parallel form PI controller. 7.30.2 Compound Type Members Table 7-31. GFLIB_CONTROLLER_PI_P_T_F32 members description Type Name Description tFrac32 f32PropGain Proportional Gain, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32IntegGain Integral Gain, fractional format normalized to fit into (-2 31, 2 31-1). tS16 s16PropGainShift Proportional Gain Shift, integer format [-31, 31]. tS16 s16IntegGainShift Integral Gain Shift, integer format [-31, 31]. tFrac32 f32IntegPartK_1 State variable integral part at step k-1. tFrac32 f32InK_1 State variable input error at step k-1. 7.31 GFLIB_CONTROLLER_PI_R_T_F16 #include <GFLIB_ControllerPIr.h> 7.31.1 Description Structure containing parameters and states of the recurrent form PI controller. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 529 GFLIB_CONTROLLER_PI_R_T_F32 7.31.2 Compound Type Members Table 7-32. GFLIB_CONTROLLER_PI_R_T_F16 members description Type Name Description tFrac16 f16CC1sc CC1 coefficient, fractional format normalized to fit into (-2 15, 2 15-1). tFrac16 f16CC2sc CC2 coefficient, fractional format normalized to fit into (-2 15, 2 15-1). tFrac32 f32Acc Internal controller accumulator. tFrac16 f16InErrK1 Controller input from the previous calculation step. tU16 u16NShift Scaling factor for the controller coefficients, integer format [0, 15]. 7.32 GFLIB_CONTROLLER_PI_R_T_F32 #include <GFLIB_ControllerPIr.h> 7.32.1 Description Structure containing parameters and states of the recurrent form PI controller. 7.32.2 Compound Type Members Table 7-33. GFLIB_CONTROLLER_PI_R_T_F32 members description Type Name Description tFrac32 f32CC1sc CC1 coefficient, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32CC2sc CC2 coefficient, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32Acc Internal controller accumulator. tFrac32 f32InErrK1 Controller input from the previous calculation step. tU16 u16NShift Scaling factor for the controller coefficients, integer format [0, 31]. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 530 NXP Semiconductors Chapter 7 Compound Data Types 7.33 GFLIB_CONTROLLER_PIAW_P_T_F16 #include <GFLIB_ControllerPIpAW.h> 7.33.1 Description Structure containing parameters and states of the parallel form PI controller with antiwindup. 7.33.2 Compound Type Members Table 7-34. GFLIB_CONTROLLER_PIAW_P_T_F16 members description Type Name Description tFrac16 f16PropGain Proportional Gain, fractional format normalized to fit into (-2 15, 2 15-1). tFrac16 f16IntegGain Integral Gain, fractional format normalized to fit into (-2 15, 2 15-1). tS16 s16PropGainShift Proportional Gain Shift, integer format [-15, 15]. tS16 s16IntegGainShift Integral Gain Shift, integer format [-15, 15]. tFrac16 f16LowerLimit Lower Limit of the controller, fractional format normalized to fit into (-2 15, 2 15-1). tFrac16 f16UpperLimit Upper Limit of the controller, fractional format normalized to fit into (-2 15, 2 15-1). tFrac32 f32IntegPartK_1 State variable integral part at step k-1. tFrac16 f16InK_1 State variable input error at step k-1. tU16 u16LimitFlag Limitation flag, if set to 1, the controller output has reached either the UpperLimit or LowerLimit. 7.34 GFLIB_CONTROLLER_PIAW_P_T_F32 #include <GFLIB_ControllerPIpAW.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 531 GFLIB_CONTROLLER_PIAW_R_T_F16 7.34.1 Description Structure containing parameters and states of the parallel form PI controller with antiwindup. 7.34.2 Compound Type Members Table 7-35. GFLIB_CONTROLLER_PIAW_P_T_F32 members description Type Name Description tFrac32 f32PropGain Proportional Gain, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32IntegGain Integral Gain, fractional format normalized to fit into (-2 31, 2 31-1). tS16 s16PropGainShift Proportional Gain Shift, integer format [-31, 31]. tS16 s16IntegGainShift Integral Gain Shift, integer format [-31, 31]. tFrac32 f32LowerLimit Lower Limit of the controller, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32UpperLimit Upper Limit of the controller, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32IntegPartK_1 State variable integral part at step k-1. tFrac32 f32InK_1 State variable input error at step k-1. tU16 u16LimitFlag Limitation flag, if set to 1, the controller output has reached either the UpperLimit or LowerLimit. 7.35 GFLIB_CONTROLLER_PIAW_R_T_F16 #include <GFLIB_ControllerPIrAW.h> 7.35.1 Description Structure containing parameters and states of the recurrent form PI controller with antiwindup. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 532 NXP Semiconductors Chapter 7 Compound Data Types 7.35.2 Compound Type Members Table 7-36. GFLIB_CONTROLLER_PIAW_R_T_F16 members description Type Name Description tFrac16 f16CC1sc CC1 coefficient, fractional format normalized to fit into (-2 15, 2 15-1). tFrac16 f16CC2sc CC2 coefficient, fractional format normalized to fit into (-2 15, 2 15-1). tFrac32 f32Acc Internal controller accumulator. tFrac16 f16InErrK1 Controller input from the previous calculation step. tFrac16 f16UpperLimit Upper Limit of the controller, fractional format normalized to fit into (-2 15, 2 15-1). tFrac16 f16LowerLimit Lower Limit of the controller, fractional format normalized to fit into (-2 15, 2 15-1). tU16 u16NShift Scaling factor for the controller coefficients, integer format [0, 15]. 7.36 GFLIB_CONTROLLER_PIAW_R_T_F32 #include <GFLIB_ControllerPIrAW.h> 7.36.1 Description Structure containing parameters and states of the recurrent form PI controller with antiwindup. 7.36.2 Compound Type Members Table 7-37. GFLIB_CONTROLLER_PIAW_R_T_F32 members description Type Name Description tFrac32 f32CC1sc CC1 coefficient, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32CC2sc CC2 coefficient, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32Acc Internal controller accumulator. Table continues on the next page... Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 533 GFLIB_COS_T_F16 Table 7-37. GFLIB_CONTROLLER_PIAW_R_T_F32 members description (continued) Type Name Description tFrac32 f32InErrK1 Controller input from the previous calculation step. tFrac32 f32UpperLimit Upper Limit of the controller, fractional format normalized to fit into (-2 31, 2 31-1). tFrac32 f32LowerLimit Lower Limit of the controller, fractional format normalized to fit into (-2 31, 2 31-1). tU16 u16NShift Scaling factor for the controller coefficients, integer format [0, 31]. 7.37 GFLIB_COS_T_F16 #include <GFLIB_Cos.h> 7.37.1 Description Array of four 16-bit elements for storing coefficients of the Taylor polynomial. 7.37.2 Compound Type Members Table 7-38. GFLIB_COS_T_F16 members description Type Name tFrac16 f16A Description Array of four 16-bit elements for storing coefficients of the Taylor polynomial. 7.38 GFLIB_COS_T_F32 #include <GFLIB_Cos.h> 7.38.1 Description Array of five 32-bit elements for storing coefficients of the Taylor polynomial. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 534 NXP Semiconductors Chapter 7 Compound Data Types 7.38.2 Compound Type Members Table 7-39. GFLIB_COS_T_F32 members description Type Name tFrac32 f32A Description Array of five 32-bit elements for storing coefficients of the Taylor polynomial. 7.39 GFLIB_HYST_T_F16 #include <GFLIB_Hyst.h> 7.39.1 Description Structure containing parameters and states for the hysteresis function. 7.39.2 Compound Type Members Table 7-40. GFLIB_HYST_T_F16 members description Type Name Description tFrac16 f16HystOn Value determining the upper threshold. tFrac16 f16HystOff Value determining the lower threshold. tFrac16 f16OutValOn Value of the output when input is higher than the upper threshold. tFrac16 f16OutValOff Value of the output when input is higher than the upper threshold. tFrac16 f16OutState Actual state of the output. 7.40 GFLIB_HYST_T_F32 #include <GFLIB_Hyst.h> 7.40.1 Description Structure containing parameters and states for the hysteresis function. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 535 GFLIB_INTEGRATOR_TR_T_F16 7.40.2 Compound Type Members Table 7-41. GFLIB_HYST_T_F32 members description Type Name Description tFrac32 f32HystOn Value determining the upper threshold. tFrac32 f32HystOff Value determining the lower threshold. tFrac32 f32OutValOn Value of the output when input is higher than the upper threshold. tFrac32 f32OutValOff Value of the output when input is higher than the upper threshold. tFrac32 f32OutState Actual state of the output. 7.41 GFLIB_INTEGRATOR_TR_T_F16 #include <GFLIB_IntegratorTR.h> 7.41.1 Description Structure containing integrator parameters and coefficients. 7.41.2 Compound Type Members Table 7-42. GFLIB_INTEGRATOR_TR_T_F16 members description Type Name Description tFrac32 f32State Integrator state value. tFrac16 f16InK1 Input value in step k-1. tFrac16 f16C1 Integrator coefficient = (E MAX/T s)(U MAX*2)*(2 -u16NShift). tU16 u16NShift Scaling factor for the integrator coefficient f16C1, integer format [0, 15]. 7.42 GFLIB_INTEGRATOR_TR_T_F32 #include <GFLIB_IntegratorTR.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 536 NXP Semiconductors Chapter 7 Compound Data Types 7.42.1 Description Structure containing integrator parameters and coefficients. 7.42.2 Compound Type Members Table 7-43. GFLIB_INTEGRATOR_TR_T_F32 members description Type Name Description tFrac32 f32State Integrator state value. tFrac32 f32InK1 Input value in step k-1. tFrac32 f32C1 Integrator coefficient = (E MAX/T s)(U MAX*2)*(2 -u16NShift). tU16 u16NShift Scaling factor for the integrator coefficient f32C1, integer format [0, 15]. 7.43 GFLIB_LIMIT_T_F16 #include <GFLIB_Limit.h> 7.43.1 Description Structure containing the limits. 7.43.2 Compound Type Members Table 7-44. GFLIB_LIMIT_T_F16 members description Type Name Description tFrac16 f16LowerLimit Value determining the lower limit threshold. tFrac16 f16UpperLimit Value determining the upper limit threshold. 7.44 GFLIB_LIMIT_T_F32 #include <GFLIB_Limit.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 537 GFLIB_LOWERLIMIT_T_F16 7.44.1 Description Structure containing the limits. 7.44.2 Compound Type Members Table 7-45. GFLIB_LIMIT_T_F32 members description Type Name Description tFrac32 f32LowerLimit Value determining the lower limit threshold. tFrac32 f32UpperLimit Value determining the upper limit threshold. 7.45 GFLIB_LOWERLIMIT_T_F16 #include <GFLIB_LowerLimit.h> 7.45.1 Description Structure containing the lower limit. 7.45.2 Compound Type Members Table 7-46. GFLIB_LOWERLIMIT_T_F16 members description Type tFrac16 Name f16LowerLimit Description Value determining the lower limit threshold. 7.46 GFLIB_LOWERLIMIT_T_F32 #include <GFLIB_LowerLimit.h> 7.46.1 Description Structure containing the lower limit. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 538 NXP Semiconductors Chapter 7 Compound Data Types 7.46.2 Compound Type Members Table 7-47. GFLIB_LOWERLIMIT_T_F32 members description Type Name tFrac32 f32LowerLimit Description Value determining the lower limit threshold. 7.47 GFLIB_LUT1D_T_F16 #include <GFLIB_Lut1D.h> 7.47.1 Description Structure containing 1D look-up table parameters. 7.47.2 Compound Type Members Table 7-48. GFLIB_LUT1D_T_F16 members description Type Name Description tU16 u16ShamOffset Shift amount for extracting the fractional offset within an interpolated interval. const tFrac16 * pf16Table Table holding ordinate values of interpolating intervals. 7.48 GFLIB_LUT1D_T_F32 #include <GFLIB_Lut1D.h> 7.48.1 Description Structure containing 1D look-up table parameters. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 539 GFLIB_LUT2D_T_F16 7.48.2 Compound Type Members Table 7-49. GFLIB_LUT1D_T_F32 members description Type Name Description tU32 u32ShamOffset Shift amount for extracting the fractional offset within an interpolated interval. const tFrac32 * pf32Table Table holding ordinate values of interpolating intervals. 7.49 GFLIB_LUT2D_T_F16 #include <GFLIB_Lut2D.h> 7.49.1 Description Structure containing 2D look-up table parameters. 7.49.2 Compound Type Members Table 7-50. GFLIB_LUT2D_T_F16 members description Type Name Description tU16 u16ShamOffset1 Shift amount for extracting the fractional offset within an interpolated interval. tU16 u16ShamOffset2 Shift amount for extracting the fractional offset within an interpolated interval. const tFrac16 * pf16Table Table holding ordinate values of interpolating intervals. 7.50 GFLIB_LUT2D_T_F32 #include <GFLIB_Lut2D.h> 7.50.1 Description Structure containing 2D look-up table parameters. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 540 NXP Semiconductors Chapter 7 Compound Data Types 7.50.2 Compound Type Members Table 7-51. GFLIB_LUT2D_T_F32 members description Type Name Description tU32 u32ShamOffset1 Shift amount for extracting the fractional offset within an interpolated interval. tU32 u32ShamOffset2 Shift amount for extracting the fractional offset within an interpolated interval. const tFrac32 * pf32Table Table holding ordinate values of interpolating intervals. 7.51 GFLIB_RAMP_T_F16 #include <GFLIB_Ramp.h> 7.51.1 Description Structure containing increment/decrement coefficients and state value for the ramp function implemented in GFLIB_Ramp. 7.51.2 Compound Type Members Table 7-52. GFLIB_RAMP_T_F16 members description Type Name Description tFrac16 f16State Ramp state value. tFrac16 f16RampUp Ramp up increment coefficient. tFrac16 f16RampDown Ramp down increment (decrement) coefficient. 7.52 GFLIB_RAMP_T_F32 #include <GFLIB_Ramp.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 541 GFLIB_SIN_T_F16 7.52.1 Description Structure containing increment/decrement coefficients and state value for the ramp function implemented in GFLIB_Ramp. 7.52.2 Compound Type Members Table 7-53. GFLIB_RAMP_T_F32 members description Type Name Description tFrac32 f32State Ramp state value. tFrac32 f32RampUp Ramp up increment coefficient. tFrac32 f32RampDown Ramp down increment (decrement) coefficient. 7.53 GFLIB_SIN_T_F16 #include <GFLIB_Sin.h> 7.53.1 Description Array of four 16-bit elements for storing coefficients of the Taylor polynomial. 7.53.2 Compound Type Members Table 7-54. GFLIB_SIN_T_F16 members description Type Name tFrac16 f16A Description Array of four 16-bit elements for storing coefficients of the Taylor polynomial. 7.54 GFLIB_SIN_T_F32 #include <GFLIB_Sin.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 542 NXP Semiconductors Chapter 7 Compound Data Types 7.54.1 Description Array of five 32-bit elements for storing coefficients of the Taylor polynomial. 7.54.2 Compound Type Members Table 7-55. GFLIB_SIN_T_F32 members description Type Name tFrac32 f32A Description Array of five 32-bit elements for storing coefficients of the Taylor polynomial. 7.55 GFLIB_SINCOS_T_F16 #include <GFLIB_SinCos.h> 7.55.1 Description Array of four 16-bit elements for storing coefficients of the Taylor polynomial. 7.55.2 Compound Type Members Table 7-56. GFLIB_SINCOS_T_F16 members description Type Name tFrac16 f16A Description Array of four 16-bit elements for storing coefficients of the Taylor polynomial. 7.56 GFLIB_SINCOS_T_F32 #include <GFLIB_SinCos.h> 7.56.1 Description Array of five 32-bit elements for storing coefficients of the Taylor polynomial. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 543 GFLIB_TAN_T_F16 7.56.2 Compound Type Members Table 7-57. GFLIB_SINCOS_T_F32 members description Type Name tFrac32 f32A Description Array of five 32-bit elements for storing coefficients of the Taylor polynomial. 7.57 GFLIB_TAN_T_F16 #include <GFLIB_Tan.h> 7.57.1 Description Output of tan(PI * f16In) for interval [0, PI/4) of the input angles is divided into eight sub-sectors. Polynomial approximation is done using a 4th order polynomial, for each sub-sector respectively. Eight arrays, each including four polynomial coefficients for each sub-interval, are stored in this (GFLIB_TAN_T_F16) structure. 7.57.2 Compound Type Members Table 7-58. GFLIB_TAN_T_F16 members description Type Name GFLIB_TAN_TAYLOR_COEF GFLIB_TAN_SECTOR _T_F16 Description Output of tan(PI * f16In) for interval [0, PI/4) of the input angles is divided into eight subsectors. Polynomial approximation is done using a 4th order polynomial, for each subsector respectively. Eight arrays, each including four polynomial coefficients for each sub-interval, are stored in this (GFLIB_TAN_T_F16) structure. 7.58 GFLIB_TAN_T_F32 #include <GFLIB_Tan.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 544 NXP Semiconductors Chapter 7 Compound Data Types 7.58.1 Description Output of tan(PI * f32In) for interval [0, PI/4) of the input angles is divided into eight sub-sectors. Polynomial approximation is done using a 4th order polynomial, for each sub-sector respectively. Eight arrays, each including four polynomial coefficients for each sub-interval, are stored in this (GFLIB_TAN_T_F32) structure. 7.58.2 Compound Type Members Table 7-59. GFLIB_TAN_T_F32 members description Type Name GFLIB_TAN_TAYLOR_COEF GFLIB_TAN_SECTOR _T_F32 Description Output of tan(PI * f32In) for interval [0, PI/4) of the input angles is divided into eight subsectors. Polynomial approximation is done using a 4th order polynomial, for each subsector respectively. Eight arrays, each including four polynomial coefficients for each sub-interval, are stored in this (GFLIB_TAN_T_F32) structure. 7.59 GFLIB_TAN_TAYLOR_COEF_T_F16 #include <GFLIB_Tan.h> 7.59.1 Description Structure containing four polynomial coefficients for one sub-interval. 7.59.2 Compound Type Members Table 7-60. GFLIB_TAN_TAYLOR_COEF_T_F16 members description Type Name const tFrac16 f16A Description Structure containing four polynomial coefficients for one sub-interval. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 545 GFLIB_UPPERLIMIT_T_F16 7.60 GFLIB_TAN_TAYLOR_COEF_T_F32 #include <GFLIB_Tan.h> 7.60.1 Description Structure containing four polynomial coefficients for one sub-interval. 7.60.2 Compound Type Members Table 7-61. GFLIB_TAN_TAYLOR_COEF_T_F32 members description Type const tFrac32 Name f32A Description Structure containing four polynomial coefficients for one sub-interval. 7.61 GFLIB_UPPERLIMIT_T_F16 #include <GFLIB_UpperLimit.h> 7.61.1 Description Structure containing the upper limit. 7.61.2 Compound Type Members Table 7-62. GFLIB_UPPERLIMIT_T_F16 members description Type tFrac16 Name f16UpperLimit Description Value determining the upper limit threshold. 7.62 GFLIB_UPPERLIMIT_T_F32 #include <GFLIB_UpperLimit.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 546 NXP Semiconductors Chapter 7 Compound Data Types 7.62.1 Description Structure containing the upper limit. 7.62.2 Compound Type Members Table 7-63. GFLIB_UPPERLIMIT_T_F32 members description Type Name tFrac32 f32UpperLimit Description Value determining the upper limit threshold. 7.63 GFLIB_VECTORLIMIT_T_F16 #include <GFLIB_VectorLimit.h> 7.63.1 Description Structure containing the limit. 7.63.2 Compound Type Members Table 7-64. GFLIB_VECTORLIMIT_T_F16 members description Type Name tFrac16 f16Limit Description The maximum magnitude of the input vector. The defined magnitude must be positive and equal to or greater than F16_MAX value. 7.64 GFLIB_VECTORLIMIT_T_F32 #include <GFLIB_VectorLimit.h> 7.64.1 Description Structure containing the limit. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 547 GMCLIB_DECOUPLINGPMSM_T_F16 7.64.2 Compound Type Members Table 7-65. GFLIB_VECTORLIMIT_T_F32 members description Type tFrac32 Name f32Limit Description The maximum magnitude of the input vector. The defined magnitude must be positive and equal to or greater than F32_MAX value. 7.65 GMCLIB_DECOUPLINGPMSM_T_F16 #include <GMCLIB_DecouplingPMSM.h> 7.65.1 Description Structure containing coefficients for calculation of the decoupling. 7.65.2 Compound Type Members Table 7-66. GMCLIB_DECOUPLINGPMSM_T_F16 members description Type Name Description tFrac16 f16Kd Coefficient k df. tS16 s16KdShift Scaling coefficient k d_shift. tFrac16 f16Kq Coefficient k qf. tS16 s16KqShift Scaling coefficient k q_shift. 7.66 GMCLIB_DECOUPLINGPMSM_T_F32 #include <GMCLIB_DecouplingPMSM.h> 7.66.1 Description Structure containing coefficients for calculation of the decoupling. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 548 NXP Semiconductors Chapter 7 Compound Data Types 7.66.2 Compound Type Members Table 7-67. GMCLIB_DECOUPLINGPMSM_T_F32 members description Type Name Description tFrac32 f32Kd Coefficient k df. tS16 s16KdShift Scaling coefficient k d_shift. tFrac32 f32Kq Coefficient k qf. tS16 s16KqShift Scaling coefficient k q_shift. 7.67 GMCLIB_ELIMDCBUSRIP_T_F16 #include <GMCLIB_ElimDcBusRip.h> 7.67.1 Description Structure containing the PWM modulation index and the measured value of the DC bus voltage. 7.67.2 Compound Type Members Table 7-68. GMCLIB_ELIMDCBUSRIP_T_F16 members description Type Name Description tFrac16 f16ModIndex Inverse Modulation Index. tFrac16 f16ArgDcBusMsr Measured DC bus voltage. 7.68 GMCLIB_ELIMDCBUSRIP_T_F32 #include <GMCLIB_ElimDcBusRip.h> 7.68.1 Description Structure containing the PWM modulation index and the measured value of the DC bus voltage. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 549 SWLIBS_2Syst_F16 7.68.2 Compound Type Members Table 7-69. GMCLIB_ELIMDCBUSRIP_T_F32 members description Type Name Description tFrac32 f32ModIndex Inverse Modulation Index. tFrac32 f32ArgDcBusMsr Measured DC bus voltage. 7.69 SWLIBS_2Syst_F16 #include <SWLIBS_Typedefs.h> 7.69.1 Description Array of two standard 16-bit fractional arguments. 7.69.2 Compound Type Members Table 7-70. SWLIBS_2Syst_F16 members description Type Name Description tFrac16 f16Arg1 First argument tFrac16 f16Arg2 Second argument 7.70 SWLIBS_2Syst_F32 #include <SWLIBS_Typedefs.h> 7.70.1 Description Array of two standard 32-bit fractional arguments. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 550 NXP Semiconductors Chapter 7 Compound Data Types 7.70.2 Compound Type Members Table 7-71. SWLIBS_2Syst_F32 members description Type Name Description tFrac32 f32Arg1 First argument tFrac32 f32Arg2 Second argument 7.71 SWLIBS_3Syst_F16 #include <SWLIBS_Typedefs.h> 7.71.1 Description Array of three standard 16-bit fractional arguments. 7.71.2 Compound Type Members Table 7-72. SWLIBS_3Syst_F16 members description Type Name Description tFrac16 f16Arg1 First argument tFrac16 f16Arg2 Second argument tFrac16 f16Arg3 Third argument 7.72 SWLIBS_3Syst_F32 #include <SWLIBS_Typedefs.h> 7.72.1 Description Array of three standard 32-bit fractional arguments. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 551 SWLIBS_VERSION_T 7.72.2 Compound Type Members Table 7-73. SWLIBS_3Syst_F32 members description Type Name Description tFrac32 f32Arg1 First argument tFrac32 f32Arg2 Second argument tFrac32 f32Arg3 Third argument 7.73 SWLIBS_VERSION_T #include <SWLIBS_Version.h> 7.73.1 Description Motor Control Library Set identification structure. 7.73.2 Compound Type Members Table 7-74. SWLIBS_VERSION_T members description Type Name Description unsigned char mcId MCLIB identification code unsigned char mcVersion MCLIB version code unsigned char mcImpl MCLIB supported implementation code Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 552 NXP Semiconductors Chapter 8 8.1 Macro Definitions 8.1.1 Macro Definitions Overview #define F16 #define F16TOINT16 #define F16TOINT32 #define F16TOINT64 #define F16_1_DIVBY_SQRT3 #define F16_SQRT2_DIVBY_2 #define F16_SQRT3_DIVBY_2 #define F32 #define F32TOINT16 #define F32TOINT32 #define F32TOINT64 #define F32_1_DIVBY_SQRT3 #define F32_SQRT2_DIVBY_2 #define F32_SQRT3_DIVBY_2 #define F64TOINT16 #define F64TOINT32 #define F64TOINT64 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 553 Macro Definitions #define FALSE #define FLT #define FRAC16 #define FRAC16_0_25 #define FRAC16_0_5 #define FRAC32 #define FRAC32_0_25 #define FRAC32_0_5 #define FRACT_MAX #define FRACT_MIN #define GDFLIB_FILTER_IIR1_DEFAULT_F16 #define GDFLIB_FILTER_IIR1_DEFAULT_F32 #define GDFLIB_FILTER_IIR2_DEFAULT_F16 #define GDFLIB_FILTER_IIR2_DEFAULT_F32 #define GDFLIB_FILTER_MA_DEFAULT_F16 #define GDFLIB_FILTER_MA_DEFAULT_F32 #define GDFLIB_FilterFIR #define GDFLIB_FilterFIRInit #define GDFLIB_FilterIIR1 #define GDFLIB_FilterIIR1Init #define GDFLIB_FilterIIR2 #define GDFLIB_FilterIIR2Init #define GDFLIB_FilterMA #define GDFLIB_FilterMAInit #define GFLIB_ACOS_DEFAULT_F16 #define GFLIB_ACOS_DEFAULT_F32 #define GFLIB_ASIN_DEFAULT_F16 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 554 NXP Semiconductors Chapter 8 #define GFLIB_ASIN_DEFAULT_F32 #define GFLIB_ATAN_DEFAULT_F16 #define GFLIB_ATAN_DEFAULT_F32 #define GFLIB_Acos #define GFLIB_Asin #define GFLIB_Atan #define GFLIB_AtanYX #define GFLIB_AtanYXShifted #define GFLIB_CONTROLLER_PIAW_P_DEFAULT_F16 #define GFLIB_CONTROLLER_PIAW_P_DEFAULT_F32 #define GFLIB_CONTROLLER_PIAW_R_DEFAULT_F16 #define GFLIB_CONTROLLER_PIAW_R_DEFAULT_F32 #define GFLIB_CONTROLLER_PI_P_DEFAULT_F16 #define GFLIB_CONTROLLER_PI_P_DEFAULT_F32 #define GFLIB_CONTROLLER_PI_R_DEFAULT_F16 #define GFLIB_CONTROLLER_PI_R_DEFAULT_F32 #define GFLIB_COS_DEFAULT_F16 #define GFLIB_COS_DEFAULT_F32 #define GFLIB_ControllerPIp #define GFLIB_ControllerPIpAW #define GFLIB_ControllerPIr #define GFLIB_ControllerPIrAW #define GFLIB_Cos #define GFLIB_HYST_DEFAULT_F16 #define GFLIB_HYST_DEFAULT_F32 #define GFLIB_Hyst #define GFLIB_INTEGRATOR_TR_DEFAULT_F16 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 555 Macro Definitions #define GFLIB_INTEGRATOR_TR_DEFAULT_F32 #define GFLIB_IntegratorTR #define GFLIB_LIMIT_DEFAULT_F16 #define GFLIB_LIMIT_DEFAULT_F32 #define GFLIB_LOWERLIMIT_DEFAULT_F16 #define GFLIB_LOWERLIMIT_DEFAULT_F32 #define GFLIB_LUT1D_DEFAULT_F16 #define GFLIB_LUT1D_DEFAULT_F32 #define GFLIB_LUT2D_DEFAULT_F16 #define GFLIB_LUT2D_DEFAULT_F32 #define GFLIB_Limit #define GFLIB_LowerLimit #define GFLIB_Lut1D #define GFLIB_Lut2D #define GFLIB_RAMP_DEFAULT_F16 #define GFLIB_RAMP_DEFAULT_F32 #define GFLIB_Ramp #define GFLIB_SINCOS_DEFAULT_F16 #define GFLIB_SINCOS_DEFAULT_F32 #define GFLIB_SIN_DEFAULT_F16 #define GFLIB_SIN_DEFAULT_F32 #define GFLIB_Sign #define GFLIB_Sin #define GFLIB_SinCos #define GFLIB_Sqrt #define GFLIB_TAN_DEFAULT_F16 #define GFLIB_TAN_DEFAULT_F32 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 556 NXP Semiconductors Chapter 8 #define GFLIB_Tan #define GFLIB_UPPERLIMIT_DEFAULT_F16 #define GFLIB_UPPERLIMIT_DEFAULT_F32 #define GFLIB_UpperLimit #define GFLIB_VECTORLIMIT_DEFAULT_F16 #define GFLIB_VECTORLIMIT_DEFAULT_F32 #define GFLIB_VectorLimit #define GMCLIB_Clark #define GMCLIB_ClarkInv #define GMCLIB_DECOUPLINGPMSM_DEFAULT_F16 #define GMCLIB_DECOUPLINGPMSM_DEFAULT_F32 #define GMCLIB_DecouplingPMSM #define GMCLIB_ELIMDCBUSRIP_DEFAULT_F16 #define GMCLIB_ELIMDCBUSRIP_DEFAULT_F32 #define GMCLIB_ELIMDCBUSRIP_FLT_DNMAX #define GMCLIB_ElimDcBusRip #define GMCLIB_Park #define GMCLIB_ParkInv #define GMCLIB_SvmStd #define INT16TOF16 #define INT16TOF32 #define INT16TOINT32 #define INT16_MAX #define INT16_MIN #define INT32TOF16 #define INT32TOF32 #define INT32TOINT16 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 557 Macro Definitions #define INT32TOINT64 #define INT32_MAX #define INT32_MIN #define INT64TOF16 #define INT64TOF32 #define INT64TOINT32 #define MLIB_Abs #define MLIB_AbsSat #define MLIB_Add #define MLIB_AddSat #define MLIB_Convert #define MLIB_ConvertPU #define MLIB_Div #define MLIB_DivSat #define MLIB_Mac #define MLIB_MacSat #define MLIB_Mnac #define MLIB_Msu #define MLIB_Mul #define MLIB_MulSat #define MLIB_Neg #define MLIB_NegSat #define MLIB_Norm #define MLIB_Round #define MLIB_ShBi #define MLIB_ShBiSat #define MLIB_ShL Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 558 NXP Semiconductors Chapter 8 #define MLIB_ShLSat #define MLIB_ShR #define MLIB_Sub #define MLIB_SubSat #define MLIB_VMac #define NULL #define SFRACT_MAX #define SFRACT_MIN #define SWLIBS_2Syst #define SWLIBS_2Syst #define SWLIBS_2Syst #define SWLIBS_3Syst #define SWLIBS_3Syst #define SWLIBS_3Syst #define SWLIBS_DEFAULT_IMPLEMENTATION #define SWLIBS_DEFAULT_IMPLEMENTATION_F16 #define SWLIBS_DEFAULT_IMPLEMENTATION_F32 #define SWLIBS_DEFAULT_IMPLEMENTATION_FLT #define SWLIBS_ID #define SWLIBS_MCID_SIZE #define SWLIBS_MCIMPLEMENTATION_SIZE #define SWLIBS_MCVERSION_SIZE #define SWLIBS_STD_OFF #define SWLIBS_STD_ON #define SWLIBS_SUPPORTED_IMPLEMENTATION #define SWLIBS_SUPPORT_F16 #define SWLIBS_SUPPORT_F32 Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 559 Macro Definitions #define SWLIBS_SUPPORT_FLT #define SWLIBS_VERSION #define SWLIBS_VERSION_DEFAULT #define TRUE #define UINT16_MAX #define UINT32_MAX Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 560 NXP Semiconductors Chapter 9 Macro References This section describes in details the macro definitions available in Automotive Math and Motor Control Library Set for KEAx devices. 9.1 Define GDFLIB_FilterFIRInit #include <GDFLIB_FilterFIR.h> 9.1.1 Macro Definition #define GDFLIB_FilterFIRInit macro_dispatcher(GDFLIB_FilterFIRInit, __VA_ARGS__)(__VA_ARGS__) 9.1.2 Description This function initializes the FIR filter buffers. 9.2 Define GDFLIB_FilterFIR #include <GDFLIB_FilterFIR.h> 9.2.1 Macro Definition #define GDFLIB_FilterFIR macro_dispatcher(GDFLIB_FilterFIR, __VA_ARGS__)(__VA_ARGS__) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 561 Define GDFLIB_FilterIIR1Init 9.2.2 Description The function performs a single iteration of an FIR filter. 9.3 Define GDFLIB_FilterIIR1Init #include <GDFLIB_FilterIIR1.h> 9.3.1 Macro Definition #define GDFLIB_FilterIIR1Init macro_dispatcher(GDFLIB_FilterIIR1Init, __VA_ARGS__) (__VA_ARGS__) 9.3.2 Description This function initializes the first order IIR filter buffers. 9.4 Define GDFLIB_FilterIIR1 #include <GDFLIB_FilterIIR1.h> 9.4.1 Macro Definition #define GDFLIB_FilterIIR1 macro_dispatcher(GDFLIB_FilterIIR1, __VA_ARGS__)(__VA_ARGS__) 9.4.2 Description This function implements the first order IIR filter. 9.5 Define GDFLIB_FILTER_IIR1_DEFAULT_F32 #include <GDFLIB_FilterIIR1.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 562 NXP Semiconductors Chapter 9 Macro References 9.5.1 Macro Definition #define GDFLIB_FILTER_IIR1_DEFAULT_F32 {{(tFrac32)0,(tFrac32)0,(tFrac32)0},{(tFrac32)0}, {(tFrac32)0}} 9.5.2 Description Default value for GDFLIB_FILTER_IIR1_T_F32. 9.6 Define GDFLIB_FILTER_IIR1_DEFAULT_F16 #include <GDFLIB_FilterIIR1.h> 9.6.1 Macro Definition #define GDFLIB_FILTER_IIR1_DEFAULT_F16 {{(tFrac16)0,(tFrac16)0,(tFrac16)0},{(tFrac16)0}, {(tFrac16)0}} 9.6.2 Description Default value for GDFLIB_FILTER_IIR1_T_F16. 9.7 Define GDFLIB_FilterIIR2Init #include <GDFLIB_FilterIIR2.h> 9.7.1 Macro Definition #define GDFLIB_FilterIIR2Init macro_dispatcher(GDFLIB_FilterIIR2Init, __VA_ARGS__) (__VA_ARGS__) 9.7.2 Description This function initializes the second order IIR filter buffers. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 563 Define GDFLIB_FilterIIR2 9.8 Define GDFLIB_FilterIIR2 #include <GDFLIB_FilterIIR2.h> 9.8.1 Macro Definition #define GDFLIB_FilterIIR2 macro_dispatcher(GDFLIB_FilterIIR2, __VA_ARGS__)(__VA_ARGS__) 9.8.2 Description This function implements the second order IIR filter. 9.9 Define GDFLIB_FILTER_IIR2_DEFAULT_F32 #include <GDFLIB_FilterIIR2.h> 9.9.1 Macro Definition #define GDFLIB_FILTER_IIR2_DEFAULT_F32 {{(tFrac32)0,(tFrac32)0,(tFrac32)0,(tFrac32)0, (tFrac32)0},{(tFrac32)0,(tFrac32)0},{(tFrac32)0,(tFrac32)0}} 9.9.2 Description Default value for GDFLIB_FILTER_IIR2_T_F32. 9.10 Define GDFLIB_FILTER_IIR2_DEFAULT_F16 #include <GDFLIB_FilterIIR2.h> 9.10.1 Macro Definition #define GDFLIB_FILTER_IIR2_DEFAULT_F16 {{(tFrac16)0,(tFrac16)0,(tFrac16)0,(tFrac16)0, (tFrac16)0},{(tFrac16)0,(tFrac16)0},{(tFrac16)0,(tFrac16)0}} Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 564 NXP Semiconductors Chapter 9 Macro References 9.10.2 Description Default value for GDFLIB_FILTER_IIR2_T_F16. 9.11 Define GDFLIB_FilterMAInit #include <GDFLIB_FilterMA.h> 9.11.1 Macro Definition #define GDFLIB_FilterMAInit macro_dispatcher(GDFLIB_FilterMAInit, __VA_ARGS__)(__VA_ARGS__) 9.11.2 Description This function clears the internal filter accumulator. 9.12 Define GDFLIB_FilterMA #include <GDFLIB_FilterMA.h> 9.12.1 Macro Definition #define GDFLIB_FilterMA macro_dispatcher(GDFLIB_FilterMA, __VA_ARGS__)(__VA_ARGS__) 9.12.2 Description This function implements a moving average recursive filter. 9.13 Define GDFLIB_FILTER_MA_DEFAULT_F32 #include <GDFLIB_FilterMA.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 565 Define GDFLIB_FILTER_MA_DEFAULT_F16 9.13.1 Macro Definition #define GDFLIB_FILTER_MA_DEFAULT_F32 {0,0} 9.13.2 Description Default value for GDFLIB_FILTER_MA_T_F32. 9.14 Define GDFLIB_FILTER_MA_DEFAULT_F16 #include <GDFLIB_FilterMA.h> 9.14.1 Macro Definition #define GDFLIB_FILTER_MA_DEFAULT_F16 {0,0} 9.14.2 Description Default value for GDFLIB_FILTER_MA_T_F16. 9.15 Define GFLIB_Acos #include <GFLIB_Acos.h> 9.15.1 Macro Definition #define GFLIB_Acos macro_dispatcher(GFLIB_Acos, __VA_ARGS__)(__VA_ARGS__) 9.15.2 Description This function implements polynomial approximation of arccosine function. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 566 NXP Semiconductors Chapter 9 Macro References 9.16 Define GFLIB_ACOS_DEFAULT_F32 #include <GFLIB_Acos.h> 9.16.1 Macro Definition #define GFLIB_ACOS_DEFAULT_F32 &f32gflibAcosCoef 9.16.2 Description Default approximation coefficients for GFLIB_Acos_F32 function. 9.17 Define GFLIB_ACOS_DEFAULT_F16 #include <GFLIB_Acos.h> 9.17.1 Macro Definition #define GFLIB_ACOS_DEFAULT_F16 &f16gflibAcosCoef 9.17.2 Description Default approximation coefficients for GFLIB_Acos_F16 function. 9.18 Define GFLIB_Asin #include <GFLIB_Asin.h> 9.18.1 Macro Definition #define GFLIB_Asin macro_dispatcher(GFLIB_Asin, __VA_ARGS__)(__VA_ARGS__) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 567 Define GFLIB_ASIN_DEFAULT_F32 9.18.2 Description This function implements polynomial approximation of arcsine function. 9.19 Define GFLIB_ASIN_DEFAULT_F32 #include <GFLIB_Asin.h> 9.19.1 Macro Definition #define GFLIB_ASIN_DEFAULT_F32 &f32gflibAsinCoef 9.19.2 Description Default approximation coefficients for GFLIB_Asin_F32 function. 9.20 Define GFLIB_ASIN_DEFAULT_F16 #include <GFLIB_Asin.h> 9.20.1 Macro Definition #define GFLIB_ASIN_DEFAULT_F16 &f16gflibAsinCoef 9.20.2 Description Default approximation coefficients for GFLIB_Asin_F16 function. 9.21 Define GFLIB_Atan #include <GFLIB_Atan.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 568 NXP Semiconductors Chapter 9 Macro References 9.21.1 Macro Definition #define GFLIB_Atan macro_dispatcher(GFLIB_Atan, __VA_ARGS__)(__VA_ARGS__) 9.21.2 Description This function implements polynomial approximation of arctangent function. 9.22 Define GFLIB_ATAN_DEFAULT_F32 #include <GFLIB_Atan.h> 9.22.1 Macro Definition #define GFLIB_ATAN_DEFAULT_F32 &f32gflibAtanCoef 9.22.2 Description Default approximation coefficients for GFLIB_Atan_F32 function. 9.23 Define GFLIB_ATAN_DEFAULT_F16 #include <GFLIB_Atan.h> 9.23.1 Macro Definition #define GFLIB_ATAN_DEFAULT_F16 &f16gflibAtanCoef 9.23.2 Description Default approximation coefficients for GFLIB_Atan_F16 function. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 569 Define GFLIB_AtanYXShifted 9.24 Define GFLIB_AtanYX #include <GFLIB_AtanYX.h> 9.24.1 Macro Definition #define GFLIB_AtanYX macro_dispatcher(GFLIB_AtanYX, __VA_ARGS__)(__VA_ARGS__) 9.24.2 Description This function calculate the angle between the positive x-axis and the direction of a vector given by the (x, y) coordinates. 9.25 Define GFLIB_AtanYXShifted #include <GFLIB_AtanYXShifted.h> 9.25.1 Macro Definition #define GFLIB_AtanYXShifted macro_dispatcher(GFLIB_AtanYXShifted, __VA_ARGS__)(__VA_ARGS__) 9.25.2 Description This function calculates the angle of two sine waves shifted in phase to each other. 9.26 Define GFLIB_ControllerPIp #include <GFLIB_ControllerPIp.h> 9.26.1 Macro Definition #define GFLIB_ControllerPIp macro_dispatcher(GFLIB_ControllerPIp, __VA_ARGS__)(__VA_ARGS__) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 570 NXP Semiconductors Chapter 9 Macro References 9.26.2 Description This function calculates a parallel form of the Proportional- Integral controller, without integral anti-windup. 9.27 Define GFLIB_CONTROLLER_PI_P_DEFAULT_F32 #include <GFLIB_ControllerPIp.h> 9.27.1 Macro Definition #define GFLIB_CONTROLLER_PI_P_DEFAULT_F32 {(tFrac32)0,(tFrac32)0,(tS16)0,(tS16)0,(tFrac32)0, (tFrac32)0} 9.27.2 Description Default value for GFLIB_CONTROLLER_PI_P_T_F32. 9.28 Define GFLIB_CONTROLLER_PI_P_DEFAULT_F16 #include <GFLIB_ControllerPIp.h> 9.28.1 Macro Definition #define GFLIB_CONTROLLER_PI_P_DEFAULT_F16 {(tFrac16)0,(tFrac16)0,(tS16)0,(tS16)0,(tFrac32)0, (tFrac16)0} 9.28.2 Description Default value for GFLIB_CONTROLLER_PI_P_T_F16. 9.29 Define GFLIB_ControllerPIpAW #include <GFLIB_ControllerPIpAW.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 571 Define GFLIB_CONTROLLER_PIAW_P_DEFAULT_F32 9.29.1 Macro Definition #define GFLIB_ControllerPIpAW macro_dispatcher(GFLIB_ControllerPIpAW, __VA_ARGS__) (__VA_ARGS__) 9.29.2 Description This function calculates a standard recurrent form of the Proportional- Integral controller, with integral anti-windup. 9.30 Define GFLIB_CONTROLLER_PIAW_P_DEFAULT_F32 #include <GFLIB_ControllerPIpAW.h> 9.30.1 Macro Definition #define GFLIB_CONTROLLER_PIAW_P_DEFAULT_F32 {(tFrac32)0,(tFrac32)0,(tS32)0, (tS32)0,INT32_MIN,INT32_MAX,(tFrac32)0,(tFrac32)0,(tU16)0} 9.30.2 Description Default value for GFLIB_CONTROLLER_PIAW_P_T_F32. 9.31 Define GFLIB_CONTROLLER_PIAW_P_DEFAULT_F16 #include <GFLIB_ControllerPIpAW.h> 9.31.1 Macro Definition #define GFLIB_CONTROLLER_PIAW_P_DEFAULT_F16 {(tFrac16)0,(tFrac16)0,(tS16)0, (tS16)0,INT16_MIN,INT16_MAX,(tFrac32)0,(tFrac16)0,(tU16)0} Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 572 NXP Semiconductors Chapter 9 Macro References 9.31.2 Description Default value for GFLIB_CONTROLLER_PIAW_P_T_F16. 9.32 Define GFLIB_ControllerPIr #include <GFLIB_ControllerPIr.h> 9.32.1 Macro Definition #define GFLIB_ControllerPIr macro_dispatcher(GFLIB_ControllerPIr, __VA_ARGS__)(__VA_ARGS__) 9.32.2 Description This function calculates a standard recurrent form of the Proportional- Integral controller, without integral anti-windup. 9.33 Define GFLIB_CONTROLLER_PI_R_DEFAULT_F32 #include <GFLIB_ControllerPIr.h> 9.33.1 Macro Definition #define GFLIB_CONTROLLER_PI_R_DEFAULT_F32 {(tFrac32)0,(tFrac32)0,(tFrac32)0,(tFrac32)0, (tU16)0} 9.33.2 Description Default value for GFLIB_CONTROLLER_PI_R_T_F32. 9.34 Define GFLIB_CONTROLLER_PI_R_DEFAULT_F16 #include <GFLIB_ControllerPIr.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 573 Define GFLIB_ControllerPIrAW 9.34.1 Macro Definition #define GFLIB_CONTROLLER_PI_R_DEFAULT_F16 {(tFrac16)0,(tFrac16)0,(tFrac32)0,(tFrac16)0, (tU16)0} 9.34.2 Description Default value for GFLIB_CONTROLLER_PI_R_T_F16. 9.35 Define GFLIB_ControllerPIrAW #include <GFLIB_ControllerPIrAW.h> 9.35.1 Macro Definition #define GFLIB_ControllerPIrAW macro_dispatcher(GFLIB_ControllerPIrAW, __VA_ARGS__) (__VA_ARGS__) 9.35.2 Description This function calculates a standard recurrent form of the Proportional-Integral controller, with integral anti-windup. 9.36 Define GFLIB_CONTROLLER_PIAW_R_DEFAULT_F32 #include <GFLIB_ControllerPIrAW.h> 9.36.1 Macro Definition #define GFLIB_CONTROLLER_PIAW_R_DEFAULT_F32 {(tFrac32)0,(tFrac32)0,(tFrac32)0, (tFrac32)0,INT32_MIN,INT32_MAX,(tU16)0} Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 574 NXP Semiconductors Chapter 9 Macro References 9.36.2 Description Default value for GFLIB_CONTROLLER_PIAW_R_T_F32. 9.37 Define GFLIB_CONTROLLER_PIAW_R_DEFAULT_F16 #include <GFLIB_ControllerPIrAW.h> 9.37.1 Macro Definition #define GFLIB_CONTROLLER_PIAW_R_DEFAULT_F16 {(tFrac16)0,(tFrac16)0,(tFrac32)0, (tFrac16)0,INT16_MIN,INT16_MAX,(tU16)0} 9.37.2 Description Default value for GFLIB_CONTROLLER_PIAW_R_T_F16. 9.38 Define GFLIB_Cos #include <GFLIB_Cos.h> 9.38.1 Macro Definition #define GFLIB_Cos macro_dispatcher(GFLIB_Cos, __VA_ARGS__)(__VA_ARGS__) 9.38.2 Description This function implements polynomial approximation of cosine function. 9.39 Define GFLIB_COS_DEFAULT_F32 #include <GFLIB_Cos.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 575 Define GFLIB_COS_DEFAULT_F16 9.39.1 Macro Definition #define GFLIB_COS_DEFAULT_F32 &f32gflibCosCoef 9.39.2 Description Default approximation coefficients for GFLIB_Cos_F32 function. 9.40 Define GFLIB_COS_DEFAULT_F16 #include <GFLIB_Cos.h> 9.40.1 Macro Definition #define GFLIB_COS_DEFAULT_F16 &f16gflibCosCoef 9.40.2 Description Default approximation coefficients for GFLIB_Cos_F32 function. 9.41 Define GFLIB_Hyst #include <GFLIB_Hyst.h> 9.41.1 Macro Definition #define GFLIB_Hyst macro_dispatcher(GFLIB_Hyst, __VA_ARGS__)(__VA_ARGS__) 9.41.2 Description The function implements the hysteresis functionality. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 576 NXP Semiconductors Chapter 9 Macro References 9.42 Define GFLIB_HYST_DEFAULT_F32 #include <GFLIB_Hyst.h> 9.42.1 Macro Definition #define GFLIB_HYST_DEFAULT_F32 {(tFrac32)0,(tFrac32)0,(tFrac32)0,(tFrac32)0,(tFrac32)0} 9.42.2 Description Default value for GFLIB_HYST_T_F32. 9.43 Define GFLIB_HYST_DEFAULT_F16 #include <GFLIB_Hyst.h> 9.43.1 Macro Definition #define GFLIB_HYST_DEFAULT_F16 {(tFrac16)0,(tFrac16)0,(tFrac16)0,(tFrac16)0,(tFrac16)0} 9.43.2 Description Default value for GFLIB_HYST_T_F16. 9.44 Define GFLIB_IntegratorTR #include <GFLIB_IntegratorTR.h> 9.44.1 Macro Definition #define GFLIB_IntegratorTR macro_dispatcher(GFLIB_IntegratorTR, __VA_ARGS__)(__VA_ARGS__) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 577 Define GFLIB_INTEGRATOR_TR_DEFAULT_F32 9.44.2 Description The function calculates a discrete implementation of the integrator (sum), discretized using a trapezoidal (Bilinear) transformation. 9.45 Define GFLIB_INTEGRATOR_TR_DEFAULT_F32 #include <GFLIB_IntegratorTR.h> 9.45.1 Macro Definition #define GFLIB_INTEGRATOR_TR_DEFAULT_F32 {(tFrac32)0,(tFrac32)0,(tFrac32)0,(tU16)0} 9.45.2 Description Default value for GFLIB_INTEGRATOR_TR_T_F32. 9.46 Define GFLIB_INTEGRATOR_TR_DEFAULT_F16 #include <GFLIB_IntegratorTR.h> 9.46.1 Macro Definition #define GFLIB_INTEGRATOR_TR_DEFAULT_F16 {(tFrac32)0,(tFrac16)0,(tFrac16)0,(tU16)0} 9.46.2 Description Default value for GFLIB_INTEGRATOR_TR_T_F16. 9.47 Define GFLIB_Limit #include <GFLIB_Limit.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 578 NXP Semiconductors Chapter 9 Macro References 9.47.1 Macro Definition #define GFLIB_Limit macro_dispatcher(GFLIB_Limit, __VA_ARGS__)(__VA_ARGS__) 9.47.2 Description This function tests whether the input value is within the upper and lower limits. 9.48 Define GFLIB_LIMIT_DEFAULT_F32 #include <GFLIB_Limit.h> 9.48.1 Macro Definition #define GFLIB_LIMIT_DEFAULT_F32 {INT32_MIN,INT32_MAX } 9.48.2 Description Default value for GFLIB_LIMIT_T_F32. 9.49 Define GFLIB_LIMIT_DEFAULT_F16 #include <GFLIB_Limit.h> 9.49.1 Macro Definition #define GFLIB_LIMIT_DEFAULT_F16 {INT16_MIN,INT16_MAX } 9.49.2 Description Default value for GFLIB_LIMIT_T_F16. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 579 Define GFLIB_LOWERLIMIT_DEFAULT_F32 9.50 Define GFLIB_LowerLimit #include <GFLIB_LowerLimit.h> 9.50.1 Macro Definition #define GFLIB_LowerLimit macro_dispatcher(GFLIB_LowerLimit, __VA_ARGS__)(__VA_ARGS__) 9.50.2 Description This function tests whether the input value is above the lower limit. 9.51 Define GFLIB_LOWERLIMIT_DEFAULT_F32 #include <GFLIB_LowerLimit.h> 9.51.1 Macro Definition #define GFLIB_LOWERLIMIT_DEFAULT_F32 {INT32_MIN } 9.51.2 Description Default value for GFLIB_LOWERLIMIT_T_F32. 9.52 Define GFLIB_LOWERLIMIT_DEFAULT_F16 #include <GFLIB_LowerLimit.h> 9.52.1 Macro Definition #define GFLIB_LOWERLIMIT_DEFAULT_F16 {INT16_MIN } Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 580 NXP Semiconductors Chapter 9 Macro References 9.52.2 Description Default value for GFLIB_LOWERLIMIT_T_F16. 9.53 Define GFLIB_Lut1D #include <GFLIB_Lut1D.h> 9.53.1 Macro Definition #define GFLIB_Lut1D macro_dispatcher(GFLIB_Lut1D, __VA_ARGS__)(__VA_ARGS__) 9.53.2 Description This function implements the one-dimensional look-up table. 9.54 Define GFLIB_LUT1D_DEFAULT_F32 #include <GFLIB_Lut1D.h> 9.54.1 Macro Definition #define GFLIB_LUT1D_DEFAULT_F32 {(tU32)0,(tFrac32 *)0} 9.54.2 Description Default value for GFLIB_LUT1D_T_F32. 9.55 Define GFLIB_LUT1D_DEFAULT_F16 #include <GFLIB_Lut1D.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 581 Define GFLIB_Lut2D 9.55.1 Macro Definition #define GFLIB_LUT1D_DEFAULT_F16 {(tU16)0,(tFrac16 *)0} 9.55.2 Description Default value for GFLIB_LUT1D_T_F16. 9.56 Define GFLIB_Lut2D #include <GFLIB_Lut2D.h> 9.56.1 Macro Definition #define GFLIB_Lut2D macro_dispatcher(GFLIB_Lut2D, __VA_ARGS__)(__VA_ARGS__) 9.56.2 Description This function implements the two-dimensional look-up table. 9.57 Define GFLIB_LUT2D_DEFAULT_F32 #include <GFLIB_Lut2D.h> 9.57.1 Macro Definition #define GFLIB_LUT2D_DEFAULT_F32 {(tU32)0,(tU32)0,(tFrac32 *)0} 9.57.2 Description Default value for GFLIB_LUT2D_T_F32. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 582 NXP Semiconductors Chapter 9 Macro References 9.58 Define GFLIB_LUT2D_DEFAULT_F16 #include <GFLIB_Lut2D.h> 9.58.1 Macro Definition #define GFLIB_LUT2D_DEFAULT_F16 {(tU16)0,(tU16)0,(tFrac16 *)0} 9.58.2 Description Default value for GFLIB_LUT2D_T_F16. 9.59 Define GFLIB_Ramp #include <GFLIB_Ramp.h> 9.59.1 Macro Definition #define GFLIB_Ramp macro_dispatcher(GFLIB_Ramp, __VA_ARGS__)(__VA_ARGS__) 9.59.2 Description The function calculates the up/down ramp with the step increment/decrement defined in the pParam structure. 9.60 Define GFLIB_RAMP_DEFAULT_F32 #include <GFLIB_Ramp.h> 9.60.1 Macro Definition #define GFLIB_RAMP_DEFAULT_F32 {(tFrac32)0,(tFrac32)0,(tFrac32)0} Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 583 Define GFLIB_RAMP_DEFAULT_F16 9.60.2 Description Default value for GFLIB_RAMP_T_F32. 9.61 Define GFLIB_RAMP_DEFAULT_F16 #include <GFLIB_Ramp.h> 9.61.1 Macro Definition #define GFLIB_RAMP_DEFAULT_F16 {(tFrac16)0,(tFrac16)0,(tFrac16)0} 9.61.2 Description Default value for GFLIB_RAMP_T_F16. 9.62 Define GFLIB_Sign #include <GFLIB_Sign.h> 9.62.1 Macro Definition #define GFLIB_Sign macro_dispatcher(GFLIB_Sign, __VA_ARGS__)(__VA_ARGS__) 9.62.2 Description This function returns the signum of input value. 9.63 Define GFLIB_Sin #include <GFLIB_Sin.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 584 NXP Semiconductors Chapter 9 Macro References 9.63.1 Macro Definition #define GFLIB_Sin macro_dispatcher(GFLIB_Sin, __VA_ARGS__)(__VA_ARGS__) 9.63.2 Description This function implements polynomial approximation of sine function. 9.64 Define GFLIB_SIN_DEFAULT_F32 #include <GFLIB_Sin.h> 9.64.1 Macro Definition #define GFLIB_SIN_DEFAULT_F32 &f32gflibSinCoef 9.64.2 Description Default approximation coefficients for GFLIB_Sin_F32 function. 9.65 Define GFLIB_SIN_DEFAULT_F16 #include <GFLIB_Sin.h> 9.65.1 Macro Definition #define GFLIB_SIN_DEFAULT_F16 &f16gflibSinCoef 9.65.2 Description Default approximation coefficients for GFLIB_Sin_F16 function. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 585 Define GFLIB_SINCOS_DEFAULT_F32 9.66 Define GFLIB_SinCos #include <GFLIB_SinCos.h> 9.66.1 Macro Definition #define GFLIB_SinCos macro_dispatcher(GFLIB_SinCos, __VA_ARGS__)(__VA_ARGS__) 9.66.2 Description This function implements polynomial approximation of sine function. 9.67 Define GFLIB_SINCOS_DEFAULT_F32 #include <GFLIB_SinCos.h> 9.67.1 Macro Definition #define GFLIB_SINCOS_DEFAULT_F32 &f32gflibSinCosCoef 9.67.2 Description Default approximation coefficients for GFLIB_SinCos_F32 function. 9.68 Define GFLIB_SINCOS_DEFAULT_F16 #include <GFLIB_SinCos.h> 9.68.1 Macro Definition #define GFLIB_SINCOS_DEFAULT_F16 &f16gflibSinCosCoef Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 586 NXP Semiconductors Chapter 9 Macro References 9.68.2 Description Default approximation coefficients for GFLIB_SinCos_F16 function. 9.69 Define GFLIB_Sqrt #include <GFLIB_Sqrt.h> 9.69.1 Macro Definition #define GFLIB_Sqrt macro_dispatcher(GFLIB_Sqrt, __VA_ARGS__)(__VA_ARGS__) 9.69.2 Description This function returns the square root of input value. 9.70 Define GFLIB_Tan #include <GFLIB_Tan.h> 9.70.1 Macro Definition #define GFLIB_Tan macro_dispatcher(GFLIB_Tan, __VA_ARGS__)(__VA_ARGS__) 9.70.2 Description This function implements polynomial approximation of tangent function. 9.71 Define GFLIB_TAN_DEFAULT_F32 #include <GFLIB_Tan.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 587 Define GFLIB_TAN_DEFAULT_F16 9.71.1 Macro Definition #define GFLIB_TAN_DEFAULT_F32 &f32gflibTanCoef 9.71.2 Description Default approximation coefficients for GFLIB_Tan_F32 function. 9.72 Define GFLIB_TAN_DEFAULT_F16 #include <GFLIB_Tan.h> 9.72.1 Macro Definition #define GFLIB_TAN_DEFAULT_F16 &f16gflibTanCoef 9.72.2 Description Default approximation coefficients for GFLIB_Tan_F16 function. 9.73 Define GFLIB_UpperLimit #include <GFLIB_UpperLimit.h> 9.73.1 Macro Definition #define GFLIB_UpperLimit macro_dispatcher(GFLIB_UpperLimit, __VA_ARGS__)(__VA_ARGS__) 9.73.2 Description This function tests whether the input value is below the upper limit. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 588 NXP Semiconductors Chapter 9 Macro References 9.74 Define GFLIB_UPPERLIMIT_DEFAULT_F32 #include <GFLIB_UpperLimit.h> 9.74.1 Macro Definition #define GFLIB_UPPERLIMIT_DEFAULT_F32 {INT32_MAX } 9.74.2 Description Default value for GFLIB_UPPERLIMIT_T_F32. 9.75 Define GFLIB_UPPERLIMIT_DEFAULT_F16 #include <GFLIB_UpperLimit.h> 9.75.1 Macro Definition #define GFLIB_UPPERLIMIT_DEFAULT_F16 {INT16_MAX } 9.75.2 Description Default value for GFLIB_UPPERLIMIT_T_F16. 9.76 Define GFLIB_VectorLimit #include <GFLIB_VectorLimit.h> 9.76.1 Macro Definition #define GFLIB_VectorLimit macro_dispatcher(GFLIB_VectorLimit, __VA_ARGS__)(__VA_ARGS__) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 589 Define GFLIB_VECTORLIMIT_DEFAULT_F32 9.76.2 Description This function limits the magnitude of the input vector. 9.77 Define GFLIB_VECTORLIMIT_DEFAULT_F32 #include <GFLIB_VectorLimit.h> 9.77.1 Macro Definition #define GFLIB_VECTORLIMIT_DEFAULT_F32 {(tFrac32)0} 9.77.2 Description Default value for GFLIB_VECTORLIMIT_T_F32. 9.78 Define GFLIB_VECTORLIMIT_DEFAULT_F16 #include <GFLIB_VectorLimit.h> 9.78.1 Macro Definition #define GFLIB_VECTORLIMIT_DEFAULT_F16 {(tFrac16)0} 9.78.2 Description Default value for GFLIBVECTORLIMIT_T_F16. 9.79 Define GMCLIB_Clark #include <GMCLIB_Clark.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 590 NXP Semiconductors Chapter 9 Macro References 9.79.1 Macro Definition #define GMCLIB_Clark macro_dispatcher(GMCLIB_Clark, __VA_ARGS__)(__VA_ARGS__) 9.79.2 Description This function implements the Clarke transformation. 9.80 Define GMCLIB_ClarkInv #include <GMCLIB_ClarkInv.h> 9.80.1 Macro Definition #define GMCLIB_ClarkInv macro_dispatcher(GMCLIB_ClarkInv, __VA_ARGS__)(__VA_ARGS__) 9.80.2 Description This function implements the inverse Clarke transformation. 9.81 Define GMCLIB_DecouplingPMSM #include <GMCLIB_DecouplingPMSM.h> 9.81.1 Macro Definition #define GMCLIB_DecouplingPMSM macro_dispatcher(GMCLIB_DecouplingPMSM, __VA_ARGS__) (__VA_ARGS__) 9.81.2 Description This function calculates the cross-coupling voltages to eliminate the dq axis coupling causing non-linearity of the field oriented control. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 591 Define GMCLIB_DECOUPLINGPMSM_DEFAULT_F32 9.82 Define GMCLIB_DECOUPLINGPMSM_DEFAULT_F32 #include <GMCLIB_DecouplingPMSM.h> 9.82.1 Macro Definition #define GMCLIB_DECOUPLINGPMSM_DEFAULT_F32 {(tFrac32)0,(tS16)0,(tFrac32)0,(tS16)0} 9.82.2 Description Default value for GMCLIB_DECOUPLINGPMSM_T_F32. 9.83 Define GMCLIB_DECOUPLINGPMSM_DEFAULT_F16 #include <GMCLIB_DecouplingPMSM.h> 9.83.1 Macro Definition #define GMCLIB_DECOUPLINGPMSM_DEFAULT_F16 {(tFrac16)0,(tS16)0,(tFrac16)0,(tS16)0} 9.83.2 Description Default value for GMCLIB_DECOUPLINGPMSM_T_F16. 9.84 Define GMCLIB_ELIMDCBUSRIP_FLT_DNMAX #include <GMCLIB_ElimDcBusRip.c> 9.84.1 Macro Definition #define GMCLIB_ELIMDCBUSRIP_FLT_DNMAX ((tFloat)1.1754942106924411e-38) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 592 NXP Semiconductors Chapter 9 Macro References 9.84.2 Description Largest denormalized floating-point value. 9.85 Define GMCLIB_ElimDcBusRip #include <GMCLIB_ElimDcBusRip.h> 9.85.1 Macro Definition #define GMCLIB_ElimDcBusRip macro_dispatcher(GMCLIB_ElimDcBusRip, __VA_ARGS__)(__VA_ARGS__) 9.85.2 Description This function implements the DC Bus voltage ripple elimination. 9.86 Define GMCLIB_ELIMDCBUSRIP_DEFAULT_F32 #include <GMCLIB_ElimDcBusRip.h> 9.86.1 Macro Definition #define GMCLIB_ELIMDCBUSRIP_DEFAULT_F32 {(tFrac32)0,(tFrac32)0} 9.86.2 Description Default value for GMCLIB_ELIMDCBUSRIP_T_F32. 9.87 Define GMCLIB_ELIMDCBUSRIP_DEFAULT_F16 #include <GMCLIB_ElimDcBusRip.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 593 Define GMCLIB_Park 9.87.1 Macro Definition #define GMCLIB_ELIMDCBUSRIP_DEFAULT_F16 {(tFrac16)0,(tFrac16)0} 9.87.2 Description Default value for GMCLIB_ELIMDCBUSRIP_T_F16. 9.88 Define GMCLIB_Park #include <GMCLIB_Park.h> 9.88.1 Macro Definition #define GMCLIB_Park macro_dispatcher(GMCLIB_Park, __VA_ARGS__)(__VA_ARGS__) 9.88.2 Description This function implements the calculates Park transformation. 9.89 Define GMCLIB_ParkInv #include <GMCLIB_ParkInv.h> 9.89.1 Macro Definition #define GMCLIB_ParkInv macro_dispatcher(GMCLIB_ParkInv, __VA_ARGS__)(__VA_ARGS__) 9.89.2 Description This function implements the inverse Park transformation. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 594 NXP Semiconductors Chapter 9 Macro References 9.90 Define GMCLIB_SvmStd #include <GMCLIB_SvmStd.h> 9.90.1 Macro Definition #define GMCLIB_SvmStd macro_dispatcher(GMCLIB_SvmStd, __VA_ARGS__)(__VA_ARGS__) 9.90.2 Description This function calculates the duty-cycle ratios using the Standard Space Vector Modulation technique. 9.91 Define MLIB_Abs #include <MLIB_Abs.h> 9.91.1 Macro Definition #define MLIB_Abs macro_dispatcher(MLIB_Abs, __VA_ARGS__)(__VA_ARGS__) 9.91.2 Description This function returns absolute value of input parameter. 9.92 Define MLIB_AbsSat #include <MLIB_AbsSat.h> 9.92.1 Macro Definition #define MLIB_AbsSat macro_dispatcher(MLIB_AbsSat, __VA_ARGS__)(__VA_ARGS__) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 595 Define MLIB_Add 9.92.2 Description This function returns absolute value of input parameter and saturate if necessary. 9.93 Define MLIB_Add #include <MLIB_Add.h> 9.93.1 Macro Definition #define MLIB_Add macro_dispatcher(MLIB_Add, __VA_ARGS__)(__VA_ARGS__) 9.93.2 Description This function returns sum of two input parameters. 9.94 Define MLIB_AddSat #include <MLIB_AddSat.h> 9.94.1 Macro Definition #define MLIB_AddSat macro_dispatcher(MLIB_AddSat, __VA_ARGS__)(__VA_ARGS__) 9.94.2 Description This function returns sum of two input parameters and saturate if necessary. 9.95 Define MLIB_Convert #include <MLIB_Convert.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 596 NXP Semiconductors Chapter 9 Macro References 9.95.1 Macro Definition #define MLIB_Convert macro_dispatcher(MLIB_Convert, __VA_ARGS__)(__VA_ARGS__) 9.95.2 Description This function converts the input value to different representation. 9.96 Define MLIB_ConvertPU #include <MLIB_ConvertPU.h> 9.96.1 Macro Definition #define MLIB_ConvertPU macro_dispatcher(MLIB_ConvertPU, __VA_ARGS__)(__VA_ARGS__) 9.96.2 Description This function converts the input value to different representation with scale. 9.97 Define MLIB_Div #include <MLIB_Div.h> 9.97.1 Macro Definition #define MLIB_Div macro_dispatcher(MLIB_Div,__VA_ARGS__)(__VA_ARGS__) 9.97.2 Description This function divides the first parameter by the second one. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 597 Define MLIB_Mac 9.98 Define MLIB_DivSat #include <MLIB_DivSat.h> 9.98.1 Macro Definition #define MLIB_DivSat macro_dispatcher(MLIB_DivSat, __VA_ARGS__)(__VA_ARGS__) 9.98.2 Description This function divides the first parameter by the second one as saturate. 9.99 Define MLIB_Mac #include <MLIB_Mac.h> 9.99.1 Macro Definition #define MLIB_Mac macro_dispatcher(MLIB_Mac, __VA_ARGS__)(__VA_ARGS__) 9.99.2 Description This function implements the multiply accumulate function. 9.100 Define MLIB_MacSat #include <MLIB_MacSat.h> 9.100.1 Macro Definition #define MLIB_MacSat macro_dispatcher(MLIB_MacSat, __VA_ARGS__)(__VA_ARGS__) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 598 NXP Semiconductors Chapter 9 Macro References 9.100.2 Description This function implements the multiply accumulate function saturated if necessary. 9.101 Define MLIB_Mnac #include <MLIB_Mnac.h> 9.101.1 Macro Definition #define MLIB_Mnac macro_dispatcher(MLIB_Mnac, __VA_ARGS__)(__VA_ARGS__) 9.101.2 Description This function implements the multiply-subtract function. 9.102 Define MLIB_Msu #include <MLIB_Msu.h> 9.102.1 Macro Definition #define MLIB_Msu macro_dispatcher(MLIB_Msu, __VA_ARGS__)(__VA_ARGS__) 9.102.2 Description This function implements the multiply accumulate function. 9.103 Define MLIB_Mul #include <MLIB_Mul.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 599 Define MLIB_MulSat 9.103.1 Macro Definition #define MLIB_Mul macro_dispatcher(MLIB_Mul, __VA_ARGS__)(__VA_ARGS__) 9.103.2 Description This function multiply two input parameters. 9.104 Define MLIB_MulSat #include <MLIB_MulSat.h> 9.104.1 Macro Definition #define MLIB_MulSat macro_dispatcher(MLIB_MulSat, __VA_ARGS__)(__VA_ARGS__) 9.104.2 Description This function multiply two input parameters and saturate if necessary. 9.105 Define MLIB_Neg #include <MLIB_Neg.h> 9.105.1 Macro Definition #define MLIB_Neg macro_dispatcher(MLIB_Neg, __VA_ARGS__)(__VA_ARGS__) 9.105.2 Description This function returns negative value of input parameter. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 600 NXP Semiconductors Chapter 9 Macro References 9.106 Define MLIB_NegSat #include <MLIB_NegSat.h> 9.106.1 Macro Definition #define MLIB_NegSat macro_dispatcher(MLIB_NegSat, __VA_ARGS__)(__VA_ARGS__) 9.106.2 Description This function returns negative value of input parameter and saturate if necessary. 9.107 Define MLIB_Norm #include <MLIB_Norm.h> 9.107.1 Macro Definition #define MLIB_Norm macro_dispatcher(MLIB_Norm, __VA_ARGS__)(__VA_ARGS__) 9.107.2 Description This function returns the number of left shifts needed to normalize the input parameter. 9.108 Define MLIB_Round #include <MLIB_Round.h> 9.108.1 Macro Definition #define MLIB_Round macro_dispatcher(MLIB_Round, __VA_ARGS__)(__VA_ARGS__) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 601 Define MLIB_ShBi 9.108.2 Description This function rounds the first input value for number of digits defined by second parameter and saturate automatically. 9.109 Define MLIB_ShBi #include <MLIB_ShBi.h> 9.109.1 Macro Definition #define MLIB_ShBi macro_dispatcher(MLIB_ShBi, __VA_ARGS__)(__VA_ARGS__) 9.109.2 Description Based on sign of second parameter this function shifts the first parameter to right or left. If the sign of second parameter is negative, shift to right. 9.110 Define MLIB_ShBiSat #include <MLIB_ShBiSat.h> 9.110.1 Macro Definition #define MLIB_ShBiSat macro_dispatcher(MLIB_ShBiSat, __VA_ARGS__)(__VA_ARGS__) 9.110.2 Description Based on sign of second parameter this function shifts the first parameter to right or left and saturate if necessary. If the sign of second parameter is negative, shift to right. 9.111 Define MLIB_ShL #include <MLIB_ShL.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 602 NXP Semiconductors Chapter 9 Macro References 9.111.1 Macro Definition #define MLIB_ShL macro_dispatcher(MLIB_ShL, __VA_ARGS__)(__VA_ARGS__) 9.111.2 Description This function shifts the first parameter to left by number defined by second parameter. 9.112 Define MLIB_ShLSat #include <MLIB_ShLSat.h> 9.112.1 Macro Definition #define MLIB_ShLSat macro_dispatcher(MLIB_ShLSat, __VA_ARGS__)(__VA_ARGS__) 9.112.2 Description This function shifts the first parameter to left by number defined by second parameter and saturate if necessary. 9.113 Define MLIB_ShR #include <MLIB_ShR.h> 9.113.1 Macro Definition #define MLIB_ShR macro_dispatcher(MLIB_ShR, __VA_ARGS__)(__VA_ARGS__) 9.113.2 Description This function shifts the first parameter to right by number defined by second parameter. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 603 Define MLIB_Sub 9.114 Define MLIB_Sub #include <MLIB_Sub.h> 9.114.1 Macro Definition #define MLIB_Sub macro_dispatcher(MLIB_Sub, __VA_ARGS__)(__VA_ARGS__) 9.114.2 Description This function subtracts the second parameter from the first one. 9.115 Define MLIB_SubSat #include <MLIB_SubSat.h> 9.115.1 Macro Definition #define MLIB_SubSat macro_dispatcher(MLIB_SubSat, __VA_ARGS__)(__VA_ARGS__) 9.115.2 Description This function subtracts the second parameter from the first one and saturate if necessary. 9.116 Define MLIB_VMac #include <MLIB_VMac.h> 9.116.1 Macro Definition #define MLIB_VMac macro_dispatcher(MLIB_VMac, __VA_ARGS__)(__VA_ARGS__) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 604 NXP Semiconductors Chapter 9 Macro References 9.116.2 Description This function implements the vector multiply accumulate function. 9.117 Define SWLIBS_VERSION #include <SWLIBS_Config.h> 9.117.1 Macro Definition #define SWLIBS_VERSION {(unsigned char)1U,(unsigned char)1U,(unsigned char)5U} 9.117.2 Description 9.118 Define SWLIBS_STD_ON #include <SWLIBS_Config.h> 9.118.1 Macro Definition #define SWLIBS_STD_ON 0x01U 9.118.2 Description 9.119 Define SWLIBS_STD_OFF #include <SWLIBS_Config.h> 9.119.1 Macro Definition #define SWLIBS_STD_OFF 0x00U Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 605 Define F32 9.119.2 Description 9.120 Define F32 #include <SWLIBS_Config.h> 9.120.1 Macro Definition #define F32 F32 9.120.2 Description 9.121 Define F16 #include <SWLIBS_Config.h> 9.121.1 Macro Definition #define F16 F16 9.121.2 Description 9.122 Define FLT #include <SWLIBS_Config.h> 9.122.1 Macro Definition #define FLT FLT Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 606 NXP Semiconductors Chapter 9 Macro References 9.122.2 Description 9.123 Define SWLIBS_DEFAULT_IMPLEMENTATION_F32 #include <SWLIBS_Config.h> 9.123.1 Macro Definition #define SWLIBS_DEFAULT_IMPLEMENTATION_F32 (1U) 9.123.2 Description 9.124 Define SWLIBS_DEFAULT_IMPLEMENTATION_F16 #include <SWLIBS_Config.h> 9.124.1 Macro Definition #define SWLIBS_DEFAULT_IMPLEMENTATION_F16 (2U) 9.124.2 Description 9.125 Define SWLIBS_DEFAULT_IMPLEMENTATION_FLT #include <SWLIBS_Config.h> 9.125.1 Macro Definition #define SWLIBS_DEFAULT_IMPLEMENTATION_FLT (3U) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 607 Define SWLIBS_SUPPORT_F32 9.125.2 Description 9.126 Define SWLIBS_SUPPORT_F32 #include <SWLIBS_Config.h> 9.126.1 Macro Definition #define SWLIBS_SUPPORT_F32 SWLIBS_STD_ON 9.126.2 Description Enables/disables support of 32-bit fractional implementation. 9.127 Define SWLIBS_SUPPORT_F16 #include <SWLIBS_Config.h> 9.127.1 Macro Definition #define SWLIBS_SUPPORT_F16 SWLIBS_STD_ON 9.127.2 Description Enables/disables support of 16-bit fractional implementation. 9.128 Define SWLIBS_SUPPORT_FLT #include <SWLIBS_Config.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 608 NXP Semiconductors Chapter 9 Macro References 9.128.1 Macro Definition #define SWLIBS_SUPPORT_FLT SWLIBS_STD_OFF 9.128.2 Description Enables/disables support of single precision floating point implementation. 9.129 Define SWLIBS_SUPPORTED_IMPLEMENTATION #include <SWLIBS_Config.h> 9.129.1 Macro Definition #define SWLIBS_SUPPORTED_IMPLEMENTATION {SWLIBS_SUPPORT_F32,\ SWLIBS_SUPPORT_F16,\ SWLIBS_SUPPORT_FLT,\ 0,0,0,0,0,0} 9.129.2 Description Array of supported implementations. 9.130 Define SWLIBS_DEFAULT_IMPLEMENTATION #include <SWLIBS_Config.h> 9.130.1 Macro Definition #define SWLIBS_DEFAULT_IMPLEMENTATION 9.130.2 Description Selection of default implementation. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 609 Define SFRACT_MIN 9.131 Define SFRACT_MIN #include <SWLIBS_Defines.h> 9.131.1 Macro Definition #define SFRACT_MIN (-1.0) 9.131.2 Description Definition of inline directive for all supported compilers. Constant representing the maximal negative value of a signed 16-bit fixed point fractional number, floating point representation. 9.132 Define SFRACT_MAX #include <SWLIBS_Defines.h> 9.132.1 Macro Definition #define SFRACT_MAX (0.999969482421875) 9.132.2 Description Constant representing the maximal positive value of a signed 16-bit fixed point fractional number, floating point representation. 9.133 Define FRACT_MIN #include <SWLIBS_Defines.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 610 NXP Semiconductors Chapter 9 Macro References 9.133.1 Macro Definition #define FRACT_MIN (-1.0) 9.133.2 Description Constant representing the maximal negative value of signed 32-bit fixed point fractional number, floating point representation. 9.134 Define FRACT_MAX #include <SWLIBS_Defines.h> 9.134.1 Macro Definition #define FRACT_MAX (0.9999999995343387126922607421875) 9.134.2 Description Constant representing the maximal positive value of a signed 32-bit fixed point fractional number, floating point representation. 9.135 Define FRAC32_0_5 #include <SWLIBS_Defines.h> 9.135.1 Macro Definition #define FRAC32_0_5 ((tFrac32) 0x40000000) 9.135.2 Description Value 0.5 in 32-bit fixed point fractional format. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 611 Define FRAC16_0_5 9.136 Define FRAC16_0_5 #include <SWLIBS_Defines.h> 9.136.1 Macro Definition #define FRAC16_0_5 ((tFrac16) 0x4000) 9.136.2 Description Value 0.5 in 16-bit fixed point fractional format. 9.137 Define FRAC32_0_25 #include <SWLIBS_Defines.h> 9.137.1 Macro Definition #define FRAC32_0_25 ((tFrac32) 0x20000000) 9.137.2 Description Value 0.25 in 32-bit fixed point fractional format. 9.138 Define FRAC16_0_25 #include <SWLIBS_Defines.h> 9.138.1 Macro Definition #define FRAC16_0_25 ((tFrac16) 0x2000) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 612 NXP Semiconductors Chapter 9 Macro References 9.138.2 Description Value 0.25 in 16-bit fixed point fractional format. 9.139 Define UINT16_MAX #include <SWLIBS_Defines.h> 9.139.1 Macro Definition #define UINT16_MAX ((tU16) 0x8000) 9.139.2 Description Constant representing the maximal positive value of a unsigned 16-bit fixed point integer number, equal to 2 15 = 0x8000. 9.140 Define INT16_MAX #include <SWLIBS_Defines.h> 9.140.1 Macro Definition #define INT16_MAX ((tS16) 0x7fff) 9.140.2 Description Constant representing the maximal positive value of a signed 16-bit fixed point integer number, equal to 2 15-1 = 0x7fff. 9.141 Define INT16_MIN #include <SWLIBS_Defines.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 613 Define UINT32_MAX 9.141.1 Macro Definition #define INT16_MIN ((tS16) 0x8000) 9.141.2 Description Constant representing the maximal negative value of a signed 16-bit fixed point integer number, equal to -2 15 = 0x8000. 9.142 Define UINT32_MAX #include <SWLIBS_Defines.h> 9.142.1 Macro Definition #define UINT32_MAX ((tU32) 0x80000000U) 9.142.2 Description Constant representing the maximal positive value of a unsigned 32-bit fixed point integer number, equal to 2 31 = 0x80000000. 9.143 Define INT32_MAX #include <SWLIBS_Defines.h> 9.143.1 Macro Definition #define INT32_MAX ((tS32) 0x7fffffff) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 614 NXP Semiconductors Chapter 9 Macro References 9.143.2 Description Constant representing the maximal positive value of a signed 32-bit fixed point integer number, equal to 2 31-1 = 0x7fff ffff. 9.144 Define INT32_MIN #include <SWLIBS_Defines.h> 9.144.1 Macro Definition #define INT32_MIN ((tS32) 0x80000000U) 9.144.2 Description Constant representing the maximal negative value of a signed 32-bit fixed point integer number, equal to -2 31 = 0x8000 0000. 9.145 Define INT16TOINT32 #include <SWLIBS_Defines.h> 9.145.1 Macro Definition #define INT16TOINT32 ((tS32) (x)) 9.145.2 Description Type casting - signed 16-bit integer value cast to a signed 32-bit integer. 9.146 Define INT32TOINT16 #include <SWLIBS_Defines.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 615 Define INT32TOINT64 9.146.1 Macro Definition #define INT32TOINT16 ((tS16) (x)) 9.146.2 Description Type casting - signed 32-bit integer value cast to a signed 16-bit integer. 9.147 Define INT32TOINT64 #include <SWLIBS_Defines.h> 9.147.1 Macro Definition #define INT32TOINT64 ((tS64) (x)) 9.147.2 Description Type casting - signed 32-bit integer value cast to a signed 64-bit integer. 9.148 Define INT64TOINT32 #include <SWLIBS_Defines.h> 9.148.1 Macro Definition #define INT64TOINT32 ((tS32) (x)) 9.148.2 Description Type casting - signed 64-bit integer value cast to a signed 32-bit integer. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 616 NXP Semiconductors Chapter 9 Macro References 9.149 Define F16TOINT16 #include <SWLIBS_Defines.h> 9.149.1 Macro Definition #define F16TOINT16 ((tS16) (x)) 9.149.2 Description Type casting - signed 16-bit fractional value cast to a signed 16-bit integer. 9.150 Define F32TOINT16 #include <SWLIBS_Defines.h> 9.150.1 Macro Definition #define F32TOINT16 ((tS16) (x)) 9.150.2 Description Type casting - lower 16 bits of a signed 32-bit fractional value cast to a signed 16-bit integer. 9.151 Define F64TOINT16 #include <SWLIBS_Defines.h> 9.151.1 Macro Definition #define F64TOINT16 ((tS16) (x)) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 617 Define F16TOINT32 9.151.2 Description Type casting - lower 16 bits of a signed 64-bit fractional value cast to a signed 16-bit integer. 9.152 Define F16TOINT32 #include <SWLIBS_Defines.h> 9.152.1 Macro Definition #define F16TOINT32 ((tS32) (x)) 9.152.2 Description Type casting - a signed 16-bit fractional value cast to a signed 32-bit integer, the value placed at the lower 16-bits of the 32-bit result. 9.153 Define F32TOINT32 #include <SWLIBS_Defines.h> 9.153.1 Macro Definition #define F32TOINT32 ((tS32) (x)) 9.153.2 Description Type casting - signed 32-bit fractional value cast to a signed 32-bit integer. 9.154 Define F64TOINT32 #include <SWLIBS_Defines.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 618 NXP Semiconductors Chapter 9 Macro References 9.154.1 Macro Definition #define F64TOINT32 ((tS32) (x)) 9.154.2 Description Type casting - lower 32 bits of a signed 64-bit fractional value cast to a signed 32-bit integer. 9.155 Define F16TOINT64 #include <SWLIBS_Defines.h> 9.155.1 Macro Definition #define F16TOINT64 ((tS64) (x)) 9.155.2 Description Type casting - signed 16-bit fractional value cast to a signed 64-bit integer, the value placed at the lower 16-bits of the 64-bit result. 9.156 Define F32TOINT64 #include <SWLIBS_Defines.h> 9.156.1 Macro Definition #define F32TOINT64 ((tS64) (x)) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 619 Define F64TOINT64 9.156.2 Description Type casting - signed 32-bit fractional value cast to a signed 64-bit integer, the value placed at the lower 32-bits of the 64-bit result. 9.157 Define F64TOINT64 #include <SWLIBS_Defines.h> 9.157.1 Macro Definition #define F64TOINT64 ((tS64) (x)) 9.157.2 Description Type casting - signed 64-bit fractional value cast to a signed 64-bit integer. 9.158 Define INT16TOF16 #include <SWLIBS_Defines.h> 9.158.1 Macro Definition #define INT16TOF16 ((tFrac16) (x)) 9.158.2 Description Type casting - signed 16-bit integer value cast to a signed 16-bit fractional. 9.159 Define INT16TOF32 #include <SWLIBS_Defines.h> Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 620 NXP Semiconductors Chapter 9 Macro References 9.159.1 Macro Definition #define INT16TOF32 ((tFrac32) (x)) 9.159.2 Description Type casting - signed 16-bit integer value cast to a signed 32-bit fractional, the value placed at the lower 16 bits of the 32-bit result. 9.160 Define INT32TOF16 #include <SWLIBS_Defines.h> 9.160.1 Macro Definition #define INT32TOF16 ((tFrac16) (x)) 9.160.2 Description Type casting - lower 16-bits of a signed 32-bit integer value cast to a signed 16-bit fractional. 9.161 Define INT32TOF32 #include <SWLIBS_Defines.h> 9.161.1 Macro Definition #define INT32TOF32 ((tFrac32) (x)) 9.161.2 Description Type casting - signed 32-bit integer value cast to a signed 32-bit fractional. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 621 Define INT64TOF16 9.162 Define INT64TOF16 #include <SWLIBS_Defines.h> 9.162.1 Macro Definition #define INT64TOF16 ((tFrac16) (x)) 9.162.2 Description Type casting - lower 16-bits of a signed 64-bit integer value cast to a signed 16-bit fractional. 9.163 Define INT64TOF32 #include <SWLIBS_Defines.h> 9.163.1 Macro Definition #define INT64TOF32 ((tFrac32) (x)) 9.163.2 Description Type casting - lower 32-bits of a signed 64-bit integer value cast to a signed 32-bit fractional. 9.164 Define F16_1_DIVBY_SQRT3 #include <SWLIBS_Defines.h> 9.164.1 Macro Definition #define F16_1_DIVBY_SQRT3 ((tFrac16) 0x49E7) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 622 NXP Semiconductors Chapter 9 Macro References 9.164.2 Description One over sqrt(3) with a 16-bit result, the result rounded for a better precision, i.e. round(1/ √(3)*2 15). 9.165 Define F32_1_DIVBY_SQRT3 #include <SWLIBS_Defines.h> 9.165.1 Macro Definition #define F32_1_DIVBY_SQRT3 ((tFrac32) 0x49E69D16) 9.165.2 Description One over sqrt(3) with a 32-bit result, the result rounded for a better precision, i.e. round(1/ √(3)*2 31). 9.166 Define F16_SQRT3_DIVBY_2 #include <SWLIBS_Defines.h> 9.166.1 Macro Definition #define F16_SQRT3_DIVBY_2 ((tFrac16) 0x6EDA) 9.166.2 Description Sqrt(3) divided by two with a 16-bit result, the result rounded for a better precision, i.e. round( √(3)/2*2 15). Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 623 Define F16_SQRT2_DIVBY_2 9.167 Define F32_SQRT3_DIVBY_2 #include <SWLIBS_Defines.h> 9.167.1 Macro Definition #define F32_SQRT3_DIVBY_2 ((tFrac32) 0x6ED9EBA1) 9.167.2 Description Sqrt(3) divided by two with a 32-bit result, the result rounded for a better precision, i.e. round( √(3)/2*2 31). 9.168 Define F16_SQRT2_DIVBY_2 #include <SWLIBS_Defines.h> 9.168.1 Macro Definition #define F16_SQRT2_DIVBY_2 ((tFrac16) 0x5A82) 9.168.2 Description Sqrt(2) divided by two with a 16-bit result, the result rounded for a better precision, i.e. round( √(2)/2*2 15). 9.169 Define F32_SQRT2_DIVBY_2 #include <SWLIBS_Defines.h> 9.169.1 Macro Definition #define F32_SQRT2_DIVBY_2 ((tFrac32) 0x5A82799A) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 624 NXP Semiconductors Chapter 9 Macro References 9.169.2 Description Sqrt(2) divided by two with a 32-bit result, the result rounded for a better precision, i.e. round( √(2)/2*2 31). 9.170 Define FRAC16 #include <SWLIBS_Defines.h> 9.170.1 Macro Definition #define FRAC16 ((tFrac16) ((x < SFRACT_MAX) ? ((x >= SFRACT_MIN) ? (x*32768.0) : INT16_MIN) : INT16_MAX)) 9.170.2 Description Macro converting a signed fractional [-1,1) number into a 16-bit fixed point number in format Q1.15. 9.171 Define FRAC32 #include <SWLIBS_Defines.h> 9.171.1 Macro Definition #define FRAC32 ((tFrac32) ((x < FRACT_MAX) ? ((x >= FRACT_MIN) ? (x*2147483648.0) : INT32_MIN) : INT32_MAX)) 9.171.2 Description Macro converting a signed fractional [-1,1) number into a 32-bit fixed point number in format Q1.31. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 625 Define FALSE 9.172 Define NULL #include <SWLIBS_Typedefs.h> 9.172.1 Macro Definition #define NULL 0 9.172.2 Description 9.173 Define FALSE #include <SWLIBS_Typedefs.h> 9.173.1 Macro Definition #define FALSE ((tBool)0) 9.173.2 Description Boolean type FALSE constant 9.174 Define TRUE #include <SWLIBS_Typedefs.h> 9.174.1 Macro Definition #define TRUE ((tBool)1) 9.174.2 Description Boolean type TRUE constant Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 626 NXP Semiconductors Chapter 9 Macro References 9.175 Define SWLIBS_2Syst #include <SWLIBS_Typedefs.h> 9.175.1 Macro Definition #define SWLIBS_2Syst SWLIBS_2Syst_FLT 9.175.2 Description Definition of SWLIBS_2Syst as alias for SWLIBS_2Syst_F32 array in case the 32-bit fractional implementation is selected. Definition of SWLIBS_2Syst as alias for SWLIBS_2Syst_F16 array in case the 16-bit fractional implementation is selected. Definition of SWLIBS_2Syst as alias for SWLIBS_2Syst_FLT array in case the single precision floating point implementation is selected. 9.176 Define SWLIBS_2Syst #include <SWLIBS_Typedefs.h> 9.176.1 Macro Definition #define SWLIBS_2Syst SWLIBS_2Syst_FLT 9.176.2 Description Definition of SWLIBS_2Syst as alias for SWLIBS_2Syst_F32 array in case the 32-bit fractional implementation is selected. Definition of SWLIBS_2Syst as alias for SWLIBS_2Syst_F16 array in case the 16-bit fractional implementation is selected. Definition of SWLIBS_2Syst as alias for SWLIBS_2Syst_FLT array in case the single precision floating point implementation is selected. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 627 Define SWLIBS_2Syst 9.177 Define SWLIBS_2Syst #include <SWLIBS_Typedefs.h> 9.177.1 Macro Definition #define SWLIBS_2Syst SWLIBS_2Syst_FLT 9.177.2 Description Definition of SWLIBS_2Syst as alias for SWLIBS_2Syst_F32 array in case the 32-bit fractional implementation is selected. Definition of SWLIBS_2Syst as alias for SWLIBS_2Syst_F16 array in case the 16-bit fractional implementation is selected. Definition of SWLIBS_2Syst as alias for SWLIBS_2Syst_FLT array in case the single precision floating point implementation is selected. 9.178 Define SWLIBS_3Syst #include <SWLIBS_Typedefs.h> 9.178.1 Macro Definition #define SWLIBS_3Syst SWLIBS_3Syst_FLT 9.178.2 Description Definition of SWLIBS_3Syst as alias for SWLIBS_3Syst_F32 array in case the 32-bit fractional implementation is selected. Definition of SWLIBS_3Syst as alias for SWLIBS_3Syst_F16 array in case the 16-bit fractional implementation is selected. Definition of SWLIBS_3Syst as alias for SWLIBS_3Syst_FLT array in case the single precision floating point implementation is selected. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 628 NXP Semiconductors Chapter 9 Macro References 9.179 Define SWLIBS_3Syst #include <SWLIBS_Typedefs.h> 9.179.1 Macro Definition #define SWLIBS_3Syst SWLIBS_3Syst_FLT 9.179.2 Description Definition of SWLIBS_3Syst as alias for SWLIBS_3Syst_F32 array in case the 32-bit fractional implementation is selected. Definition of SWLIBS_3Syst as alias for SWLIBS_3Syst_F16 array in case the 16-bit fractional implementation is selected. Definition of SWLIBS_3Syst as alias for SWLIBS_3Syst_FLT array in case the single precision floating point implementation is selected. 9.180 Define SWLIBS_3Syst #include <SWLIBS_Typedefs.h> 9.180.1 Macro Definition #define SWLIBS_3Syst SWLIBS_3Syst_FLT 9.180.2 Description Definition of SWLIBS_3Syst as alias for SWLIBS_3Syst_F32 array in case the 32-bit fractional implementation is selected. Definition of SWLIBS_3Syst as alias for SWLIBS_3Syst_F16 array in case the 16-bit fractional implementation is selected. Definition of SWLIBS_3Syst as alias for SWLIBS_3Syst_FLT array in case the single precision floating point implementation is selected. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 629 Define SWLIBS_VERSION_DEFAULT 9.181 Define SWLIBS_VERSION_DEFAULT #include <SWLIBS_Version.c> 9.181.1 Macro Definition #define SWLIBS_VERSION_DEFAULT {SWLIBS_ID, SWLIBS_VERSION, SWLIBS_SUPPORTED_IMPLEMENTATION } 9.181.2 Description 9.182 Define SWLIBS_MCID_SIZE #include <SWLIBS_Version.h> 9.182.1 Macro Definition #define SWLIBS_MCID_SIZE ((unsigned char)4U) 9.182.2 Description 9.183 Define SWLIBS_MCVERSION_SIZE #include <SWLIBS_Version.h> 9.183.1 Macro Definition #define SWLIBS_MCVERSION_SIZE ((unsigned char)3U) Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 630 NXP Semiconductors Chapter 9 Macro References 9.183.2 Description 9.184 Define SWLIBS_MCIMPLEMENTATION_SIZE #include <SWLIBS_Version.h> 9.184.1 Macro Definition #define SWLIBS_MCIMPLEMENTATION_SIZE ((unsigned char)9U) 9.184.2 Description 9.185 Define SWLIBS_ID #include <SWLIBS_Version.h> 9.185.1 Macro Definition #define SWLIBS_ID {(unsigned char)0x90U,(unsigned char)0x71U,(unsigned char)0x77U,(unsigned char)0x68U} 9.185.2 Description Library identification string. Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 NXP Semiconductors 631 Define SWLIBS_ID Automotive Math and Motor Control Library Set for KEAx devices, Rev. 7 632 NXP Semiconductors How to Reach Us: Home Page: nxp.com Web Support: nxp.com/support Information in this document is provided solely to enable system and software implementers to use NXP products. There are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits based on the information in this document. NXP reserves the right to make changes without further notice to any products herein. NXP makes no warranty, representation, or guarantee regarding the suitability of its products for any particular purpose, nor does NXP assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation consequential or incidental damages. “Typical” parameters that may be provided in NXP data sheets and/or specifications can and do vary in different applications, and actual performance may vary over time. All operating parameters, including “typicals,” must be validated for each customer application by customerʼs technical experts. NXP does not 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, NXP SECURE CONNECTIONS FOR A SMARTER WORLD, COOLFLUX, EMBRACE, GREENCHIP, HITAG, I2C BUS, ICODE, JCOP, LIFE VIBES, MIFARE, MIFARE CLASSIC, MIFARE DESFire, MIFARE PLUS, MIFARE FLEX, MANTIS, MIFARE ULTRALIGHT, MIFARE4MOBILE, MIGLO, NTAG, ROADLINK, SMARTLX, SMARTMX, STARPLUG, TOPFET, TRENCHMOS, UCODE, Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, ColdFire+, C-Ware, the Energy Efficient Solutions logo, Kinetis, Layerscape, MagniV, mobileGT, PEG, PowerQUICC, Processor Expert, QorIQ, QorIQ Qonverge, Ready Play, SafeAssure, the SafeAssure logo, StarCore, Symphony, VortiQa, Vybrid, Airfast, BeeKit, BeeStack, CoreNet, Flexis, MXC, Platform in a Package, QUICC Engine, SMARTMOS, Tower, TurboLink, and UMEMS are trademarks of NXP B.V. All other product or service names are the property of their respective owners. ARM, AMBA, ARM Powered, Artisan, Cortex, Jazelle, Keil, SecurCore, Thumb, TrustZone, and μVision are registered trademarks of ARM Limited (or its subsidiaries) in the EU and/or elsewhere. ARM7, ARM9, ARM11, big.LITTLE, CoreLink, CoreSight, DesignStart, Mali, mbed, NEON, POP, Sensinode, Socrates, ULINK and Versatile are trademarks of ARM Limited (or its subsidiaries) in the EU and/or elsewhere. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. The Power Architecture and Power.org word marks and the Power and Power.org logos and related marks are trademarks and service marks licensed by Power.org. © 2016 NXP B.V. Document Number KEAXMCLUG Revision 7