AutomationDirect
Search
Login | Register
Accounts & Orders
Cart
0
$0.00

Recent Orders

View and Manage | Request Cancellation

Your Account

Account Home

Checkout   $0.00


  • My Orders
  • Product Returns (RMAs)
  • Pay Proforma Invoices
  • Pay Freights
  • Invoices / Invoice Reprint
  • Quotes / Favs / BOMs
  • Packing List Reprint
  • My Product Docs
  • Credit Application
  • Tax Exemption
| Direct Sales in US and Canada | 1-800-633-0405 | About Us | Contact Us | Line Card
Products | Support
| Compare
  
Ordering Tools  
warning Cookies are not enabled on your browser.
Cookies are required for our site. Please enable cookies in your browser preferences to continue.
We will be performing maintenance on several web store related systems this evening, Wednesday, May 14th beginning around 8:00 PM ET. We expect this maintenance to be completed prior to 12:00am ET (Midnight).
There may be brief outages and some store features may be unavailable periodically during this time. We regret any inconvenience this may cause.
+
Navigation
+
Shopping Categories
  • Barcode / RFID / Vision
  • Bulk Wire & Cable
  • Cables (Terminated)
  • Circuit Protection / Fuses / Disconnects
  • Communications
  • Drives & Soft Starters
  • Enclosure Thermal Management & Lights
  • Enclosures & Racks
  • Field I/O
  • HMI (Human Machine Interface)
  • Hydraulic Components
  • Motion Control
  • Motor Controls
  • Motors
  • Pneumatic Components
  • Power Products (Electrical)
  • Power Transmission (Mechanical)
  • Process Control & Measurement
  • Programmable Controllers
  • Pushbuttons / Switches / Indicators
  • Relays / Timers
  • Safety
  • Sensors / Encoders
  • Stacklights
  • Structural Frames / Rails
  • Tools & Test Equipment
  • Valves
  • Water (Potable) Components
  • Wiring Solutions
  • Retired Products
+
Learn More
  • Brand Line Card
  • What's New
  • E-newsletter
  • Online PDF Catalog
  • Video Tutorials
  • Company Reviews
  • Learning Library
  • Affordable Training
  • Free Online PLC training
  • Cybersecurity
+
In Depth Product Sites
  • Programmable Logic Controllers
  • Productivity1000 PLCs
  • Productivity2000 PLCs
  • Productivity3000 PLCs
  • ProductivityCODESYS
  • LS Electric XGB Series PLCs
  • ProductivityOpen
  • CLICK PLCs
  • Do-more H2 PLCs or
    Do-more T1H Series
  • Do-more BRX PLCs
  • C-more Touch Panels
  • AC & DC Drives
  • Motion Control Components
  • Servos
  • StrideLinx
  • Pneumatics
+
Product Selectors &
Configuration Utilities
  • PLC Family Selector
  • P1000 PLC Systems
  • P2000 PLC Systems
  • P3000 PLC Systems
  • ProductivityCODESYS
  • CLICK PLC Systems
  • Do-more® BRX PLC Systems
  • LS-Electric® XGB PLC Systems
  • Productivity®Open Systems
  • AC Motors
  • Datalogic® Safety Light Curtains
  • LS-Electric® Servo Systems
  • Nitra® Pneumatic Grippers
  • Object Detection (Sensors)
  • PAL Controller Configurator
  • Precision Gearbox Selector
  • Protos X® Field I/O
  • Quadritalia® Modular Enclosures
  • Stellar® Soft Starters
  • Stepper System Selector
  • SureFrame T-slot Extrusion
  • SureMotion® XYZ Gantry
  • SureServo2® System Selector
  • SureStep® Linear Actuators
  • Timing Belts & Pulleys
  • Werma® Stacklights
  • ZIPLinks

BRX Do-more Designer Using Subroutines from AutomationDirect


Related Products

BX-DM1E-M-D
BX-DM1E-M-D Thumbnail
BX-DM1E-M
BX-DM1E-M Thumbnail
BX-DM1-10AR-D
BX-DM1-10AR-D Thumbnail
BX-DM1-10ER-D
BX-DM1-10ER-D Thumbnail
BX-DM1-10ED1-D
BX-DM1-10ED1-D Thumbnail
BX-DM1-10ED2-D
BX-DM1-10ED2-D Thumbnail
BX-DM1E-10AR3-D
BX-DM1E-10AR3-D Thumbnail
BX-DM1E-10ER3-D
BX-DM1E-10ER3-D Thumbnail
BX-DM1E-10ED13-D
BX-DM1E-10ED13-D Thumbnail
BX-DM1E-10ED23-D
BX-DM1E-10ED23-D Thumbnail
BX-RTB10
BX-RTB10 Thumbnail
BX-RTB10-1
BX-RTB10-1 Thumbnail
BX-RTB10-2
BX-RTB10-2 Thumbnail
BX-DM1-18ER-D
BX-DM1-18ER-D Thumbnail
BX-DM1-18ED2-D
BX-DM1-18ED2-D Thumbnail
BX-DM1-18ED1-D
BX-DM1-18ED1-D Thumbnail
BX-DM1E-18ER3-D
BX-DM1E-18ER3-D Thumbnail
BX-DM1E-18ED23-D
BX-DM1E-18ED23-D Thumbnail
BX-DM1E-18ED13-D
BX-DM1E-18ED13-D Thumbnail
BX-DM1-18AR
BX-DM1-18AR Thumbnail
BX-DM1-18ER
BX-DM1-18ER Thumbnail
BX-DM1-18ED2
BX-DM1-18ED2 Thumbnail
BX-DM1-18ED1
BX-DM1-18ED1 Thumbnail
BX-DM1E-18AR3
BX-DM1E-18AR3 Thumbnail
BX-DM1E-18ER3
BX-DM1E-18ER3 Thumbnail
BX-DM1E-18ED23
BX-DM1E-18ED23 Thumbnail
BX-DM1E-18ED13
BX-DM1E-18ED13 Thumbnail
BX-RTB18
BX-RTB18 Thumbnail
BX-RTB18-1
BX-RTB18-1 Thumbnail
BX-RTB03
BX-RTB03 Thumbnail
BX-RTB03-1
BX-RTB03-1 Thumbnail
BX-RTB05
BX-RTB05 Thumbnail
BX-RTB05-1
BX-RTB05-1 Thumbnail
BX-RTB05-2
BX-RTB05-2 Thumbnail
BX-RTB06
BX-RTB06 Thumbnail
BX-RTB06-1
BX-RTB06-1 Thumbnail
BX-DM1-36ER-D
BX-DM1-36ER-D Thumbnail
BX-DM1-36ED2-D
BX-DM1-36ED2-D Thumbnail
BX-DM1-36ED1-D
BX-DM1-36ED1-D Thumbnail
BX-DM1E-36ER3-D
BX-DM1E-36ER3-D Thumbnail
BX-DM1E-36ED23-D
BX-DM1E-36ED23-D Thumbnail
BX-DM1E-36ED13-D
BX-DM1E-36ED13-D Thumbnail
BX-DM1-36ER
BX-DM1-36ER Thumbnail
BX-DM1-36AR
BX-DM1-36AR Thumbnail
BX-DM1-36ED2
BX-DM1-36ED2 Thumbnail
BX-DM1-36ED1
BX-DM1-36ED1 Thumbnail
BX-DM1E-36ER3
BX-DM1E-36ER3 Thumbnail
BX-DM1E-36AR3
BX-DM1E-36AR3 Thumbnail
BX-DM1E-36ED23
BX-DM1E-36ED23 Thumbnail
BX-DM1E-36ED13
BX-DM1E-36ED13 Thumbnail
BX-RTB36
BX-RTB36 Thumbnail
BX-RTB36-1
BX-RTB36-1 Thumbnail
BX-P-SER2-RJ12
BX-P-SER2-RJ12 Thumbnail
BX-P-SER2-TERM
BX-P-SER2-TERM Thumbnail
BX-P-SER4-TERM
BX-P-SER4-TERM Thumbnail
BX-P-USB-B
BX-P-USB-B Thumbnail
BX-P-ECOMLT
BX-P-ECOMLT Thumbnail
BX-RTB03S
BX-RTB03S Thumbnail
BX-08ND3
BX-08ND3 Thumbnail
BX-12ND3
BX-12ND3 Thumbnail
BX-16ND3
BX-16ND3 Thumbnail
BX-08NF3
BX-08NF3 Thumbnail
BX-08TD1
BX-08TD1 Thumbnail
BX-08TD2
BX-08TD2 Thumbnail
BX-12TD1
BX-12TD1 Thumbnail
BX-12TD2
BX-12TD2 Thumbnail
BX-16TD1
BX-16TD1 Thumbnail
BX-16TD2
BX-16TD2 Thumbnail
BX-08CD3R
BX-08CD3R Thumbnail
BX-12CD3D1
BX-12CD3D1 Thumbnail
BX-12CD3D2
BX-12CD3D2 Thumbnail
BX-16CD3D1
BX-16CD3D1 Thumbnail
BX-16CD3D2
BX-16CD3D2 Thumbnail
BX-RTB08
BX-RTB08 Thumbnail
BX-RTB08-1
BX-RTB08-1 Thumbnail
BX-RTB08-2
BX-RTB08-2 Thumbnail
BX-08NB
BX-08NB Thumbnail
BX-12NB
BX-12NB Thumbnail
BX-16NB
BX-16NB Thumbnail
BX-08NA
BX-08NA Thumbnail
BX-12NA
BX-12NA Thumbnail
BX-16NA
BX-16NA Thumbnail
BX-08TA
BX-08TA Thumbnail
BX-12TA
BX-12TA Thumbnail
BX-08TR
BX-08TR Thumbnail
BX-12TR
BX-12TR Thumbnail
BX-16TR
BX-16TR Thumbnail
BX-05TRS
BX-05TRS Thumbnail
BX-08AD-1
BX-08AD-1 Thumbnail
BX-08AD-2B
BX-08AD-2B Thumbnail
BX-08DA-1
BX-08DA-1 Thumbnail
BX-08DA-2B
BX-08DA-2B Thumbnail
BX-04THM
BX-04THM Thumbnail
BX-PGM-CBL
BX-PGM-CBL Thumbnail
BX-DM1-START
BX-DM1-START Thumbnail
BX-DM1E-START
BX-DM1E-START Thumbnail
H2-DM1
H2-DM1 Thumbnail
H2-DM1E
H2-DM1E Thumbnail
H2-DM1E-START
H2-DM1E-START Thumbnail
T1H-DM1E
T1H-DM1E Thumbnail
T1H-DM1
T1H-DM1 Thumbnail
T1H-CTRIO
T1H-CTRIO Thumbnail
T1H-08TDS
T1H-08TDS Thumbnail


