The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Modeling >> Behavioral Models >> Oscillator Modelling by Dipolar Method
https://designers-guide.org/forum/YaBB.pl?num=1601054947

Message started by Vitor on Sep 25th, 2020, 10:29am

Title: Oscillator Modelling by Dipolar Method
Post by Vitor on Sep 25th, 2020, 10:29am

Hello everyone,

I'm currently working on a 32768kHz oscillator and I found some papers/articles/manuals regarding this dipolar method to speed up the simulation (example attached).

I'm kinda stucked in the nonlinear equation solvering mentioned in those texts but, in the aforementioned link, the author says that it is possible to use a verilog-a model to deal with it.

I tried to do this but, since I'm kinda beginner in verilog-a modelling, I was not able to model it. Can anyone help me?

Thank you and regards,
Vitor

Title: Re: Oscillator Modelling by Dipolar Method
Post by Vitor on Sep 25th, 2020, 11:10am


Vitor wrote on Sep 25th, 2020, 10:29am:
Hello everyone,
I tried to do this but, since I'm kinda begginer in verilog-a modelling, I was not able to model it. Can anyone help me?


Adding how I tried to do this modelling below:

First of all, I tried to implement a rms algorithm to extract the amplitude of the current and then used it to solve the polinomials for R(ampl) and L(ampl).

Find below my (unsuccessful) atempt to implement it in Verilog-A.

[EDITED]I realized that I commited a typo that was violationg Nyquist's sampling principle. Below a new approach just for the nonlinear resistor. Unfortunatelly, it is not behavioring as I expected yet.

`include "constants.vams"
`include "disciplines.vams"

module Zd_model(p,m);

//----------------Pins Declaration-------------------//
inout p,m;

electrical p,m;
//---------------------------------------------------//

//---------------------Variables---------------------//
real R,A1,A0,SUM,X,vr,ir;
localparam real period=1/32768;
localparam real speriod=period/(10*128);
localparam real speriodd=period/128;
integer N;
//============================//

analog begin

     @(initial_step) begin

           A0=0;
           SUM=0;

     end

     @(timer(0,speriod)) begin

           A1=I(p,m);
           SUM=0.5*(pow(A0,2) + pow(A1,2))+SUM;
           A0=A1;
           N=N+1;

     end

     @(timer(0,speriodd)) begin

           X=sqrt(2)*sqrt(SUM/N);
           SUM=0;
           N=0;
           R=-307034+X*(-2e11+X*(5e18+X*(-4e24+X*(-2e31+X*(5e37+X*(-3e43))))));

     end

     ir=I(p,m);
     vr=ir*R;

     V(p,m)<+vr;

     $bound_step(speriod);
end
endmodule


Thank you and regards,
Vitor

Title: Re: Oscillator Modelling by Dipolar Method
Post by Ken Kundert on Sep 26th, 2020, 2:39pm

What is going wrong?

-Ken

Title: Re: Oscillator Modelling by Dipolar Method
Post by Vitor on Sep 28th, 2020, 11:22am

Hi Ken,

Thank you for your answer.

As I said in my post, I'm trying to implement this resistor varying according to the current amplitude.

When I perform a simulation to validade the model mentioned above, I'm not getting the resistance I expected according to the function R (verilog-a model available in my second post).

For example, for a current amplitude of 10nA (X=10nA):

R=-307034+X*(-2e11+X*(5e18+X*(-4e24+X*(-2e31+X*(5e37+X*(-3e43)))))) = -307034 Ohms

But, simulating that, I'm getting a resistance about 1586826243911 Ohms.

Then, I don't know if my mistake is in the attempt to extract the current amplitude (routine implemented with the two timer functions) or in some other point.

To perform the aforementioned test, I'm applying a sinusoidal current with a frequency of 32768Hz and an amplitude of 10nA in parallel with the model. Then, I'm getting the FFT from both the current and the voltage drop at the resistor model and, at last, I'm getting the real part of the quotient between the voltage and the current, both of them at 32768Hz.

Do you have any advice/suggestion to helping me to solve this issue? Please let me know if I was not clear in any point of my explanation.

Thank you and regards,

Vitor

Title: Re: Oscillator Modelling by Dipolar Method
Post by Ken Kundert on Sep 29th, 2020, 6:49am

This may be a simple debugging issue. I recommend that you print/plot your variables, especially R, and see if you are getting the values you expect.

I see two other confounding issues. First, the resistance appears to change every 128 cycles.  If your FFT spans these changes then you will be measuring some kind of average resistance rather than the instantaneous resistance., which is what you calculated by hand.

Also, are you sure speriod should be 1280 cycles and speriodd be 128 cycles. Perhaps those two values should be swapped?  It seems like the way it is SUM will be 0 90% of the time.

-Ken

Title: Re: Oscillator Modelling by Dipolar Method
Post by Vitor on Sep 30th, 2020, 5:21am

Hi Ken,

Thank you very much for your response!


Ken Kundert wrote on Sep 29th, 2020, 6:49am:
This may be a simple debugging issue. I recommend that you print/plot your variables, especially R, and see if you are getting the values you expect.


You hit the bull's-eye :) ! Debugging the model, I realized that it was not entering in the timer routine.

Looking more carefully, I noted that, despite their declaration, the compiler was interpreting period and consequently speriod as integer variables, assigning 0 for both of them.

This issue was fixed adding .0 to the numbers used to those variables calculations.


Ken Kundert wrote on Sep 29th, 2020, 6:49am:
I see two other confounding issues. First, the resistance appears to change every 128 cycles.  If your FFT spans these changes then you will be measuring some kind of average resistance rather than the instantaneous resistance., which is what you calculated by hand.


That was a very usefull observation. I took care of it, thank you.


Ken Kundert wrote on Sep 29th, 2020, 6:49am:
Also, are you sure speriod should be 1280 cycles and speriodd be 128 cycles. Perhaps those two values should be swapped?  It seems like the way it is SUM will be 0 90% of the time.


In fact, speriod is (1/1280) cycles and speriodd is (1/128) cycles. I believe there was a misreading here. Anyway, I changed it a little bit, adding an if statement inside the timer routine to do the operation of speriodd given a specific N. Now it seems to work perfectly.

Again, thank you very much for your help!

Kind regards,

Vitor

Title: Re: Oscillator Modelling by Dipolar Method
Post by Ken Kundert on Sep 30th, 2020, 3:13pm

Ah yes. The integer division problem strikes again.

The Designer's Guide Community Forum » Powered by YaBB 2.2.2!
YaBB © 2000-2008. All Rights Reserved.