vii Contents
5 Software Applications 5-1 . . . . . . . . . . . . . . . . .
5.1 Integer Calculation Subroutines 5-2 . . . . . . . .
5.1.1 Unsigned Multiplication 16 x 16-Bits 5-2 . . . .
5.1.2 Signed Multiplication 16 x 16-Bits 5-7 . . . . . .
5.1.3 Unsigned Multiplication 8 x 8-Bits 5-11 . . . . . .
5.1.4 Signed Multiplication 8 x 8-Bits 5-13 . . . . . . . .
5.1.5 Unsigned Division 32/16-Bits 5-16 . . . . . . . . . . .
5.1.6 Signed Division 32/16-Bits 5-17 . . . . . . . . . . . .
5.1.7 Shift Routines 5-19 . . . . . . . . . . . . . . . . . . . . .
5.1.8 Square Root Routines 5-20 . . . . . . . . . . . . . . .
Contents
5.1.9 Signed and Unsigned 32-Bit Compares 5-25 . . . .
5.1.10 Random Number Generation 5-26 . . . . . . . .
5.1.11 Rules for the Integer Subroutines 5-29 . . . . . . .
5.2 Table Processing 5-32 . . . . . . . . . . . . . . . . . . . .
5.2.1 Two Dimensional Tables 5-34 . . . . . . . . . . . . . . .
5.2.2 Three-Dimensional Tables 5-41 . . . . . . . . . . . . . .
5.3 Signal Averaging and Noise Cancellation 5-45 . . . . .
5.3.1 Oversampling 5-45 . . . . . . . . . . . . . . . . . . . . . . . .
5.3.2 Continuous Averaging 5-46 . . . . . . . . . . . . . . . . . .
5.3.3 Weighted Summation 5-48 . . . . . . . . . . . . . . . . . . .
5.3.4 Wave Digital Filtering 5-49 . . . . . . . . . . . . . . . . . . .
5.3.5 Rejection of Extremes 5-50 . . . . . . . . . . . . . . . . . . .
5.3.6 Synchronization of the Measurement to Hum 5-52 . . .
5.4 Real-Time Applications 5-55 . . . . . . . . . . . . . . . . .
5.4.1 Active Mode 5-55 . . . . . . . . . . . . . . . . . . . . . . . .
5.4.2 Normal Mode is Low-Power Mode 3 (LPM3) 5-55 . . .
5.4.3 Normal Mode is Low-Power Mode 4 (LPM4) 5-55 . . .
5.4.4 Recommendations for Real-Time Applications 5-56 . .
5.5 General Purpose Subroutines 5-57 . . . . . . . . . . . . . . .
5.5.1 Initialization 5-57 . . . . . . . . . . . . . . . . . . . . . . . . . .
5.5.2 RAM clearing Routine 5-58 . . . . . . . . . . . . . . . . . . . .
5.5.3 Binary to BCD Conversion 5-58 . . . . . . . . . . . . . . . . .
5.5.4 BCD to Binary 5-60 . . . . . . . . . . . . . . . . . . . . . . . . . .