Author Topic: Count pulses on pulse frequency inputs  (Read 15001 times)

congo

  • Newbie
  • Posts: 16
  • I'm a llama!
    • View Profile
Count pulses on pulse frequency inputs
« on: April 22, 2016, 12:14:31 PM »
Can someone tell me what the best way is to capture the accumulated number of pulses on a PULSEFREQUENCY[] channel.

I'm using the input channels to measure rotating frequency of a conveyor but would also like to capture the number of pulses on that same channel.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Count pulses on pulse frequency inputs
« Reply #1 on: April 23, 2016, 05:50:26 PM »
You can define HSC input using HSCDEF and you will then be able to capture both the number of pulses on the HSCPV[1] to HSCPV[3] variable. At the same time you can use the PULSEFREQUENCY and PULSEPERIOD functions to capture the frequency or the period of the incoming pulses.

Note that HSC inputs are defined in a pair so if you use HSC channel #1 on the FMD PLC it will takes up input #3 and #4 even if you only need just one input. Please refer to Chapter 6 of the PLC's user manual for the mapping of the HSC inputs to the physical inputs.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

congo

  • Newbie
  • Posts: 16
  • I'm a llama!
    • View Profile
Re:Count pulses on pulse frequency inputs
« Reply #2 on: April 23, 2016, 07:02:10 PM »
That works thanks. Alternatively if the pulses are not that high of speed (10-30Hz) is there a way to count theses pulses while utilizing all 4 PULSEFREQUENCY[] inputs? I'd like to use 4 sensors wired to inputs on the FMD8810 for 4 separate conveyor speeds as well as accumulate pulses on each channel.

For counting purposes I've tried using a normally open contact driven by one of my prox sensors which energizes a {dCusF} containing a line of code like:
DM[6]= DM[6]+1. This works but misses pulses occasionally due to the program scan time, not adequate.

If all 4 PULSEFREQUENCY[] channels are fast enough to measure frequencies of 100Hz+ then I'm thinking I should be able to capture and count pulses without resorting to calling the HSC. Is there another way?

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Count pulses on pulse frequency inputs
« Reply #3 on: April 24, 2016, 09:38:18 AM »
Another option to consider is to use the periodic interrupt to call a CF once every second.  In the custom function call PulseFrequeny[] for each of the 4 sensors. As you are measuring time on very accurate boundaries you can simply accumulate the measured frequency of each input (pulses per second) as the running count of pulses.

Please be aware that PulseFrequency[] is not very accurate at low speeds. With an input of 10Hz you may see an error of 10% (+/- 1Hz).  If you need better accuracy, use PulsePeriod[] in place of PulseFrequency[] and scale the integers.

gary D*ickinson
« Last Edit: April 24, 2016, 09:40:30 AM by garysdickinson »

congo

  • Newbie
  • Posts: 16
  • I'm a llama!
    • View Profile
Re:Count pulses on pulse frequency inputs
« Reply #4 on: April 27, 2016, 04:32:41 PM »
So to trigger that:

Does the INTRDEF18,cfnum,x get initiated in an initial scan triggered custom function? Then calls the referenced custom function of choice on a ladder rung?  What contact if any is on that rung?

I'm not too sure how to construct that and haven't found a full explanation of it in the documentation yet.

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:Count pulses on pulse frequency inputs
« Reply #5 on: April 27, 2016, 10:40:45 PM »
The Intrdef statement should be executed on the first scan of the program using the 1st.Scan special bit.

This is a trivial version of a CF that you would call on the 1st.Scan:

' Init CF called on first scan of ladder logic to initialize the system
'
INTRDEF 18, TimerInterrupt, 1000      ' interrupt once every second (1000 ms)
[/font][/color]

Now you need to write the custom function, "TimerInterrupt".  A simple version might look like this:

' TimerInterrupt
'
DM[1] = DM[1] + 1      ' keep a running count of interupts processed
ToggleIO TestBit      ' toggle an OUTPUT bit so that you can "see" that the program is working
[/font][/color]

The CF, TimerInterrupt is not triggered by a ladder logic rung, but is triggered every 1000 ms by a hardware timer in the PLC.

Best regards,
Gary D*ickinson