Autor Thema: Proposal for new function under engineering/conversion  (Gelesen 6840 mal)

0 Mitglieder und 1 Gast betrachten dieses Thema.

Offline mbruck

  • Newbie
  • *
  • Beiträge: 8
    • Profil anzeigen
    • E-Mail
Proposal for new function under engineering/conversion
« am: 03. April 2013, 00:20:04 »
Hi!

I have using this funcion in Arduinos software:
http://arduino.cc/en/Reference/map

I believe this would be valuable function in Oscat basic library under engineering/conversion category.  :)

Regards !

Mladen Bruck

alexdrik

  • Gast
Re: Proposal for new function under engineering/conversion
« Antwort #1 am: 05. April 2013, 12:23:48 »

Hi,

as they do give the mathematics, it isn`t too hard to do the coding. I attached the function for CoDeSys2.

you have to call the function like this:

millivolts := map(milliamps,4,20,0,10000);          (* Converts 4..20mA into 0..10 Volt *)

Regards
     Alex



[gelöscht durch Administrator]

Offline shooter

  • Jr. Member
  • **
  • Beiträge: 70
  • Shooting Fuzzy temperatures
    • ICQ Messenger - 60155180
    • Profil anzeigen
    • E-Mail
Re: Proposal for new function under engineering/conversion
« Antwort #2 am: 10. April 2013, 16:00:04 »
nachteil von alex ist integer, ich wurde vorschlagen um es in real zu tun. dan gibts auch kein probleme mit negativ werte.

Offline mbruck

  • Newbie
  • *
  • Beiträge: 8
    • Profil anzeigen
    • E-Mail
Re: Proposal for new function under engineering/conversion
« Antwort #3 am: 10. April 2013, 22:35:50 »
Hi Alex !

Thank you for code...

I meant it vould be valuable for including to library. However, I noticed code later,  and I have writen function block since I don't know how to use function in ladder yet. :(

But, I declared all variables as REAL like so:
FUNCTION_BLOCK MAP
VAR_INPUT
Start:BOOL;
In:REAL;
fromLow:REAL;
fromHigh:REAL;
toLow:REAL;
toHigh:REAL;
END_VAR
VAR_OUTPUT
End:BOOL;
Out:REAL;
END_VAR
VAR
END_VAR

Funcion body>
Out := (In-fromLow) * (toHigh - toLow) / ((fromHigh - fromLow) + toLow) ;

Is this would be problem ?