I plan to simulate the current through a coil with flyback (or freewheel) diode for an arbitrary voltage signal (square or PWM modulated signal is possible).
You can find the circuit diagram over here: https://en.wikipedia.org/wiki/Flyback_diode#/media/File:Flyback_Diode.svg
My idea to use NDSolve worked out very well for my first step calculating the coil without the diode. I used:
res =
NDSolveValue[{l*i'[t] + r*i[t] == u[t], i[0] == 0},i, {t, timeStart, timeEnd}]
Where u[t] is a function that is not necessarily continuous (pulse width manipulation signal is possible), l stands for inductivity, r for Ohms resistance and i[t] for the current I am looking for.
My problems occur when I want to take the flyback diode into account. My first very simple approaches to use add a function like:
uFB[i_: 0, u_: 0] := If[i > 0 && u > 0, -1, 0];
It failed, producing the message:
NDSolveValue::smpf: Failure to project onto the discontinuity surface when computing Filippov continuation at time 0.`.
The message disappears when I use the option Method -> {"DiscontinuityProcessing" -> False}, but then the results I produce don't fit the physical behavior of the part (for example: setting the resistance to 0 and giving different values for the amount of uFB does not change the solution)
I also tried to find a solution using WhenEvent, but this was also not successful.
I am interested in any suggestions that might solve my problem.

