Sign in to follow this  
Followers 0
Linas

Comparing

7 posts in this topic

I need to compare analog input PIW256 (WORD) with setpoint that is defined in data block as REAL. Problem is that there are no comparators for WORD format variables. I managed to compare them by using this formula: REAL=WORD*100/27648 code: A I 0.1 = L 0.0 A L 0.0 JNB _001 L 27648 T MD 4 _001: NOP 0 A L 0.0 JNB _002 L 100 T MD 8 _002: NOP 0 A L 0.0 JNB _003 L DB1.DBD0 L MD 4 *R T MD 12 _003: NOP 0 A L 0.0 JNB _004 L MD 12 L MD 8 /R T MD 16 _004: NOP 0 A L 0.0 JNB _005 L PIW 256 ITD T MD 20 _005: NOP 0 A L 0.0 JNB _006 L MD 20 DTR T MD 24 _006: NOP 0 A L 0.0 A( L MD 24 L MD 16 >=R ) S M 0.0 A L 0.0 AN M 0.0 JNB _007 L 27648 T PQW 256 _007: NOP 0 as you can see it took lots of memory MD4 to MD24. IS THERE A MORE SIMPLE WAY TO COMPARE AND GENERATE AN OUTPUT SIGNAL?

Share this post


Link to post
Share on other sites
You are making this way too difficult. L DB1.DBD0 //Load the real. L 276.48 *R // Do you know where this comes from? L PIW256 // Load the input data. AD DW16#0000FFFF // convert to a DWORD make sure the high bits are 0 DTR // convert DWORD to R =R // Compare the two accumulators any way you want I will let you work out the details.

Share this post


Link to post
Share on other sites
A L 0.0 JNB _003 L "OP3_data (DB1)".VAR_TE1 L MD 4 *R // in this part I use 'multiply real' function MD4 x MD12 = DB1.DBD0 * 27648 T MD 12 A L 0.0 JNB _004 L MD 12 L MD 8 /R // here I divide MD12 / MD 8 ;MD8 = 100 T MD 16 this is real mess I'll try your suggestion Edited by Linas

Share this post


Link to post
Share on other sites
L DB1.DBD0 I have tried to load content of DB1.DBD0 (REAL) its value 160 when I checked the content of accumulator 1 it was = 43200000 (in Hex) why I get this value in accu 1? If I load PIW256 everything goes right - I get the same value in accu1 as specified one in input. Edited by Linas

Share this post


Link to post
Share on other sites
43200000 hex looks about right. Hint, how do you represent a floating point number in binary? What bits represent the sign? Which bits represent the mantissa and which represent the exponent? I know, more questions than answers.

Share this post


Link to post
Share on other sites
It is simple. To compare, the input and setpoint must the same unit. Analog input is Word, you convert to DWORD using ITD instruction. And using DTR to make real number. Now you can compare it.

Share this post


Link to post
Share on other sites
Is the REAL value some kind of engineering value (x.x degr. C or something like that) ? Then you probably need to scale the analog input to an engineering value as well. You can make your own scaling function as others have suggested, but you can also use the "regular" one. In the standard library, under TI-S7 converting blocks, there is FC105 SCALE that converts an analog input to a REAL engineering value. It allows you to easily specify MIN and MAX range for the scaling, including sensors with "offsets" (like -50 degr. C to + 80 degr. C for example). Edited by JesperMP

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