qucs_s icon indicating copy to clipboard operation
qucs_s copied to clipboard

Add potentiometer component

Open tomhajjar opened this issue 2 years ago • 7 comments

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.

tomhajjar avatar Jul 22 '22 01:07 tomhajjar

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 https://github.com/Qucs/qucs/pull/471 it's possible to backport it into the Qucs-S.

ra3xdh avatar Jul 22 '22 10:07 ra3xdh

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

tomhajjar avatar Jul 30 '22 03:07 tomhajjar

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

ra3xdh avatar Jul 30 '22 06:07 ra3xdh

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

Potentiometer_Test_prj.zip .

tomhajjar avatar Jul 30 '22 16:07 tomhajjar

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

ra3xdh avatar Jul 30 '22 16:07 ra3xdh

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

tomhajjar avatar Aug 01 '22 14:08 tomhajjar

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 avatar Aug 01 '22 14:08 ra3xdh

Assume this issue has been resolved. Closing ticket.

ra3xdh avatar Oct 04 '22 16:10 ra3xdh

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 avatar Nov 28 '23 18:11 ra3xdh

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

tomhajjar avatar Nov 30 '23 22:11 tomhajjar

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 avatar Dec 01 '23 06:12 ra3xdh

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

ra3xdh avatar Dec 01 '23 15:12 ra3xdh

image

ra3xdh avatar Dec 01 '23 15:12 ra3xdh

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?

BURN-MICROSUCK avatar Dec 01 '23 15:12 BURN-MICROSUCK

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.

ra3xdh avatar Dec 01 '23 15:12 ra3xdh

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?

BURN-MICROSUCK avatar Dec 06 '23 16:12 BURN-MICROSUCK

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

ra3xdh avatar Dec 06 '23 16:12 ra3xdh

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.

BURN-MICROSUCK avatar Dec 06 '23 16:12 BURN-MICROSUCK

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.

ra3xdh avatar Dec 06 '23 17:12 ra3xdh

@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

tomhajjar avatar Dec 06 '23 18:12 tomhajjar

@BURN-MICROSUCK I have just added a fix for device rotation. See https://github.com/ra3xdh/qucs_s/issues/92#issuecomment-1852227360 You may compile and test the current branch.

ra3xdh avatar Dec 12 '23 15:12 ra3xdh

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

Tone_Controls_prj.zip

tomhajjar avatar Dec 25 '23 17:12 tomhajjar

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

ra3xdh avatar Dec 25 '23 18:12 ra3xdh

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

tomhajjar avatar Feb 16 '24 00:02 tomhajjar