Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug using clipping opamp model #35

Closed
lkoeper opened this issue Dec 11, 2020 · 1 comment · Fixed by #36
Closed

Bug using clipping opamp model #35

lkoeper opened this issue Dec 11, 2020 · 1 comment · Fixed by #36
Labels

Comments

@lkoeper
Copy link

lkoeper commented Dec 11, 2020

Using the clipping opamp model in a circuit description throws a MethodError when calling the method DiscreteModel.

circ=@circuit begin
    j_in=voltagesource()
    R1=resistor(10e3)
    R2=resistor(100e3)
    A=opamp(Val{:macak}, 1000, -4, 4)
    #A=opamp()
    j_out=voltageprobe()

    j_in[+]==R1[1]
    R1[2]==R2[1]==A["in-"]
    R2[2]==A["out+"]==j_out[+]
    A["in+"]==A["out-"]==j_in[-]==j_out[-]
end

model=DiscreteModel(circ, 1/fs)

The error is:
LoadError: MethodError: no method matching dcat(::Float64, ::StaticArrays.SArray{Tuple{0,0},Float64,2,0})

@martinholters
Copy link
Member

I think the fix is simple:

--- a/src/elements.jl
+++ b/src/elements.jl
@@ -527,6 +527,7 @@ Pins: `in+` and `in-` for input, `out+` and `out-` for output
             vi_scaled = vi * (gain/scale)
             res = @SVector [tanh(vi_scaled) * scale - vo]
             J = @SMatrix [gain / cosh(vi_scaled)^2 -1.0]
+            return (res, J)
         end
     return Element(mv=[0 0; 1 0; 0 1], mi=[1 0; 0 0; 0 0], mq=[0 0; -1 0; 0 -1],
                    u0=[0; 0; offset],

But the fact that this has gone unnoticed for so long indicates that this is also missing test coverage...

martinholters added a commit that referenced this issue Dec 11, 2020
Somehow this was missing the `return` which rendered it unusable...
Fixes #35.
martinholters added a commit that referenced this issue Dec 11, 2020
Somehow this was missing the `return` which rendered it unusable...
Fixes #35.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants