Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


Interesting thing about PLC counters and system tics.

Interesting thing about PLC counters and system tics.

I was commissioning a PLC based filter-plant controller yesterday and needed to display the instantaneous flow. I had the flow coming in as a pulse per gallon. And was expecting a flow of around 20GPM.

To get the most recent instantaneous value I decided to count how many 10ms periods occurred between rising edges of the flow pulses. Then I would essentially invert that captured count of 10ms periods and multiply by 6000 to get gallons per minute. [(1/10ms counts) x 100 ms/s x 60s/min].

I ran the system and the indicated flow was 20~21GPM. Sweet! Then I looked at the actual flow meter and saw it was doing only 14GPM. Gack! My calculated flow was off by quite a bit.

Reviewing my method:
I was using a _10ms system generated contact to increment a counter.
When a flow pulse rising edge came in I would snatch the counter value into a register.
Then I would reset the counter in the next rung down.
The counter would again start totalizing the 10ms contact closures generated by the PLC.
Then I'd do the above mentioned math and send the result off to the HMI display.

After a whole lot of head scratching I realized that the pulses coming from the water meter were about 4.2 seconds apart. Yet the totals my counter was coming up with were numbers like 286 (10ms periods) which, of course, means 2.89 seconds!! (Hence the greater indicated flow from the inverted result)

I'd always wondered about the asynchronous aspects of a PLC, where it comes by on a scan and checks a system contact at some quasi beat frequency - what happens? Since the scan time was running 5~6ms the system generated _10ms contact was being missed about 1/3 the time. Nasty. Now I know.

There's probably a better way but I don't see it on this relatively simple PLC (CLICK).

Keith Cress
kcress -

RE: Interesting thing about PLC counters and system tics.

I'm not sure if I followed what you're doing, but doesn't the PLC have a free-running counter function? Most PICs, I think, have a hardware counter that you can set up to count, and it runs independent of the software loop, so:
> receive pulse
> read counter
> zero counter; counter runs on its own
> calculate flow rate
> wait for next pulse

FAQ731-376: Forum Policies

Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers

RE: Interesting thing about PLC counters and system tics.

I think you need to use either the "Pulse Catcher" or "Interrupt" setting under Setup\ CPU Builtin I/O. You have to use the I/O on the actual PLC, not Extended modules so some rewiring might be required. I need to try the same thing on an application where we're trying to detect falling pieces of clear plastic and getting inconsistent results that I thought were from the sensor, but now I'm not so sure.

RE: Interesting thing about PLC counters and system tics.

Does the CLICK support interrupts? If so use them. Another alternative is to generate you own 10 ms clock using a timer. Or use a timer and then calculate the flow from the accumulator value.

RE: Interesting thing about PLC counters and system tics.

Hi IR; That is exactly what I'm doing. And no the CLICK doesn't have a free running timer that you can directly read. Hence my attempt at creating one...which falls short. (Of counts) :(

John2025: !!!! Thanks for pointing out that route to interrupts. Wow. Don't know how I missed that. Maybe since it's a pull down I rarely needed to go to. :I
I see that 'CPU Inputs' requirement thing too. Now that I understand how to use the interrupts on a CLICK it still doesn't solve my problem since with that interrupt I can't read any kind of system free-running timer.

djs: Yes as mentioned by John! Hmmmm Maybe the Timers all keep correct time? That's an idea I will try. I'll have to deal with the timer reaching its terminal value.. Wait, I can reset the timer on every edge, after reading it out. I'll go try that.

I also came up with a way to use the scheme I have running now without the aliasing under-count issue I described happening. You can set the CLICK's scan rate to be fixed! So I can set the scan rate to be 10ms and trigger the existing counter with a _scan contact. I'll try this too.

Keith Cress
kcress -

RE: Interesting thing about PLC counters and system tics.

If your counting a pulse that is coming true every 4 seconds then you monitor that input at 2x the rate. If you use timed interrupt task would get it if set for 2 secs. Then one shot that pulse when its true to get your flow. Otherwise, I see you counting a scan time like your doing. This is the only thing I remembered from digital systems class.

Or you can use a event driven task that goes true when the event comes true and count it in that task routine. I never liked using counters, add instructions are always full proof.

RE: Interesting thing about PLC counters and system tics.

I didn't know about those other input modes either until you brought up this subject. I have a hard time remembering that Leading Edge to the Click means a change of value from one scan to the next. I think the Pulse Catcher works for the shorter than scan cycle pulses, but djs's idea about the timer sounds like a simpler solution that doesn't require rewiring.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close