Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: Bolt on August 15, 2019, 09:48:11 AM

Title: Delta Contact for a Range
Post by: Bolt on August 15, 2019, 09:48:11 AM
Is there an easy way to have a range of Delta Contacts to trigger a rung?  For example, ORDLT C600:C631?  ORDLT N600:N631? I think bits could be written to a (double)word and compared, but how would I do integers?  I don't think a sum would work, as 2 values could swap in the same scan and not trigger.
Title: Re: Delta Contact for a Range
Post by: BobO on August 15, 2019, 10:04:04 AM
Is there an easy way to have a range of Delta Contacts to trigger a rung?  For example, ORDLT C600:C631?  ORDLT N600:N631? I think bits could be written to a (double)word and compared, but how would I do integers?  I don't think a sum would work, as 2 values could swap in the same scan and not trigger.

Cast. C0:D = C0-C31.

That has limited benefit for words like N, but you can get 2 N locations with N0:D.
Title: Re: Delta Contact for a Range
Post by: ATU on August 15, 2019, 07:10:46 PM
You could probably write a subroutine that would work efficiently. Pass the starting point in N memory and number of registers. Do a for loop comparing the current data with old data which is an offset in High N memory. For instance use an offset of 10,0000.  Previous data stored for N0 to N100 would be stored at N10000 to N10100. After the compare you store the new data into the previous data register inside the same loop.
Title: Re: Delta Contact for a Range
Post by: Controls Guy on August 16, 2019, 12:00:39 PM
I think bits could be written to a (double)word and compared, but how would I do integers?  I don't think a sum would work, as 2 values could swap in the same scan and not trigger.

What if you checksummed the range and looked at STRDLT MyCheckSum?
Title: Re: Delta Contact for a Range
Post by: BobO on August 16, 2019, 01:05:49 PM
I think bits could be written to a (double)word and compared, but how would I do integers?  I don't think a sum would work, as 2 values could swap in the same scan and not trigger.

What if you checksummed the range and looked at STRDLT MyCheckSum?

With a CRC, this would work well.
Title: Re: Delta Contact for a Range
Post by: Bolt on August 16, 2019, 03:37:51 PM
Thanks.  The C0:D is exactly what I was looking for, and then N0:D will work in a pinch.  Checksum seems like too much work for this spot in my project  ???
Title: Re: Delta Contact for a Range
Post by: BobO on August 16, 2019, 03:39:28 PM
Thanks.  The C0:D is exactly what I was looking for, and then N0:D will work in a pinch.  Checksum seems like too much work for this spot in my project  ???

CHECKSUM is an instruction.
Title: Re: Delta Contact for a Range
Post by: Bolt on August 16, 2019, 03:51:35 PM
Yes, but how do I enter N600:N632 as the criteria?
Title: Re: Delta Contact for a Range
Post by: BobO on August 16, 2019, 04:18:39 PM
Yes, but how do I enter N600:N632 as the criteria?

CHECKSUM
Buffer N600:UB0
Function CRC16
0 initial
0 offset
ending offset 64
Title: Re: Delta Contact for a Range
Post by: ATU on August 16, 2019, 08:25:25 PM
What if you checksummed the range and looked at STRDLT MyCheckSum?

Great Idea!   I could use that one.
Title: Re: Delta Contact for a Range
Post by: PLCwannabe on August 17, 2019, 11:36:22 AM
Trying to read between the lines here. I have 50 different C's triggering the same alarm. For me this is 50 rungs of code. Is there a more efficient way to do this with less rungs?
Title: Re: Delta Contact for a Range
Post by: Controls Guy on August 17, 2019, 12:04:02 PM
Great Idea!   I could use that one.

Yes it is (but not mine)!  I was working on something similar several years ago and another poster suggested that idea, I think it was actually in this forum.
Title: Re: Delta Contact for a Range
Post by: BobO on August 17, 2019, 12:09:08 PM
Trying to read between the lines here. I have 50 different C's triggering the same alarm. For me this is 50 rungs of code. Is there a more efficient way to do this with less rungs?

Probably. What is your current logic doing? I'd like to see a couple of your rungs.
Title: Re: Delta Contact for a Range
Post by: PLCwannabe on August 17, 2019, 12:37:30 PM
Here is a screenshot of all the c,s triggering a program. It keeps going right down to C1050.
Title: Re: Delta Contact for a Range
Post by: BobO on August 17, 2019, 12:38:02 PM
I assumed that you want a one shot any time a C bit goes from 0 to 1. This single rung triggers on 64 C bits.
Title: Re: Delta Contact for a Range
Post by: BobO on August 17, 2019, 12:39:21 PM
The only requirement is that the C bits need to be contiguous and aligned on 32 bit boundaries.
Title: Re: Delta Contact for a Range
Post by: BobO on August 17, 2019, 01:42:48 PM
And your existing code could be reduced to something much simpler, like what I've attached. The problem is that won't re-trigger properly unless all alarms go completely away. The MATH box approach will trigger a new alarm regardless of the state of previous ones.
Title: Re: Delta Contact for a Range
Post by: ATU on August 17, 2019, 11:28:45 PM
Would CHECKSUM run faster than a series of OR'd  Delta Contacts using 32bit registers?  Is CHECKSUM native or one of those encapsulated instructions packed with hidden sub instructions?
Title: Re: Delta Contact for a Range
Post by: BobO on August 17, 2019, 11:54:03 PM
Would CHECKSUM run faster than a series of OR'd  Delta Contacts using 32bit registers?  Is CHECKSUM native or one of those encapsulated instructions packed with hidden sub instructions?

It?s native, but it isn?t going to be faster than deltas.
Title: Re: Delta Contact for a Range
Post by: PLCwannabe on August 23, 2019, 12:43:03 AM
I assumed that you want a one shot any time a C bit goes from 0 to 1. This single rung triggers on 64 C bits.

Could you explain how this rung works? Is the copy instruction also part of checking all the c's?Thanks.
Title: Re: Delta Contact for a Range
Post by: BobO on August 23, 2019, 09:02:30 AM
Could you explain how this rung works? Is the copy instruction also part of checking all the c's?Thanks.

The MATH box is is simply doing a bitwise comparison of the 64 C bits and 64 bits within two D locations. Basically it returns true if any single C bit is set, but the corresponding bit in the Ds is not. Then the COPY just pushes the current state of the Cs into the Ds. It's just detecting the rising edge of the Cs. This allows the alarm handler to trigger in response to each rising edge event.

If you want the alarm handler to run when the first alarm is triggered, and then not run again until all alarms are cleared, then the other rung I gave you will work.