News:

  • May 14, 2026, 10:35:36 AM

Login with username, password and session length

Author Topic: Delta contact not performing as expected.  (Read 11454 times)

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Delta contact not performing as expected.
« on: November 02, 2025, 04:16:38 PM »
I'm runnig into a problem with a delta contact used to increment daily, monthly, and yearly totalizers.  Everytime the total gallons for a  flowmeter goes up by one, (about 1-2 times per second) the delta contact should increment all the totalizers by one, but its not happening that way.For every 80 gallons metered, the totalizers are only going up by about 60 gallons. See the attached few rungs. (Flow rate as calculated from hi speed input is correct, total pulses register & total gallons register are all both correct as well.(cal factor is 78.11 pulse/gallon)  What am I missing here? I know I could use different ways to calculate the totals, but I'm thinking this should work well enough.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3814
    • Host Engineering
Re: Delta contact not performing as expected.
« Reply #1 on: November 03, 2025, 09:18:25 AM »
If the delta is 2, the INC only increments by 1.  Is this the desired behavior, i.e. count the number of times it changes, not the actual number of gallons?

Can you guarantee that it is always only going up by 1 (never by 2 or more).  Add some logic to actually calculate the delta and see if that logic returns the right value.  The assumption may be the issue (just guessing - I'm looking at it logically, not physically, but I also try to not to assume).


Sorry - I see the issue.  You are attempting to utilize HSC edge logic in regular ladder.   Need to look at this again - sorry.
« Last Edit: November 03, 2025, 09:20:29 AM by franji1 »

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3814
    • Host Engineering
Re: Delta contact not performing as expected.
« Reply #2 on: November 03, 2025, 10:25:33 AM »
Sadly, my background is not strong for when to utilize Pulse Catch vs. a plain High Speed Counter for integration of volume.

Someone more knowledgeable can definitely point you in the right direction.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6156
  • Yes Pinky, Do-more will control the world!
Re: Delta contact not performing as expected.
« Reply #3 on: November 03, 2025, 10:54:34 AM »
The question is simply the delta contact, not the source of signal. It looks for changes, triggers the output, and stores the current state.

The only thing that would make it "fail" is if the source signal is counting more than once between invocations of the delta instruction. There are multiple reasons why that might be, but I would first prove it. Add logic to the increment rung to store the previous state of the signal and take the difference between current and last and store as a max...dSig = max(dSig, CurSig-LastSig)
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: Delta contact not performing as expected.
« Reply #4 on: November 03, 2025, 02:59:37 PM »
 I think the issue is that rung number 4 is only calculating once per second rather than every scan. Shouldn't the alwayson bit be triggering a calculation every scan?

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6156
  • Yes Pinky, Do-more will control the world!
Re: Delta contact not performing as expected.
« Reply #5 on: November 03, 2025, 03:21:54 PM »
I think the issue is that rung number 4 is only calculating once per second rather than every scan. Shouldn't the alwayson bit be triggering a calculation every scan?

That math box will solve every scan. If this is only happening once per second, it is more likely that your task isn't running continuously.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: Delta contact not performing as expected.
« Reply #6 on: November 03, 2025, 03:36:23 PM »
The task is running continueosly, but I've figured out what the issue is. When I cleared  MeterTotalPulses0 to zero, the issue resolved instantly. After follow up troubleshooting I've determined that when MeterTotalPulses0  register  increments greater than 1.06 billion, that is when the issue starts with the math instruction in rung 4, not calculating every scan. Are the D registers useful right up to their max of 2.1 billion?

Scooter

  • Jr. Member
  • **
  • Posts: 13
Re: Delta contact not performing as expected.
« Reply #7 on: November 04, 2025, 09:43:13 AM »
What I find odd is that if you take the value of MeterTotalPulse0, which is 1095958347, and divide that by your cal factor of 78.11 you should get 14030961 and not 14010541 which is the result shown in rung 4. In order to get the answer that you did, the CalFactorMater0 term would have to be 78.223842.

And then assuming the value for your MeterPulseRate0 in rung 2 is the freqcnt value from rung 1 (6309.48), I see that the result of 80.659 shown doesn't quite match up with a cal factor of 78.11 but in this case would be 78.2241287. Which raises the question, why is the value for CalFactorMater0 slightly different between rungs 2 and 4???

Is your cal factor term changing dynamically?

PLCwannabe

  • Hero Member
  • *****
  • Posts: 208
Re: Delta contact not performing as expected.
« Reply #8 on: November 04, 2025, 11:43:22 AM »
The cal factor is actually 78.22385, the rest has to be rounding errors. The issue in rung 3&4 actually starts when the Total Pulse value reaches 1,073,741,823, which is exactly half the max value of a Dword, which means it has something to do with the final bit in the dword. My workaround is to clear all values to 0 when they reach 1 billion.