5
\$\begingroup\$

I'm wondering if anyone has already done this, to save me going down some rabbit hole.

I'm trying to make a pwm that is initially on 100% for some X period of time, then changes to some Y duty cycle at around 40kHz. I know I could make a PWL file, but that seems way too tedious, for doing things on ~100ms+ timelines.

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
1
  • \$\begingroup\$ Make x (simple) PWM as more you need. Then add and/or multiply the waves as needed. \$\endgroup\$
    – Antonio51
    Commented Aug 18, 2022 at 17:47

3 Answers 3

7
\$\begingroup\$

You can do that with a regular pulse as long as the duty cycle and frequency are going to be constant.

  1. Set Vinitial to whatever your high voltage is.
  2. Set Von to 0 V
  3. Set Tdelay to the delay you want at the beginning
  4. Set Tperiod to the length of one cycle at the frequency you want
  5. Set Ton to the portion of the period you want the waveform to be low to get the duty cycle you want.
  6. You might want to change the rise and fall times to something other than the default values.

So if you wanted 40 kHz at 90% duty cycle you would use 25 \$\mu\$s period and 2.5 \$\mu\$s on time so that it is high for 22.5 \$\mu\$s and low for 2.5 \$\mu\$s.

enter image description here

\$\endgroup\$
5
  • \$\begingroup\$ This is exactly why I asked. I was overlooking the simple path. Thanks! \$\endgroup\$
    – Aaron
    Commented Aug 18, 2022 at 17:49
  • 2
    \$\begingroup\$ Not a fan of setting rise and fall to zero. You should always define them since LTspice replaces the zeroes with unknown values it picks itself, which are based on the timesteps it calculates internally. \$\endgroup\$
    – Ste Kulov
    Commented Aug 19, 2022 at 2:57
  • 2
    \$\begingroup\$ @SteKulov If tr, tf are not specified then the formula is min( T - Ton, Ton ) / 10. \$\endgroup\$ Commented Aug 19, 2022 at 6:06
  • \$\begingroup\$ @SteKulov I just went with the defaults and left them blank in the example, it must have filled them in with zeros. Added the suggestion to set them in the answer. \$\endgroup\$
    – GodJihyo
    Commented Aug 19, 2022 at 6:16
  • 1
    \$\begingroup\$ @GodJihyo You'll need to change the last part to say: 2.5 us = Ton + (tr + tf)/2. Also, it's \$\mu\text{s}\$ (seconds), not \$\mu\text{S}\$ (Siemens). \$\endgroup\$ Commented Aug 19, 2022 at 6:19
4
\$\begingroup\$

One thing you could do is do two pwm's and then use another switch or something to switch between them at a given time.

Another option would be to have one turn off and then the other turn on, then add the outputs together with a b-source

enter image description here

\$\endgroup\$
4
  • \$\begingroup\$ For adding them together with behavioral voltage source, do you just set V=V1+V2? \$\endgroup\$
    – Aaron
    Commented Aug 18, 2022 at 17:56
  • \$\begingroup\$ Yeah, you can use functions in a bv source. But it's v = V(V1)+V(V2), you have to specify if you want the current of the netname or the voltage from the netname \$\endgroup\$
    – Voltage Spike
    Commented Aug 18, 2022 at 18:11
  • \$\begingroup\$ LTSpice is fun! So turns out you can't pick the voltage V(V1) like that (But you can for current I(V1) ). To get the voltages I had to use the net name on the positive terminal. So V=V(hold)+V(pick) \$\endgroup\$
    – Aaron
    Commented Aug 18, 2022 at 18:16
  • \$\begingroup\$ Yeah, provided a picture so its easier to understand. You can also use the delays an ncycles to provide some control when the PWM's turn on and off. \$\endgroup\$
    – Voltage Spike
    Commented Aug 18, 2022 at 18:34
4
\$\begingroup\$

If you need a fixed duty cycle PWM then the two solutions above will suffice but, if your aim is to have a time-variable PWM then a simple source will not be sufficient:

PWM with delay

V1 acts as the ramp generator and V2 as the controlling DC signal, A1 is the comparator. It's a PWL() source that starts with a value of 1.1 V for 0.1 s, then switches to 0.1 V in 1 us, and then goes on in a ramp until 0.9 V at 1 s. The two OTAs above, A2, A3, form a 2nd order Bessel with fc = 5 Hz, filtering V(out) to show that it does, indeed, vary as V(DC) dictates (shown as the red and blue traces). For the comparator, vt, vh are the threshold and hysteresis settings, vhigh, vlow self-explanatory, and tau, tripdt are temporal helpers to help preserve the sharpness of the edges while avoiding slowing down the simulation.

TLDR: as long as V(DC) is greater than the ramp, the output will be logic 1 (and logic zero if it's less than the ramp). Anything in-between will generate the PWM. It's flexible and allows for a dynamic modification of the output.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ My primitive brain can't wrap around how you did the Bessel with the OTAs. \$\endgroup\$
    – Ste Kulov
    Commented Aug 18, 2022 at 19:09
  • 1
    \$\begingroup\$ @SteKulov It's derived from the middle one (bottom Laplace for confirmation). Also see this file, it's exactly the same approach, only since this one has no zeros, the a coefficients are eliminated in favour of a differential input for the first OTA. \$\endgroup\$ Commented Aug 18, 2022 at 19:42
  • \$\begingroup\$ Nice post, Looks Fancy... \$\endgroup\$
    – Voltage Spike
    Commented Aug 19, 2022 at 0:17
  • \$\begingroup\$ @VoltageSpike Thank you, hopefully it's also useful. \$\endgroup\$ Commented Aug 19, 2022 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.