Engee documentation
Notebook

Simulation of an LC oscillator based on the Kolpits scheme

This example shows the implementation of a Colpits oscillator circuit with a nominal frequency of 9 MHz. The oscillation frequency is given by the formula:

LC oscillators have good frequency selectivity due to higher Q-factor levels compared to RC oscillators.

Model diagram:

lc_oscillator--1734963351199.png

Defining the function to load and run the model:

In [ ]:
function start_model_engee()
    try
        engee.close("lc_oscillator", force=true) # closing the model
        catch err # if there is no model to close and engee.close() is not executed, it will be loaded after catch.
            m = engee.load("$(@__DIR__)/lc_oscillator.engee") # loading the model
        end;

    try
        engee.run(m) # launching the model
        catch err # if the model is not loaded and engee.run() is not executed, the bottom two lines after catch will be executed.
            m = engee.load("$(@__DIR__)/lc_oscillator.engee") # loading the model
            engee.run(m) # launching the model
        end
end
Out[0]:
start_model_engee (generic function with 1 method)

Running the simulation

In [ ]:
try
    start_model_engee() # running the simulation using the special function implemented above
    catch err
    end;

Writing from simout to voltage signal variables:

In [ ]:
res = collect(simout)
V = collect(res[1])
Out[0]:
7001×2 DataFrame
6976 rows omitted
Rowtimevalue
Float64Float64
10.04.08249
21.0e-811.9085
32.0e-89.00624
43.0e-85.58947
54.0e-86.79576
65.0e-87.37572
76.0e-87.26239
87.0e-86.60988
98.0e-85.7106
109.0e-85.90388
111.0e-78.27166
121.1e-79.73887
131.2e-79.79918
69906.989e-59.92202
69916.99e-59.48484
69926.991e-59.03062
69936.992e-58.69916
69946.993e-58.59152
69956.994e-58.73975
69966.995e-59.09795
69976.996e-59.55646
69986.997e-59.97573
69996.998e-510.2294
70006.999e-510.2408
70017.0e-510.0048

Visualization of simulation results

In [ ]:
using Plots
In [ ]:
plot(V[:,1], V[:,2], label="Voltage, V", linewidth=2, title="LC Oscillator voltage")
Out[0]:
In [ ]:
plot(V[:,1], V[:,2], label="Voltage, V", linewidth=2, xlim=(4e-5, 4.1e-5), title="LC oscillator voltage for 1 microsecond")
Out[0]: