Counter Block Like a PLC


Recommended Posts

I am started in this, I usually schedule with PLCs, and I need to make a pulse counter block, but I fail to define the variable with a rise or decrease flank.

example:

Var.count_1 = 0
Var.count_2 = 0
Var.Habilitacion = 0

while(1)
   
If (Var.habilitacion >= 1)
   
   Var.count_2 = Var.count_2 + Var.count_1
   
Endif

Endwhile

 

When var.counter_1 is 1, the application does not count from 1 in one if not in several numbers with respect to the PC scan.

 

The difference in the application that will use an input as an accountant instead of a variable.

 

Var.count_1 = CO_0 for exaple.

Thanks for the attencion. 

Link to comment
Share on other sites

A couple things:

1) I recommend against using var. notation.  This is left over from very old ( > 15 years) releases of DAQFactory.  Instead use variable declaration.  So:

global count_1 = 0
global count_2 = 0
global habilitacion = 0
while(1)
   if (habilitacion >= 1)
      count_2 = count_2 + count_1
   endif
endwhile

2) you have an infinite while() loop without any delay.  This script will use a lot of CPU power, most of which will be wasted.  I suggest adding at least a delay(0.01) before the endwhile.

As for the rest, the script looks fine.  It will loop forever and whenever habilitacion >=0, it will increment count_2 by count_1.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.