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

Add potentiometer component #122

Closed
tomhajjar opened this issue Jul 22, 2022 · 24 comments
Closed

Add potentiometer component #122

tomhajjar opened this issue Jul 22, 2022 · 24 comments
Milestone

Comments

@tomhajjar
Copy link

tomhajjar commented Jul 22, 2022

Is a potentiometer in a future release? Since log or alternate taper pots are pretty much gone today a simple linear one would suffice. The ability to alter resistance via a variable would be a plus.

@ra3xdh
Copy link
Owner

ra3xdh commented Jul 22, 2022

No, I don't planning to add potentiometer device. Qucs-S has no interactive simulation mode so the potentiometer will be not so useful. For Ngspice it's need to emulate potentiometer using the connection of two resistors and define its resistances using the variable. It will be not easy to use this combined device in parameter sweep, because the parameter sweep is implemented using the alter command which cannot directly sweep variables. But I am planning to add a Tuner feature that can resolve some tasks for potentiometer. There was an unfinished tuner PR for Qucs Qucs/qucs#471 it's possible to backport it into the Qucs-S.

@tomhajjar
Copy link
Author

I did some experimenting trying to get a potentiometer to work. Having issues passing multiple "W" values via Parameter Sweep. Not sure how to use .PARAM to do it.

Potentiometer_Test_prj.zip

@ra3xdh
Copy link
Owner

ra3xdh commented Jul 30, 2022

The .PARAM section has effect only before the simulation. It is not passed to .control .. .endc section of the netlist, so it will not help you. The problem with potentiometer implementation comes from this fact that Ngspice has no separte parameter sweep analysis type (like .SW for Xyce) And Qucs-S needs to emulate the parameter sweep using auto-generated Nutmeg script. See https://github.com/imr/ngspice/blob/master/examples/various/param_sweep.cir for example. The alter command accepts only a single device and doesn't accept variables. It is fundamental limitation of the Ngspice. Probably something will be changed in the future, because Ngspice team is currently working on .SW simulation type. The similar problem exists with sweep and vector parameters like SIN source #53

So you can sweep only device but not variable. Your schematic will not work and you need only to write a custom nutmeg script (Simulation->Nutmeg script device). Something like this. There is no other way to get the variable sweep with Ngspice.

let start_w = 0.1
let stop_w = 0.9
let delta_w = 0.1 
let w_act = start_w
let rpot = 1k
* loop
while w_act le stop_w
  let  r1_act = (1-w)*rpot 
  let r2_act = w*rpot
  alter r1 r1_act
  alter r2 r2_act
  tran 0.1m 5m
  write dc-sweep.out v(out)
  set appendwrite
  let w_act = w_act + delta_w
end

@tomhajjar
Copy link
Author

I'm missing something. Tried multiple changes but no Bueno

Potentiometer_Test_prj.zip
.

@ra3xdh
Copy link
Owner

ra3xdh commented Jul 30, 2022

There was a typo in the script. This schematic works as expected.
image
image

@tomhajjar
Copy link
Author

Hate to beat a dead horse....

Something is either either wrong with my Nutmeg script or I am doing something wrong. I cannot reproduce your plot even though the console output shows "Vout" is correct, 0.1, 0.2...0.9. Netlist doesn't work running under the DuSpice GUI either

  1. Is file dc-sweep.txt a temporary file? I can find Potentiometer_Nutmeg_custom.txt but not dc-sweep.txt.
  2. Why is w_act saved twice and r1_act not saved at all in the netlist? -> Potentiometer_Nutmeg_custom.txt V(Vout) VPr1#branch w_act r2_act w_act

Potentiometer_Test_prj.zip

@ra3xdh
Copy link
Owner

ra3xdh commented Aug 1, 2022

The node name Vout doesn't match the node name in the script out. You need either to change node name on schematic or in script. This line should be:

write dc-sweep.txt v(vout)

Why is w_act saved twice and r1_act not saved at all in the netlist?

Automatic variables recognition may fail sometimes. Just append the missing variables to the semicolon separated list manually.

@ra3xdh
Copy link
Owner

ra3xdh commented Oct 4, 2022

Assume this issue has been resolved. Closing ticket.

@ra3xdh ra3xdh closed this as completed Oct 4, 2022
@ra3xdh
Copy link
Owner

ra3xdh commented Nov 28, 2023

It makes sense to add potentiometer after implementation of the tuner feature and adding alterparam support. Reopening this. The potentiometer device is planned for the next release.

