1 / 29

Power PMAC Mathematical Features November 2013

Power PMAC Mathematical Features November 2013. Power PMAC Floating-Point Math. Power PMAC processor has hardware floating-point engine 5–10x (+) faster than Turbo PMAC software-library implementation Single-precision (IEEE 32-bit) supported

abedi
Download Presentation

Power PMAC Mathematical Features November 2013

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Power PMAC Mathematical FeaturesNovember 2013

  2. Power PMAC Floating-Point Math • Power PMAC processor has hardware floating-point engine • 5–10x (+) faster than Turbo PMAC software-library implementation • Single-precision (IEEE 32-bit) supported • Double-precision (IEEE 64-bit) supported, default for user programs • Double-precision provides much greater resolution and range than PMAC/Turbo PMAC 48-bit format • 18 more bits in the mantissa – 256K x increase in resolution/range • Range of ±1.80 x 10±308 • Suitable for key automatic motor calculations • Suitable for axis calculations (trajectories, kinematics, lookahead) • Suitable for user-program calculations

  3. Power PMAC Numerical Representations • Receiving numerical values in text strings (e.g. P1=3) • Standard decimal format • No arbitrary limit on number of decimal places permitted • Scientific notation • Format {mantissa}E{exponent} (e.g. -1.76E10) • Mantissa does not need to be normalized (e.g. -17.6E9 is OK) • Hexadecimal (with $ prefix) • Non-negative integers only • Reporting numerical values in text strings • Reporting format independent of receiving (e.g. hex vs. decimal) • Automatic decision on number of decimal places reported (formatting to fixed number of decimal places must be done in host computer) • When not an exact floating-point representation of fraction, full length is reported (~16 digits)

  4. Floating-Point Math in Automatic Routines • Motor phase and servo routines use floating-point math • Were fixed-point math in PMAC/Turbo PMAC • Speed and precision of floating-point math now suitable for these calculations • Many problems with fixed-point math eliminated • Register units are standardized (e.g. counts, milliseconds) • No position rollover worries • No velocity saturation worries • Minimal quantization noise introduced in “aggressive” filtering • No conversion overhead from axis calculations • Axis calculations use 64-bit floating-point math • Effective range before resolution-loss problems increased 256K times compared to Turbo PMAC

  5. Floating-Point Math in User Script Programs • Machine control applications require the use of many different numerical formats • Inputs and outputs are fixed-point (Boolean, 16-bit, 32-bit, etc.) • Most motion calculations are floating-point • Power PMAC Script environment does automatic type matching of different numerical formats • Fixed-point and floating-point representations • 1-bit to 64-bit formats • All “inputs” to calculations converted to 64-bit floating-point format • All mathematical operations done in this format • If calculation has a “result”, it is converted (if necessary) to required format • User does not need to concern himself with format conversions • (Note that user C-language programs must follow C rules for type matching and format conversions)

  6. Special Floating-Point Representations • Special representations that are part of IEEE-754 standard • Power PMAC reports these “values” with the text shown here • inf, -inf (+/-infinity) • Obtained (for example) by division by 0 • Operations that generate +/-inf do not create errors • inf > any finite number, -inf < any finite number, in a comparison • nan (not-a-number) • Obtained (for example) by function domain error (e.g. sqrt(-1) ) • Obtained when requesting value of element in non-existent hardware • Operations that generate nan do not create errors • Boolean isnan function can be used to check • -0 (minus zero) • Obtained by underflow of negative values • Equivalent to 0 (“plus zero”) in any subsequent operations • +/-inf, nan generally useful as diagnostics; in application, best to check before operation that could produce

  7. User Global Variables • “Global” variables can be shared between programs • P-variables (65,536 total) • Double-precision (64-bit) floating-point variables • Accessible from all coordinate systems • Declared as “global” (outside of a program) for IDE substitutions • Accessible from C programs with pshm->P[i] • Q-variables (8192 per coordinate system, not overlapping) • Double-precision (64-bit) floating-point variables • Separate coordinate systems access different variables for same name • Declared as “csglobal” (outside of a program) for IDE substitutions • Accessible from C programs with pshm->Coord[x].Q[i] • M-variables (16,384 total) • Pointer variables; take on format of what is pointed to • Accessible from all coordinate systems • Declared as “ptr” (outside of a program) for IDE substitutions • Not directly accessible from C programs (use API functions)

  8. Using M-Variables in Power PMAC • Most registers can be accessed without M-variables, by element name • M-variables with declared names can be convenient • Software (memory) registers rarely accessed with M-variables • Most users satisfied with standard data structure names • Some users want to shorten names • e.g. ptr Mtr1FE->Motor[1].PosError • Some users want to customize names • e.g. ptr LoadAxisEndPos->Coord[1].TPExec.Pos[6] • Hardware (I/O) registers commonly accessed with M-variables • Declared M-variable name will be meaningful for application • e.g. ptr LaserOn->Acc68E[1].DataReg[4].6 • Some I/O registers have no element name, defined by address • e.g. ptr LightCurtainBroken->u.io:$D00004.10.1

  9. Defining M-Variables • Defined to data structure element (takes on format of element) M{constant}->{data structure element} • General definition in I/O space M{constant}->{format}.io:{adr_offset}[.{start}[.{width}]] • General definition in user shared memory space M{constant}->{format}.user:{adr_offset}[.{start}[.{width}]] • Self-defined (useful to create particular numerical format) M{constant}->*{format}[.{width}] • M-variable formats • s – signed integer that saturates • i – signed integer that rolls over • u – unsigned integer that rolls over • f – short (32-bit) floating-point (does not take {start} or {width} ) • d – long (64-bit) floating-point (does not take {start} or {width} ) • {start} = 0 to 31 (default is 0, not limited to 1 & multiples of 4) • {width} = 1 to 32 (default is 32, not limited to 1 & multiples of 4)

  10. Power PMAC I-Variables • “Legacy” feature intended for convenience of experienced Turbo PMAC users • Point to Power PMAC data-structure savable setup elements that are essentially equivalent to present Turbo PMAC I-vars: • For Motors 0 – 31: I0 – I3199 • For Coordinate Systems 0 – 15: I5000 – I6599 • (Note that I0 – I99 taken for Motor 0, I5000 – I5099 for C.S. 0) • For “Gate1” ICs 0 – 19: I7000 – I7999 • For “Gate2” ICs 0 – 3: I6800 – I6999 • Usable in programs and on-line commands • Setup elements for new features, motors, C.S.’s generally not given I-variable numbers • Can find out what element is used by an I-variable with on-line command I{constant}-> e.g.: I428-> I428->Motor[4].InPosBand

  11. Power PMAC User Local Variables • “Local” variables are used within a program • L-variables (8192 per C.S., PLC, & on-line command processor) • Double-precision (64-bit) floating-point variables • Not (directly) accessible outside of program where used • Declared as “local” (inside of a program) for IDE substitutions • R-variables are renamed L-variables for passing/returning values to/from general subroutines • Rnof calling routine equivalent to Ln of called routine • Permit true “stack” argument passing to subroutines • C-variables are renamed C.S. L-variables for passing/returning axis values to/from kinematic subroutines • Cn is equivalent to L(MAX_MOTORS+n) for C.S. • C.S. and PLC data structures provide full read access to local variables • Coord[m].Ldata.L[n] or PLC[m].Ldata.L[n] accesses Ln relative to L0 of present program • Coord[m].Ldata.Lindex or PLC[m].Ldata.Lindex accesses number of L0 of present program relative to root L0 • Coord[m].Ldata.R[n] or PLC[m].Ldata.R[n] accesses Rn relative to R0 of present program

  12. Local Variable Stack Example • This example uses default “stack offset” of 256 • Other offsets can be declared • IDE declares optimal offsets automatically • Rn of calling routine equivalent to Ln of called routine • Rn of calling routine equivalent to L(n + StackOffset) of calling routine • Pass/return arguments should start with R0 of calling, L0 of called • IDE manages these definitions and assignments automatically

  13. Local D-Variables • “Non-stack” set of local variables for each C.S., PLC, communications thread • Separate from L, R, & C “stack” local variables • 53 variables (D0 – D52) for each environment • Used for “read” argument passing from letter/number format • Especially useful for RS-274 “G-Code” CNC-style programs • Not intended for multiple levels of subroutines (no stack) • Used for storing queried axis values • From commands like pread, dread, vread, fread • D0 used for kinematic routine input/output flags • Can be accessed “externally” by structure name • e.g. Coord[x].Ldata.D[n], Plc[i].Ldata.D[n]

  14. Auto-Assigning User Names to Variables • Requires use of Project Manager in IDE • When you don’t care what variable is assigned, use declarations • global MyPvar1, MyPvar2, MyPvar3(16); • csglobal MyQvar1, MyQvar2, MyQvar3(256); • ptr MyMvar1->{definition}, MyMvar2->{definition}; • local MyLvar1, MyLvar2, MyLvar3(7); • Project manager automatically assigns variables to names • Can set starting variable numbers for auto-assign with PVARSTARTn, QVARSTARTn, MVARSTARTn directives • Directives in /usrflash/project/pp_proj.ini • Defaults are PVARSTART8192, QVARSTART1024, MVARSTART8192 • Variables with lower numbers available for manual assignment or “raw” use • Local variable auto-assigns always start with L0 • L0 to L(n-1) for n arguments into routine, Lnand up for internally declared

  15. Capabilities with Declared Variable Names • When writing programs, just use declared variable names, e.g.: MyPvar1 = MyMvar2 + 7; • Can access from IDE terminal, watch window, etc., e.g.: MyPvar1 &2MyQvar3 MyMvar2 = 1 • If non-local variable declared with a value, e.g.: global MyPvar4 = 3; • Value is automatically assigned to the variable on download, power-up, and reset • Very useful for setting power-up default values • Value can be expressed as constant or expression (e.g. 5 * 65536), but expression cannot use variables • Communications program gpascii -2 can use declared variable names

  16. Manual Assigning User Names to Variables • Requires use of Project Manager in IDE • When you do care what variable is assigned, use definitions • #define MyPvar1 P10 • #define MyQvar7 Q50 • #define MyMvar3 M200 • Simple text substitution on download • Should use variables numbered below P/Q/MVARSTART # • Communications program gpascii -2 can use defined variable names • Can be most important for local (L) variables to coordinate variable passing properly (IDE does automatically for subroutine arguments) • #define MyLvar1 L0 • #define MyLvar2 L1 • #define MyRvar1 R0 • #define MyRvar2 R1

  17. Power PMAC Variable Arrays • For any numbered variable type (P, Q, M, I, L, R, D, C) • Specific variable can be specified by mathematical expression in parentheses • e.g. P(P1-P2+7), L(Index-1) • Technically, these are function calls, so use ( ), not [ ] • Compare to indexed data structures, which use [ ] for index • Computed expression value rounded down to next integer (if necessary) before used to select particular variable • Usable in motion and PLC programs, & many on-line commands • Can use arrays with variable declarations in IDE • global MyParray(32) declares 32-element P-variable array • If IDE project manager assigns P620 – P651 to this array, MyParray(Index) becomes P(620+Index) • No protection against index exceeding declared array length • Note distinction between arrays, vectors, and (2D) matrices

  18. Power PMAC Script Math: Scalar Functions • Trig functions using radians: sin, cos, tan, sincos • Inverse trig functions using radians: asin, acos, atan, atan2 • Trig functions using degrees: sind, cosd, tand, sincosd • Inverse trig functions using degrees: asind, acosd, atand, atan2d • Hyperbolic trig functions: sinh, cosh, tanh • Inverse hyperbolic trig functions: asinh, acosh, atanh • Log/exponent functions: log (or ln), log2, log10, exp, exp2, pow • Root functions: sqrt, cbrt, qrrt, qnrt • Rounding/truncation functions: int, rint, floor, ceil • Random number generation : rnd (32-bit), randx (64-bit), seed • Miscellaneous functions: abs, sgn, rem, madd (mult & add), isnan

  19. Power PMAC Script Vector & Matrix Functions • Treat sets of consecutively numbered variables as 1D vectors or 2D matrices for mathematical operations • Global P-variables if Ldata.Control = 0 (power-on default) • Local L-variables if Ldata.Control = 1 • Global user shared memory Sys.Ddata[i] variables if Ldata.Control = 2 (new in V1.5) • Particular variables used in vector or matrix specified by function arguments: • Starting variable number • Length for vectors • Number of rows and columns for matrices • Functions permit more compact user code • Functions execute much faster than multiple user code scalar operations

  20. Power PMAC Script Math: Vector Functions • Operate on continuously numbered set of variables • Same set of variables can be treated as 2D matrix for other purposes • Functions that produce new vectors (returned value is “OK” flag – must “put” somewhere even if don’t use) • vadd: Adds 2 vectors together to produce 3rd vector • vcopy: Copies contents of vector into 2nd vector • vscale: Multiplies each vector element by common scale factor, result in 2nd vector • Functions that produce scalar (as returned value) only • sum: Adds a number of evenly spaced elements together (as for trace of matrix) • sumprod: Multiplies pairs of elements of 2 vectors together, adding products into returned value (as for dot product)

  21. Power PMAC Script Math: Matrix Functions • Operate on consecutively numbered set of variables • Elements in same row are consecutively numbered • Functions that produce new matrices (returned value is “OK” flag or determinant of result matrix – must “put” somewhere even if don’t use) • mmul: Multiplies 2 matrices together to create 3rd matrix • mmadd: Multiplies 2 matrices together, adds product to 3rd matrix • minv: Inverts a square matrix to create a 2nd matrix • mtrans: Transposes a matrix to create a 2nd matrix • msolve: Solves simultaneous set(s) of equations represented by square (coefficient) matrix and 2nd (constant) vector/matrix • Functions that produce scalar (as returned value) only • mdet: Calculates determinant of square matrix • mminor: Calculates specified minor determinant of square matrix

  22. Declared Vector and Matrix Names • In IDE, can declare array variables for vectors and matrices, e.g.: global MyVector1(3), MyVector2(3); // P-variables, declared outside program global MyMatrix1(9), MyMatrix2(9); local MyVector3(3), MyVector4(6); // L-variables, declared inside program Local MyMatrix3(9), MyMatrix4(36); • Function calls can then use declared names, e.g.: Ldata.Control = 0; // Use global P-variables MyResult = sum(&MyVector1(0), 3, 1); MyTest = vcopy(&MyVector1(0), &MyVector2(0); MyResult = mdet(&MyMatrix1(0), 3); MyTest = minv(&MyMatrix1(0), &MyMatrix2(0), 3); Ldata.Control = 1; // Use local L-variables MyResult = sumprod(&MyVector3(0), &MyVector4(3), 3, 3, 1); MyTest = vscale(&MyVector3(0), 2.5, &MyVector4(3), 3); MyResult = mminor(&MyMatrix3(0), 3, 1, 2); MyTest = msolve(&MyVector4(0), MyMatrix4(0), 6, 6); • Note that do not need to start with element 0 of vector/matrix

  23. Operators and Conditional Comparators • Arithmetic operators • + (add), - (subtract), * (multiply), / (divide), % (modulo) • Normal rules of algebraic precedence apply • Bit-by-bit logical operators • & (bit-by-bit AND), | (bit-by-bit OR), ^ (bit-by-bit exclusive OR) • ~ (bit-by-bit invert; unary operator – technically a function) • << (shift left), >> (shift right) • Conditional comparators • == (equals), != (not equals), ~ (approx. eq.), !~ (not approx. eq.) • > (greater than), < (less than) • >= (greater than or equal to), <= (less than or equal to) • Condition combinatorial operators • && (AND), || (OR) • Condition negation operator ! (NOT)

  24. Standard Assignment Operators • General syntax: {variable}{operator}{expression} • Expression following operator evaluated during program flow • Resulting value immediately used to set value of variable preceding operator • If motion program is looking ahead due to blending, buffered dynamic lookahead, and/or tool radius compensation, assignments can appear out of sequence with executed motion • Use synchronous assignments to delay actual assignment until resulting executed motion • Simple assignment: = (expression value written into variable) • Assignments with arithmetic operation: +=, -=, *=, /=, %= • Assignments with logical operation: &=, |=, ^= • Assignments with shift operation: >>=, <<= • Increment/decrement assignments: ++, --

  25. Synchronous Variable Assignments • Needed primarily because motion programs must calculate ahead during sequence of blended moves • Standard assignments would occur “too soon” compared to moves • Synchronous assignments are delayed to be in sequence with moves • General syntax: {variable}{synchronous operator}{expression} • Most variable types can receive synchronous assignment • Not just M-variables as in PMAC/Turbo PMAC • Including pre-defined data structure elements • No local variables or self-referenced M-variables can receive • Expression following operator evaluated during program flow • Resulting value stored in buffered queue along with operation type • Each coordinate system has an independent buffered queue • Actual assignment using operator occurs at beginning of execution of next commanded move (at start of blend) • In PLC programs, use to assure that commanded move has started

  26. Synchronous Variable Assignments (cont.) • Simple assignment: == (expression value written into variable) • For any type of variable format • Assignments with arithmetic operation: +==, -==, *==, /==, %== • *==, /==, %== for floating-point variables/elements only • Assignments with logical operation: &==, |==, ^== • For integer variables/elements only • Increment/decrement assignments: ++=, --= • Useful in PLC programs to know that commanded move has started, e.g.: P1=0; P1==1; jog1=100000; // P1 set at start of jog move while (!(P1) || !(Motor[1].InPos)) { } // Move not started or ongoing M1=1; // Set output when move has finished and settled // Motor must be assigned to a C.S. to trigger sync assignment in PLC

  27. Synchronous Assignment Motion Program Example • One move lookahead (for simple blending): X10; // 1st move X20; // 2nd move Q1 = 30; // Standard assignment M1 = 1; // Standard assignment M2 == 1; // Sync assignment X(Q1); // 3rd move • Q1 set to 30 at X=10 (t1) • Needs to be done at lookahead time to calculate next move properly • M1 set to 1 at X=10 (t1) • Output would appear out of sequence • M2 set to 1 at X=20 (t2) • Output would appear in sequence

  28. Synchronous Assignment Buffer • Synchronous assignments must be buffered from time encountered in program until delayed execution • Default buffer space for 1M (1,048,576) synchronous assignments • Size can be changed in IDE Project Manager (pp_proj.ini file) • Coord[x].SyncOps specifies how many of these assignments reserved for this C.S. in buffer • Default value of 8192 for each C.S. (sufficient for almost all applications) • To change buffer organization, set new values for Coord[x].SyncOps, save, and reset (new buffer offsets calculated automatically on reset) • No need to define second-stage buffer with special lookahead • C.S. needs to buffer for length of lookahead and retrace at any given time (buffer space is reused) • Large numbers of buffered assignments only needed for applications with special lookahead (and especially lengthy retrace)

  29. Power PMAC Script String Functions • Operate on character (byte) arrays in user shared memory buffer • Specify string variable with starting index value i in Sys.Cdata[i] • Functions that manipulate string variables: • sprintf, strcat, strcpy, strncat, strncpy, strtolower, strtoupper • Functions that interrogate string variables: • strchr, strcmp, strcspn, strlen, strncmp, strpbrk, strrchr, strspn, strstr, strtod • All functions return a value that must be “put” somewhere • Methods to use/transmit strings: • Script program send, cmd, system commands • Referenced within text by %s designator • Starting character index for string specified after text • e.g. send1"Error: %s“,512 • C routines and applications • Access string with character (byte) pointer into user shared memory buffer • Note that C can use strings elsewhere as well (but no Script access to these)

More Related