Page 349 - Programming Microcontrollers in C
P. 349

334    Chapter 6  Large Microcontrollers

                              The convolution is little more than a series of dot products, one dot
                          product for each output sample. Therefore, if you have a function that
                          will calculate a dot product, it can also calculate a convolution.
                              An item of consequence is the use of modular arithmetic in calcu­
                          lation of the data addresses. Often times, it is desirable to traverse an
                          array and return to its beginning automatically when the end is reached.
                          Modular arithmetic allows this type of operation. When working in
                          combination with an unusual step value, modular arithmetic will per­
                          mit the collection of coefficients from a rectangular array placed in
                          linear memory space. Here the step value refers to one of the numbers
                          associated with the mac or the rmac instruction. These two values are
                          called xo and yo. This value is used to increment the address of the
                          corresponding register whenever data is loaded into either the H or the
                          I register. The location of the array in memory should be placed at
                          special location in memory. This location is discussed below. The ef­
                          fective address for the next value to be placed in the X after the value
                          is incremented by the xo register is given by
                   IX = (IX)&~XMASK | ((IX)+xo)&XMASK

                              Note that XMASK here is an 8-bit mask that defines the length of
                          the circular array. The array length must be a power of two less than
                          or equal to 256. The value placed in XMASK is one less than the array
                          length. When the contents of IX, or (IX), is anded with the comple­
                          ment of the sign extended value of XMASK, the value that is left is the
                          starting address of the array. The second term above causes the con­
                          tents in IX to be incremented. As the value in IX is replaced by
                          ((IX)+ xo)&XMASK after each multiply and accumulate opera­
                          tion. Since XMASK  must contain a number that is one less than a
                          power of two raised to the n: its least significant n bits are 1. The
                          value placed in IX is the address with the n least significant bits
                          masked off. When these two values are ORed together, an address is
                          created that will range from the beginning to the end of the array and
                          then back to the beginning in steps of xo. The requirements to make
                          this scheme work are:
                              1. The array length must be a power of two less than or equal to
                                 256.
                              2. The array must begin on a specific address. This address is any
                                 value where the least n bits are zero. Here n is determined by
   344   345   346   347   348   349   350   351   352   353   354