I got error :”Derivative is infinite or NaN” when i use 'Fixed step'. What should I do?

bat.plecs (178.9 KB)

The model posted uses the fixed-step solver with a step size of 2e-6. However, the battery model has a low-pass filter with a time constant of 1e-9 which is incompatible with the step-size you’ve chosen. The error message points you directly to the transfer function component that implements the low-pass filter.

Changing to a variable-step solver resolves the error message in this case. I set the solver type to “auto” and it quickly detected this is a numerically stiff system.

If i must use the ‘fixed-step solver’,which value should i change?

You can set the fixed step size appropriately, but is there a reason why you must you a fixed step solver? It will force your simulation to run excessively slow and result in very high data storage requirements. I cannot see a motivation to use a solver that will be both slower and less accurate in this particular model.

Thank you. The RT-BOX must use fixed-step solver.

That’s correct. Your model isn’t configured with the RT Box target so I assumed you were performing an offline simulation.

This battery model is taken from another PLECS demo model and one should understand its implementation when applying it to other applications. Looking under the mask of the battery model, you can see that the 1e-9 low pass filter is used to break the algebraic loop associated with the current measurement. The current measurement is used to determine the current direction when modeling the polarizing resistance. However, you have the polarizing resistance disabled in your mask commands, therefore you can simply remove the entire signal chain. If you want to include polarizing resistance, then for a discrete time model one can simply use a one-sample delay using the current from the last time step. This assumes the current direction does not frequently change from positive to negative.

Also, modeling with a fixed-step solver is not the same as the code that will run on the RT Box. See this recent forum post for a brief discussion on the topic.