## 11.6 Round logic

Data accumulation is carried out with 40-bit data. The architecture of the of the dsPIC30F devices, however, is 16-bit, meaning that the conversion to 16-bit values has to be done. A higher number of bits for calculating the sums by DSP instructions is intended for increasing the accuracy and the operating range of values and so reduce the error owing to the finite word length. The purpose of individual bits within the accumulator is presented in Fig. 11-4.

**Fig. 11-4 Purpose of individual bits within accumulator**

As can be seen from Fig. 11-4, the upper 8 bits serve for extending the range and the lower 16 bits for increasing the operational accuracy. Increasing the range is sometimes useful as an intermediate step, but the end result should not overrun the basic range. If this occurs, the result will not be correct. The consequences can be mitigated by enabling the saturation logic, but not completely neutralized.
After the calculation is completed, it is required to save the result as a 16-bit quantity. In order to do that, the accuracy of the result has to be reduced. For doing this process automatically, the DSP module is added a block which automatcally rounds off the result during an accumulator write back. From Fig. 11-3 it can be seen that the round logic is placed between the accumulator and X data bus. If the round logic is on (in the CORCON register), by using a separate instruction the result from the accumulator is rounded off and saved in the desired location in the data memory.
The round logic can perform a conventional (biased) or convergent (unbiased) round function.
The conventional round function implies the following. If the MS bit of the accuracy increase bits (bit 15) is logical one, the result will be one step incremented. One step is the least significant positive value that can be saved in the selected format (1 for integer, 1.15 for fractional point), specifically 0.000030517578125. A consequence of this algorithm is that over a succession of random rounding operations, the value will tend to be biased slightly positive.
The convergent round function assuming that bit 16 is effectively random in nature, will remove any rounding bias that may accumulate. If the convergent round function is enabled, the LS bit of the result will be incremented by 1 if the value saved in the accuracy increase 16 bits is greater than 0x08000, or if this value is equal to 0x08000 and bit 16 is one. This algorithm can be readily be explained by using integers. If the middle 16 bits contain an integer, the rounding algorithm will tend towards even integers. This is demonstarted by the examples in Table 11-1.

**VALUE TO BE ROUNDED** |
**THE RESULT** |
**BINARY FORM OF THE VALUE TO BE ROUNDED** |
**BINARY FORM OF THE RESULT** |

12.75 |
13 |
0000 0000
0000 0000 0000 **1100**
1100 0000 0000 0000 |
0000 0000 0000 **1100** |

12.5 |
12 |
0000 0000
0000 0000 0000 **1100**
1000 0000 0000 0000 |
0000 0000 0000 **1100** |

13.5 |
14 |
0000 0000
0000 0000 0000 **1101**
1000 0000 0000 0000 |
0000 0000 0000 **1110** |

**Table 11-1 Covergent round function.**
The convergent round function usually gives better results and its use is recommended.