Hello, it's me again with my FPGA adventures, learning VHDL by practicing it.
Today I have tried to implement a PSD controller (just PS to be specific). Being bit more knowledgeable I have gone straight to the incremental form to spare myself the pain experienced by many others. PS controller difference equation should be:
y(n) = y(n-1) + A0*x(n) + A1*x(n-1)where the transformed coefficients shall be
A0 = Kp + Ki
A1 = KpI have tried to implement it using just my own ideas cobbling together some state machine, that should go through the equation step by step. But that failed miserably, making the horrendous mess you can see attached. Very resource hungry and very ineffective. After seeing what my original code has synthesized to, I have realized it would be better to start from scratch and think a bit more before writing some code, rather than doing it the other way round.
After bit of paper + pencil + brain time, I came up with this circuit idea below. The idea is to have a 16bit precision input/output controller, with an internal 32bit accumulator. Following the equation mentioned above, it seems to me, the whole PS controller can be calculated in just two multiply-accumulate steps, using the same 32bit adder and the same 16x16 multiply, just by multiplexing the inputs to the multiplier.
That way I think I can get the best resource usage and a sensible implementation that will probably also work. Also, it would be handy to add intermediate registers around the multiplier to speed stuff up, but those were omitted for clarity (and I do not need that much speed anyway).
The register on the left side is the z
-1 representing the
x(n-1) term.
The whole then shall be controlled by a simple state machine: Either idle (waiting to trigger the calculation), or then in the two states of calculating the two products of
A0*x(n) and
A1*x(n-1).
The question is, is this a sensible approach or not and why?
I have tried at first to find a suitable beginner tutorial, but I only mostly find it implemented in the most ugly way that could compete with my original one.
//EDIT: Ugly typos.