Posted 26 Jan 2012 I am using PRV881 to track encoder pulses when a motor is turning. On a Limit Switch Rise I am looking to extract the value, when the same Limit Switch Falls I am looking to extract the value. I then take sample 2 from sample 1 to give me a result, and calculate sheet size in mm. Every combination I try I keep getting a rolling count, ideally I am looking for a one shot reading. Is there a function or method to extract just one set of reading for the rise and one for the fall of the limit? Share this post Link to post Share on other sites
Posted 26 Jan 2012 I am not sure which PLC you are using, so I guessed that it is a CP1H. The picture below illustrates some code that should get you what you need. I did not have time to test it, but it should work. If not, let me know and I can test later. Here is the file: PRV example.cxp Good luck. Share this post Link to post Share on other sites
Posted 26 Jan 2012 I tried the above and still got the rolling count. I was using 1 pvt and detecting switches then moving sample 1 to -404 then detecting fall of switch and writing it as sample 2 - subtracting 1 from 2. I have 2off limits and a process start command, I have been attempting to latch via set/ rset, 1 shot pulse and mov. All keep returning a rolling count from the encoder. Share this post Link to post Share on other sites
Posted 26 Jan 2012 Sorry, I should have looked a little closer before I answered your question, I reverted back to the old days. You do not need the PRV instruction for reading the PV (present value) of the newer product. I still do not know if this is a CP1H or not, but I am going to go on the assumption that it is. The present values for the high speed counters are stored (as double integers, 2 words long) in A270, A272, A316 and A318 for each of the four counters, so you need the code below to do what you want. Here is the modified code: Counter example.cxp Give that a try. 1 person likes this Share this post Link to post Share on other sites
Posted 26 Jan 2012 (edited) I just tried both sets of code in the same project using the same high speed counter, but writing the counter value and the subtraction to different addresses. BOTH sets of code work and they provide the exact same answer (see pic below). I did have to change my limit switch input to a different input as high speed counter 0 uses input 0 for the high speed counter. Perhaps you can post your code and I can figure out what is wrong with it. Edited 26 Jan 2012 by Michael Walsh Share this post Link to post Share on other sites
Posted 26 Jan 2012 Appologies, I am using a CP1L with NQ3 Attached. Code snippet as is: Share this post Link to post Share on other sites
Posted 26 Jan 2012 Actually, I was using a CP1L in my online test shown above. The problem with your code is one of the contacts that you used. See the picture below: You have used a normally closed differentiated down contact. This means that it will be true all of the time, except for one scan when the limit switch turns off. This will make the move statement constantly move the present value of the counter in that rung. Change the contact as shown in the picture and it will work for you. Share this post Link to post Share on other sites
Posted 26 Jan 2012 I will give it a whirl online in the morning using the actual encoder. Got head buried in interupts @ 23:13pm........not good! Many thanks, I will test am Friday Share this post Link to post Share on other sites
Posted 27 Jan 2012 Works great in simulation mode. connect to actual running machine and I get no first count. I removed S1 and process active so I was only looking at S2 upward and S2 downward pulses. The S2 downward works great for some reason but the upward just doesn't fire........where am I going wrong? I have even reduced the input settings for S2 to read every 2ms as the endoder is every 3ms, made no difference. I can run simulation and it works perfectly, does the calculation and outputs the correct sheet length......suprisingly! Share this post Link to post Share on other sites
Posted 27 Jan 2012 I am not sure what could be wrong. Could you post your CX-Programmer file with it as it is right now (with just the S2 up and downs)? Share this post Link to post Share on other sites
Posted 28 Jan 2012 S1 and process active were not needed as S2 will only be active on its own. just cant understand why the first count does not fire on upwards pulse. Share this post Link to post Share on other sites
Posted 23 Apr 2018 On 1/26/2012 at 9:45 AM, Michael Walsh said: Sorry, I should have looked a little closer before I answered your question, I reverted back to the old days. You do not need the PRV instruction for reading the PV (present value) of the newer product. I still do not know if this is a CP1H or not, but I am going to go on the assumption that it is. The present values for the high speed counters are stored (as double integers, 2 words long) in A270, A272, A316 and A318 for each of the four counters, so you need the code below to do what you want. Here is the modified code: Counter example.cxp Give that a try. 2 Hello, Could you please provide an updated link to the Counter example.cxp file - this link is broken. Thanks Share this post Link to post Share on other sites