resistor-calc

Crates.ioresistor-calc
lib.rsresistor-calc
version0.1.0
sourcesrc
created_at2018-05-16 17:36:53.999953
updated_at2018-05-16 17:36:53.999953
descriptionA rust library to calculate nearest resistor values for circuit design.
homepage
repositoryhttps://github.com/HarkonenBade/resistor-calc
max_upload_size
id65754
size18,250
Tom (HarkonenBade)

documentation

https://docs.rs/resistor-calc/

README

Crates.io Docs.rs

A resistor value optimiser for circuit design.

When provided with a set of constraints and relations for a series of resistors R1, R2, ..., it can present sets of values from standard series in order of increasing inaccuracy.

Example

Given the following resistor network:

diagram

Where VADJ must remain at 0.8v, as R2 varies from no to full resistance, VOUT varies from 6v to 12v

We can then describe the problem via the following constraints, plus a few extra bounds to eliminate either very small, or very large values, both of which may cause current issues.

extern crate resistor_calc;

use resistor_calc::*;

fn main() {
    let rcalc = RCalc::new(vec![&E24, &E6, &E24]);

    println!("Number of combinations: {}", rcalc.combinations());

    let res = rcalc
        .calc(
            ROpBuilder::new()
                .bound("R1+R2+R3 <= 1e6")
                .bound("R1+R2+R3 >= 1e4")
                .bound("0.8 * (1 + R1/R3) ~ 6.0")
                .bound("0.8 * (1 + (R1+R2)/R3) ~ 12.0")
                .finish(),
        )
        .expect("Error: No values satisfy requirements");

    res.print_best();
}

Running this example produces the results:

Number of combinations: 1185408
Match 1:
Error: 0.000
Values: R1: 13K, R2: 15K, R3: 2K

Match 2:
Error: 0.000
Values: R1: 130K, R2: 150K, R3: 20K
Commit count: 6

cargo fmt