Hi,
I want to simulate a resonant DCDC converter (LLC) which uses frequency modulation as a way to regulate the output voltage.
I have a module in C which calculates the desired switching frequency fsw. Can you propose implementation methods for the variable frequency?
I have seen an approach using the C block where the simulation time variable is used but I wonder whether there’s a lighter implementation, maybe one that does not use the time variable.
TSW = 1 / fsw; //Switching period
t_var = t/TSW - floor(t/TSW); //this is a sawtooth with frequency = fsw
if ((t_var) < 0.5) output = 1
else output = 0;
The if part can be easily substituted by a behavioral voltage source although I don’t know what is lighter for the simulation.
Before, I was using a pulse voltage source and the simulation got more than 10 times slower.
After some optimization the code got as simple as:
product = t * fsw_ref;
VM = product - (int)product;
and this VM is the sawtooth which I compare externally with bv, but still is excessively slow.
Thanks and regards