Beckhoff TwinCAT frequecy calculation from Pulse counting module

bgtorque

Member
Join Date
Oct 2013
Location
Northampton
Posts
127
Hi, any advice would be useful.
We have an EL1512 that is counting pulses from a flow meter. We need to ascertain the frequency of the pulses as this is proportional to flow and we can control from this.

Now this is a fairly dopey loop with 5-100Hz being the full range of pulse frequnecy we could expect to see.

We don't need rapid response or are looking at particularuly dynamic transient flow. We thought the best method would be to look at the time to count 5 pulses and determine the frequency from that, but i'm open to suggestions. I'm relatively new to Beckhoff, so any thoughts or examples of this would be useful and appreciated.

Thanks
 
seems like a decent plan.


five seem small: at 100Hz that is 50ms so the scan time, which is likely the majority of the error budget, may be an issue.


I would choose a power of two (8, 16, 32), so it's easy to test and clear (rising edge or 1 in bit 3 or 4 or 5; clear either with 0 or AND with 7 or 15 or 31).


But it's a balance between update time and accuracy; waiting for the 32nd pulse at 5Hz takes over 6s. Maybe mark the time and ordinal of the last pulse and then perform the calculation (average) at 1Hz.


What is the time source? For an A-B MicroLogix 1xxx it could accumulate the per-scan times of the 10kHz clock (S:35, IIRC).


Update: I thought the PLC would do the timing, but I see the EL1512 has a 1Ghz clock and the ability to count two channels; can the 1GHz clock feed the second counter? Maybe read/calculate the 1GHz counter increment at every flow meter pulse and maintain a moving average of the last 5?
 
Last edited:
Indeed, we could use the scan clock and run the cycle a number of times and see how many pulses we counted. Just not sure how to go about this, for something on the face of it that is quite simple, it has been a struggle. Not getting much joy with getting a solution from Beckhoff to be honest.
If it was a compactlogix PLC i'd be able to sort this without a problem. I could just start a timer of sufficiently long length (>1sec) and count 'X' number of pulses and then look at the timer accumulator and divide the pulses by that value to get my frequency. then reset the timer and start again. This would be fine, surely I could do something similar in Beckhoff world?
 
Still, that's 2% of 50ms.

very true.

The other way would be to start a 1sec timer and move the pulses to a counter and then move the counter value to the Freq destination everytime the timer completes and then reset the timer and the counter?

Just need to figure out how to do this in TwinCAT is all...
 
very true.

The other way would be to start a 1sec timer and move the pulses to a counter and then move the counter value to the Freq destination everytime the timer completes and then reset the timer and the counter?

Just need to figure out how to do this in TwinCAT is all...


Same idea, but I would run a 2s timer and on the first pulse where the ET (Elapsed Time) is > 1000ms, divide the pulse count by the ET, and reset the timer and the pulse count. So there is a new value every 1010ms (at 100Hz) to 1200ms (at 5Hz).


Obviously the choice of 1000ms is arbitrary.


Sorry I seem to be the only one responding but I have no idea about TwinCAT; like you say it is trivial with the manufacturer we know. Time to ask The Google about TwinCAT manuals, I guess :-/


Update: we also need to decide what happens when the 2s timer expires (lost signal, zero flow, etc.).
 
Last edited:
Has the flow meter got a 4-20ma output, most that I have used have, if so you could use that into an analogue card.
As stated above you could sample the pulses at a time interval, what is the pulse i.e. 1 pulse every litre ? obviously, the more pulses per litre the better but what accuracy do you need.
The problem is without this sort of information you will get the techno nerds here leading to accuracy only achieved in high spec instruments whereas if the accuracy you need is not to such a high standard then you will get more relevant replies. for example: a CIP system that needs a flow of 6 m3/m +-10% then you would not need high accuracy.
 
Last edited:
The EL1512 has 1kHz counting capability. You sample the count from the card's internal buffer every 1ms task cycle and calculate the difference between cycles. So if you have a sample count of say 34 in one cycle, 35 in the next, 36, 37[...] then you are getting one pulse every ms, a difference of 1 and thus 1000 pulses every 1000 cycles = 1 kHz.
Or am I completely misunderstanding what you are asking?
 
Just to get you started, here is some structured text code that will determine the frequency, updating once per second.

Code:
Timer1(IN:=NOT Timer1.Q, PRE:=T#1000_ms);

IF Timer1.Q THEN
  FreqHz := CounterValue - LastValue;
  LastValue := CounterValue;
END_IF
Timer1 is a self-resetting TON timer.
FreqHz is the frequency.
CounterValue would be linked to the register from the EL1512.
LastValue is the count value from the previous calculation.

As others have mentioned, this may or may not be the best approach. Accuracy of the calculated frequency will decrease with lower rates. More math would be required if your timer preset is anything other than 1 second.
 

Similar Topics

Hi everyone, This is my first time posting, so please forgive any omissions or mistakes. I am attempting to control the velocity of a stepper...
Replies
18
Views
1,081
Hello, I was wondering if anyone know how to upload a PLC program to the Beckhoff TwinCAT 3 from a file? i.e. without having the development pc...
Replies
0
Views
793
Hi anyone got any tips and tricks?? I'm at a stage wherei need to tidy up my hmi project and give all objects sensible names, I did start this...
Replies
0
Views
974
Hello, I have a System running a beckhoff IPC with twincat 2 software on it, Also i have no original source code. Is it possible with the...
Replies
1
Views
1,283
Hi all, I've inherited someone else's program and can't for the life of me figure out his use of the # symbol in one of his structured text...
Replies
5
Views
1,931
Back
Top Bottom