Followers 0

# 32-bit Floating-point number

## 7 posts in this topic

Hi all, Using: CJ1M, NS5 I am trying to get the Tangent of an angle. I have a user enter the angle in degrees on the touchpanel. That number (storage type?) is stored in a Data Memory location on the PLC. (Using a MOV command) I am trying to convert that number first from Degrees to Radians, then take the Tangent of the Radians. Here's my example: (Angle = 9 Degrees) MOV D140 D142 RAD D142 D144 TAN D144 D146 ...Where D140 is entered from the Touchpanel. First, what Storage Type should I be using to store the Angle in Degrees (INT, REAL, etc)? Second, is the command I want to use the MOV command? Third, how do I (or do I) manipulate that number to being a 32-bit Floating-point number? I am a relative newbie to programming, so any help is greatly appreciated! Thanks in advance!

##### Share on other sites
First, you need to define the registers you are using as REAL. In the NS-Designer change the data type for your numeric field to REAL. In CX-Programmer add your Data Memories to the symbol table and define them as REAL. A REAL value takes up two words, so in your application degrees will be DM140 and 141. Now all the values will be in the correct format. Omron's radian and tangent instructions requires the data be in REAL format to execute. By having the DM's already assigned as REAL the conversion is done. This instructions use two inputs and two output words. You should be using the Double Move (MOVL) instruction. This will move the real values properly. Hope this helps.

##### Share on other sites
Ok, I've done that. When I do a MOVL with my D140 input being 9, 41100000 gets put in D142. I then have RAD D142 D144 TAN D144 D146 My output for D146 is 3E222F88, so: D146: 2F88 -> 12168 D147: 3E22 -> 15906 When I calculate the actual Tangent of 9 Degrees, I get 0.15838 What further steps do I need to do to get D146/D147 to correspond to the actual Tangent of the angle? THANK YOU FOR YOUR HELP SO FAR!

##### Share on other sites
I see now that what I have in D146/D147 is actually the 32-bit floating-point value for 0.15838. I need to find a way to multiply this number by 100,000 before I use FIXL(?) to get the data back to useable form (since FIXL truncates everything past the decimal). I have tried using all the multiplies in the list, but none of them seem to work. Any suggestions on how I can do this? Thanks! Tigamaroo

##### Share on other sites
I did a test program on this. You will want to use the floating point mutiply (*F). Your first word should be the 100000, which I loaded in a data memory (REAL data type). The second word is your D146 and then the third is your result (2 words). One thing to remember is as long as the logic is true the multiply function is executing (re-calculating). On a CJ1 that can be alot of calculations. If you want it to execute once when the logic goes true then put a "@" in front of the function (example: @*F). This will differentiate (one-shot) the function. It won't execute until the logic goes false and then true. This works on all the math and move functions in the Omron.

##### Share on other sites
THANK YOU! I DID WHAT YOU SAID, AND BAM! 15838 THANK YOU EVERYONE!

##### Share on other sites
Good job, Darin! You may be on the way to being our next Omron guru.