To learn more: https://www.automationdirect.com/do-more?utm_source=OdsHuIAH11E&utm_medium=VideoTeamDescription

(VID-DM-0046)

Subroutines are an awesome addition in Do-more Designer 2.0. Learn how to use them in this brief tutorial.
** Software Version used in this video: Do-more Designer 2.0.3

Online Support Page: https://community.automationdirect.com/s/?utm_source=OdsHuIAH11E&utm_medium=VideoTeamDescription

**Please check our website for our most up-to-date product pricing and availability.


Hide Transcript
View Transcript

Subroutines are great for building re-useable and easy to maintain code because it let’s you use one chunk of code in multiple places. And that saves you time and effort. Let’s do an example so you can see how to use subroutines and learn exactly what you can and – and more importantly - can’t do with them. Suppose we have an analog input measuring something like the fluid level of a tank. And when it gets to a certain level let’s scale the input by some scaling factor in R10 and put that in D1. And when we reach a certain calculated result, we want to turn on an output coil and an analog output that is a scaled version of the input. Now suppose we need to use this code for several different machines or processes. The temptation is to copy this code, change the input, the calibration parameters and the outputs. Then copy it and do it again and again and again for each machine. But that’s a lot of work, the code is really hard to read and when it comes time to change or update the code you have to do it all these different places and hope you didn’t miss anything. The easy way to do this is to create a single subroutine using this code which is identical every time we use it and then just tell the subroutine which inputs, calibration data and outputs to use. To do that, you call the subroutine with a call instruction. We haven’t created that subroutine yet, so we’ll just do that here by giving it a new name. The yellow dot is reminding me the subroutine doesn’t exist yet. That’s ok – we’ll fix that shortly. Our input to the routine is WX0 so internally we’ll copy that to N100 for the subroutine to use internally and we only need one of those. We’re multiply the input by R10 – that’s fine. And for outputs we need a digital internal register to map to Y0 and an internal analog register to map to WY0. You can re-arrange the rows, delete rows, and move rows around. We’ll use this as a power flow enabled subroutine – you can make it edge triggered if you want to - and we can add a counter that keeps track of the number of times this routine gets used. That can be handy when you are debugging. We’ll leave it disabled for now. Hit OK and Do-more designer reminds us we have a new subroutine name – did we want allocate memory for that? Yep. Do we want to create the Subroutine for that? Yep. The name is already filled in and since you can’t do time slicing in subroutines all of this is greyed out. You can password protect the subroutine – but be careful. Make sure you don’t forget that password – if you do the only way to recover the PLC is to clear it and reset it to factory default. Well look. Here’s our new empty subroutine. I’ll use Shift up arrow to select, and control-X to cut. Go over to the new subroutine and I’ll use control-Z to paste it in. This block of ladder code still has the original references so let’s change those to the generic internal references. WX0 becomes N100 here and here. Y0 becomes C0. WY0 becomes N101. All subroutines require a RETURN instruction at the end, but Do-more designer already put one there for us so we are good to go, though I am going to delete these extra rungs just to clean things up a bit. So whatever gets mapped into N100 will get compared to this and if it exceeds that, then that result will get multiplied by whatever is in R10. If that result is greater or equal to than this, C0 will get set and the result will be copied to N101. To use the subroutine we just use the CALL Instruction to map the external values we want to use to the internal registers in the CALL instruction - which we already did - so we are done. In this subroutine we are using R10 as a scaling factor. That could be set anywhere, OR we could set it in the CALL instruction. It’s nice to do it here in the Call instruction because now everything you need to know is in one place. That’s all there is to setting up a subroutine. You create the subroutine, map external registers to internal registers, and you are ready to go. But here is the real power. When we need that code to run another machine, we just use another CALL instruction. And look at this. Do-more Designer asks if we want to use an existing parameter list – of course we do. We want this guy’s parameter list with the 2 ins and 2 outs. Look at that. The parameter list is ready to go – we just fill in the empty boxes. Suppose this new machine’s analog input is coming from WX1, the calibration number we need is this, the output coil goes to Y2, the analog output goes to WY1 for this new machine. Done. So this line of code is calling the subroutine using these I/O can parameters. And this line is calling the exact same routine with but with these parameters. I can now do this on as many machines as I want and every one of them will use the exact same code in the subroutine. So if I ever need to change that code I only have to change it in one place. And that makes maintain and debugging your code so much easier. There are a couple things to keep in mind when using subroutines. You CAN use loops in a subroutine, just beware that since subroutines don’t have time slicing the routine won’t exit until that loop is done which could have a big impact on your scan time. If an OUT instruction in a subroutine turns on a coil inside a subroutine that coil will stay on when you exit the routine because the subroutine is really just a continuation of the calling logic so the power flow is always present. When you exit a program the power flow is disrupted so the active OUT instruction turns off. So make sure you understand that difference – it’s really important. You can’t use edge triggered inputs inside a Subroutine because they require two scans to see one state of the signal on one scan and then the changed state on the second scan. And there is no way to guarantee the subroutine will be run for more than one scan. So that’s why Do-more designer won’t allow you to use edge triggered instructions in a subroutine. Same thing for asynchronous instructions. They require more than one scan and we can’t guarantee the subroutine will be run for more than one scan so Do-more Designer warns us when we attempt to do that. Other than those couple special cases, for all practical purposes subroutines are no different than your main code block. By the way, Subroutines CAN call Subroutines. You can nest those calls up t 84 calls deep. Just beware that will have an impact on your scan time. Subroutines can also call themselves. We call that recursion. That’s real handy if you are searching for files in directory structures. You have a routine that goes down into a folder and looks for a file. If it finds a folder, it calls another copy of itself to drop down into that folder and search for the file. If it finds another folder, it calls another copy of itself to drop down into that folder and search for the file. Etc. We call that recursive programming. Will you need this very often in your day to day PLC programming? Probably not. But when you do – it’s an awesome feature to have in your back pocket. Just be careful – as you can image this can have a huge impact on your scan time. Finally, subroutines don’t have a structure associated with the like the other code blocks do. Which explains why this counter is an extra thing off to the side. The other code block have that built into their structures – right? We’ll that ought to be enough to get you going with subroutines. If you have any questions, please contact AutomationDirect’s free award winning tech support during regular business hours. They will be happy to help. And don’t forget the forums – there are lots of automation professionals there that love to share their years of experience. Just don’t post anything directed at AutomationDirect’s support team there, they don’t monitor the forums on a regular basis.



No data returned!
An error has occurred! Please contact support
Videos Home > BRX Do-more Designer Using Subroutines from AutomationDirect
Contact, Connect & More
Sign Up
to receive:
FREE e-Newsletter
sign up today!
Connect With Us
Social Media Channels:
linkedin    facebook    x    instagram    youtube
Company Information
About Us
Brand Line Card
System Integrator Program
International Sales
Panel Builder Program
Site Help
Company Reviews
Download Price List
Contact Us
Contact Options
1-800-633-0405
Monday - Friday
9 a.m. - 6 p.m. ET
excluding holidays
Career Opportunities
Voted #1 mid-sized employer in Atlanta
We're a great place to work!
Check out our job openings

Need Training?
Affordable Training by Interconnecting Automation
Free Online PLC Training
FREE Video Tutorials
Information & News
What's New / In The News
FREE e-Newsletter
Automation Notebook
Product Literature
White Papers
News, Product and Training Bulletins
E-Books
Shop with confidence
Checked   Safe & Secure
payment methods


We accept VISA, MasterCard, Discover, American Express, PayPal or company purchase orders.
AutomationDirect

BBB Accredited

Voted #1 mid-sized employer in Atlanta
Check out our job openings

Copyright © 1999-2025 AutomationDirect.  ALL RIGHTS RESERVED.
Site Map     Send Us your Feedback     Unsubscribe     Email Preferences     Legal & Business Policies     YouTube Terms of Service
Clear login credentials



Back to Top


spinner Updating...
Info
„