Resetting integer (DS) to 0 in Ladder Logic for PLC (Koyo's Click PLC) - automation

I'm not sure if this is the good website for ladder logic programming questions but I will it a try.
I'm using a Click PLC C0-01 DR-D by Koyo (Desc page: http://www.automationdirect.com/adc/Overview/Catalog/Software_Products/Programmable_Controller_Software/CLICK_PLC_Programming_Software) with it's free software. I'm trying to make a program in Ladder Logic to executes multiples operations by the PLC. To keep track of the current operation, I use an integer value I'm incrementing as the current operation ID. However, I'm not able to reset this value to 0.
First I tried with the COPY but there's a radio button to ignore zeros. This radio button is checked and disabled (can't change it). . The documentation of the software says "Option: This Option is available when the Source is a Data Memory Register Address and the Destination is a TXT Address." But since I just want an ID and I need to compare this ID with = everywhere in my program and increment it, I don't want to put a string.
Then, I can use math to assign a formula to a variable. I tried put zero and it's working half the time. Note that the "One shot" checkbox isn't selected even if it may to be acting like so.
About this option, the documentation says "One Shot: Select One Shot to solve the formula only once after each OFF-to-ON transition of the enabling rung."
However, to be able to set the value to 0 again, I need to restart the PLC. When I first execute the program everything is fine because the value is already 0. When I restart it, the value didn't reset so it's still 7 and it skips all my operations. Then it resets to 0 (it's doing so at the end) and when I restart the PLC, I'm able to run it normally for one time.
Here an example of the current passing but the value not set:
Is it a bug from the PLC ? Is there a workaround ?
In short, I'm looking for a reliable way to set a value to 0.
Thanks in advance for the answers. Sorry If I violated 40 rules, I'm new and happy to join this community.

I though I resolved my problem but I just pushed it further. Thanks to Garry Shortt with his youtube channel dedicated to PLC programming for helping me out with my problem.
His explanation to the problem is "Changed the math to a copy command and placed it in the main program where you had it before. The program seems to work well.
The only thing that I can think of is when you use subroutines, and they are not being scanned. The items within the routine is the same unless you them changed in another part of your program."
Hope it will be helpful for someone someday.

Related

Credential Provider V2 Combobox unexpected behavior

I've been developing our company's credential provider for windows 10 for almost a year now.
Now, I encountered a problem. I don't usually ask questions on forums, blogs, because in most cases I find the solution, but this time I've been struggling with an issue for a month now and I found the root of the problem.
Brief description of the problem itself: The credential provider uses a combobox, which worked before without a problem. Now, I rewrote the whole code to manage a big update, but a strange bug got into the system. The bug only occurs at a specific scenario. I'm developing and testing the code on my personal laptop.
The scenario:
1) The laptop is plugged in to my monitor / power, etc.
2) I make it go sleep.
3) I unplug all cables (including power).
4) I wake it up from sleep.
Than, the combobox doesn't show a default selected item, it's empty. When I drop it down, it shows all the necessary items. Than the credprov crashes and restarts, than everything is fine.
I know, that in similar "strange" scenarios, in most of the cases, a memory leak or something related causes the problem. When I check the event viewer it shows me c0000005, which is access violation. I started to debug where the violation is. Than I found out that the program refers the combobox item list array (actually vector in my case) at a very very high index (out of range could be the reason for the violation). The actual index is obviously stored in the "selectedComboItemIndex" variable (DWORD).
I was curious when did it change to this strange number, than I found an unexpected behavior.
The SetComboBoxSelectedValue method randomly gets called once (when the bug happens) with an insanely high index value. I don't even call this method in my code, so I have no idea, why does it get called. The call happens even when I don't drop down the combobox.
I give it a chance that it could be a bug in the credprov itself. What do you think? Have you seen this problem before?
Thank you in advance!
I solved the problem by stopping to use "SetSelected" and "SetDeselected" methods. Furthermore, I filtered the "SetComboBoxSelectedValue" input parameters to accept valid numbers only. When the index parameter is invalid, I recall the same method with the index parameter replaced to the first item (0).

How to find the size of a reg in verilog?

