| The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers. |
AN331-15 Basic Matrix Functions ADMC331 AN331-15 Analog
Top Searches for this datasheetBasic Matrix Functions ADMC331 AN331-15 Basic Matrix Functions ADMC331 AN331-15 Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 AN331-15 Table Contents SUMMARY. 1.10 1.11 1.12 MATRIX FUNCTIONS LIBRARY ROUTINES. matrix format Usage matrix routines Usage registers Matrix Initialisation Matrix Write Matrix Read Matrix Addition Matrix Subtraction.9 Matrix Multiplication.10 Matrix Transpose Matrix Determinant Matrix Error SOFTWARE EXAMPLE: TESTING MATRIX FUNCTIONS. Usage Matrix Routines: Example.15 main program: main.dsp.15 main include file: main.h Example outputs 2.4.1 Matrix Initialisation Matrix Write 2.4.2 Matrix Addition.18 2.4.3 Matrix Subtraction 2.4.4 Matrix Multiplication 2.4.5 Matrix Transpose 2.4.6 Matrix Determinant.20 Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 AN331-15 Summary This application note demonstrates basic matrix functions subroutines such additions, subtractions multiplications. organisation this application note follows. section one, matrix function library routines will presented. section two, software examples will shown illustrate matrix functions subroutines. Matrix Functions Library Routines matrix format Each element matrix stored data memory. association between each matrix element corresponding position data memory shown follows: Data Memory Matrix Matrix Figure Declaration matrix data memory Fig.1, matrix size declare matrix data memory, number rows, followed number columns specified first. After that, each element specified shown Fig.1. Hence, matrix having elements will result p+2) elements data memory. Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 AN331-15 Usage matrix routines routines developed easy-to-use library, which linked user's application. library consists files. file "matrix.dsp" contains assembly code subroutines. block compiled then linked application. user include header file "matrix.h", which provides function-like calls subroutines. following table summarises macros that defined this library. example file Section will demonstrate usage routines. Operation Initialisation Write matrix Read matrix Addition Subtraction Multiplication Transpose Determinant Usage Explanation M_Initialize(Matrix_A, number_of_rows, Initialise matrix with elements number_of_columns, arbitrary constant) arbitrary value M_Write(Matrix_A, row_number, value) M_Read(Matrix_A, row_number) column_number, Write value into matrix element column_number, value stored matrix element Matrix_C Matrix_A Matrix_B Matrix_C Matrix_A Matrix_B Matrix_C Matrix_A Matrix_B Matrix_B (Matrix_A)T Determinant Det(Matrix_A) M_Add(Matrix_A, Matrix_B, Matrix_C) M_Sub(Matrix_A, Matrix_B, Matrix_C) M_Mul(Matrix_A, Matrix_B, Matrix_C) M_Transpose(Matrix_A, Matrix_B) M_Determinant2(Matrix_A, Determinant) Table Implemented routine routines require configuration constants from main include-file "main.h" that comes with every application note. more information about general structure application notes including libraries into user applications refer Library Documentation File. Section shows example usage this library. following sections each routine explained detail with relevant segments code which found either "matrix.h" "matrix.dsp". more information comments those files. Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 AN331-15 Usage registers macro listed Table based subroutines listed Table Each subroutine will discussed following sections. following table gives overview what registers used this macro: Inputs1 I0=^Matrix_A Row, column number, arbitrary constant M_Write_ I0=^Matrix_A Row, column number Matrix element value M_Read_ I0=^Matrix_A Row, column number M_Add_ I0=^Matrix_A I1=^Matrix_B I2=^Matrix_C M_Sub_ I0=^Matrix_A I1=^Matrix_B I2=^Matrix_C M_Mul_ I0=^Matrix_A I1=^Matrix_B I2=^Matrix_C M_Transpose_ M_Determinant2_ I0=^Matrix_A I2=^Matrix_B I0=^Matrix_A I2=^Determinant ax0, ay0, ax1, ay1, L0=L1=L2=0, M0=M1=M2=1 ax0, ay0, ax1, ay1, L0=L1=L2=0, mx1, my1, mx0, my0, M1=M2=1 ax0, ay0, ax1, L0=L2=0, M0=1 ax0, ay0, mx0, my0, L0=L2=0, mx1, my1, M0=1, M2=0 ay0, ay1, mx0, ax0, ax1, my0, my1, ay0, ay1, ax0, ax1, my0, my1, Outputs2 Subroutine M_Initialise_ Modified registers ax0, ax1, Other registers L0=0, M0=1 L0=0, M0=1 L0=0, M0=1 ax0, ay0, ax1, ay1, L0=L1=L2=0, M0=M1=M2=1 Table Input output format, modified registers matrix routines ^vector stands `address vector' Most output values stored output vector Data Memory. Page Analog Devices Inc., November 2000 Basic Matrix Functions ADMC331 AN331-15 Matrix Initialisation Once matrix name size, which includes number rows columns, defined, this subroutine used initialise matrix with elements arbitrary value. Note: .INIT approach equally valid initialise matrix, this routine serves runtime alternative Test shows subroutine initialising matrix. M_Initialise_: DM(I0,M0)=AX0; DM(I0,M0)=AX1; CNTR=AX1; ClearLoop00 until CNTR=AX0; ClearLoop01 until ClearLoop01:dm(I0,M0)=AR; ClearLoop00:nop; pass rts; error occurred} Matrix Write Writing values matrix performed using matrix write subroutine. exact, shown Matrix value entered into aij, then macro call will M_Write(MatrixA, Matrix Test shows subroutine writing values matrix. M_Write_: mx0=ar; AX0=DM(I0,M0); AX1=DM(I0,M0); my0=I0; none=pass ax1; jump M_Error_; none=pass ax0; jump M_Error_; ar=ax0-ay1; jump M_Error_; ar=ax1-ay0; jump M_Error_; Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 mr=0; ar=ay1-0x1; sr=lshift 1(LO); mr0=sr0; ar=ay0-0x1; my1=ax0; mr=mr+ar*my1(uu); SR=lShift -1(LO); M1=sr0; modify(I0,M1); DM(I0,M0)=mx0; I0=my0; pass rts; error occurred} AN331-15 Matrix Read Reading element matrix accomplished using matrix read subroutine. value read from matrix stored register. instance, from Matrix above, macro call M_read(MatrixA, will result writing value into Test shows subroutine reading values from matrix. M_Read_: AX0=DM(I0,M0); AX1=DM(I0,M0); my0=I0; none=pass AX0; jump M_Error_; none=pass AX1; jump M_Error_; mr=0; ar=ay1-0x1; SR=LShift (LO); mr0=sr0; ar=ay0-0x1; my1=ax0; mr=mr+ar*my1(uu); SR=LShift -1(LO); M1=sr0; modify(I0,M1); ar=DM(I0,M0); I0=my0; pass rts; error occurred} Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 AN331-15 Matrix Addition Given matrices same size, addition implemented using matrix addition subroutine. However, input matrices have different sizes, Matrix Error will occur. resulting matrix will have same size original matrices. mechanism this addition shown Table. Please note that this routine only partially optimized full optimization obtained only argument resides program memory other data memory. Matrix Operations Matrix Matrix Data Memory Matrix Matrix Matrix Matrix Table Matrix additions Test shows subroutine calculating matrix addition according Table. M_Add_: {MatrixC MatrixA MatrixB; AX0=DM(I0,M0); AX1=DM(I0,M0); AY0=DM(I1,M1); AY1=DM(I1,M1); AR=AX0-AY0; jump M_Error_; AR=AX1-AY1; jump M_Error_; DM(I2,M2)=AX0; DM(I2,M2)=AX1; mx0=ax0; my0=ax1; mr=mx0*my0(ss); SR=LSHIFT -1(LO); {setting size final matrix} {the input matrices have same sizes} {Get sizes input matrices} I0=^MatrixA; I1=^MatrixB; I2=^MatrixC;} Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 CNTR=SR0; ax1=dm(I0,M0); until {matrix addition} AN331-15 ay0=dm(I1,M1); ar=ax1+ay0, ax1=dm(I0,M0); Sum:dm(I2,M2)=AR; pass rts; error occurred} Matrix Subtraction Same matrix addition, given matrices same size, subtraction implemented using matrix subtraction subroutine. However, input matrices have different sizes, Matrix Error will occur. resulting matrix will have same size original matrices. mechanism this addition shown Table. Please note that this routine only partially optimized full optimization obtained only argument resides program memory other data memory. Matrix Operations Matrix Matrix Data Memory Matrix Matrix Matrix Matrix Table Matrix subtractions Test shows subroutine calculating matrix subtraction according Table. M_Sub_: {MatrixC=MatrixA MatrixB; AX0=DM(I0,M0); AX1=DM(I0,M0); AY0=DM(I1,M1); I0=^MatrixA; I1=^MatrixB; I2=^MatrixC;} {Get sizes input matrices} Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 AY1=DM(I1,M1); AR=AX0-AY0; jump M_Error_; AR=AX1-AY1; jump M_Error_; DM(I2,M2)=AX0; DM(I2,M2)=AX1; mx0=ax0; my0=ax1; mr=mx0*my0(ss); SR=LSHIFT -1(LO); CNTR=SR0; ax1=dm(I0,M0); until {matrix addition} ay0=dm(I1,M1); ar=ax1-ay0, ax1=dm(I0,M0); Sub:dm(I2,M2)=AR; pass rts; error occurred} {setting size final matrix} {the input matrices have same sizes} AN331-15 Matrix Multiplication Given matrices, Matrix_A Matrix_B, multiplication (e.g. Matrix_A Matrix_B) achieved provided that number columns Matrix_A equals number rows Matrix_B. Otherwise, will cause Matrix Error. This multiplication implemented using matrix multiplication subroutine. resulting matrix will have same number Matrix_A same column number Matrix_B. mechanism this addition shown Table. Please note that this routine only partially optimized full optimization obtained only argument resides program memory other data memory. Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 AN331-15 Matrix Operations Matrix Matrix Matrix Data Memory Matrix Matrix Matrix Table Matrix multiplications where Test shows subroutine calculating matrix multiplication according Table. this subroutine, input matrices, which 1.15 format, multiplied. preliminary result 1.31 format, then most significant bits extracted stored resulting matrix. M_Mul_: MatrixC MatrixA MatrixB; AY0=DM(I0,M0); {Get sizes matrices} AX0=DM(I0,M0); AY1=DM(I1,M1); AX1=DM(I1,M1); AR=AX0-AY1; {number columns matrix equal number rows matrix jump M_Error_; MX1=I0; MY1=I1; DM(I2,M2)=AY0; DM(I2,M2)=AX1; M0=ay0; M3=ay1; CNTR=ax1; Save pointer} Save pointer} {set sizes Matrix I0=^MatrixA; I1=^MatrixB; I2=^MatrixC; Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 AXLoop until CNTR=ay0; I0=MX1; SI=MX1; BXloop until I1=MY1; mr=0; CNTR=ay1; mx0=dm(I0,M0); innerloop until my0=dm(I1,M1); innerloop: (RND); dm(I2,M2)=mr1; I0=SI; modify(I0,M1); BXloop: SI=I0; I1=MY1; modify(I1,M3); AXLoop: pass rts; MY1=I1; error occurred} {Advance pointer} {Advance column pointer {enables multiplication saturation} mr=mr+mx0*my0 (ss), mx0=dm(I0,M0); {calculate each element resulting matrix} {calculate matrix multiplication each column resulting matrix} {calculate matrix multiplication each resulting matrix} AN331-15 1.10 Matrix Transpose Given matrix, e.g. Matrix_A size matrix transpose accomplished using matrix transpose subroutine. resulting matrix will have size Matrix Operations Matrix Matrix Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 AN331-15 Data Memory Matrix Matrix Table Matrix transpose Test shows subroutine calculating matrix transpose according Table. M_Transpose_: MatrixB MatrixA'; I0=^MatrixA; I2=^MatrixB; AX0=DM(I0,M0); {get size Matrix_A} AX1=DM(I0,M0); none=pass AX0; jump M_Error_; none=pass AX1; jump M_Error_; DM(I2,M2)=AX1; {set size Matrix_B} DM(I2,M2)=AX0; AY0=I2; m2=ax1; CNTR=AX1; {implement transpose each column} TranLoop00 until CNTR=AX0; {implement transpose each row} TranLoop01 until ar=dm(I0,M0); TranLoop01: dm(I2,M2)=ar; I2=AY0; modify(I2,M0); AY0=I2; TranLoop00: pass rts; nop; error occurred} Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 AN331-15 1.11 Matrix Determinant Given matrix with size determinant that matrix calculated using matrix determinant routine. matrix operation follows: Matrix Operations a11a21 a12a22 Data Memory Matrix 0002 0002 Table Matrix Determinant Test shows subroutine calculating matrix determinant according Table. M_Determinant2_: ax0=DM(I0, M0); ay0=DM(I0, M0); ar=ax0-ay0; {check square matrix} jump M_Error_; ar=ax0-0x2; {check matrix size jump Det2Order; jump MatrixError; Det2Order: mx0=dm(I0,M0); mx1=dm(I0,M0); my0=dm(I0,M0); my1=dm(I0,M0); mr=mx0*my1(ss); {determinant calculation} mr=mr-mx1*my0(ss); DM(I2,M2)=mr1; pass rts; error occurred} Determinant a11a21 a12a22 1.12 Matrix Error Matrix Error will occur certain criteria before implementing matrix functions. register will 0x0001 indication error, otherwise AF=0x000. Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 AN331-15 Software Example: Testing Matrix Functions Usage Matrix Routines: Example example shows matrix subroutines. This only template used reference applications. example will initialise several matrices, Matrix Matrix Matrix Matrix Matrix Matrix Matrix with hexadecimal values written them follows: 3D72 1222 2082 2342 3642 6212 5622 6C22 1012 Matrix Matrix Matrix Matrix Matrix Matrix 2122 3242 Matrix following matrix operations implemented, final result stored Matrix Determinant. Matrix Matrix Matrix Matrix Matrix Matrix Matrix Matrix Matrix Matrix (Matrix Determinant (Matrix main program: main.dsp file "main.dsp" contains initialisation Sync Trip interrupt service routines. batch file build.bat applied either within prompt double-clicking from Windows Explorer, compiles every file application, links them together builds executable file main.exe. This file Motion Control Debugger. brief description code given follows: Start code declaring start location program memory Main_Program; Next, general systems constants configuration constants (main.h next section) included. Also included library, interface library matrix library. Include General System Parameters Libraries #include <main.h>; #include <pwm331.h>; #include <matrix.h>; (Matrix Transpose Matrix Det(Matrix determinant Matrix Page Analog Devices Inc., November 2000 Basic Matrix Functions ADMC331 Some variables defined hereafter. Here where matrices declared initialised. .var/ram/dm/SEG=USER_DM1 MatrixA[11]; {Define matrix size 3x3} .INIT MatrixA: .var/ram/dm/SEG=USER_DM1 MatrixB[11]; {Define matrix size 3x3} AN331-15 .INIT MatrixB: .var/ram/dm/SEG=USER_DM1 MatrixC[11]; .INIT MatrixC: 3,3,0,0,0,0,0,0,0,0,0; .var/ram/dm/SEG=USER_DM1 MatrixD[11]; .INIT MatrixD: 3,3,0,0,0,0,0,0,0,0,0; .var/ram/dm/SEG=USER_DM1 MatrixE[11]; .INIT MatrixE: 3,3,0,0,0,0,0,0,0,0,0; .var/ram/dm/SEG=USER_DM1 MatrixF[11]; .INIT MatrixF: 3,3,0,0,0,0,0,0,0,0,0; .var/ram/dm/SEG=USER_DM1 MatrixG[6]; .INIT MatrixG: 2,2,0x2122,0x3242,0x6a5,0x128; .var/ram/dm/SEG=USER_DM1 Determinant; Define Determinant} Define matrix size 2x2} {Define matrix size 3x3} {Define matrix size 3x3} {Define matrix size 3x3} {Define matrix size 3x3} initialisation block executed. Note interrupt vectors PWMSync PWMTrip service routines passed arguments. Then interrupt IRQ2 enabled setting corresponding IMASK register. Start program code Startup: PWM_Init(PWMSYNC_ISR, PWMTRIP_ISR); 0x80; 0x200; IMASK; ay0; IMASK Main: jump Main; rts; Wait interrupt occur} IRQ2 ints fully enabled here} Clear pending IRQ2 inter.} unmask irq2 interrupts.} Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 following piece code demonstrate usage matrix routines. shown below, typically executed within interrupt service routine, that Tsample determined frequency (10kHz this example). Interrupt Service Routine AN331-15 PWMSYNC_ISR: M_Add(MatrixA, MatrixB, MatrixC); None= pass jump Matrix_Error; M_Sub(MatrixA, MatrixB, MatrixD); M_Mul(MatrixA, MatrixB, MatrixE); M_Transpose(MatrixA, MatrixF); M_Determinant2(MatrixG, Determinant); RTI; Matrix_Error: IDLE; {dummy routine error recovering} check error occurred main include file: main.h This file contains definitions ADMC331 constants, general-purpose macros configuration parameters system library routines. should included every application. more information refer Library Documentation File. This file mostly self-explaining. already mentioned, matrix library does require configuration parameters. following defines parameters used this example. Library: block file PWM331.dsp Application Note: Usage ADMC331 Pulse Width Modulation Block .CONST PWM_freq .CONST PWM_deadtime .CONST PWM_minpulse 10000; 1000; 1000; {Desired deadtime [nsec] {Desired minimal pulse time [nsec] {Desired sync pulse time [nsec] {Desired switching frequency [Hz] .CONST PWM_syncpulse 1540; Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 AN331-15 Example outputs 2.4.1 Matrix Initialisation After implementing matrix initialisation using .INIT approach, following matrices formed data memory. Data Memory Matrix 0003 0003 3D72 2342 5622 1222 3642 6C22 2082 6212 1012 Matrix 0003 0003 0212 0324 0117 06A5 0128 0304 0669 0476 08F4 Matrix 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 Matrix 0002 0002 2122 3242 06A5 0128 2.4.2 Matrix Addition Addition Matrix Matrix achieved using matrix addition subroutine. result stored Matrix follows: Data Memory Matrix 0003 0003 3D72 2342 5622 1222 3642 6C22 2082 6212 1012 Matrix 0003 0003 Matrix 0003 0003 3F84 2666 5739 18C7 376A 6F26 26EB 6688 1906 Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 AN331-15 2.4.3 Matrix Subtraction Subtraction Matrix from Matrix achieved using matrix subtraction subroutine. result stored Matrix follows: Data Memory Matrix 0003 0003 3D72 2342 5622 1222 3642 6C22 2082 6212 1012 Matrix 0003 0003 Matrix 0003 0003 3B60 201E 550B 0B7D 351A 691E 1A19 5D9C 071E 2.4.4 Matrix Multiplication Multiplication Matrix Matrix achieved using matrix multiplication subroutine. result stored Matrix follows Data Memory Matrix 0003 0003 3D72 2342 5622 1222 3642 6C22 2082 6212 1012 Matrix 0003 0003 Matrix 0003 0003 01B7 02BD 042F 041F 04A2 05D4 05FC 0A84 0935 Analog Devices Inc., November 2000 Page Basic Matrix Functions ADMC331 AN331-15 2.4.5 Matrix Transpose Transpose Matrix accomplished using matrix transpose subroutine. result stored Matrix follows: Data Memory Matrix 0003 0003 3D72 2342 5622 1222 3642 6C22 2082 6212 1012 Matrix 0003 0003 3D72 1222 2082 2342 3642 6212 5622 6C22 1012 2.4.6 Matrix Determinant Determinant matrix calculated using matrix determinant subroutine. result stored variable called Determinant. Data Memory Matrix 0002 0002 2122 3242 06A5 0128 Determinant FDB1 Analog Devices Inc., November 2000 Page Other recent searchesTS1G - TS1G TS1G Datasheet 2GSDG - 2GSDG 2GSDG Datasheet NTE1503 - NTE1503 NTE1503 Datasheet MAX202E - MAX202E MAX202E Datasheet MAX213E - MAX213E MAX213E Datasheet MAX232E - MAX232E MAX232E Datasheet MAX241E - MAX241E MAX241E Datasheet MAX211E - MAX211E MAX211E Datasheet MAX213E - MAX213E MAX213E Datasheet MAX241E - MAX241E MAX241E Datasheet MAX202E - MAX202E MAX202E Datasheet MAX232E - MAX232E MAX232E Datasheet MAX203E - MAX203E MAX203E Datasheet MAX205E - MAX205E MAX205E Datasheet MAX206E - MAX206E MAX206E Datasheet MAX207E - MAX207E MAX207E Datasheet MAX208E - MAX208E MAX208E Datasheet KV1837K - KV1837K KV1837K Datasheet HFTC-19+ - HFTC-19+ HFTC-19+ Datasheet 1N4148WS-V - 1N4148WS-V 1N4148WS-V Datasheet
Privacy Policy | Disclaimer |