Mark Sluser

MrPLC Member
  • Content count

    4
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Mark Sluser

  • Rank
    Hi, I am New!

Profile Information

  • Gender Male
  • Location Alberta
  • Country Canada
  1. An easier solution I found was to round the float to an int using a regular move block. Then compare the float to the new int. For positive numbers: If the new int is greater than the original float, the number rounded up If the new int is less than the original float, the number rounded down. For negative numbers, the exact opposite. So for positive numbers, if there was a rounding up, subtract 1. For negative numbers, if there was a rounding down, add 1. Cheers -Mark
  2. The problem for me was using floating point numbers for data converstion. I have bit of logic that converts a 32bit unsigned integer (stored as 2 integers) to a float, and then back to a 32bit unsigned int. I am not interested in rounding, just data conversion so the problem had to be solved. Thank you for your help PLC Moderator. At least I can say I am not totaly crazy. -Makr
  3. Are you sure you just need to subtract 0.5? 3.0 - 0.5 = 2.5 Because PLC-5 has round to nearest even, the result of rounding 2.5 is 2.0, not 3.0. In the case of 4.0 - 0.5 = 3.5 Rounding 3.5 rounds to the nearest even, the result is 4.0 so it works this time. Please get back to me, I would like to know if I am wrong! -Mark
  4. I have been wracking my brains trying to get a PLC-5/40E processor using RSLogix5 7.10 to truncate a floating point number into an integer. For those that don't know, when converting a float to a integer, PLC5 (at least the enhanced and newer versions) have round to the nearest even number. This plays out as follows. 4.0 -> 4 3.5 -> 4 3.0 -> 3 2.5 -> 2 2.0 -> 2 1.5 -> 2 1.0 -> 1 0.5 -> 0 0 -> 0 -0.5 -> 0 -1.5 ->-1 -2.0 ->-2 My application was converting a 32bit unsigned integer to a float and back. I am trying to convert a 32 bit unsigned integer to a float and back. I don't want rounding, just truncate. Some people call this a floor function as well. CPT to the rescue! I didn't realize you could put MOD commands in CPT blocks. It isn't listed in the CPT documentation, but it worked. To get the fraction part of a real number use the following in a CPT block. CPT F8:1 F8:0 MOD 1.0 Then subtract the faction from the original real, and send it directly to a integer SUM F8:0 F8:1 N7:0 Any comments ? Hope this helps. Mark Sluser Calgary, AB Oops posted a mistake, subtract is SUB not SUM. Then subtract the faction from the original real, and send it directly to a integer SUB F8:0 F8:1 N7:0