I set the sampling time of the C script as Ts and implemented a simple discrete PI controller. For the previous error value, the example indicates that it should be defined using DiscState and updated within the update function. However, I chose to define the previous error as a global variable in the code declaration section. I found that when updating it in the update function, the global variable seemed to be reinitialized to zero. What could be the cause of this behavior? Theoretically, if the sampling time is fixed, shouldn’t global variables and DiscState behave the same way?
Hi Jason, is it possible to share your model - it would make it easier to understand and responding to your question