Ng syntax dual diode

Just started trying to learn ng spice.

I created a very simplified dual diode component, named pins B & C anodes and K cathode. It produces a full wave rectified output.

My question is whether despite seeming to work, did I do it the right way? My circuit drives the two anodes from a CT=ground AC. Note that anode ‘C’ is used, but not ‘B’ anode. Should I be making two statements, one for C K like I have and another B K for the other diode ?

I guess that “BIA C K” is defining a current calculation between C and K from the following function.

.subckt Dx2 B C K
BIA C K I=URAMP(V(B,K)) + URAMP(V(C,K))
.ENDS

Just to say:

I have not used NGSpice. But in LTSpice, they do not seem to bother with multiples. For example a quad op amp part number just gives you the single op amp, and I think that the same happens with multiple diodes such as BAV99. While there may be some SLIGHT differences between using two single diodes versus using a double diode (???) I don’t think the models get into that.

With something like a multiple op amp, I suppose it is a little more likely that activity by one op amp might affect another in the same package. Such as one amplifier is swinging large peak-peak at high current and high frequency while another is amplifying low level signals. But regardless, I do not think that spurious coupling between diodes or amplifiers in a package is included in the model.

Check out this tutorial on how to handle multi-part devices: KiCad Eeschema as GUI for ngspice, tutorial for setting up the simulation

The example there is an op-amp, but you can do the same with diodes.

Thanks for the inputs.

A dual diode has 2 inputs and 1 output similar to an op-amp . Just think of it as a math-block, and for the component outline just draw a square box with B&C inputs and K output pins. I finally realized that my post was more about spice syntax than diodes.

For example R 1 0 100 refers to the component name R, followed by 2 node numbers followed by a value.

My usage follows that same pattern:

BIA C K I=URAMP(V(B,K)) + URAMP(V(C,K)) the component name BIA stands for ( Behavioral, Current Source, XSPICE model, took a while to find that)

The nodes are C (or B) & K from the subckt line pin list

The value is the equation [ I=URAMP(V(B,K)) + URAMP(V(C,K)) ]

At every spice interval the equation V(B,K) produces V=B-K and the URAMP function returns either the difference value or zero if it is negative. It is safe in this case to add the two together since when one is negative, the other is positive because of the nature of the AC input. Then the result of the function is assigned to the variable I.

My confusion in part, is [ BIA C K ] or [ BIA B K ], in which the B or the C, make no difference. The output node is always K, however the first node can be either of the two input nodes in the subckt line, but the syntax requires something in that position. I think the B or the C is just a syntax placeholder and doesn’t enter into the equation.

I’m not sure I fully understand yet, but ngspice doesn’t complain.

.subckt Dx2 B C K
BIA C K I=URAMP(V(B,K)) + URAMP(V(C,K))
.ENDS

Let me explain in detail what @lucas has suggested:

A diode in ngspice (in all spices) is instantiated by two lines:
the instance line
D1 A K dmod
and the .model line. The simplest .model line is using some parameters defaulted by ngspice:
.model dmod D
This model may be replaced by any diode model, e.g. 1N4148, avalable at Spice models and model parameters for ngspice circuit simulator or other places in the web.

If you have 2 diodes, connected at the cathode (common cathode), you will have

D1 A1 K dmod
D2 A2 K dmod
.model dmod D

To be able to attach this dual diode to a 3-pin symbol, you have to put it into a subcircuit, like

* symbol pins     1  2  3
.subckt dualdiode A1 A2 K
D1 A1 K dmod
D2 A2 K dmod
.model dmod D
.ends

put this into a file, e.g. my model.lib, and attach it to the symbol in the usaul way. If the pin numbering of the symbol is different, change the sequence of A1 A2 K accordingly.

Holger and all. Thanks for explaining in greater detail. I am in spice kindergarten. Your dual model worked without changes.

Antique radio is a hobby, so I want to create models of vacuum tube rectifiers, but also modern silicon rectifiers and selenium rectifiers. Selenium rectifiers can probably use the diode model with proper parameters.

As you know, vacuum tube diodes obey Child’s Law, which is embedded in the subckt formula below. I = (2.335e-6AV^(3/2) )/d^2 with the 3 constants (2.33…&A&d) combined for specifically the #80 rectifier tube. I think the math approach is probably better for vacuum tubes than the semiconductor model.

  • Type 80 vacuum tube
    .subckt Dx2 B C K
    BIA C K I=URAMP(V(B,K))**1.5 * 0.00026895718 + URAMP(V(C,K))**1.5 * 0.00026895718
    .ENDS

Its not about the details of the model equation background, but about the actual model you are presenting.

You drive a current by nodes C and K, depending on both the voltages V(B,K) and V(C,K). There is no current in the branch B, K.

I guess that’s not what you want.

Take my example, which contains 2 independent diode instances. So just do the same, using your vacuum tube diode model! You don’t need a .model line, as you don’t have any model parameters.

Holger, thanks for being patient. I had a wrong concept in my mind, like regular programming I was thinking in terms of a value assignment, but this is a circuit topology description, not executed code. Despite doing my equation wrong, I got a correct looking waveform since I tested with a symmetrical waveform.

A full wave rectifier can also be thought as ‘or-tied’ diodes, which is common in a shortcut sometimes used in digital logic circuits. I started to realize this in your example, each of the two lines describe a current path, and logic programming statements do not apply.

I made the following circuit where I apply different frequencies to the two diodes which performs a ‘whichever is greater’ function waveform output, which for me makes it more clear. Thanks again.

.subckt dualdiode A1 A2 K
D1 A1 K dmod
D2 A2 K dmod
.model dmod D
.ends

dualdiodemodelcir

This is correct now

.subckt Dx2 B C K
BI1 B K I=URAMP(V(B,K))**1.5 * 0.00026895718
BI2 C K I=URAMP(V(C,K))**1.5 * 0.00026895718
.ENDS
1 Like