I was wondering if there were a way to compute the size of a reg in Verilog. I researched it quite a bit, and found $size(a), but it's only in SystemVerilog, and it won't work in my verilog program.
Does anyone know an alternative for this??
I also wanted to ask as a side note; I'm having some trouble with my test bench in the sense that when I update a value in the file, that change is not taken in consideration when I simulate. I've been told I might have been using an old test bench but the one I am continuously simulating is the only one available in this project.
EDIT:
To give you an idea of what's the problem: in my code there is a "start" signal and when it is set to 1, the operation starts. Otherwise, it stays idle. I began writing the test bench with start=0, tested it and simulated it, then edited the test bench by setting start to 1. But when I simulate it, the start signal remains 0 in the waveform. I tried to check whether I was using another test bench, but it is the only test bench I am using in this project.
Given that I was on a deadline, I worked on the code so that it would adapt to the "frozen" test bench. I am getting now all the results I want, but I wanted to test some other features of my code, so I created a new project and copy pasted the code in new files (including the same test bench). But when I ran a simulation, the waveform displayed wrong results (even though I was using the exact same code in all modules and test bench). Any idea why?
Any help would be appreciated :)
There is a standardised way to do this, but it requires you to use the VPI, which I don't think you get on Modelsim's student edition. In short, you have to write C code, and dynamically link it to the simulator. In the C code, you can get object properties using routines such as vpi_get. Useful properites might be vpiSize, which is what you want, vpiLeftRange, vpiRightRange, and so on.
Having said all that, Verilog is essentially a static language, and objects have to be declared with a static width using constant expressions. Having a run-time method to determine an object's size is therefore of pretty limited value (since you should already know it), and may not solve whatever problem you actually have. Your question would make more sense for VHDL (and SystemVerilog?), which are much more dynamic.
Note on Icarus: the developers have pushed lots of SystemVerilog stuff back into the main language. If you take advantge of this you may find that your code is not portable.
Second part of your question: you need to be specific on what your problem actually is.

Labview 2012 Passing Dynamic data into/out of a while loop

I'm trying to pass data which is continuously changed from the inside of one While loop to the inside of another While loop of a sub-vi. The main program on the left is constantly reading new data and the program on the right is adding 1 to the new value. My issue is that I cannot input new values to a While loop which is already running and thus my sub-vi is never updated. I've tried a global variable ("write" from the main program control and then "read" into the sub-vi) but that doesn't work either (same result as if the main were just passing data into the sub).
I apparently don't have enough reputation to post a picture of my program but I'm basically trying to run parallel loops (almost inside each other). Can anyone lend me an experienced hand?
The most common problem with while loops are based on lack of knowledge how exactly does the while loop work in LabVIEW.
First of all the information will be given outside the loop only if the condition terminal (right down corner of the loop) will be flagged as true.
If you want to pass the data earlier (while the loop is running) you have to choose easiest option:
Use queue (is the most common and well working). I can elaborate how this one work in practise if you want, or just try to run an example from LabVIEW help.
local/shared variables - you can define in your own library variables and pass the data by READ/WRITE option.
Please try to upload some documentation to an external server (as you are blocked here), and post a link, and then I could help you with a specific example.
HelpĀ»Find Examples. Search for "queue". Pick out an example with parallel loops.
You might want to look into Queues or Notifiers as means of passing data between running loops.

How to find or create the iteration number box in a For loop

I have a large, somewhat messy For loop in which I can not find the iteration number box. Is there any way of searching for this component or simply creating a second iteration number box?
You can't create a second iterator terminal, but you can use scripting to move the iterator to a typical location (bottom left) with this VI Snippet.
Be sure the file is open before running the script.
This is a bit of a gamble, but you can try the Clean Up Diagram tool and see if that helps. If it doesn't it should still expose the iteration icon, and you can find out what wires it is connected to. Hit Ctrl-Z to undo the clean-up, and double click on the wire indicated previously and it should expose everywhere the wire routes to. Hopefully you can track it down then.
A messy diagram means that sub-vis or an architecture re-design is badly needed.
Depending on what version of labview you are using, you can use Block Diagram Cleanup tool, as mentioned by Austin. But you can also highlight a section of code and clean that up individually. This 'selective cleanup' feature was introduced in 2012.
Regardless, you can't search for an iteration counter. Use your eyeballs...how bad could this for loop be? Hint hint: I want to see it :-)

Detect limit switch reached

I'm having a little bit of a problem with LabVIEW 6.x concerning the motion control stuff. How do I detect whether a limit switch has been reached? So far I haven't found a way to do that. So what I'm trying to do is detect the minimum and maximum position of the attached device. To do that, I initiate a movement by using "Load Target Position" und "Start Movement" (don't recall the exact name of the latter). Now, if the position reaches a limit, the movement stops. But how do I detect that it stopped because the physical limit has been reached? I tried using the error output, but it just tells me that there is no error, although it displays a message box telling me that the limit in the direction of travel has been reached. It also tells me that this is warning 70026. But that number doesn't appear anywhere else, particularly not in the error code where I expected it to be. So I hope I made clear what I'm trying to accomplish and am grateful for any help on that. Thanks in advance.
For completeness sake:
Your looking into the wrong property, 'enabled' means that the device is equipped with a limit switch and 'listening' to it.
Active means that the limit switch is triggered.