Author Topic: LTspice IF statement syntax  (Read 7511 times)

0 Members and 1 Guest are viewing this topic.

Online FaringdonTopic starter

  • Super Contributor
  • ***
  • Posts: 2069
  • Country: gb
LTspice IF statement syntax
« on: February 04, 2024, 01:36:06 pm »
Hi,
The attached doesnt work in changing the duty cycle. Do you know the "IF"  syntax which will unlock the required action?
'Perfection' is the enemy of 'perfectly satisfactory'
 

Offline berke

  • Frequent Contributor
  • **
  • Posts: 258
  • Country: fr
  • F4WCO
Re: LTspice IF statement syntax
« Reply #1 on: February 04, 2024, 01:51:47 pm »
You can't change the parameters of a PWL dynamically, but you can do what I think you're trying to do using a behavioural voltage source like this.
2002726-0
 
The following users thanked this post: Faringdon

Offline Kean

  • Supporter
  • ****
  • Posts: 2139
  • Country: au
  • Embedded systems & IT consultant
    • Kean Electronics
Re: LTspice IF statement syntax
« Reply #2 on: February 04, 2024, 02:29:24 pm »
I don't think the IF math function can be used just on its own, so you need to use it as part of the .param definition or as the expression on a behavioral voltage source.
 
The following users thanked this post: Faringdon

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19659
  • Country: gb
  • 0999
Re: LTspice IF statement syntax
« Reply #3 on: February 05, 2024, 06:47:55 pm »
Use a comparator to generate the PWM. The UniversalOpamp2 model can be used to make an ideal comparator. Note I upped the gain, slew rate and GBWP to mimic a very high speed comparator.
 
The following users thanked this post: Faringdon

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14717
  • Country: fr
Re: LTspice IF statement syntax
« Reply #4 on: February 06, 2024, 12:12:07 am »
You can't step a *parameter* during simulation as far as I know anyway. Parameter stepping triggers a different simulation for each value and gathers all results after that.
Use a behavioral voltage source instead to implement this, and look at the list of all functions available for these.
 
The following users thanked this post: Faringdon

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12936
Re: LTspice IF statement syntax
« Reply #5 on: February 06, 2024, 05:02:39 pm »
Yep, anything in braces (required for .param parameter usage) is evaluated before the individual simulation run starts and treated as a constant for the duration of that run.  .step causes multiple runs, changing the parameter before each.

Only behavioral* component's user defined expressions are evaluated at each timestep during each run.  Note that if the expression is discontinuous or to a lesser extent has a discontinuous derivative, the simulation is likely to drastically slow down near each discontinuity.

I posted an example of how to do voltage controlled PWM here:
https://www.eevblog.com/forum/eda/ltspice-pwm-input-signal-creation-for-motor-soft-start/
Its very similar to Zero999's suggestion above.

* Documented: behavioral voltage and current sources; Undocumented: behavioral resistors
« Last Edit: February 06, 2024, 05:08:04 pm by Ian.M »
 
The following users thanked this post: Faringdon

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19659
  • Country: gb
  • 0999
Re: LTspice IF statement syntax
« Reply #6 on: February 06, 2024, 10:37:44 pm »
I tried the differential Schmitt and the rise/fall times were slow. Changing trise and tfall to 10ns didn't help. I tried setting tau to 10n, but the made the output over/undershoot.
 
The following users thanked this post: Faringdon


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf