I need to take an INT input, and convert it to a WORD value.
VAR
DRV2Speed : WORD; //IO card takes a WORD where 16000 = full 10V output (equivalent to 50Hz)
PumpFillSpeed : INT; //Users enter a value between 0 and 50
END_VAR
IF <conditions> THEN
DRV2Speed :=INT_TO_WORD((PumpFillSpeed/50)*16000);
END_IF </conditions>
According to me this should work - but it stays at 0, no matter what.
What am I doing wrong?
π
1
Last edit: Wiresplus 2024-01-26
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That calculation will not work the way you expect it to. If PumpFillSpeed is limitied to 0-50 then the only whole number would be 50/50 = 1 everything else is 0.0-0.9999... and since you are using word and integer only 50 would work since there is no representation for mantissa in integer values. Declare a temporary real variable and do the calculation and then do a REAL_TO_WORD in the DRV2Speed assignment.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I need to take an INT input, and convert it to a WORD value.
VAR
DRV2Speed : WORD; //IO card takes a WORD where 16000 = full 10V output (equivalent to 50Hz)
PumpFillSpeed : INT; //Users enter a value between 0 and 50
END_VAR
IF <conditions> THEN
DRV2Speed :=INT_TO_WORD((PumpFillSpeed/50)*16000);
END_IF </conditions>
According to me this should work - but it stays at 0, no matter what.
What am I doing wrong?
Last edit: Wiresplus 2024-01-26
more posts ...
That calculation will not work the way you expect it to. If PumpFillSpeed is limitied to 0-50 then the only whole number would be 50/50 = 1 everything else is 0.0-0.9999... and since you are using word and integer only 50 would work since there is no representation for mantissa in integer values. Declare a temporary real variable and do the calculation and then do a REAL_TO_WORD in the DRV2Speed assignment.
Thankyou. worked fine.
Last edit: Wiresplus 2024-01-26