Sawtooth waveform isn't straight

I’ve implemented a sawtooth PWM just like in Marcos Alonzo’s video, but the duty cycle is not uniformly 50%. The sawtooth also shows some irregularities. Anyone know why? I reduced the maxstep already.

RPP_part1.qsch (17.2 KB)
rpp_part1_x1.cpp (1.5 KB)

Here are the changes I made. I noticed that you uploaded a schematic with a DLL block that added a parameter (float frq), which caused some issues. I deleted that and re-created the template.

  1. There is no syntax like “.tran 300/frq MaxStep=.1u” because “maxstep” is an option. If you need to generate a sawtooth waveform from the DLL block, you must ensure that “maxstep” is much smaller than the operating frequency and use the correct syntax to make it effective.
  2. This schematic needs to be run with Qspice80.exe, or it may return “timestep is too small” error. You can disable fast math in the preferences, or added “.option fastmath=0” to achieve that.

RPP_part1_modify.qsch (17.3 KB)
rpp_part1_x1.cpp (1.5 KB)

I used your suggestion here for the frq param input. What did I do wrong?

I kept my original circuit and code block and added .option MAXSTEP=1/frq/1000 to the schematic, and now it works as intended. With the frq param too.