Modulo Addressing

To fully appreciate the utility of modulo addressing, we should first understand the concept of a circular buffer. A circular buffer is basically a region in memory which is used to store a fixed-size data array, such that after reaching the end of the array, one needs to “wrap around” and continue accessing data from the beginning of the array. The data access is thus required to be always bounded within the limits of the buffer. A common use of circular buffers is to access the delay line in an FIR filter computation.

The dsPIC® architecture renders it unnecessary for the user software to manually monitor the buffer pointer and correct the pointer if it is crossing the buffer limits. When an access is made to an address outside the modulo buffer limits, the dsPIC central processing unit (CPU) automatically performs an address “correction” such that the Effective Address generated lies within the buffer. If the pointer was pre-modified or post-modified, then the W register used as the pointer now contains the modulo-corrected address.

A modulo buffer may be classified into three types, based on the functioning of the address correction mechanism. The type a particular modulo buffer belongs to is determined by the start and end addresses assigned to it by the user.

  1. For an incrementing buffer, modulo address correction is only performed by the CPU when an instruction accesses data above the upper address limit.
  2. For a decrementing buffer, modulo address correction is only performed by the CPU when an instruction accesses data below the lower address limit.
  3. Bi-directional buffers are set up by the user such that the conditions for both incrementing and decrementing modulo buffers are satisfied.
Buffers(1).png

Modulo addressing operates only with indirect addressing mode and designated W register. Two independent modulo buffers may be established, one for X data space, and one for Y data space. It should be noted that X space modulo addressing works with DSP instructions as well as MCU instructions; however, it is only applicable to indirect addressing. Another important point to remember is that X space modulo addressing works for byte-sized data too, wherever applicable. For example, modulo addressing may be used to efficiently perform a character search, or to buffer characters for visual display. Lastly, a modulo buffer may have a size of up to 64KB.

Configuration Control

  • XMODSRT (X Modulo Start Address)
  • YMODSRT (Y Modulo Start Address)
    • Contains the buffer start address
    • Address must satisfy boundary conditions, depending on the type of buffer needed

The XMODSRT register is initialized with the start address of a modulo buffer located in X data space. YMODSRT performs a similar function, but for a modulo buffer located in Y data space.
If the buffer being configured is required to be an incrementing buffer, then the start address must be suitably aligned based on the buffer size.

  • XMODEND (X Modulo End Address)
  • YMODEND (Y Modulo End Address)
    • Contains the address of last byte occupied by the buffer
    • Address must satisfy boundary conditions, depending on the type of buffer needed

The XMODEND register is initialized with the end address of a modulo buffer located in X data space. YMODEND performs a similar function, but for a modulo buffer located in Y data space.
If the buffer being configured is required to be a decrementing buffer, then the end address must be suitably aligned based on the buffer size.

MODCON: Modulo and Bit-Reversed Addressing Control Register

R/W-0 R/W-0 U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0
XMODEN YMODEN BWM3 BWM2 BWM1 BWM0
bit 15 bit 8

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
YWM3 YWM2 YWM1 YWM0 XWM3 XWM2 XWM1 XWM0
bit 7 bit 0

bit 15

XMODEN: X AGU Modulo Addressing Enable bit

1 = X AGU modulo addressing enabled
0 = X AGU modulo addressing disabled

bit 14

YMODEN: Y AGU Modulo Addressing Enable bit

1 = Y AGU modulo addressing enabled
0 = Y AGU modulo addressing disabled

bit 13-12

Unimplemented: Read as '0

bit 11-8

BWM<3:0>: X AGU Register Select for Bit-Reversed Addressing bits

1111 = Bit-reversed addressing disabled
1110 = W14 selected for bit-reversed addressing
1101 = W13 selected for bit-reversed addressing
.
.
0000 = W0 selected for bit-reversed addressing

bit 7-4

YWM<3:0>: Y AGU W Register Select for Modulo Addressing bits

1111 = Modulo addressing disabled
1110 = W10 selected for modulo addressing
1101 = W11 selected for modulo addressing

bit 3-0

XWM<3:0>: X AGU W Register Select for Modulo Addressing bits

1111 = Modulo addressing disabled
1110 = W14 selected for modulo addressing
.
.
0000 = W0 selected for modulo addressing

Avoid use of the W14 register because it's used as a frame pointer by C.

Example

ModuloAddressingExample.png
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.