OSCAT Forum

oscat.lib => oscat.lib fuer TwinCAT/CoDeSys => Thema gestartet von: mbruck in 03. April 2013, 00:20:04

Titel: Proposal for new function under engineering/conversion
Beitrag von: mbruck in 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
Titel: Re: Proposal for new function under engineering/conversion
Beitrag von: alexdrik in 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]
Titel: Re: Proposal for new function under engineering/conversion
Beitrag von: shooter in 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.
Titel: Re: Proposal for new function under engineering/conversion
Beitrag von: mbruck in 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 ?