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
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]
nachteil von alex ist integer, ich wurde vorschlagen um es in real zu tun. dan gibts auch kein probleme mit negativ werte.
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 ?