nagaraj Posted October 27, 2010 Report Share Posted October 27, 2010 I have the following timer logic to display elapsed time in Hours. Minute Timer to increment MI 0 If MI 0 = 6, Increment MI 1 and Store 0 in MI 0. Hence MI 1 should be equal to tenths of elapsed time in hours. Many of the units we shipped is off by almost an hour after about 1200 hours. Am I doing anything wrong? Quote Link to comment Share on other sites More sharing options...
Stein Yair Posted October 28, 2010 Report Share Posted October 28, 2010 Is the timer running all the time? is it in the main routine or in a subroutine? if it is in a subroutine, is this subroutine called every scan? if not, send the application to Support@unitronics.com for examination. Quote Link to comment Share on other sites More sharing options...
stembera Posted October 28, 2010 Report Share Posted October 28, 2010 Let me guess. Your timer is running 60000 milliseconds. In the last program cycle, let us say, 59998ms, is still not elapsed. The first scan which "sees" the timer elapsed, is the next cycle, e.g. 60004ms. Now you have lost 4ms and you will start next instance of the timer. In the second minute the situation will be similar and the error will accumulate. After many loops of the timer you can get gross inaccuracy. The better solution of your task is to use system real time clock: In the system integer SI30 you have actual second in minute. If your minute counter will be incremented if ((SI30 == 0) AND (SB13 == ON)), your task will be more accurate. (SB13 is on every second for one program cycle). Next possible solution is using of SI36, minute in hour. If you put (((SI36 mod 6) == 0) AND (SI30 == 0) AND (SB13 == ON)), you will get one pulse every six minutes, i.e. every one tenth of hour. ("Mod" stands for modulo, the remainder after integer division). Quote Link to comment Share on other sites More sharing options...
nagaraj Posted October 28, 2010 Author Report Share Posted October 28, 2010 I sent the program to support. Please let me know what you find out. Quote Link to comment Share on other sites More sharing options...
nagaraj Posted October 28, 2010 Author Report Share Posted October 28, 2010 Thank you very much Stembera. That makes perfect sense. I may not completely use your solution since I want to calculate elapsed time that may not have any relation to the real time clock. I would rather use SB13 or SB3 to increment MI0 and increment MI1 when MI0=360. Quote Link to comment Share on other sites More sharing options...
Damian Posted October 29, 2010 Report Share Posted October 29, 2010 Why wouldn't "elaspsed time" have anything to do with the RTC?? When the start condition happens store the RTC in a variable. Now have a Subtraction function block that takes the current value of the RTC, subtracts the Start value, and places into another variable (your elapsed time). That is the most accurate elasped time you will be able to get. Quote Link to comment Share on other sites More sharing options...
Phil Salkie Posted October 29, 2010 Report Share Posted October 29, 2010 I just put up a Blog entry which touches on this exact issue - have a look at it here. What you seem to be running into is the fact that when you try to accumulate time values, you have a small amount of error due to the scan time of the PLC. It's possible to get around this by using timed interrupt routines and counting up time in 2.5 millisecond increments - but for longer values, it's easier to use the RTC->UTC conversion function to get a value for "Now" in seconds, save that value as your "Start" time, then calculate elapsed time with ("Now" - "Start"). 1 Quote Link to comment Share on other sites More sharing options...
nagaraj Posted November 1, 2010 Author Report Share Posted November 1, 2010 You are right. Thank you very much. Do you think the SB3 method will accumulate errors? Why wouldn't "elaspsed time" have anything to do with the RTC?? When the start condition happens store the RTC in a variable. Now have a Subtraction function block that takes the current value of the RTC, subtracts the Start value, and places into another variable (your elapsed time). That is the most accurate elasped time you will be able to get. Quote Link to comment Share on other sites More sharing options...
Phil Salkie Posted November 2, 2010 Report Share Posted November 2, 2010 Considerably less than using a timer, which adds an average of 1/2 scan time each time the timer turns on. The SB3 method will add up to 1 timer period at the beginning of the timing, and 1/2 scan time to the overall amount, but since the time base is constant and not dependent on the scan of the program, it should work as well as using the RTC to UTC method, and almost as well as counting 2.5ms interrupts. Quote Link to comment Share on other sites More sharing options...
External Moderators Nacho Posted November 4, 2010 External Moderators Report Share Posted November 4, 2010 Thank you very much Stembera. That makes perfect sense. I may not completely use your solution since I want to calculate elapsed time that may not have any relation to the real time clock. I would rather use SB13 or SB3 to increment MI0 and increment MI1 when MI0=360. If you want to calculate elapsed time you can use the UTC time instead RTC, UTC is in seconds, this way if you substract the start value of the end value you will get the elapsed seconds. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.