I was working on doing various calculations in fixed point math, but the so urces provide equations that are intended to be done in floating point. Th ere are squares and coefficients with 10^-6 and other items that make using fixed point a PITA. So I'm going to use floating point in the FPGA. It's actually not so hard. Many years ago I worked on a machine that did 32 bi t floating point math in hardware, so I know the basics. It's a bit odd th at addition takes more steps than multiplication as the exponents must be t he same value, so the lesser exponent must be adjusted up and the mantissa adjusted down before the add. Multiplication can be done without this adju stment. Both must be normalized after the operation, but the result of the multiply only ever needs adjusting by one bit position while the addition may need normalizing by the length of the mantissa.
The FPGA I'm working with has various limitation in the DSP MAC units that makes it a bit harder to use than I would like. The adder can be set for a ddition or subtraction, but not switched in real time. So I'm ditching the accumulator and only using the multiplier with an add/sub chain from the F PGA fabric. With that the floating point ops can be done in multiple cycle s each.
In the end this will be easier than trying to adjust all the calculations a nd coefficients to keep the fixed point calculations in a range that preser ves significant bits. In particular a flow sensor that requires a square r oot calculation involved a lot of detailed coefficients for various compens ation factors could have been very problematic in fixed point.
Fortunately the clock speed is not all that fast so it won't require the fu ll speed of the DSP block and external logic can be used to implement all t he operations of floating point. The calculations aren't all that involved and there are many clock cycles available so it won't be hard to configure this. I'm a bit disappointed the DSP block wasn't more useful. I found t hat in many configurations the accumulator output did not include the msb o f the actual register, but rather it either duplicated the next to msb or w as set to zero depending on the signed/unsigned setting of the output. Why calculate it and then not make it available? The user can always choose t o use it or not on their own, but if you don't give the choice...?