I am developing a core on Spartan 6 which needs to do divisions like 1/6,2/4 etc... so the values are always between 0 and 1. As I dont need the precision of floating point I am want to use a fixed point divider as division is costly. I found some dividers on opencores.org but all of them can computer normal division problems like 4/2,8/4 etc... well but cannot do 1/6 kind of operations. Can anyone point to a suitable divider for my application
Thank You
-
1\$\begingroup\$ Are the divisors constants or do they vary? \$\endgroup\$Joe Hass– Joe Hass2013年01月19日 17:54:33 +00:00Commented Jan 19, 2013 at 17:54
-
2\$\begingroup\$ What kind of bandwidth (results per second) and latency does your application require? I developed a pipelined divider that can deliver a result per clock @150 MHz, but that's because I needed to compute 1024 scale factors during the vertical blanking interval of a HD video stream. If you don't need that kind of bandwidth, there are other approaches that are less resource-intensive. My divider is in VHDL; it could be translated to Verilog (but not for free). \$\endgroup\$Dave Tweed– Dave Tweed2013年01月19日 17:56:35 +00:00Commented Jan 19, 2013 at 17:56
-
\$\begingroup\$ @JoeHass: If the divisors are constants, you don't need a divider at all; you just multiply by 1/x instead. \$\endgroup\$Dave Tweed– Dave Tweed2013年01月19日 17:59:20 +00:00Commented Jan 19, 2013 at 17:59
-
\$\begingroup\$ @DaveTweed: Yes, that's exactly why I asked. I've learned never to take anything for granted on stackexchange. \$\endgroup\$Joe Hass– Joe Hass2013年01月19日 18:01:06 +00:00Commented Jan 19, 2013 at 18:01
-
1\$\begingroup\$ Actually, even if the divisors vary, computing 1/x is a very viable approach if you don't need a result per clock. The Newton-Rhapson method just needs one multiplier to compute 1/x in a few clocks, and then one more multiply gets you your quotient. There are many commercial computers throughout history that have used exactly this method. \$\endgroup\$Dave Tweed– Dave Tweed2013年01月19日 18:12:02 +00:00Commented Jan 19, 2013 at 18:12
1 Answer 1
You say that you have found dividers that do "normal" division. Fixed-point division is normal division, except that the dividend must be scaled up (shifted left). Shift the dividend to the left 8 places (multiply by 256), then do a normal division. The fixed-point fractional result is equal to the integer result from the division, divided by 256. So, if you want to calculate 1/6 you will actually divide (1*256)/6, which is 42. The real result is therefore 42/256 = 0.1640625, which is reasonably close to the true value of 0.1666... We would normally say that this result is a fixed-point number with 8 bits to the right of the decimal point. If you want greater precision, use a larger scale factor.
-
\$\begingroup\$ My problem is if I do 1/4 with this divider I am getting zero as answer. Following your method if I do 256/4 I get 64. Again if I do 64/256 I would get zero because any division with numerator less than denominator is resulting in zero. What to do ? :( \$\endgroup\$8A52– 8A522013年02月19日 00:01:10 +00:00Commented Feb 19, 2013 at 0:01
-
\$\begingroup\$ You have to scale the dividend up. If you want to do integer division and have the result represent a fraction, you have to multiply the dividend by some power of 2 beforehand. \$\endgroup\$Joe Hass– Joe Hass2013年02月20日 02:55:26 +00:00Commented Feb 20, 2013 at 2:55
-
\$\begingroup\$ A bit of example code would help me a lot. I tried and tried but had no success at all. Please help me \$\endgroup\$8A52– 8A522013年03月07日 21:21:33 +00:00Commented Mar 7, 2013 at 21:21
-
\$\begingroup\$ If you are doing integer divisions then it is impossible to get a result that is not an integer. The key concept is how you interpret that integer. In your example above you would not try to divide 64/256, you would just recognize that the result is a fraction multiplied by the integer 256. \$\endgroup\$Joe Hass– Joe Hass2013年03月19日 21:40:19 +00:00Commented Mar 19, 2013 at 21:40