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 Operational Amplifier (OpAmp) Module and Start with a Few Basic Formulas #70

Open
engineerjoe440 opened this issue May 7, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@engineerjoe440
Copy link
Owner

It'll be good to add a submodule electricpy.opamp to contain a variety of op-amp related formulas. We can start with the formulas laid out in BasicTables. We should make a unique function for each formula and include an example and copy of the image for each.

@engineerjoe440 engineerjoe440 added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels May 7, 2022
@Lakshmikanth2001
Copy link
Contributor

please assign me this issue

@Lakshmikanth2001
Copy link
Contributor

Lakshmikanth2001 commented Dec 30, 2022

let me know if like the code structure for electricpy.opamp

def non_inverting(Vin = None, Vout = None, Rg = None, Rf = None):
    """
    """
    if not (Vin or Vout or Rg or Rf):
        raise ValueError(f"Atleasr 3 out of (Vin, Vout, Rg, Rf) => \
        {(Vin, Vout, Rg, Rf)} should be supplied to find out the other one")

    if Rg < 0 or Rf < 0:
        raise ValueError("Rg and Rg both must be positive")

    if Vout == None:
        try:
            Vout = Vin*(Rg + Rf)/(Rg)
        except TypeError:
            raise ValueError(f"To find out Vout (Vin, Rg, Rf) => {(Vin, Rg, Rf)} \
            should not be None")
        except ZeroDivisionError:
            raise ValueError("Rg should be non zero")

    if Vin == None:
        try:
            Vin = Vout*(Rg)/(Rg + Rf)
        except TypeError:
            raise ValueError(f"To find out Vin (Vout, Rg, Rf) => {(Vout, Rg, Rf)} \
            should not be None")
        except ZeroDivisionError:
            raise ValueError("Rg+Rf should be non zero")

    if Rg == None:
        try:
            Rg = (Vin)*Rf/(Vout -Vin)
        except TypeError:
            raise ValueError(f"To find out Rg (Vout, Vin, Rf) => {(Vout, Vin, Rf)}  \
            should not be None")
        except ZeroDivisionError:
            raise ValueError("Vin and Vout should not be equal \
            if Rf and Rg are present")

    if Rf == None:
        try:
            Rf = Rg*(Vin - Vout)/Vin
        except TypeError:
            raise ValueError(f"To find out Rf (Vout, Vin, Rg) => {(Vout, Vin, Rg)}  \
            should not be None")
        except ZeroDivisionError:
            raise ValueError("Vin cannot be found if Rf = 0")

    return {
        "Vin": Vin,
        "Vout": Vout,
        "Rg": Rg,
        "Rf": Rf,
    }

@engineerjoe440
Copy link
Owner Author

Hi, @Lakshmikanth2001!

Looks like it's off to a great start! 😄 I've only got small suggestions about wording.

  • looks like there's a typo in the very first ValueError entry

Let me give an effort with the docstring... (feel free to modify, we'll work out the details in your the pull request)

def non_inverting(Vin = None, Vout = None, Rg = None, Rf = None):
    """
    Non-Inverting Op-Amp Solver

    This function will accept three inputs for the common operational amplifier
    formulas related to a non-inverting operational amplifier (op-amp) and will
    solve for the fourth value. All inputs default to `None`, to solve for any
    value, leave its input as `None` and set all other inputs.

    .. image:: https://www.basictables.com/media/non-inverting-opamp-circuit.png

    Examples
    --------
    >>> from electriclpy.opamp import non_inverting
    >>> non_inverting(Vin=10, Rg=10, Rf=10) # Solve for Vout
    {...}
    >>> non_inverting(Vin=10, Vout=10, Rg=10) # Solve for Rf
    {...}

    Parameters
    ----------
    Vin:    [int, float]
            Input voltage, in volts. Default is None.
    Vout:   [int, float]
            Output voltage, in volts. Default is None.
    Rg:     [int, float]
            Ground-resistor value, in ohms. Default is None.
    Rf:     [int, float]
            Forward-resistor value, in ohms. Default is None.

    Returns
    -------
    dict:   Dictionary of the resultant values, includes the following:

            - Vin
            - Vout
            - Rg
            - Rf
    """
    ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants