Jump to content

Recommended Posts

Posted
I understand that a subroutine is a (usually) small bit of code embedded in the main code, and when called, it will execute all the way through and then return control back to the main code. OK...so in a situation like this what happens: A PID loop is controlling airstream temperature. On the same machine, a valve must open from time to time to re-pressurize a vessel when the pressure drop below say 15 psi. The valve control is done through a subroutine... So when the pressure drops, the "re-pressurize" subroutine starts, and the tank is filled back up. Say this takes 2 minutes, to fill the tank....what happens to the PID loop while control is shifted over to the "repressurize "subroutine? Does it freeze or does it run in the background? And what happens if the "stop" button is pressed while in a subroutine?
Posted
Depending on how the sub routine was written u would find in the majority of cases that the code simply enable this bit of code to be executed and become part of the scanned code so execute subroutine return excute rest of code PID etc return to top of program... scan logic ... extcute sub ... execute PID etc...
Posted
That makes sense...it basically "inserts" the sub into the code until something kills it, at which point it's "deleted"...it's not like everything comes to a grinding halt while the sub runs...
Posted
Jumps can do the same thing ... but they are a little different... a subroutine can be jump to from any where in the code so to speak and return etc... a jump is part of a section of code that can be simply executed or jumped over
Posted
The pressurization subroutine better not hog the processor or you will have infinite scan time and the processor will fault. You should avoid long for or while loops in the subroutine or any code for that matter. Hopefully you can run both subroutines one after the other in the same scan. If not there will be trouble.because the scan will be too long. A subroutine is just a second of code that the processor can call. The difference between a jump and a call is that the processor will first save the return address and any other important info on the stack before making the jump. When the processor executes the return instruction in the subroutine, the previous info and return address are restore and the processor resumes executing at the instruciton after the call.

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.   Restore formatting

  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...