Generate chirp signal in Kicad

Is it possible to generate a voltage source that sweeps linearly over a range of frequencies, i.e.: a linear chirp? I’m trying to simulate the ‘sweep’ signal that some function generators have. see attached image.
Thanks,
-May
290px-Linear-chirp.svg|290x194

I am not aware of a readily available linear sweep generator.

As a first trial you might investigate the FFM voltage source (see chapt. 4.1.5 of the ngspice manual). This will give you a sinusoidal modulation of your frequency. And if you use a controlling signal with a very low frequency and a suitable phase offset, then you might explore the “quasi linear” portion of the controlling sine wave.

Best if you make a circuit comprising of the FFM source (library Simulation_SPICE:VSFFM) and run some transient simulations with varying parameters, to see if this somehow fits your needs.

If it is not sufficient, you may construct a chirp generator by assembling a subcircuit with appropriate ngspice components and attach this to a suitable KiCad symbol. First of all you would need to define some specifications, e.g. start time, stop time, start frequency, and stop frequency. Then we need a VCO, for example the ngspice code model 12.2.20 Controlled Sine Wave Oscillator. And we have to control it by a time based voltage ramp, made for example by a pwl voltage source (chapt. 4.1.4 of the ngspice manual).

Ngspice can work with Gnu Octave
Octave can generate chirps easily.
http://ngspice.sourceforge.net/octavespice.html
and
https://wiki.octave.org/Ocs_package

My littel project of a chirp generator with Eeschema/ngspice:

* chirp generator by Holger Vogt
* public domain
* bt start time, et end time of chirp
* bf start frequency, ef end frequency of chirp
* code model 'sine' will not accept control value 0, so 1e-12 is used
* r=0 will lead to repeated chirp pattern, cannot be parameterized, so
*    has to be removed if a single shot only is required
* to be called by 'XChirp pp 0 chirp bf=1k ef=10k bt=80m et=120m'
.subckt chirp p m params: bf=200 ef=2k bt=30m et=100m
* Start at t=0 with 1e-12, ramp up to t=et-bt with output et, ramp down
*      to 1e-12 after another 5% of ramp up time (to catch output 0 again).
*      Delay the whole pattern by bt 
vcont cc 0 dc 1e-12 pwl ( 0 1e-12 {et - bt} {et} {(et - bt) * 1.05} 1e-12 td={bt} r=0 )
* amplitude is set by out_low, out_high
asine cc %vd(p m) in_sine
.model in_sine sine(cntl_array = [ 0 {bt} {et} ]
+ freq_array=[ 0 {bf} {ef} ] out_low = -5.0
+ out_high = 5.0)
.ends

Symbol was generated by checking out Simulation_SPICE:VSIN and adding to it the subcircuit model found in chirp.lib fromChirp.zip (4.0 KB).

2 Likes

Thanks David. I’m not familiar with Octave.

Thanks a lot Holger. This looks very much like what I need. I’m new to KiCad, and circuit simulation in general. I downloaded the zip file you had attached and added the chirp-test-chache.lib file to the symbols library. The other lib file threw an error. Next, I tried to replicate the schematic, but I don’t have a VSIN-CHIRP component. When I search with ‘chirp’ in the component list, I see the chirp library and the Simulation_SPICE:VSIN component. I selected it and tried to edit its SPICE model, but didn’t know which file to select as model? Should there be a .mod file?
Again, taking my baby steps here :slight_smile:

Place Simulation_SPICE:VSIN
Double click to open ‘Symbol Properties’ Window --> Edit Spice Model --> Select File -->chirp.lib–>Type: Subcircuit
In line Model: you now have ‘chirp’. Add 'bf=1k ef=3k bt=30m et=70m ’ to get
chirp bf=1k ef=3k bt=30m et=70m
–> ok
In ‘Symbol Properties’ Window, set line ‘Value’ to ‘VSIN-CHIRP’ --> ok

2 Likes

Thanks a ton Holger! Got it to work :slight_smile:
and I guess I can change the amplitude by changing the out_low and out_high paramters inside the chirp.lib file.
Thanks again,
-May

1 Like

You can parameterize the amplitude in the LIB file too. That way you don’t have to keep changing it.

* chirp generator by Holger Vogt
* modified by Ste Kulov, so he might've screwed it up, proceed with caution
* public domain
* bt start time, et end time of chirp
* bf start frequency, ef end frequency of chirp
* amp amplitude of chirp
* code model 'sine' will not accept control value 0, so 1e-12 is used
* r=0 will lead to repeated chirp pattern, cannot be parameterized, so
*    has to be removed if a single shot only is required
* to be called by 'XChirp pp 0 chirp bf=1k ef=10k bt=80m et=120m amp=1.0'
.subckt chirp p m params: bf=200 ef=2k bt=30m et=100m amp=5.0
* Start at t=0 with 1e-12, ramp up to t=et-bt with output et, ramp down
*      to 1e-12 after another 5% of ramp up time (to catch output 0 again).
*      Delay the whole pattern by bt 
vcont cc 0 dc 1e-12 pwl ( 0 1e-12 {et - bt} {et} {(et - bt) * 1.05} 1e-12 td={bt} r=0 )
* amplitude is set by out_low, out_high
asine cc %vd(p m) in_sine
.model in_sine sine(cntl_array = [ 0 {bt} {et} ]
+ freq_array=[ 0 {bf} {ef} ] out_low = {-amp}
+ out_high = {amp})
.ends
1 Like

That is way more convenient. Thanks Ste! :slight_smile:

Dear Holger
I’m trying to get familiar with this chirp generator. I can’t get it to work. I added the library simulation-spice. and I did what you told about editing spice model. After running simulation i get zero for both current and voltage of resistor.
this is the log I get:

Circuit: KiCad schematic
Error on line 0 :
a.xv1.asine xv1.cc %vd /out 0 xv1:in_sine
MIF-ERROR - unable to find definition of model xv1:in_sine
Warning: Model issue on line 0 :
.model xv1:in_sine sine(cntl_array=[0 2.99999999999999989e-02 7. …
Unknown model type sine - ignored
Reducing trtol to 1 for xspice ‘A’ devices
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
Initial Transient Solution

Node Voltage


xv1.cc 1e-12
/out 0
v.xv1.vcont#branch 0
Reference value : 0.00000e+00
No. of Data Rows : 20014

Thanks very much…

This message is typical for an Eeschema/ngspice installation problem. The code models are missing or are not found.

What are your operating system and your KiCad version?

2 Likes

I’m on Debian Buster and KiCad 5.0.2.

Would you mind to update?

In buster backports you will find KiCad 5.1.9 with ngspice-34.

2 Likes

I will. And I will report whether the problem is solved or not.
Thanks very much.

By updating the ngspice engine, my problem is solved. Thanks, dear Holger.

2 Likes