Which Is Correct Equation To Convert To C Embedded Code #1240
|
Hello community, I have a simple question that I hope you can help me with. When I print the compensator discrete transfer function, I get the following result: I now would like to convert it to usable C embedded code. Do I need to divide by z so that I obtain the transfer function in terms of If I assume I can work directly as is from the original printed compensator transfer function, then the difference discrete output function would be:
or, if I divide by
Can someone please clarify this small issue. Thank you. |
Replies: 5 comments
|
Solved. After a little digging, confirmed that I need to convert to |
|
Yes, the second recurrence is the correct one. Starting from divide both numerator and denominator by Cross-multiplying gives and therefore so the implementation is The first recurrence in the question is not equivalent: it swaps the current and previous error coefficients and changes their signs. A minimal floating-point update would look like: double u = u_prev + 31.5 * e - 28.5 * e_prev;
e_prev = e;
u_prev = u;The stored values must be initialized deliberately. For an actual actuator, also account for output saturation and integrator windup; otherwise the internal |
|
thank you for following up and confirming the results. Yes, I have accounted for saturation Cheers! |
|
Glad the derivation was useful. Since this is a Q&A discussion and it still appears as unanswered, would you mind marking the explanatory response as the accepted answer? That will make the resolved recurrence easier for future readers to find. |
|
No problemo. Thank you @AMBRA7592. Much appreciated. |
Yes, the second recurrence is the correct one.
Starting from
divide both numerator and denominator by
z. This does not change the transfer function; it only rewrites it using the unit-delay operator:Cross-multiplying gives
and therefore
so the implementation is
The first recurrence in the question is not equivalent: it swaps the current and previous error coefficients and changes their signs.
A minimal floating-point update would look like:
…