Example #1
0
    def _get_generator_values(pricegen):
        """
        TODO This function should be parcelled out to conventions
        """
        if pricegen['type'] == 'simple':
            return pricegen['values']
        values = []

        if pricegen['type'] == 'resistor':
            if 'resistances' in pricegen.keys():
                for resistance in pricegen['resistances']:
                    values.append(resistance)
            if 'generators' in pricegen.keys():
                for generator in pricegen['generators']:
                    if generator['std'] == 'iec60063':
                        rvalues = iec60063.gen_vals(generator['series'],
                                                    iec60063.res_ostrs,
                                                    start=generator['start'],
                                                    end=generator['end'])
                        for rvalue in rvalues:
                            values.append(
                                construct_resistor(
                                    resistance=rvalue,
                                    wattage=generator['wattage']))
                    else:
                        raise ValueError
            if 'values' in pricegen.keys():
                if pricegen['values'][0].strip() != '':
                    values += pricegen['values']
            return values

        if pricegen['type'] == 'capacitor':
            if 'capacitances' in pricegen.keys():
                for capacitance in pricegen['capacitances']:
                    values.append(capacitance)
            if 'generators' in pricegen.keys():
                for generator in pricegen['generators']:
                    if generator['std'] == 'iec60063':
                        cvalues = iec60063.gen_vals(generator['series'],
                                                    iec60063.cap_ostrs,
                                                    start=generator['start'],
                                                    end=generator['end'])
                        for cvalue in cvalues:
                            values.append(
                                construct_capacitor(
                                    capacitance=cvalue,
                                    voltage=generator['voltage']))
                    else:
                        raise ValueError
            if 'values' in pricegen.keys():
                if pricegen['values'][0].strip() != '':
                    values += pricegen['values']
            return values
Example #2
0
    def _get_generator_values(pricegen):
        """
        TODO This function should be parcelled out to conventions
        """
        if pricegen['type'] == 'simple':
            return pricegen['values']
        values = []

        if pricegen['type'] == 'resistor':
            if 'resistances' in pricegen.keys():
                for resistance in pricegen['resistances']:
                    values.append(resistance)
            if 'generators' in pricegen.keys():
                for generator in pricegen['generators']:
                    if generator['std'] == 'iec60063':
                        rvalues = iec60063.gen_vals(generator['series'],
                                                    iec60063.res_ostrs,
                                                    start=generator['start'],
                                                    end=generator['end'])
                        for rvalue in rvalues:
                            values.append(
                                construct_resistor(rvalue,
                                                   generator['wattage'])
                            )
                    else:
                        raise ValueError
            if 'values' in pricegen.keys():
                if pricegen['values'][0].strip() != '':
                    values += pricegen['values']
            return values

        if pricegen['type'] == 'capacitor':
            if 'capacitances' in pricegen.keys():
                for capacitance in pricegen['capacitances']:
                        values.append(capacitance)
            if 'generators' in pricegen.keys():
                for generator in pricegen['generators']:
                    if generator['std'] == 'iec60063':
                        cvalues = iec60063.gen_vals(generator['series'],
                                                    iec60063.cap_ostrs,
                                                    start=generator['start'],
                                                    end=generator['end'])
                        for cvalue in cvalues:
                            values.append(
                                construct_capacitor(cvalue,
                                                    generator['voltage'])
                            )
                    else:
                        raise ValueError
            if 'values' in pricegen.keys():
                if pricegen['values'][0].strip() != '':
                    values += pricegen['values']
            return values
Example #3
0
def find_resistor(resistance, footprint, device="RES SMD", wattage=None):
    # TODO This should return a symbol instead, and usages should be adapted
    # accordingly to make consistent with find_capacitor
    if isinstance(resistance, str):
        try:
            resistance = Resistance(resistance)
        except ValueError:
            raise NoGedaSymbolException(resistance)
    if isinstance(resistance, Resistance):
        resistance = resistance._value
    if footprint[0:3] == "MY-":
        footprint = footprint[3:]
    if device == "RES THRU":
        resistances = iec60063.gen_vals(iec60063.get_series("E24"), iec60063.res_ostrs)
        if resistance in [parse_resistance(x) for x in resistances]:
            return construct_resistor(normalize_resistance(resistance), "0.25W")  # noqa
        else:
            raise NoGedaSymbolException(resistance, device)
    for symbol in gsymlib:
        if symbol.device == device and symbol.footprint == footprint:
            res, watt = parse_resistor(symbol.value)
            sym_resistance = parse_resistance(res)
            if resistance == sym_resistance:
                return symbol.value
    raise NoGedaSymbolException(resistance)