@ra3xdh ra3xdh reopened this Nov 28, 2023
@ra3xdh ra3xdh added this to the 24.1.0 milestone Nov 28, 2023
@tomhajjar
Copy link
Author

tomhajjar commented Nov 30, 2023

I know this isn't what is needed, but I recreated the Verilog Potentiometer component used in Qucs 0.0.19. The symbol files may be useful for a ngspice compatible potentiometer.

Qucs doesn't allow using the same component name in a project as a "native" component. I had to rename potentiometer.va to variable_resistor.va.

2023-11-30_171323

Verilog-A_Potentiometer_prj.zip

@ra3xdh
Copy link
Owner

ra3xdh commented Dec 1, 2023

The related work should be done in C++ level. It's need to provide a SPICE entry for potentiometer like it was done for INDQ and CAPQ. The symbol for this device already exists, but is hidden as SPICE-incompatible.

ra3xdh added a commit that referenced this issue Dec 1, 2023
@ra3xdh
Copy link
Owner

ra3xdh commented Dec 1, 2023

I have added SPICE entry for the potentiometer. This device will be available since the next release.

@ra3xdh
Copy link
Owner

ra3xdh commented Dec 1, 2023

image

@ra3xdh ra3xdh closed this as completed Dec 1, 2023
@BURN-MICROSUCK
Copy link

Yesssss THANK YOU SO MUCH kind sir!!! Any estimate when will the next update be available? ...and/or can i clone/checkout the source code with potentionmeter from git right now?

@ra3xdh
Copy link
Owner

ra3xdh commented Dec 1, 2023

I am planning to make an update in January or February. Yes, you may compile the current branch for git. It contains the new device.

@BURN-MICROSUCK
Copy link

Hello, i just compiled current branch, it does indeed have the potentiometer device but it's not possible to wire it, i think because the pins don't "align" to the grid. I was able to get the wires to cross once and it stayed connected, but this is unusable. How can i fix this?

@ra3xdh
Copy link
Owner

ra3xdh commented Dec 6, 2023

@BURN-MICROSUCK Use right click on the device and then "Align to grid" from the context menu. It is a known issue. See #92

@BURN-MICROSUCK
Copy link

BURN-MICROSUCK commented Dec 6, 2023

Thanks again. Another issue i'm facing is that capacitors don't filter like they're supposed to. Doing a quick test circuit that uses an op-amp to mix 3 sinewaves at different frequencies (100Hz, 1KHz, 10KHz) the shunt cap (output to ground) should filter out nearly all of the 10KHz signal, see screenshot:

https://imgur.com/a/uTVWF5D

I'm presuming the same would go for inductors in series and parallel, making it impossible to simulate RC / RCL circuits.

@ra3xdh
Copy link
Owner

ra3xdh commented Dec 6, 2023

I'm presuming the same would go for inductors in series and parallel, making it impossible to simulate RC / RCL circuits

This simulation is correct. The ideal opamp has zero output resistance. The time constant of the output stage RC=0. The output signal doesn't depend on the capacitance. Try to replace the opamp with the model from the library. But it also may have very low output resistance. For example for LM358 is set to RO=50 Ohm in the model. And RC gives 2.35us, which gives cutoff frequency 425kHz.

@tomhajjar
Copy link
Author

tomhajjar commented Dec 6, 2023

@BURN-MICROSUCK

In real life you would never place a large capacitor across the output of a "standard" OpAmp. It can cause instability. The circuit must be designed to drive capacitive loads.

https://www.analog.com/en/analog-dialogue/articles/ask-the-applications-engineer-25.html

@ra3xdh
Copy link
Owner

ra3xdh commented Dec 12, 2023

@BURN-MICROSUCK I have just added a fix for device rotation. See #92 (comment) You may compile and test the current branch.

@tomhajjar
Copy link
Author

I'm not getting the potentiometer working. I used the standard method from Qucs.

Tone_Controls_prj.zip

@ra3xdh
Copy link
Owner

ra3xdh commented Dec 25, 2023

I'm not getting the potentiometer working. I used the standard method from Qucs

Define the variable with .PARAM and everything works as expected. Also fix the R4 value. The automatic converter assumes that the value without unit (Ohm) uses SPICE notation and parses it as 1mOhm.
image

@tomhajjar
Copy link
Author

I converted a Qucs tone control project in December using the new potentiometer model. I don't remember uploading it.

2024-02-15_195324

2024-02-15_195338

2024-02-15_195359

Tone_Controls_prj.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants