Sign in to follow this  
Followers 0
Sleepy Wombat

Scaling Data in CJ1/CS1 PLCs...

13 posts in this topic

SLEEPY WOMBATS TIPS CLASS #101 The use of the old scaling functions SCL really suck when it comes to the new CJ1/CS1 PLC's, mainly because it still relies on BCD etc....Today is so easy to use INT, UINT values in the program i hardly ever use BCD any more..... Therefore I needed to find a way to scale Analogue Data. Probably 95% of scaling functions would be done on an Analogue Input or Output Data. The other criteria i set my self was to make it as easy to use as the Scale with Paramters Instruction as found in AB (newer models). So here it is..... USE THE ALL POWERFUL AND CONQUERING APR FUNCTION...... This is how you do it.... Firstly Setup the symbols eg D29000 = Setup Control Word for APR -- (we will set this to #0801) D29001 = Raw Data Min Value (typically we will set this to &0) D29002 = Scaled Result Min Value (Signed Value) D29003 = Raw Data Max Value (typically we will set this to &4000) D29004 = Scaled Result Max Value (Signed Value) Secondly Create a little logic that sets up the initial data words LD CF113 MOV #0801 D29000 MOV &0 D29001 MOV &4000 D29003 Thirdly..Any time you want to use the scale function simply set your Min and Max Scaled Values to D29002 and D29004 respectively before using the APR call The following will scale the Raw data to 0 TO 2000 The source data is in D0 the Destination is D1 LD CF113 MOV &0 D29002 MOV +2000 D29004 APR D29000 D0 D1 If you wanted to scale between -100 and 200 then the code would have looked like LD CF113 MOV -100 D29002 MOV +200 D29004 APR D29000 D0 D1 IT's that SIMPLE Please find an example below.... Scaling Cx-programmer File Link BTW if you delve into the APR function a little more you could actually use floating point data as well....

Share this post


Link to post
Share on other sites
Yep. Been using it for years on fuel tanks. The tank is round, laying on it's side with rounded ends. Just get the tank manufacturer to let you know how many ma = how many litres and set up APR. Really easy. Have also had to do it myself with a transducer and a stick marked in centimetres. Gradually fill the tank and check every couple of centimetres. The tank manufacturer should be able to provide a chart with depth versus litres. By the way, I have not seen this command in any other PLC. Does anyone else have it? I used it as far back as the C200HS. That is a year or two. Edited by BobB

Share this post


Link to post
Share on other sites
It can also be used for a small lookup table where the input value points to a set of absolute coordinate values based on pre-stored motion profiles. The values do not necessarily have to be on a curve.

Share this post


Link to post
Share on other sites
Yeh Bob i too have used this function for tank profiling just as you said... and No i do not believe that there is any other PLC outthere who cna do Linear Extrapolation, Sine, Cosine operations with the one powerful function like APR. Jay, thats i cool trick for motion profiles.... i have never come across that particlular problem before but i sure as hell know the quick know the soln now. I appreciate the feedback...Perhaps we should form the unofficial fan club for the APR function. Yehah... The original posting was to point out a real neat and tidy way of scaling without having to think much. Ie I just want to scale this analogue value input to -100 to 200 to display on a MMI correctly or do some calcs on based upon comparisons to setpoints....Plus i don;t want to have to do any out of range clamping. All i want to have to put in is the Scaled (engineering ) values and get the right answer. I hope that this little bit of code can help any one achieve that with a minimum of fuss.... BTW "When you stop having a OSR in the morning, you must be getting old...."

Share this post


Link to post
Share on other sites
What's the significance of #0801 in D29000? Why did you use D29000?

Share this post


Link to post
Share on other sites
Just a quick question will it work by reversing the #s so if your raw data is high your scaled data is low..... Never mind it does work tryed it out and it works well I am still having a problem with the Hex showing up in the Result. The scaling works but it comes in as hex. :( Ok I am just not that smart it seems....LOL I got it figured out. For some reason it wont allow you to change the channel to int in online edit Edited by KinK

Share this post


Link to post
Share on other sites
No real reason other then to keep this data out of the way. I originally wrote the code while writing a program with over 6000 + tags (symbols)....The PLC is to sit on a controller link network also...Therefore i just reseved this area for this kind of stuff...

Share this post


Link to post
Share on other sites
Sleepy, Thanks for gettting back to me. If I understand you correctly, the choice of D29000 was some what arbitrary after you took into consideration what other locations were allocated and/or mapped. Regarding #0801, I've looked thru the documentation I have (W394-E1-03, W393-E3-04, & W395-E1-02) and can't find any details on the significance of the control word except that 0 and 1 compute the sine and cosine of a value. Where in the documentation have you found the details for the APR control word? Thanks again, MickeyBob

Share this post


Link to post
Share on other sites
08=Signed Binary Data 01=Number of Line segments The manual you need is known as the CJ Instruction Reference Manual (W340-E1-07). W340-E1-07 CS/CJ Instruction Reference Manual @ omron.com

Share this post


Link to post
Share on other sites
08=Signed Binary Data 01=Number of Line segments The manual you need is known as the CJ Instruction Reference Manual (W340-E1-07). W340-E1-07 CS/CJ Instruction Reference Manual @ omron.com

Share this post


Link to post
Share on other sites

Even simplier way is to use function block...

BR, Andrej.

Scaling.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0