0
Answered
What is the easiest way of making quick triggers for Event counter
Not sure how to put the correct term to this request, but to explain what I basically want to do is use VDIN buttons as EVENT COUNTER triggers. But when holding the button down for say a second then it must start triggering the event counter continuously in quick successions of say 100ms.
There must be a simple way to do this?
Customer support service by UserEcho
One easy way is to use two internal digital channels, one for the one second delay and one for the 100 ms trigger.
Use your VDIN as the activating condition for the first channel and just add a delay on to get the 1 second delay.
Use the first channel as the activating condition for the second channel, and then you use the second channel as the blocking condition inside the second channel (it will be looking at itself).
You then have the second channel as the trigger for the counter.
To get the correct time between activation's you can set a 'delay on' on the second channel.
But if yo have a 50 ms cycle time you will already have a 100ms delay between each trigger for the counter (one cycle on, one cycle off....).
You could also do everything in the counter directly with the help of Qcode but that would not be as easy
My initial approach was using two internal digital channels similar as you described and it works just fine, but it becomes crowded and daunting to setup if there are plenty of these adjustable values that each gets 2 triggers. There must be a simpler way for sure.
So as you mentioned Qcode could work directly on the coounter? I've done similar setup features in Codesys with structure text before so the Qcode surely sounds like the simpler approach to me.
Why do you say it would not be easy, is there a catch?
Have you perhaps done this before and have a snippet of code I could use as reference?
Thanks for the response.
I would not say that it is very hard to do it in Qcode, just not as easy.
One thing is that you will be working with number of cycles as the delay instead of having a built in timer.
----------------------------------------------
Static initial := 20 //initial delay in number of cycles.
static pulse := 2 //delay between count trigger in cycles.
If VDIN and initial>0 then initial:=initial-1 //count down the initial "timer"
if not(VDIN) then
initial:=20 //resets initial "timer" if button is released.
pulse:=2 // resets pulse timer.
endif
if initial=0 then pulse:=pulse-1 //count down puls counter if initial timer is 0
if pulse =0 then
QIncrease //increase counter
pulse:=2 //resets pulse counter
endif
----------------------------------------------
If you copy this in to a counter and replace VDIN with your channel name it should work.
I made this to work as you described when you have a 50 ms cycle time.
Thanks Thomas...
The piece of Qcode works very well and keeps the overall structure of the code nice and neat. Exactly what I wanted.
I just added another "counter button" within this Qcode for adding and subrtracting the value. It is working very well.
Thanks again.
Also just to add to this thread.
I also discovered there is actually a simpler way of getting the event counter to start "rolling":
compared to this that only triggers once when pressed:
my first attempt at using the event counter was with object list (not even considering Qcode at that stage) and I needed to get the value rolling when you hold the counter button, so I tried timers and triggers which worked, but you end up with so many blocks and lines especially when you have a lot of variable values to make available.
Then Thomas posted the solution that I basically directly applied in one of my applications with excellent results also leaving the program nice and neat and easy to read too. But today I was just tinkering on Iqan Design and noticed this result, which seems to be an even simpler and direct way of getting the result I want. I'm happy.
When using the object list you need the rising flank of the trigger for the increase to happen.
In this case the rising flank of the VDIN channel.
When using Qcode you do not need the flank, it will run trough the code every cycle and if the statement is true it will increase the counter.
But this will happen every cycle for you now, with no time limitation between triggers.
If you want the Qcode to work on only flank you have the PositiveFlank() and NegativeFlank() functions.
The reason i did the way i did was because of the time limitations that you wanted for the counter.
For sure Thomas, it starts counting rapidly as soon as you touch the button, but that is fine it still gets to the exact value I want quickly and it is also still very easy to count single digits by only tapping the counter button quickly.
I just thought having some sort of timed trigger/reset would be the only way of getting the counter to actually start rolling.
The more I get to work and learn with IQAN the more I really like it. There are always some way or another to get certain things done.
Thanks for all the information and assistance.