Sign in to follow this  
Followers 0
Gnomes

Subroutine Question

6 posts in this topic

Hello, I've been experimenting a little with using subroutines and call functions. I'm running into a problem and I don't know why it doesn't work. Below is a picture of my main code. In the first two subroutines (Hello, Clear) are just some block move instructions that set up a data block for the commreq. The last call command (dummy) has some move instructions along with the commreq. All of these commreq's are for a write bytes command. Hello prints hello to my hyperterm window while clear is a new page command (Clears my window) and dummy prints dummy. What I'm running into is after downloading my program to the plc I flip input one and hello appears on my screen. I set input two my screen clears, then I switch on input three and dummy appears on my screen. So everything seems to be working all right. So I try it again and there is hello and clear page but I get no "dummy" appearing. It looks like when I have the commreq in my call function it only seems to work on the first time after downloading the program whereas when the commreq isn't in my call function it appears to work every time. What do I have to do to be able to keep my commreq in my call function for it to work each time? Thanks for any help!

Share this post


Link to post
Share on other sites
The Hello and Clear Com_reqs are contolled by 1_Shots, is Dummy? If not that is probably the problem. Also I suggest that you arrange your logic so the Hello, Clear, and Dummy Blocks are called by the 1_Shots, you can move them to the same rung as the Com_Req.

Share this post


Link to post
Share on other sites
Here's a picture of the Dummy subroutine. I am using a one shot for my commreq and from my knowlege I thought this would work but for some reason it only wants to work once on the intial power up of the plc and then no more. So it's also a good idea to use a one shot when using a call funtion as well?

Share this post


Link to post
Share on other sites
No, only a Call that is used just for setting up a Comm_Req, or doing just Math, or some other functions that are better used with 1_Shots. You still need to remember that any coils turned "ON" in a Called Block will stay on if the the Block is no longer called.

Share this post


Link to post
Share on other sites
I think the problem is due to the One-Shot inside the subroutine. Assuming that Dummy_?????? (the variable for the One-Shot coil) is non-retentive, then upon powerup, it is off. You turn on the switch that triggers the call to the Dummy block and that also fires the Dummy_????? One-Shot. The transition table remembers that the One-Shot has fired so it doesn't fire again. Now you turn off the switch that calls the Dummy block. Since the block is no longer called, the memory associated with the variable (including the transition table) doesn't get changed. Now you turn on the switch that calls the Dummy block again. The CPU starts processing the rungs inside the block. When it evaluates what to do with the One-Shot coil it checks the transition table for the last state of the address. The transition table shows the last state as on, so the One-Shot does not fire. One solution would be to put the One-Shot coil that enables the COMREQ instruction outside of the Dummy block.

Share this post


Link to post
Share on other sites
Thanks for your help Steve and Russ. I moved the one shot coil and that seemed to solve the problem I was having now it's time to try and see if I can figure out some other troubles I'm having!

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
Sign in to follow this  
Followers 0