Author Topic: Monitoring and comparing IO  (Read 12781 times)

TTCSR

  • Newbie
  • Posts: 30
  • I'm a llama!
    • View Profile
Monitoring and comparing IO
« on: September 17, 2012, 03:55:22 AM »
I am using a T100MD1616+ and a MMI6050 and have run into a few issues with my project.

I want to monitior and compare inputs.  For example, if input 1 is on and any other input or combination of inputs turns on, I want to be able to distinguish this and output an error message.  Is there a command line to compare and monitor all the inputs?  
TESTIO (1-20) something like that.  


support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Monitoring and comparing IO
« Reply #1 on: September 17, 2012, 08:01:29 AM »
You can monitor a channel of 16 inputs using INPUT[n] and if any of these turns ON it will return a non zero value.

E.g. INPUT[1] represent input bit #1 to #16.

What you want to do can be coded as follow:

IF TESTBIT (INPUT[1],0)      ' if input #1 is ON
   IF INPUT[1] & &HFFFE      '  check if any other input (#2 to #16) is ON
        CALL reportError  ' call subroutine to report error.
   ENDIF
ENDIF
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

TTCSR

  • Newbie
  • Posts: 30
  • I'm a llama!
    • View Profile
Re:Monitoring and comparing IO
« Reply #2 on: September 17, 2012, 11:27:34 AM »
Thank you, it sort of works, but there is still an issue.  My code looks like this:

IF TESTBIT (INPUT[1],2) THEN
 IF INPUT[1] & HFFFE THEN
  SETLCD 0,0, CHR$(1)
  SETLCD 1,1,"SHORT CIRCUIT BETWEEN"
  SETLCD 2,1,"PIN A3 &"
  CALL 8:
  DELAY 1000
ENDIF
END IF

CALL 8 LOOKS LIKE THIS....

IF TESTIO(A1_CS)=1 THEN
 SETLCD 3,1,"PIN A1"
 DELAY1000
ENDIF
IF TESTIO(A5_CS)=1 THEN
 SETLCD 3,1,"PIN A5"
 DELAY1000
ENDIF
IF TESTIO(A7_CS)=1 THEN
 SETLCD 3,1,"PIN A7"
etc......

The problem now is the messages only appear if the first A5_CS occurs.  If the other inputs are ON, they cycle, which is fine, however, if A5_CS is gone, the rest will not display their message.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Monitoring and comparing IO
« Reply #3 on: September 17, 2012, 05:04:45 PM »
You have changed the statement to:

IF TESTBIT (INPUT[1],2)

This means bit #2  of the input word must be ON (which corresponds to digital input #3) in order for the inner block of the IF statement to execute. Is that what your intention is?

Also the mask &FFFE is to mask out bit 0 (digital input #1) of the INPUT[1]. If you want to mask out bit 2 then it should be changed to &FFFB  (1111 1111 1111 1011)
« Last Edit: September 17, 2012, 05:06:04 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

TTCSR

  • Newbie
  • Posts: 30
  • I'm a llama!
    • View Profile
Re:Monitoring and comparing IO
« Reply #4 on: September 18, 2012, 05:36:49 AM »
Awesome!  I didn't realize that (INPUT[1],2) corresponded to input #3, I thought it was #2.  The mask out info helped as well.  If works now, thank you very much  ;D

TTCSR

  • Newbie
  • Posts: 30
  • I'm a llama!
    • View Profile
Re:Monitoring and comparing IO
« Reply #5 on: September 18, 2012, 09:41:20 AM »
I've noticed that even when input #3 is on and inputs 1# to #16 are off, the message...

  SETLCD 0,0, CHR$(1)
  SETLCD 1,1,"SHORT CIRCUIT BETWEEN"
  SETLCD 2,1,"PIN A3 &"

...still remains, should it not disappear?

TTCSR

  • Newbie
  • Posts: 30
  • I'm a llama!
    • View Profile
Re:Monitoring and comparing IO
« Reply #6 on: September 18, 2012, 10:04:23 AM »
 ::) Oops nevermind, I put the wrong hexidecimal number in  :P

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Monitoring and comparing IO
« Reply #7 on: September 19, 2012, 03:26:58 AM »
I notice your code uses a lot of DELAY function. Although this may work if the system is not expected to handle any input event during the time when the DELAY is being executed, it is probably not the best practice and won't work at all if your system need to still monitor any input changes during this time. One way to provide a delay for something without locking up the CPU into an idle delay time is to use the timer and let the timer contact run another custom function to execute the code after the time out.  Another way is to define some interrupt inputs so that critical code associated with the input can run even if the CPU is locked up executing the DELAY function.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS