sdarella

Micrologix 1400 Timer

5 posts in this topic

Hi, everyone,

I started learning very recently, and I have been writing this little program in which I communicate through RS-232 with a machine. Every time I send a command from the PLC I wait a couple milliseconds for the machine to send a response (a response must always exist, even if it's a mere acknowledgement response), then I save the response that the machine has sent. I organized my ladder logic by the commands that the PLC has to send to the machine (4 commands total, for example: execute this, give me status on that, etc). I started every ladder with an OSR and an AWA instruction, and when AWA is done I have a timer in the next rung to wait for the machine response, and after timer I have a ABL activated when TON is done. The Ladders are related in the sense that the end of each LAD contains a JSR instruction to the next command/ladder. So the commands/ladder always execute in a predefined sequence (LAD2 -> LAD3 -> LAD4 -> LAD5). The logic inside each ladder is like this (the last rung is a little different for the others, this is LAD2):

] start [ ----------------------------------------- [ OSR ]

] OSR OUTPUT BIT [ -------------------- [ AWA ]

] AWA/DN [ ---------------------------------- [ TON ]

] TON/DN [ ----------------------------------- [ ABL ]

] ABL/FD [ ------------------------------------ [ ARL ]

] test if ARL string is 0 [ ----------------[ JSR ]

1) Since I have to use timers so often in my program (they all last for the same period of time) I wonder if I could use the same timer every time (same Control File R6). But I'm quite lost on WHEN I would have to reset the timer, or if this would not be recommended at all, since the timer is still counting for more than one scan. Although I want to believe that the timer for that Ladder would never be counting after the JSR instruction, I think this is true only for the first time since the next time I turn "start" ON the ARL is not zero, so JSR would occur while the timer is still counting. I tried resetting my timer parallel to JSR and using the same timer in the next ladder, but then the timer only counted up for the first time "start" goes ON (I believe because the timer was constantly being reset at every scan).

2) Also using OSR with AWA was the only way I found of making AWA and TON to "behave" (that is, to make AWA only go ON once per start and the timer to go ON every time AWA is DONE). Would there be a better way to do this or is this acceptable? When I tried connecting "start" to AWA directly the program just didn't behave the way I expected at all, I believe because AWA would always be enabled for more than one scan, although I cannot explain why this would be a problem since AWA should only execute from the transition false to true, no?

3) I never clear my buffers or reset my ASCII instructions... when I try to clear in parallel with JSR some of the ASCII instructions' bit ER goes ON, and when resetting my ASCII instructions sometimes I don't see any before/after difference, but oftentimes I just see an undesirable behavior, and to be honest I'm not even sure where in the code I should do it, so I wonder if I should bother. More specifically, in which situations should I care about doing it when writing a program, and where in the program is it recommended to do it? So far I don't seem to have a problem, so I'm being willingly ignorant about it :-1

Any suggestion regarding my code/logic is much appreciated! Thank you!

Edited by sdarella

Share this post


Link to post
Share on other sites

Two quick things-

The ladder scan is already linear so you don't have to jump thru hoops to try to force it to be linear

 

You can use one timer and do compares with the timer accumulator. For instance if you used a 10s timer and wanted something to happen every second use an accumulator GEQ 1000, 2000, 3000, ETC to trigger events 

 

Someone else will chime in before I get a chance to read this on something other than a phone.

Share this post


Link to post
Share on other sites

Many thanks, Michael :)

When you say I'm forcing my program to be linear by jumping through hoops, you mean the fact that I'm using JSR, right? So I could for example use an OTE and toggle the input for next ladder from it? The reason why I did it this way is because I read some examples in a book and the author used JSR when going to another ladder, so I thought that was how we were supposed to do it.

Share this post


Link to post
Share on other sites

Yes, that's what I meant. For me (everyone does things their way so YMMV) I use a Main routine that calls subroutines. In your case you can put your ASCII comm routine a routine called ACOMM or whatever you want to call it and then put a call to that routine in your Main routine.

I've attached one of my LACT unit programs (no comm in it) and while it doesn't have anything to do with what you were doing it does give you an idea of program structure and memory management techniques that I use. Again, YMMV. 

The program might be completely worthless to you. My hope is that it is helpful. I also included the IO sheet. To be honest I didn't check to see if I updated the last two tabs of the IO sheet. I probably didn't. I was pretty busy back then and that level of detail was usually a luxury. Typically I at least flesh out the alarm and shutdown tab before I write the program. 

Dilly Station LACT Unit 405 IO Sheet Rev 0.xls

LACT 405_07_35_14.RSS

Share this post


Link to post
Share on other sites

I like your idea of using a main routine to call subroutines very much and I will try to apply that. Thank you so much for the example. I have been a little busy fixing a plethora of mistakes in my program (I was finally forced to properly reset DN bits). Thank you very much, Michael, the forums have been my main source of information regarding PLC programming.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now