Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

This isn't a complicated, glamorous, or earth-shattering bit of Perl code. Quite the opposite really, it's an overly simple problem to solve for Perl, but that's sort of the point. It's more or less an example of one of the little things I'm apt to use Perl for everyday. I had a relatively simple Electrical Engineering problem I had to solve that became tedious to resolve anytime I'd fiddle with my exact component choices. This is the type of thing I used to do with Mathcad when I actually had a license for the full version, but usually a combination of Perl and Excel can make up 90% or more of the same functionality with a bit of clever manipulation.

use utf8; use 5.022; use strict; use warnings; my $excitation_voltage = 5; # excitation voltage for load cel +l (volts) my $load_cell_sensitivity = 0.015; # adjusted (down via rheosat) loa +d cell full scale sensitivity (volts/volt) my $pot_taps1 = 128; # number of tap settings allowed +by diff amp gain pots my $pot_taps2 = 128; # number of tap settings allowed +by non-inverting amp gain pot my $desired_max_output = 4.8; # maximum final output voltage de +sired at full scale (volts), usually a limitation of the selected op +amp or for ADC input headroom my $allowed_output_deviation = 0.01; # how much deviation from $desire +d_max_output due to the limited number of pot settings is acceptable +(e.g. 0.01 would be 1%) my $printf_format = "%8s%15s%12s%15s%15s%14s"; printf "\n$printf_format\n$printf_format\n\n", "Diff Amp", "Non-Inv Am +p", "Diff Amp", "Non-Inv Amp", "Total", "Max Output", "Pot Set", "Pot + Set", "Gain", "Gain", "Gain", "Voltage"; my $possible = 0; foreach my $gain1 (map { ($pot_taps1-$_)/$_ } (1..$pot_taps1/2)) # + for diff amp, only half of pot taps usable since gains less than 1 a +re not allowed { foreach my $gain2 (map { ($pot_taps2-$_)/$_+1 } (1..$pot_taps2)) # + for non-inverting amp { if ( abs($desired_max_output-$gain1*$gain2*$excitation_voltage +*$load_cell_sensitivity)/$desired_max_output <= $allowed_output_devia +tion ) { printf "$printf_format\n", sprintf("%.0f", $pot_taps1/($ga +in1+1)), sprintf("%.0f", $pot_taps2/$gai +n2), sprintf("%.3f", $gain1), sprintf("%.3f", $gain2), sprintf("%.3f", $gain1*$gain2), sprintf("%.6f", $excitation_vol +tage*$load_cell_sensitivity*$gain1*$gain2); $possible = 1; } } } say "\nNo combination of potentiometer settings meets your criteria.\n +Try allowing for more \$allowed_output_deviation\nand/or adjusting yo +ur \$desired_max_output." if (!$possible);

Plus, doing these sorts of things in Perl keeps my coding ability from going completely stagnant during long dry spells of an actual Perl project of any complexity. :-)

Just another Perl hooker - Yep, I've definitely seen more than my share of d*cks in the world, that's for sure.

In reply to Digitally Adjustable Multi-Stage Op-Amp Gain Calculator - It's the Simple Things in Perl you Appreciate by perldigious

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (11)
    As of 2017-10-20 13:17 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My fridge is mostly full of:

















      Results (263 votes). Check out past polls.

      Notices?