Oddly-behaved behavioural voltage source

Thread Starter

Alec_t

Joined Sep 17, 2013
14,329
I was playing at generating a sine-wave oscillation in LTspice, supposedly with a frequency which rises then falls as a control voltage rises then falls. This is the result :-

1665948181043.png

The first half of the sim is as expected, but the second half is not a mirror image of the first half. Why not?
(Setting the maximum timestep to various values did not help).
 

WBahn

Joined Mar 31, 2012
30,072
The first half of the sim is as expected
Is it, really? What frequency do you expect it to be wiggling at at time = 2 s? 2 Hz, right? Between 1 s and 2 s it is wiggling at less that 2 Hz, right?

Yet how far back before 2 s do you have to go before you have two complete cycles? Looks like about 3/4 of a second, so it is wiggling at considerably more than 2 Hz well before you get to time = 2 s.
 

WBahn

Joined Mar 31, 2012
30,072
Hi Alex

You have to use idt() function so it tracks over time correctly.
Or use Modulate device.

View attachment 278633
So I understand this that this is calculating the phase angle over time, but it seems like there is an unintended hysteretic nature to it. By this, I mean let's say that we have to controlling waveforms, freq1(t) and freq2(t), Before some time, T1, they are different, but after time T1 they are constant and the same. If we have

v1 = A sin(2pi·freq1(t)·t)
v2 = A sin(2pi·freq2(t)·t)

Then, after T1, v1 = v2. Not only are they at the same frequency, but they are in phase.

But if, instead, we do

v1 = A sin( 2pi · integral{(freq1(t)·dt}_0^t) )
v2 = A sin( 2pi · integral{(freq2(t)·dt}_0^t) )

then they will be at the same frequency, but the phase will be determined by the difference in the histories of freq1(t) and freq2(t) prior to T1.

Am I correct in that?

For many applications it may not matter, but if you need to control the instantaneous phase of the waveform, how would you do it (using the math functions, not a special modulation block).
 

Thread Starter

Alec_t

Joined Sep 17, 2013
14,329
You have to use idt() function so it tracks over time correctly.
Thanks for the fix.
I realise that a varying frequency parameter is not ideal for the sine function calculation and clearly will generate sine distortion and phase anomalies, but the reason why decreasing that parameter results in an increase in the sine frequency in the latter half of my sim still eludes me. Then again, the inner workings of Spice in general are beyond my pay grade :).
Am I correct in that?
I think so.
if you need to control the instantaneous phase of the waveform, how would you do it (using the math functions ....)
I understand the behavioural sources allow phase to be specified, but I've never used that feature.
 

Thread Starter

Alec_t

Joined Sep 17, 2013
14,329
Thanks for confirming.
Further investigation of the original sim shows that the oddity arises when the commanded rate of decrease of frequency is greater than 0.5Hz per sec.
 
Top