Example #4
0
 def gen_vals(self, stype=None, start=None, end=None):
     if stype != self._stype:
         raise TypeError('This {0} series is not defined for {1}'
                         ''.format(self._stype, stype))
     if start is None:
         start = self._start
     if end is None:
         end = self._end
     for value in iec60063.gen_vals(self._series, self._ostrs,
                                    start=start, end=end):
         yield self._typeclass(value)
 def gen_vals(self, stype=None, start=None, end=None):
     if stype != self._stype:
         raise TypeError('This {0} series is not defined for {1}'
                         ''.format(self._stype, stype))
     if start is None:
         start = self._start
     if end is None:
         end = self._end
     for value in iec60063.gen_vals(self._series,
                                    self._ostrs,
                                    start=start,
                                    end=end):
         yield self._typeclass(value)
Example #6
0
def get_iec60063_contextpart(stype, series, start=None, end=None):
    return {
        "iec60063vals": [
            i
            for i in iec60063.gen_vals(
                iec60063.get_series(series), iec60063.get_ostr(stype), start, end  # noqa  # noqa
            )
        ],
        "iec60063stype": stype,
        "iec60063series": series,
        "iec60063start": start,
        "iec60063end": end,
    }
Example #7
0
    def _set_vout(self, target_vout):
        if not isinstance(target_vout, Voltage):
            target_vout = Voltage(target_vout)

        rfb1_dev = self.get_elem_by_idx('RFB1').data['device']
        rfb1_fp = self.get_elem_by_idx('RFB1').data['footprint']
        rfb2_dev = self.get_elem_by_idx('RFB2').data['device']
        rfb2_fp = self.get_elem_by_idx('RFB2').data['footprint']
        if rfb1_fp[0:3] == "MY-":
            rfb1_fp = rfb1_fp[3:]
        if rfb2_fp[0:3] == "MY-":
            rfb2_fp = rfb2_fp[3:]

        allowed_rfb1_vals = iec60063.gen_vals(self._configdict['Rseries'],
                                              iec60063.res_ostrs,
                                              start='8.2K',
                                              end='10K')

        allowed_rfb2_vals = iec60063.gen_vals(self._configdict['Rseries'],
                                              iec60063.res_ostrs,
                                              self._configdict['Rmin'],
                                              self._configdict['Rmax'])

        allowed_rfb1_vals = [x for x in allowed_rfb1_vals]
        allowed_rfb2_vals = [x for x in allowed_rfb2_vals]
        best_match = None

        for pair in itertools.product(allowed_rfb1_vals, allowed_rfb2_vals):
            vout = self._get_Vout(*pair)
            error = abs(vout - target_vout)
            if best_match is None or error < best_match[1]:
                best_match = (vout, error, pair[0], pair[1])

        rfb1_value = gsymlib.find_resistor(best_match[2], rfb1_fp, rfb1_dev)
        self.get_elem_by_idx('RFB1').data['value'] = rfb1_value

        rfb2_value = gsymlib.find_resistor(best_match[3], rfb2_fp, rfb2_dev)
        self.get_elem_by_idx('RFB2').data['value'] = rfb2_value
Example #8
0
def get_iec60063_contextpart(stype, series, start=None, end=None):
    return {
        "iec60063vals": [
            i for i in iec60063.gen_vals(
                iec60063.get_series(series),  # noqa
                iec60063.get_ostr(stype),  # noqa
                start,
                end)
        ],
        "iec60063stype":
        stype,
        "iec60063series":
        series,
        "iec60063start":
        start,
        "iec60063end":
        end,
    }
Example #9
0
    def _autoset_ilim(self):
        rlim_dev = self.get_elem_by_idx('RLIM').data['device']
        rlim_fp = self.get_elem_by_idx('RLIM').data['footprint']

        icl = self.Iout * Decimal(1.2 - 0.33)

        self.target_rlim = (icl / Current('85uA')) * self.fet_Rdson

        allowed_rlim_vals = iec60063.gen_vals(self._configdict['Rseries'],
                                              iec60063.res_ostrs,
                                              self._configdict['Rmin'],
                                              self._configdict['Rmax'])

        best_match = None
        for r in allowed_rlim_vals:
            r = Resistance(r)
            if r > self.target_rlim:
                if best_match is None or r < best_match:
                    best_match = r

        rlim_value = gsymlib.find_resistor(best_match, rlim_fp, rlim_dev)
        self.get_elem_by_idx('RLIM').data['value'] = rlim_value
Example #10
0
    def _autoset_Cff(self):
        cff_dev = self.get_elem_by_idx('CFF').data['device']
        cff_fp = self.get_elem_by_idx('CFF').data['footprint']

        Zfb = self.RFB1 * (self.RFB2 / (self.RFB1 + self.RFB2))
        self.target_cff = Capacitance(
            (self.Vout / self.Vin_min) / (self.Fsw.value * Zfb.value)
        )

        allowed_cff_vals = iec60063.gen_vals(self._configdict['Cseries'],
                                             iec60063.cap_ostrs,
                                             self._configdict['Cmin'],
                                             self._configdict['Cmax'])

        best_match = None
        for c in allowed_cff_vals:
            err = abs(self.target_cff - Capacitance(c))
            if best_match is None or err < best_match[0]:
                best_match = (err, c)

        cff = gsymlib.find_capacitor(best_match[1], cff_fp, cff_dev)
        self.get_elem_by_idx('CFF').data['value'] = cff.value
Example #11
0
    def _autoset_fsw(self):
        ron_dev = self.get_elem_by_idx('RON').data['device']
        ron_fp = self.get_elem_by_idx('RON').data['footprint']

        self.d_min = DutyCycle(
            100 * self.Vout / self.Vin_max
        )

        self.d_max = DutyCycle(
            100 * self.Vout / self.Vin_min
        )

        self.ton_min = TimeSpan(self._configdict['Ton_min'])
        self.fs_max_ontime = self.d_min / self.ton_min

        self.toff_min = TimeSpan(self._configdict['Toff_min']) + \
            TimeSpan(self._configdict['Toff_fet'])
        self.fs_max_offtime = (1 - self.d_max.value / 100) / self.toff_min

        self.fs_max = Percentage('80%') * min([self.fs_max_ontime, self.fs_max_offtime])  # noqa

        self.target_ron = Resistance(
            self.Vout.value / (Charge('100pC').value * self.fs_max.value)
        )

        allowed_ron_vals = iec60063.gen_vals(self._configdict['Rseries'],
                                             iec60063.res_ostrs,
                                             self._configdict['Rmin'],
                                             self._configdict['Rmax'])

        best_match = None
        for r in allowed_ron_vals:
            fsw = self._get_fsw(r)
            if self.fs_max > fsw:
                if best_match is None or fsw > best_match[0]:
                    best_match = (fsw, r)

        ron_value = gsymlib.find_resistor(best_match[1], ron_fp, ron_dev)
        self.get_elem_by_idx('RON').data['value'] = ron_value
Example #12
0
    def Fc(self, value):
        c1_dev = self.get_elem_by_idx('C1').data['device']
        c1_fp = self.get_elem_by_idx('C1').data['footprint']
        if c1_fp[0:3] == "MY-":
            c1_fp = c1_fp[3:]

        allowed_cap_vals = iec60063.gen_vals(self._configdict['Cseries'],
                                             iec60063.cap_ostrs,
                                             self._configdict['Cmin'],
                                             self._configdict['Cmax'])

        required_cap_val = 1 / (2 * pi * float(self.R1) * value)

        cval = None
        for val in allowed_cap_vals:
            lastval = cval
            cval = electronics.parse_capacitance(val)
            if cval >= required_cap_val:
                self.get_elem_by_idx('C1').data['value'] = gsymlib.find_capacitor(lastval, c1_fp, c1_dev).value  # noqa
                break

        if cval is None:
            raise ValueError
 def values(self):
     if self.std == 'iec60063':
         return iec60063.gen_vals(self.series, self._ostrs,
                                  start=self.start, end=self.end)
Example #14
0
    def _get_data(self):
        with open(self._genpath) as genfile:
            gendata = yaml.load(genfile)
        if gendata["schema"]["name"] == "gsymgenerator" and \
           gendata["schema"]["version"] == 1.0:

            if gendata['type'] == 'simple':
                self._type = 'Simple'
                self._ivalues = [
                    v for v in gendata['values']
                    if v is not None and v.strip() is not None
                ]
                return gendata['values']
            values = []

            if gendata['type'] == 'resistor':
                self._type = 'Resistor'
                giseries = None
                for resistance in gendata['resistances']:
                    if resistance is not None:
                        values.append(resistance)
                        self._iunits.append(resistance)
                if 'composite_series' in gendata.keys():
                    from tendril.conventions.series import CustomValueSeries
                    try:
                        name = gendata['composite_series']['name']
                        tsymbol = GedaSymbol(self._sympath)
                        giseries = CustomValueSeries(
                            name,
                            'resistor',
                            device=tsymbol.device,
                            footprint=tsymbol.footprint)
                    except KeyError:
                        pass
                if 'generators' in gendata.keys():
                    dcomponents = jb_resistor_defs()
                    for generator in gendata['generators']:
                        self._igen.append(generator)
                        if generator['std'] == 'iec60063':
                            rvalues = iec60063.gen_vals(
                                generator['series'],
                                iec60063.res_ostrs,
                                start=generator['start'],
                                end=generator['end'])
                            components = {}
                            for dcomponent in dcomponents:
                                if dcomponent.code in generator.keys():
                                    try:
                                        dcomponent.typeclass(
                                            generator[dcomponent.code])  # noqa
                                        components[
                                            dcomponent.code] = generator[
                                                dcomponent.code]  # noqa
                                    except:
                                        raise ValueError
                            for rvalue in rvalues:
                                pval = construct_resistor(resistance=rvalue,
                                                          **components)
                                values.append(pval)
                                if giseries is not None:
                                    giseries.add_value(rvalue, pval)
                        else:
                            raise ValueError
                if giseries is not None:
                    self._iseries.append(giseries)
                if 'values' in gendata.keys():
                    if gendata['values'][0].strip() != '':
                        values += gendata['values']
                        self._ivalues.extend(gendata['values'])
                if 'custom_series' in gendata.keys():
                    from tendril.conventions.series import CustomValueSeries
                    for name, series in viewitems(gendata['custom_series']):
                        if series['detail'].pop('type') != 'resistor':
                            raise ValueError('Expected a resistor series')
                        vals = series['values']
                        tsymbol = GedaSymbol(self._sympath)
                        iseries = CustomValueSeries(
                            name,
                            'resistor',
                            device=tsymbol.device,
                            footprint=tsymbol.footprint)
                        for type_val, val in viewitems(vals):
                            iseries.add_value(type_val, val)
                        iseries._desc = series['detail'].pop('desc')
                        iseries._aparams = series['detail']
                        self._iseries.append(iseries)
                        values.extend(vals.values())
                return values

            if gendata['type'] == 'capacitor':
                self._type = 'Capacitor'
                giseries = None
                for capacitance in gendata['capacitances']:
                    if capacitance is not None:
                        values.append(capacitance)
                        self._iunits.append(capacitance)
                if 'composite_series' in gendata.keys():
                    from tendril.conventions.series import CustomValueSeries
                    try:
                        name = gendata['composite_series']['name']
                        tsymbol = GedaSymbol(self._sympath)
                        giseries = CustomValueSeries(
                            name,
                            'capacitor',
                            device=tsymbol.device,
                            footprint=tsymbol.footprint)
                    except KeyError:
                        pass
                if 'generators' in gendata.keys():
                    dcomponents = jb_capacitor_defs()
                    for generator in gendata['generators']:
                        self._igen.append(generator)
                        if generator['std'] == 'iec60063':
                            cvalues = iec60063.gen_vals(
                                generator['series'],
                                iec60063.cap_ostrs,
                                start=generator['start'],
                                end=generator['end'])
                            components = {}
                            for dcomponent in dcomponents:
                                if dcomponent.code in generator.keys():
                                    try:
                                        dcomponent.typeclass(
                                            generator[dcomponent.code])  # noqa
                                        components[
                                            dcomponent.code] = generator[
                                                dcomponent.code]  # noqa
                                    except:
                                        raise ValueError
                            for cvalue in cvalues:
                                pval = construct_capacitor(capacitance=cvalue,
                                                           **components)
                                values.append(pval)
                                if giseries is not None:
                                    giseries.add_value(cvalue, pval)
                        else:
                            raise ValueError
                if giseries is not None:
                    self._iseries.append(giseries)
                if 'values' in gendata.keys():
                    if gendata['values'][0].strip() != '':
                        values += gendata['values']
                        self._ivalues.append(gendata['values'])
                if 'custom_series' in gendata.keys():
                    from tendril.conventions.series import CustomValueSeries
                    for name, series in viewitems(gendata['custom_series']):
                        if series['detail'].pop('type') != 'capacitor':
                            raise ValueError('Expected a capacitor series')
                        vals = series['values']
                        tsymbol = GedaSymbol(self._sympath)
                        iseries = CustomValueSeries(
                            name,
                            'capacitor',
                            device=tsymbol.device,
                            footprint=tsymbol.footprint)
                        for type_val, val in viewitems(vals):
                            iseries.add_value(type_val, val)
                        iseries._desc = series['detail'].pop('desc')
                        iseries._aparams = series['detail']
                        self._iseries.append(iseries)
                        values.extend(vals.values())
                return values
            elif gendata['type'] == 'wire':
                for gauge in gendata['gauges']:
                    for color in gendata['colors']:
                        values.append('{0} {1}'.format(gauge, color))
                return values
        else:
            logger.ERROR("Config file schema is not supported")
