Sign in to follow this  
Followers 0
Winall

Scaling function SCL-Pls explain urgent

10 posts in this topic

According to the programming manual for CPM2A (excerpt): SCL Operand Data Areas: S: Source word P1: First parameter word where P1=Ay, P1+1=Ax, P1+2=By, P1+3=Bx R: Result word Limitations: S must be BCD The results can be calculated by first converting all values to BCD and then usingthe following formula: Results = BY – [(BY – AY)/(BX – AX) × (BX – S)] Example: LD 00000 @SCL(66) DM 0100 DM 0150 DM 0200 Data values of parameter words: DM 0150 =0010 DM 0151= 0005 DM 0152= 0050 DM 0153= 0019 When 00000 is turned ON in the following example, the BCD source data in DM 0100 (#0100) is converted to hexadecimal according to the parameters in DM 0150 to DM 0153. The result (#0512) is then written to DM 0200. Some questions: - The example said that source data is "converted to hexadecimal ". Why?? What we want is BCD value, not hexa? - In the example, source data #100 should be calculated as 100 decimal or 256 decimal? - I cannot obtain the result of #0512 (512 decimal) using the above formula. Can somebody do so? Many thanks. Edited by Winall

Share this post


Link to post
Share on other sites
Firstly, The code does work.... Secondly - I concur with your trouble to understand the manual at times, i've been there... I call it "Jinglish" - Japanese to English translation. Thirdly - HEX and BCD are the same up till the value of 9 All values in the PLC memory are stored as Channel (HEX), instructions execute expecting to see the correct data in the operands. ie if a BCD instruction then the data you pass to it will have a BCD representaion otherwse youmay get results that don;;t make sense. ie for a value of decimal of 10 in HEX that is #000A and in BCD this is #0010. (Theres the trap #0010 BCD is in HEX #0010 which equals &16 decimal) Forthly... The SCL function was developed to convert a Decimal number (HEX or another term of Bin) to a BCD result. Why ? Because in the older Omron PLC's 90% of data manipulation was done with BCD numbers not HEX, this certainly made it easier to read code. So this means that when an analogue signal came into the PLC it was a value of between &0 and &4000 decimal which is #0000 hex and #0FA0 hex. We would then use the SCL function to scale this to a BCD result. So in the avove example Source Word is in HEX (or Decimal is you like) So a decaimal value of &100 = #0064 Hex D150 = #10 (BCD) D151 = #5 = &5 (DECIMAL) D152 = #50 (BCD) D153 = #19 = &25 (DECIMAL) NOTE The Result is in BCD .....ie you will see a value of #0200 BCD for a Source of #0064 (&100 Decimal) Regarding the result of #0200 BCD, take windows calculator and put in #0200 Hex in and convert to decimal, what'd you get ? 512 decimal right... Hope i hav'nt confused you more....

Share this post


Link to post
Share on other sites
Hi Sleepy, Yes, the I came up to the results of 200decimal (i.e &200 in the CJ/CS designation) if I noticed that D153 = #19 = &25 (DECIMAL), and D152 = #50 is still 50 decimal in the function ("first converting all values to BCD" in manual confused me), and the source word DM100=#0100=100 decimal (no conversion). But it still confused me that the result of 200decimal should be put into DM 0200 as #200 as BCD value, not as #512. Can U clarify? I think this function is not the only function that is very tricky in the way it handles data type.

Share this post


Link to post
Share on other sites
As mentioned in my post - The scale function takes a decimal (HEX) soruce word and scales it and creates the result as BCD. Hence you get #0200 BCD. In the example it is simple taking a value and scaling it to a ration of 1:2 so a source of &100 dec will produce #0200 BCD

Share this post


Link to post
Share on other sites
Hi Sleepy, Pls clarify point by point: 1- The manual said "Limitations: S must be BCD", meaning the source word must be in BCD, not HEX. If the source word is in HEX, not BCD, then sometimes the data will not be a valid BCD (say #00A0). True or False? 2- The Result word is in BCD. Meaning for a result word of #100 Hex, it should be interpreted as 100 dec, not 256 dec. True or False? 3- So, if the scaling results in 100dec, what value will be written to the Result word? #100 or #256? Many thanks for your attention.

Share this post


Link to post
Share on other sites
1. Manual wrong.... must be BIN (HEX) eg in decimal speak &00000 - &04000 (NOTICE THE & symbol i use for decimal.....) or HEX #0000 - #0FA0 2. Yes..the reult is in BCD - Binary Coded Decimal....therefore if your input source word was &00100 according to the scale param in the example the resul will be #0200 BCD. 3. see 2. More backgournd... bit = 1 (on or off) nibble = 4 bits byte = 8 bits word = 16 bits HEX - BIN decimal representation of a number uses the whole word - channel so be casue with have 16 bit in a word that is 2^16 (2 power 16 = &65535 decimal or in HEX this is equal to #FFFF) BCD breaks the word down into 4 x nibbles (4 bits) with each nibble representing a number between 0 to 9 hence if a word contains BCD data the larest number that will be displayed in BCD is #9999 Note a number in BCD of #9999 in binary form is 1001 1001 1001 1001 Now if i was to look at this same data which of course you can and view is as HEX i would have a HEX number of #9999 which in decimal terms = 39321....

Share this post


Link to post
Share on other sites
Hi Sleepy, I had to try actual program on PLC to see the truth about it. The manual really sucks and is not trustable. The CX-P software is better in providing info on data type of each parameter, but not really enough. Thanks again.

Share this post


Link to post
Share on other sites
I'm confused couple question. I)Why in first parameter need to write as below? DM150 = #0010 DM151 = #0005 DM152 = #0050 DM153 = #0019 II)If DM200 result is 200 Bcd, then what I need to do 200 Bcd to setting encoder motor. Thanks in advance

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