Using Behavioral Voltage/Current Sources in QSPICE for implementing this formula

Hello,

I would greatly appreciate any guidance you could provide on whether it’s possible to use behavioral voltage/current sources in QSPICE in order to replicate the below formula and plot? Thanks!

image
image


Your request is to have an output with sine wave where its frequency follows the control voltage, i.e. Vctrl=2V outputs a 2MHz sine wave, Vctrl=1V outputs a 1MHz sine wave?

So, bascially… a VCO?

Yes, its a VCO.

The request is to have an output with pulse wave where its frequency follows the control voltage, i.e. Vctrl=0V outputs a 2MHz pulse wave, Vctrl=0.4V outputs a 1.6MHz pulse wave, Vctrl=1V outputs a 1MHz pulse wave, Vctrl=2V outputs a 0MHz pulse wave.

I have a custom symbol VCO-SINE-PULSE.qsym for it (https://github.com/KSKelvin-Github/Qspice/tree/main/Symbols-KSKelvin/source/vco). Here is an example. I added a real-time PWM measurement symbol in this example to plot the frequency.
By using View > Netlist, you can study the B-source formula for this VCO;

V=sin(2*pi*idt(f0+Kvco*V(ctrl),0)+theta0*pi/180)>(sin((1-V(duty)*2)*pi/2))

Here is a reference for this method. : PFM (Pulse Frequency Modulation) with Adaptive Deadtime - QSPICE - Qorvo Tech Forum

VCO-B-source.qsch (7.4 KB)

1 Like

@Cornel ,

Here’s another simple solution using the idt() function in a B-source.
Vco.qsch (1.9 KB)

Hope this helps.

1 Like

Would you happen to know if there’s a way to convert this sine wave output (out) to a pulse wave?

Thank you …Would you happen to know if there’s a way to convert this sine wave output (out) to a pulse wave?

my version is pulse (can set duty too), did you check that?

Ok, I see now, thanks!

Are you looking for 50%DC?

Len

Then just use a comparator… :stuck_out_tongue:

Well… my custom symbol in above post uses a single formula with a compare operator “>” for the pulse VCO with duty control. Still missing something?

Of course, if TTOL timestep is required, a comparator ¥-Device must be added to it.
And I think if the VCO frequency spans a high dynamic range (e.g., from a few Hz to a few MHz), changing it to a DLL block where the maxstep is modified based on the frequency setpoint can optimize the timestep during simulation.

@Cornel,

Here’s a simple Vco with a squared output (~50%DC)


Vco(squared out).qsch (2.1 KB)
Len

Hello Cornel

I can see that you’ve chosen an answer but, there may be another solution: the builtin modulator. However, it doesn’t work quite as advertised in the help (or as in LTspice, almost). What I understand is that the voltage at the AM input works like this:

  • V(AM)=0.7 => +0.7*sin(x)
  • V(AM)=-1.2 => -1.2*sin(x), clipped at Vdd/Vss
  • V(AM)=0 => 0

But, what I see is that it takes the “0” point at Vss and its range is +/-1 from there, on: Vss+1 is max amplitude, Vss-1 is min (clipping above/below these values).

As for the frequency, the help says that 0 at the FM input means the output is at “space” Hz but, that only happens at V(FM) = Vss. Make mark > 0 and the output is zero. Also, be sure to keep the FM pin at Vss, not GND, or floating, or the simulation starts craaawwling. Maybe I should have sent this to Mike as a bug.

Otherwise, you have a one block solution there, as native as it gets: the frequency formula is space + V(FM) * (mark - space) so, if you want a linear mapping, use space = -1, mark = 0. For your case, use mark = 3meg, space = 2meg, which results in 2meg + V(FM) * (3meg - 2meg). And, if you want square pulses, just use V(AM) = 100 * Vdd or so. No need to reinvent the wheel (but, doing it will help you understand it better, aka engineering).

Vlad


(edit: corrected the formula)

Also, the frequency output seems to be influenced by the supplies so, again, Vss seems to be taken as the reference: V(FM) = 1 with Vss = -2 and mark = 2, space = 0 results in 6 Hz = 2 * (1 - (-2)). Also, V(AM) floating means increasing clipping, as if V(AM) = 0 (grounded behind the scene) means its value is V(AM) - Vss.

I still recommend it. If these are bugs, Mike will fix them and what will be left is a native element that does what you need.

About ¥-Device ULATOR – AM/FM Modulator



Hello Kevin

Yes, you’re just emphasizing that the reference is Vss, not GND, as is the case (and was for the past 20+ years) with LTspice’s, as is typically the case just about everywhere where bipolar supplies exist. If you’d want to generate controlling voltages from some device/element/etc you shouldn’t need to do level shifting, instead of comfortably generating them referenced to GND, as the whole ULATOR block is, bipolar supplies or not. The fact that the median output is the arithmetic average has nothing to do with it, in the same way that the same average for the threshold has no influence on the reference of the logic gates. I think it’s a bug, not a feature but, that’s up to Mike to declare it.

Vlad