Sign in to follow this  
Followers 0
angeraer

How to reset a counter?

14 posts in this topic

Hello, I'm new to programming a PLC so maybe it's a very newbie question, but here I go. I'm building a windmill and want to controll everything using a PLC. I got my hands on an Omron C200HX type. Now I'm trying to determine the windspeed. I have to count pulses from the windsensor and calculate a 10 minute average. I have created some kind of array (10 elements, 1 for each minute) and with a counter I put the results of each minute in the array. The first 10 minutes I need to divide the total of the array through the number of filled elements. After 10 minutes I need to divide the total of the array though 10. I used a counter to count from 10 to 1. But when I reset the PLC, the SV value of the counter isn't reset. So I have a problem that my array counter isn't in line with the counter. My question : Can I set a counter to 10 during the First_Cycle event? I attached the code. All advice is appreciated!!! Thanks, Andy. Edited by angeraer

Share this post


Link to post
Share on other sites
I do not have the Rar archiving software, but... The first Cycle Flag is bit 253.15 Use this bit to reset the counter on power-up.

Share this post


Link to post
Share on other sites
Jay, I'm already using the First cycle event to clear some fields. But I also would like to reset the counter I'm using further in my program. I attached my program uncompressed. Thanks, Andy. Windmolen.cxp

Share this post


Link to post
Share on other sites
By using a DM as the reference point for the counter SV, you can alter it at any time. CNT10 DM2000 Instead of CNT10 #10 Write the value you require to DM2000 MOV #10 (or any number you wish up to 9999) DM2000

Share this post


Link to post
Share on other sites
Is it possible that this doesn't work? I Tried it like you said. Created a symbol: counter_value at address DM31 with value #10. Created a MOV instruction to reset the value to 10 at First_Cycle. Checked my counter and it isn't set to 10. It's using the SV value counter_value. In the monitor window I see : CNT1 value : 2 (BCD) and counting down... counter_value : 10 Thanks, Andy.

Share this post


Link to post
Share on other sites
Try setting up counter 10 as CNT 10 DM2000 Then use the move command MOV #10 DM2000 Then change the MOV value Mov #35 DM2000 You should see the SV in counter 10 change from 10 to 35. And yes, it does work. I use it regularly to develop random ni=uimbers for timers and counters by using the @INC instruction into the data memory, then move the vaule, at the appropriate time, into tghe data memory to change the SV for the next count or time period.

Share this post


Link to post
Share on other sites
Here is a fairly simple program for a commercial swimming pool with simple random number generation and @MOV commands to data memories for use in timers and counters as SVs. You will notice that the DM shows up as the SV in the timers and counters. Yes it does work. This is a working program, before commissioning. In fact, it is such a simple program I have not even bothered to comment it. KURRI_KURRI.cxp Edited by BobB

Share this post


Link to post
Share on other sites
Thanks for the example, I'll take a look at it. I just did a test. See attached printscreen. I can change the SV of the Counter, but it's only changed/activated when I trigger the reset of the counter? Is this how it should work? Thanks, Andy.

Share this post


Link to post
Share on other sites
The SV can be changed at any time. The new SV will only be valid after the counter has been reset. The counter will continue to use the SV it started with until it is reset. Sounds like you need to reset the counter to take advantage of the new SV, or change the PV at the same time. You would need to reset the counter after writing the new SV. If you reset the counter before writing the new SV, the counter will use the old SV.

Share this post


Link to post
Share on other sites
I suggest you to use an "INC" function; every time your lr3.00 will go on, you will have your Dm incremented by one, make a comparison (f20) with your target value (another Dm), with the normal flag (255.06 or 255.05 or 25507) in order to detect when the target value is reached or overpassed; you 'll be free to set the target value as you want in every cycle, and to reset the counting value as well, moving #0000 in your incremented Dm. Ciao, Mike

Share this post


Link to post
Share on other sites
I'm sorry...it was me. I did't log me in.. Ciao, Mike

Share this post


Link to post
Share on other sites
Agreed!!! Use it all the time. Suggest you use @INC (differentiated). Then the channel will only increment on the rising edge of the signal. If you use INC and the input stays on, the numbers will increase by far more than 1. I am still not quite sure what Andy is trying to do.

Share this post


Link to post
Share on other sites
What I'm trying to do? Calculate average windspeed over the past 10 minutes. Each minute again. Therefor I tried to work with some kind of array (10 elements) where I fill in the results of windspeed pulses each minute. This array is then used to calculate the SUM of all values and then divided by the number of filled elements. The first 10 minutes the number of filled elements starts from 1 element to 10 elements. After 10 minutes there are always 10 filled elements. Some kind of LIFO (Last in First out) array. Andy. Here is the working example. Maybe it's bad coding, but it's my first attempt. Windmolen.cxp

Share this post


Link to post
Share on other sites
BobB, the program our friend has posted, has the Lr3.00 which is already a "difu" contact! You don't need to program a differential mode function. Angeraer, how's goiog? ciao, Mike

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0