Example #15
0
    def _get_data(self):
        with open(self._genpath) as genfile:
            gendata = yaml.load(genfile)
        if gendata["schema"]["name"] == "gsymgenerator" and gendata["schema"]["version"] == 1.0:

            if gendata["type"] == "simple":
                self._type = "Simple"
                self._ivalues = [v for v in gendata["values"] if v is not None and v.strip() is not None]
                return gendata["values"]
            values = []

            if gendata["type"] == "resistor":
                self._type = "Resistor"
                for resistance in gendata["resistances"]:
                    if resistance is not None:
                        values.append(resistance)
                        self._iunits.append(resistance)
                if "generators" in gendata.keys():
                    for generator in gendata["generators"]:
                        self._igen.append(generator)
                        if generator["std"] == "iec60063":
                            rvalues = iec60063.gen_vals(
                                generator["series"], iec60063.res_ostrs, start=generator["start"], end=generator["end"]
                            )
                            for rvalue in rvalues:
                                values.append(construct_resistor(rvalue, generator["wattage"]))  # noqa
                        else:
                            raise ValueError
                if "values" in gendata.keys():
                    if gendata["values"][0].strip() != "":
                        values += gendata["values"]
                        self._ivalues.extend(gendata["values"])
                if "custom_series" in gendata.keys():
                    from tendril.conventions.series import CustomValueSeries

                    for name, series in viewitems(gendata["custom_series"]):
                        if series["detail"].pop("type") != "resistor":
                            raise ValueError("Expected a resistor series")
                        vals = series["values"]
                        tsymbol = GedaSymbol(self._sympath)
                        iseries = CustomValueSeries(
                            name, "resistor", device=tsymbol.device, footprint=tsymbol.footprint
                        )
                        for type_val, val in viewitems(vals):
                            iseries.add_value(type_val, val)
                        iseries._desc = series["detail"].pop("desc")
                        iseries._aparams = series["detail"]
                        self._iseries.append(iseries)
                        values.extend(vals.values())
                return values

            if gendata["type"] == "capacitor":
                self._type = "Capacitor"
                for capacitance in gendata["capacitances"]:
                    if capacitance is not None:
                        values.append(capacitance)
                        self._iunits.append(capacitance)
                if "generators" in gendata.keys():
                    for generator in gendata["generators"]:
                        self._igen.append(generator)
                        if generator["std"] == "iec60063":
                            cvalues = iec60063.gen_vals(
                                generator["series"], iec60063.cap_ostrs, start=generator["start"], end=generator["end"]
                            )
                            for cvalue in cvalues:
                                values.append(construct_capacitor(cvalue, generator["voltage"]))  # noqa
                        else:
                            raise ValueError
                if "values" in gendata.keys():
                    if gendata["values"][0].strip() != "":
                        values += gendata["values"]
                        self._ivalues.append(gendata["values"])
                if "custom_series" in gendata.keys():
                    from tendril.conventions.series import CustomValueSeries

                    for name, series in viewitems(gendata["custom_series"]):
                        if series["detail"].pop("type") != "resistor":
                            raise ValueError("Expected a resistor series")
                        vals = series["values"]
                        tsymbol = GedaSymbol(self._sympath)
                        iseries = CustomValueSeries(
                            name, "resistor", device=tsymbol.device, footprint=tsymbol.footprint
                        )
                        for type_val, val in viewitems(vals):
                            iseries.add_value(type_val, val)
                        iseries._desc = series["detail"].pop("desc")
                        iseries._aparams = series["detail"]
                        self._iseries.append(iseries)
                        values.extend(vals.values())
                return values
            elif gendata["type"] == "wire":
                for gauge in gendata["gauges"]:
                    for color in gendata["colors"]:
                        values.append("{0} {1}".format(gauge, color))
                return values
        else:
            logger.ERROR("Config file schema is not supported")