The lpm_div outputs quotient and remainder. Can it be used to implement fixed point division??The remainder is not equal to the fractional part. I am not sure how to calculate fractional part of output from it. Also, the lpm_div takes a 100s of logic elements (and no DSP blocks) to carry out its bidding. It seems that the block is purely combinatorial. Is there a way to make it use less resources but take more clock cycles?
You can set the number of pipeline stages using the pipeline parameter - this is the latency of the block. The higher the latency, the better the fmax (up to a point). Resource usage will be roughly the same, just increased register usage for higher pipeline length.As for fixed point division - just remember that fixed point is just integer arithmatic. For your lpm divide, you just need to offset your inputs to get the correct result. Lets look at the example - 4/0.125 = 32. 4 = 0100 0.125 = 001 >> 3. So instead of shifting 0.125 to the right by 3, shift 4 to the left by 3. So now you have 0100000 / 0000001 = 0100000 = 32. This will always work. 10 / 1.625 = 6 remainder 0.25 Shift 10 by 3: 1010000 /0001101 = 6 remainder 2 (which in this case is 0.25) What you are actually doing is appending a fractional position to the integer number. You are making both operands have the same number of bits where the bits align by 2^n.
OK, I understand how to use the shifting trick. Thanks.It is just that I know that adder/subtractor needs only limited logic elements, and multiplier can use a DSP block. So when I saw the logic usage by the divider I was shocked! Basically like multiplication is just shift and add, in contrast division is shift and subtract. Therefore, it does not make sense to me why it needs 100s of logic elements.