Jump to content

Another timer problem


MWD

Recommended Posts

I wanted to make a accumulated hour meter. Seemed simple enough by just using the 1 sec pulse to trigger multiple count up accumulators, SEC, MIN, Hours.  It appears that there is a limit for the number of function blocks that can be nested.  In the attached example the first increment counter (sec) counts to 59 then resets MI20 to 0.  The store command enables the second INC function M21 (MIN).  This all works properly except for the last compare and store to reset the minute counter to 0.  When the MI21 INC function ENO goes high, the compare block does not do the AB compare nor does the STORE function reset MI21 to 0. A trace does show the blocks are enabled but the function themselves do not work. 

 

Is there a limitation for the number of functions that can be chained?  Theoretically I should be able to add another chain for hours.  

 

Other suggestions for a simple run time timer?

 

 

post-1428-0-91304700-1453359066_thumb.png

Link to comment
Share on other sites

  • MVP 2023

There is absolutely no reason to chain all that logic into a single ladder rung. This forum topic is "Best Programming Practices" and it should be noted that every bit of added complexity in a single ladder rung increases the chances that the compiled code will not be what you expected. In this case, it SHOULD all work, but why do it? Your example should be broken into 3 ladder rungs.

 

Also note, you don't need SB1 (I find SB1 to be very useful to chain items in parallel, but you don't need it here when everything is in series), and MI20 is counting up to 6 seconds, not 60 seconds. Is that what you want?

Link to comment
Share on other sites

Thanks fellows, the example you attached is really the same as I was going to do in multiple rungs.  I realize the ladder I wrote is not ideal, its just that sometimes I hack together a concept just to see how the blocks might work and then optimize after its understood.  I ran into the problem submitted and was just wondering what the issue might be.

 

Regards and thanks again for the input. 

Link to comment
Share on other sites

Thanks fellows, the example you attached is really the same as I was going to do in multiple rungs.  I realize the ladder I wrote is not ideal, its just that sometimes I hack together a concept just to see how the blocks might work and then optimize after its understood.  I ran into the problem submitted and was just wondering what the issue might be.

 

Regards and thanks again for the input. 

 

Hello,

 

After talking with colleagues in the office here, I understand now why this does not work and why we thought it would work: I was reading the statement you created as a "nested IF statement".  But in reality, it is an "AND statement".  Once the seconds register reach a value of '60', a value of '0' is stored into the seconds register, and makes the first compare statement not true anymore.  So the minutes compare statement never gets evaluated. 

 

If you put the compare statements in parallel with eachother (making it an "OR statement") or place the second compare in the next net, the logic will work.

 

Hope this helps.

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.

×
×
  • Create New...