Jump to content

Memory Manipulation Best Practices Question


Recommended Posts

Hi, I'm new to ladder logic and unitronics but I've got some v130s and I'm building my first project.  I've gotten the core functionality working but I'm now expanding my program to include the hmi and user interactive modifications.  

The core of my project utilizes 42 total, 32 and 36 byte hex vectors sent via "UDP RAW" these 42 vectors are primarily composed of the same bytes, but in different sequences. For my proof of concept, I have been simply typing in the data into the power up values but now I need to manipulate individual bytes and store into my vectors.  

I'm seeking some insight into best practices for this configuration stage of the program, initially, I was going to make a conditional subroutine to be called at the conclusion of the initial user input configuration,  so that the user input values would be compared to predefined sequences of either vector operations, store direct, or data tables. ( I'm still learning which operations would be best).     

After reading the forum, I've learned conditional subroutines should never be used. I'm a bit lost as to how to complete the 1 time memory remap/ sequencing without constantly rewriting the memory each cycle or clogging up my main routine.   Should I simply call the subroutine in the main routine every cycle and add a switch or compare to every rung of my remap subroutine so it only activates upon a button press or MB compare+ state change to disable. I'm open to any suggestions.

thank you in advance for the help and thank you for bearing with any misunderstandings I have, I've only been learning for a week so far.

Link to comment
Share on other sites

  • MVP 2023
5 hours ago, Sailor_Poon69 said:

After reading the forum, I've learned conditional subroutines should never be used.

Never say never, but in general it's bad practice. The reason is that it's easy to leave coils in "limbo" causing unexpected results. If you're very careful and know what you're doing it can work fine. That said, don't do it anyway.

 

5 hours ago, Sailor_Poon69 said:

Should I simply call the subroutine in the main routine every cycle and add a switch or compare to every rung of my remap subroutine so it only activates upon a button press or MB compare+ state change to disable.

Yes, this is the proper way, IMO.

Link to comment
Share on other sites

  • MVP 2023

The Help system is your friend, along with doing simple trial and error learning.  To fully understand something new, work on that one concept alone as a project until you fully understand how it works and can then relate it to your other needs.

At present I would also have a good read of everything HMI related in Help, and also some other things that are important to know with regards to how the scan proceeds and can actually take a few scans to settle HMIs, in Program Sequencing: Modules, Subroutines, Labels & Jumps. (copy that into Search and it should be the 2nd topic). With single calls it is very easy to muck things up if other ladder elements have not got to where you think  they are!  Sometimes a relocation in the ladder is all that is needed.  I often use a Negative Transition Contact for using the physical button pushes on 130s (ie no touch screen) and this inherent delay is useful.

Everyday you learn something new.

cheers, Aus

  • Like 1
Link to comment
Share on other sites

  • 5 weeks later...

I like to use subroutines in two ways:

  1. PROGRAMS. Split the ladder program in manageable and easily navigable sections. So instead of having one single ladder program with 1000+ rungs, we have a program tree in which we can easily find, add, remove, or debug functions. Example in C language would be creating different units like: main.c, inputs.c, outputs.c, hmi.c, hmi_extras.c, .....
  2. FUNCTIONS. Make program functions which can be called multiple times. Example in C language would be having a library, like: io.h, printf.h, strcat.h, .....

When using subroutines like PROGRAMS, you must call functions only once, and without any condition. That way you've made your program easy to read, and you can be sure that all ladder code is always executed during scan. No "dead code".

When using subroutines like FUNCTIONS, you can call the functions per condition as your program demands. Similar to C or ST functions. These functions subroutines should be marked differently or be placed in a separate program module. Examples of such subroutines might be:

  • a function which creates a real-time string from RTC system registers
  • a function which resets all specific process bits to zero
  • a function which checks if a data table contains valid data
  • a function which converts an array of bits into a register
  • etc, etc.,

Hope this helps!

  • Upvote 2
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...