Help - Search - Members - Calendar
Full Version: Real MOV in CJ1
Forums.MrPLC.com > PLCs and Supporting Devices > Omron > CX-Programmer
Riggs
Hello All,

I've got a real number (x_REAL) which I want to fix into an INT (x_INT).
If the value of x_REAL is above 32768 or below -32767 I want to limit it to those values. I am trying to do this with a couple of compare instructions followed by MOVF instructions:

>=F x_REAL +32768
which turns on a MOVF +32768 x_REAL instruction

and

<=F x_REAL -32767
which turns on a MOVF -32768 x_REAL instruction

Then a FIX x_REAL x_INT instruction.

BUT: the CJ1 dosen't support MOVF, and I cant see another way to assign a value to a real on a CJ1.

Am I missing something really obvious here?

Any help would be much appreciated!

James.

(P.S. I'm on a bit of a steep learning curve here, so will probably be asking a few stupid questions over the next few weeks... and I'm spending a lot of time poring over the manuals, before anyone asks!)
dweste
I suppose you want to go up to +32767, thats the maximum for a 16-bit signed integer?

Instead of 'MOVF +32767 x_REAL' you can use 'FLT +32767 x_REAL'.
Instead of 'MOVF -32768 x_REAL' you can use 'FLT -32768 x_REAL'.
banker
Hi

Real format is 32 bit you can use MOVL Move long.
But in you case you need to use a Convert instruction FIX. Real to 16 bit.
Use CXP instruction help. yes.gif

Banker

Riggs
Aha, thanks for that dweste, I hadn't spotted the FLT instruction. And yes, I do mean 32767.

Banker,
I realise that this has been covered over and over again in the forums, but I was under the impression that if you MOV a 16 bit integer into a 32 bit real, then the PLC will interpret the real number incorrectly?

I've rejigged the program now to use FIX, and if the FIX turns the error flag on, I then do the comparisons and use FIX to load the 32767's into the x_INT register.

Thanks for your excellent replies,

James.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.