dsPIC30F Family Reference Manual
DS70050C-page 3-12 © 2004 Microchip Technology Inc.
3.3.4 Modulo Addressing Initialization for Incrementing Modulo Buffer
The following steps describe the setup procedure for an incrementing circular buffer. The steps
are similar whether the X AGU or Y AGU is used.
1. Determine the buffer length in 16-bit data words. Multiply this value by 2 to get the length
of the buffer in bytes.
2. Select a buffer starting address that is located at a binary ‘zeros’ boundary based on the
desired length of the buffer. Remember that the buffer length in words must be multiplied
by 2 to obtain the byte address range. For example, a buffer with a length of 100 words
(200 bytes) could use 0xXX00 as the starting address.
3. Calculate the buffer end address using the buffer length chosen in Step 1 and the buffer
start address chosen in Step 2. The buffer end address is calculated using Equation 3-1.
4. Load the XMODSRT (YMODSRT) register with the buffer start address chosen in Step 2.
5. Load the XMODEND (YMODEND) register with the buffer end address calculated in
Step 3.
6. Write to the XWM<3:0> (YWM<3:0>) bits in the MODCON register to select the W register
that will be used to access the circular buffer.
7. Set the XMODEN (YMODEN) bit in the MODCON register to enable the circular buffer.
8. Load the selected W register with address that points to the buffer.
9. The W register address will be adjusted automatically at the end of the buffer when an
indirect access with pre/post increment is performed (see Figure 3-5).
Figure 3-5: Incrementing Buffer Modulo Addressing Operation Example
0x1100
0x1163
Start Addr = 0x1100
End Addr = 0x1163
Length = 50 Words
Byte
Address
MOV #0x1100,W0
MOV W0,XMODSRT ;set modulo start address
MOV #0x1163,W0
MOV W0,XMODEND ;set modulo end address
MOV #0x8001,W0
MOV W0,MODCON ;enable W1, X AGU for modulo
MOV #0x0000,W0 ;W0 holds buffer fill value
MOV #0x1100,W1 ;point W1 to buffer
DO #49,FILL ;fill the 50 buffer locations
FILL:
MOV W0,[W1++] ;fill the next location
;W1 = 0x1100 when DO loop completes