Jump to content

Recommended Posts

Posted
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?
Posted
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.
Posted (edited)
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
Posted (edited)
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
Posted
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.
Posted
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.
Posted (edited)
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...