Hello guys, maybe someone has made a program for converting 1 32bit value to 2 16 bit?
I need to send encoder value that is 32 bit via group outputs?
Hello guys, maybe someone has made a program for converting 1 32bit value to 2 16 bit?
I need to send encoder value that is 32 bit via group outputs?
Maybe don't use GOs at all. Just set up a 32-bit range of DOs, and set them using a loop with DIV2 to act as a bit-shift-right, and MOD 2 to basically check the lowest bit :
1: R[1]=2.14748e+09 ;
2: R[3]=0 ;
3: ;
4: LBL[1] ;
5: R[3]=R[3]+1 ;
6: R[2]=R[1] MOD 2 ;
7: IF (R[2]=0) THEN ;
8: DO[R[3]]=OFF ;
9: ELSE ;
10: DO[R[3]]=ON ;
11: ENDIF ;
12: R[1]=R[1] DIV 2 ;
13: IF R[3]=32,JMP LBL[100] ;
14: //PAUSE ;
15: ;
16: JMP LBL[1] ;
17: LBL[100] ;
Display More
My TP is weak, but this seemed to work okay when I tested it.
EDIT: well, maybe not. Once I got into very large numbers, it looks like the lower-order bits seem to get lost. Maybe rounding error in the DIV function?
For example, if I input 252645136 (1111 0000 1111 0000 1111 0000 1111), DOs 29-32 are set ON, but 1-4 are set False, and DO 5 is ON.
Divide the value by 65536 (per DIV) this is the upper 16 bit value, then subtract this value multiplied with 65536 from the original this is the lower 16 bit value.
Well, trying to do it directly, DIV and MOD seem to break between 4294967040 and 4294967168 with "CAL_MATRIX failed."
The fanuc handles registers (especially at the range of 2^31) a bit strange.
Sometimes he handles them as integer and sometimes he handles them as float.
If integer is the actual state, you can only handle values from -2,147,483,648 to +2,147,483,646 then the direct method works if it is a positive value. For negative values a special calculation will be necessary.
+2,147,483,647 is displayed as "*******"
And one more strange behaviour: f.e. if you try to change a register to 2147483500 he value will be accepted but changed to 2147483520.
values from round about 2147483600 are changed to floats.