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

Partially implemented devices #63

Open
FabriceSalvaire opened this issue Sep 25, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@FabriceSalvaire
Copy link
Owner

commented Sep 25, 2017

Unimplemented value types

  • NonLinearVoltageSource E
    NonLinearCurrentSource G
    raw_spice should help to pass unimplemented value types

Unimplemented node/value types

  • XSpiceElement A

Low priority

  • GSSElement N TCAD not documented in Ngspice manual

@FabriceSalvaire FabriceSalvaire added this to the V2 milestone Sep 25, 2017

@HGrabas

This comment has been minimized.

Copy link

commented Oct 27, 2017

I have checked and implementing the PULSE ngspice source using as_A definition makes a functional pulsed current source. See code below.

This is useful to have - and maybe that coud be included in the next release.

Comes the question of the implementation. In ngspice there is no distinction between a pulsed voltage source or a pulsed current source other that the units of the initial values being V or A.

So

Vpulse source 0 PULSE(0V 12V 4e-08s 0s 0s 2e-09s 1s)
implements a pulsed voltage source
Ipulse source 0 PULSE(0A 0.006A 100ns 0s 0s 1ns 1us)
implements a pulsed current source.

There are both PULSE

In PySpice
class PySpice.Spice.HighLevelElement.Pulse(name, node_plus, node_minus, initial_value, pulsed_value, pulse_width, period, delay_time=0, rise_time=0, fall_time=0)

inherits from PySpice.Spice.BasicElement.VoltageSource

So this limits the pulse source to a voltage one even though it should be possible to have pulsed current source.

It is my understanding that a similar argument could be made for PWL sources.

class IPulse(CurrentSource):

    """This class implements a pulse waveform.

    Nomenclature:

    +--------+---------------+---------------+-------+
    | Name   + Parameter     + Default Value + Units |
    +--------+---------------+---------------+-------+
    | I1     + initial value +               + V, A  |
    +--------+---------------+---------------+-------+
    | I2     + pulsed value  +               + V, A  |
    +--------+---------------+---------------+-------+
    | Td     + delay time    + 0.0           + sec   |
    +--------+---------------+---------------+-------+
    | Tr     + rise time     + Tstep         + sec   |
    +--------+---------------+---------------+-------+
    | Tf     + fall time     + Tstep         + sec   |
    +--------+---------------+---------------+-------+
    | Pw     + pulse width   + Tstop         + sec   |
    +--------+---------------+---------------+-------+
    | Period + period        + Tstop         + sec   |
    +--------+---------------+---------------+-------+

    Spice Syntax::

        PULSE ( I1 I2 Td Tr Tf Pw Period )

    A single pulse so specified is described by the following table:

    +-------------+-------+
    | Time        | Value |
    +-------------+-------+
    | 0           | I1    |
    +-------------+-------+
    | Td          | I1    |
    +-------------+-------+
    | Td+Tr       | I2    |
    +-------------+-------+
    | Td+Tr+Pw    | I2    |
    +-------------+-------+
    | Td+Tr+Pw+Tf | I1    |
    +-------------+-------+
    | Tstop       | I1    |
    +-------------+-------+

    Note: default value in Spice for rise and fall time is the simulation transient step, pulse
    width and period is the simulation stop time.

    Public Attributes:

      :attr:`delay_time`

      :attr:`fall_time`

      :attr:`initial_value`

      :attr:`period`

      :attr:`pulse_width`

      :attr:`pulsed_value`

      :attr:`rise_time`

    """

    ##############################################

    def __init__(self, name, node_plus, node_minus,
                 initial_value, pulsed_value,
                 pulse_width, period,
                 delay_time=0, rise_time=0, fall_time=0):

        # Fixme: default
        #  rise_time, fall_time = Tstep
        #  pulse_width, period = Tstop

        super().__init__(name, node_plus, node_minus)

        self.initial_value = as_A(initial_value)
        self.pulsed_value = as_A(pulsed_value)
        self.delay_time = as_s(delay_time)
        self.rise_time = as_s(rise_time)
        self.fall_time = as_s(fall_time)
        self.pulse_width = as_s(pulse_width)
        self.period = as_s(period) # Fixme: protect by setter?

        # # Fixme: to func?
        # # Check parameters
        # found_none = False
        # for parameter in ('rise_time', 'fall_time', 'pulse_width', 'period'):
        #     parameter_value = getattr(self, parameter)
        #     if found_none:
        #         if parameter_value is not None:
        #             raise ValueError("Parameter {} is set but some previous parameters was not set".format(parameter))
        #     else:
        #         found_none = parameter_value is None

    ##############################################

    @property
    def frequency(self):
        return self.period.frequency

    ##############################################

    def format_spice_parameters(self):

        # Fixme: to func?
        return ('PULSE(' +
                join_list((self.initial_value, self.pulsed_value, self.delay_time,
                           self.rise_time, self.fall_time, self.pulse_width, self.period)) +
                ')')

####################################################################################################
@FabriceSalvaire

This comment has been minimized.

Copy link
Owner Author

commented Oct 31, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.