Jump to content

Change over time, analog output scaling, and best emergency stop practices

Truman E

Recommended Posts

Good day,

I need a few pointers.  I am fairly new to Unitronics and the UniLogic systems.  I have some experience with ladder logic from past projects, the most recent of which used the Keyence ladder builder software.  It’s like coming out of the Stone Age!  If I need to separate this into sections please let me know.  I appreciate any guidance you can provide.

I am working on a project for a production machine.  The machine is utilizing modular design from discrete components that can function on their own, so I am somewhat limited on my approach options.  I will try and outline what those are as I go along if they are important.  I’m using a USP-156-B10 with a WCB1 and a UID-0808R with the latest software available (as of 11/21/18).  Currently, I have three items to review.  I think that will be all I need help with, as the rest of the control program is very straightforward (now). 

Item 1.  I need to write code for a change over time function.  I am reading off of a motor drive encoder which I need to ensure is at 0 speed (stopped) before advancing.  As the drive is not a servo, and the drive could stop with the encoder reading high or low, I need a change in condition over time.  While it is simple to say, I have not found a solution working through the manual or the examples but it is possible I missed something.  Ideal logic is: no change in state (can be high or low) for x amount of time (x being relatively quick, perhaps .1 sec), in a continuous readout (no reset if possible to allow for continuous operation) that would change the status of a binary variable (stopped or not).

Item 2.  I have not found an incredible wealth of knowledge dealing with the application of analog outputs.  I am in a position to write this section a few different ways.  The analog output can be in mA or V, as we are using a signal conditioner to isolate the PLC from the motor drive controller.  If the value of this were to remain constant I could see some options to directly output, but we may need at least a two-stage output (one speed forward one speed reverse) as we can control accelerate and decelerate through the drive controller.  I imagine that the same function could just be duplicated for as many states and drives as are necessary.  The target speed should be settable via HMI interface, with a slider bar going from 0 to 100, but the real output needs to be limited to 9V, not 10V (or 90% on current).  I do not readily see how to code this.

Item 3.  I might already have an idea on how to do this, but I want to know the best practices.  Upon recovering from an emergency stop I want to give the user the option to either return to “home” or to resume the operation.  Either way, I need to make sure the machine either completes the cycle or is reset to its initial state.   My previous mentor had some unorthodox methods, which I will not take the time to elaborate here.  Again, looking for what is the best practice.

Thank you in advance!

Link to comment
Share on other sites

  • MVP 2023

3).  Emerg stops.  Very machine dependent.  If the machine is likely to involve (further) danger to a human (the reason for the emerg stop in the first place?) by resetting itself to "home" positions after reset, you ideally have a totally different "emerg stop" control set that lets every action of the machine be manually (and carefully) controlled.  This may be useful for "rescuers".  From this worst case situation there are myriad layers of control scenarios, right back to fully reset the machine to "home" on restart.  It is definitely a case of fully assess and theorise all the risks, allowing that some humans are incredibly stupid, and cater for anything that needs to happen.

cheers, Aus

Link to comment
Share on other sites

  • MVP 2023
3 hours ago, Truman E said:

I need a few pointers. 

I hope you get the help you need, but what you need is more than just a few pointers. The problems you describe are complex, difficult, and very situation-dependent.

I wish I had time right now to devote to helping you further, but I am headed out of the country and don't have a minute to spare. However, I do want to make one unhelpful comment ( :) ). Your item #1 reminded me that I've always wanted VisiLogic to have the contact equivalent to the toggle coil - just a transition contact that indicates a change of state of an MB, either turning on or off.

Link to comment
Share on other sites

Thank you both for your input so far!

Let me try to break down the individual items I need to find resources for, perhaps it will help us find the answers I need to execute this program (or maybe I need better search terminology):  

1-     I’ve been pondering and I’m pretty sure I was over-thinking it.  I can use the encoder input for a TOF timer which I can use to set a zero motion state.  I.e. No reset in 0.1 sec, then no motion.  I was thinking too narrowly about my encoder input, only as speed/position.  Solved?

2-     Let me restart perhaps.  How do you use an analog output?  Can I reference examples or have the process for controlling the output better explained?  I can probably figure out the nuances if I can find better examples to work from.

3-     Is there a pause/resume option for the logic other than the idle command?  I want the same function but with more control.  Perhaps Idle until an input changes?  I would use the emergency stop input as the idle command on, then trigger a reset or resume from where it stopped - the operator would choose to let the idle expire (resume) or initiate a "return home" command.  I've got everything else down, but the "idle."   

4-     (3a) It would be extra neat if the hypothetical Idle would be able to apply to specific processes?  This also makes me feel like I’m missing it as in #1.  I’ll keep pondering and reading.  I feel like I’m close to getting it figured out.

Ausman- this particular situation has little risk to life or limb but mishaps could be costly still.  The operator would only need two possible recovery solutions: one- if the stop were tripped unnecessarily, the user could select to resume from where the system left off; two- the e-stop were pressed due to or in prevention of a mess, in which case the ideal recovery solution is to keep the motors stopped and reset motion to home (this is the easier one, for sure).    -- and I fully agree with your process.  We have to consider every eventuality and risk, along with how to handle exceptions.  I've been designing and building this entire machine around that premises, including "fail-safes" which include a number of additional sensors and logic steps. 

Flex- Safe Travels!  While I understand that the implementation will certainly take more than a few pointers (and has already), and I'm definitely on the learning curve with UniLogic- I am very interested in learning this incredible development platform.  VisiLogic, with the in-depth support, was very appealing when I was contemplating which HMI and PLC to use for this project.  There have been a number of times where I found useful advice under the VisiLogic platform only to discover it was not available in the same way as UniLogic, e.g. button functionality, which I did find a work-around for that seems to function well.  I ultimately decided to run with the UniLogic as the controllers have functionality that I will need for future projects. 

Thank you again!

Link to comment
Share on other sites

  • MVP 2023

1.  In the WCB1 module you can configure an HS block as a counter, which includes a Frequency value in the IO struct.  When the Frequency goes to zero you've stopped.  Look at both the installation and the specification data sheets for the module.




2.  The WCB1 only has 0-10V outputs, so you're not going to be able to make your drive go in reverse with the speed signal.  It should have a reverse digital input you can use.  Use the Accel and Decel values in the drive; there is no need to program these in logic unless you want to stretch them out longer than your programmed parameters.  As far as limiting the value of the output, use a >= block to limit your output value to a maximum-



3.  You'll have to program the machine's behavior when the E-stop is pressed, which brings up my personal favorite way of programming - the "State Machine".

Look at this post and Visilogic example-


One of the states is called "Idle".  This is not the same as the UniLogic "Idle" function (I would never use that).  You'll need to create a state for "Paused", triggered by the E-Stop, where you copy the current state number to a buffer so the PLC remembers where it left off.  You can then choose to exit that state and either return to where you were or program an orderly shutdown to the initial condition.

I didn't say this was going to be easy, but if you beat on it and post your code we can be of more help.  I just downloaded and installed UniLogic v 1.25.56, so use this version.

Joe T.




Link to comment
Share on other sites

Thank you, Joe.

I see exactly what you're saying.  These controllers are much more powerful and capable than the systems I've dealt with in the past.  I know that the voltage output would not be capable of reversing a drive; I will be using a separate trigger to control drive direction as you mentioned.  The question is control over the analog output during different machine states, which I think I can figure out with the references you have given.  Thank you for the detailed response. 

I will revert back here once I have reviewed these notes and written these program steps, along with the full program for your review.  I am trying hard to glean as much information from the forums as possible, and do frequently reference the available documentation.  

Link to comment
Share on other sites

  • 2 weeks later...

Following this, I asked about #3 at the Unilogic 2 day course and was recommended Calling a subroutine to help manage this that had an exit strategy.  I'm working on a similar machine, 15" Unistream controlling 2 robots, a keyence  vision system for inspection and to guide both robots, 8 IAI actuators, and 5 flex feeders.  Recovering from a fault or emergency stop is going to be complicated. 

Linear programming is a little easier to handle this situation such as in robot controllers as they have traps that can do a "pause" and "resume" on emergency stop. 

#2 This is why I pretty much strictly use actuators with field networked controllers, the extra $ is work it in programming time to me. I have in a diy project using a sabertooth motor controller controlled by micro-controllers over serial divided an 8 bit in half.

255= Full Speed Forward

127= zero speed

0= Full Speed Reverse

I feel like you could use a similar technique in your ladder to compare and control the DIR output and Speed(0-9V)  to your stepper controller as long as you cap your output at 90% as explained above.

Link to comment
Share on other sites


I’ve been a little preoccupied and out of town getting married, apologies for the delay in response.  I have been working through the suggestions here, and appreciate the input. 

1.      Joe, Samples of the zero speed concepts I have now are below.  One is set based off of a timer as I considered as a possible solution, with the timer set to 0.1 sec to ensure no motion.  The other is my interpretation of your suggestion.  At this time I would think that either option would suffice but I do like the integration of the frequency as a trip point, it will be a little simpler to program. 



2.      I will leave props to you in the code comments (if anyone ever sees them other than us).  I have not been near the prototype to trial whether or not my code is functional, but I do see how you are handling the situation and it should work fine once I iron out any kinks on my side.

3.      I will set a simple e-stop for now and program in the resume function later, as this project has to be live in a few days.  I do understand better now how to implement, but the time to do so and validate is possibly out of range for this first run for next week.

The program will be shared very soon but it has been two weeks since my last post and I want to keep this thread going.  THANK YOU!


Link to comment
Share on other sites

Program Submission & Debug Questions

I am actively searching for a solution to my bugs on the forum.  I would normally delay reaching out for help at this point, but I am short on time on long on need.  Apologies.

It seems as though I am missing something in the code to allow for correct function.  It may be when I reference an output to a coil or a bit to a coil that has already been used once elsewhere in the program, same function or not.  Should I need to use Jumps?   I tried combining all of the instructions into one function and that did not make a difference so I wouldn't think so with this type of program. 

For a direct example, with the current program if the user inputs Nozzle UP (HMI advanced screen) the Noz up command is not picked up in the instructions.  Motion control function, nozzle dive control.  Noz up has been referenced more than once. 

What am I missing?  I am going to keep beating on it.  I'm thinking I'll try to add more tags.?.  It's along the lines of what I faced early on in the project.  Is it too complex of a rung somewhere tripping me up?

I tried to follow best practices on the logic coding, and am most certainly still learning.  There are still a few components I have to add and will continue to work through these next week, they aren't necessary for the initial trials.  Future build-ins includes the optional resume from emergency stops, formula saves, process monitors, cycle times, and user access controls.

Notes on Linearize with the analog V out – I used the Y2 value to scale so that the input sliders would remain 100% useful throughout their range.  When I put in the raw value as suggested it output way too high.  It seems as though 100 is being seen as 10.0V, so when it hit even 1% on the scale, value out was 74 and the real measured output was 7.4V.

Unitronics for upload.zip

Link to comment
Share on other sites

So I learned a few things regarding this program this evening, outlined below.  Updated program attached. This one nearly works, I'll finish functional testing tomorrow.

1st- I was missing the TimerOut.bit bit.

2nd- Four Coils, Four Bits... Zero Coils, ZERO BITS... lol, a little fifth element humor

3rd- Not sure if this was holding me back but it's generally not a good idea to reset a rung within itself.  My logic was power flow> 1, 2, 3, set next, reset this.  I was able to "get away with it" in a few spots.

Off-topic but same program:  I still can't figure out how to use the Timer Box.  I have read only unchecked and the enable data entry bit set to a constant-on bit.  HMI input once you press OK just resets to the preset value. (settings page)


Link to comment
Share on other sites

  • 2 weeks later...

I've made a lot of progress and got through the demo of the machine.  A few notes based on discussions above:

The reason my linear function performed differently than expected is the configuration under the I/O section allows for custom settings.  Apparently, early on I had changed those values from 0 to 100, which works fine for this application and explains the erroneous output from before.  If I had the default values in place the suggestion Joe made above would/should have been perfectly OK.

I had a bad encoder sensor which was throwing all kinds of difficulty my way during bench tests.  Now repaired.

Timer value input was easy once I selected the correct option in the box setup, from the current value to the preset value.  d'oh

I am going to keep working through the development and debug process and will post final program &/or links to other discussions related to this project here to hopefully shed light for other programmers one day.

Thanks again for all of the assistance!

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.

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