adccommunitymod (AutomationDirect) asked a question.

High Precision Timer

Created Date: December 08,2006

Created By: Malachi

**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****

Right now I am using a TMRAF box on the DL06. This goes out to 0.01 seconds. I need more precision, preferably to 0.001 second. Is there any sort of solution for this (internal or external)?


  • adccommunitymod (AutomationDirect)

    Created Date: December 08,2006

    Created by: Tech Guy

    Nothing internal that I can think of offhand. Externally I really don't know how you would get it into the PLC with any precision. Scan time variability would tend to throw it off.

  • adccommunitymod (AutomationDirect)

    Created Date: December 08,2006

    Created by: Malachi

    Interrupts could take the scan time out of the equation, couldn't they?

  • adccommunitymod (AutomationDirect)

    Created Date: December 08,2006

    Created by: allukes

    The CTRIO modules have a time measurement feature that would be external of the scan time. This could trigger interrupts to execute code outside the scan. The 405 processors, although slower than some of the newer CPU's, does have the capability to have 16 interrupts. Very handy for high speed control. Event driven programing with interrupts is much faster, however, if you keep interrupting the CPU, it will slow down the response of system tasks, like communications and the normal scan. Best to make a timing diagram of what is occuring, and the time between events.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: December 08,2006

    Created by: Malachi

    What I'm trying to do is time how long a test takes. My shortest time is about 5 seconds, but I need to know to about 0.001 seconds how long the test has taken. I use the number in the accumulator (TAx) to do some calculations after this.

    I have a H0-CTRIO card in this PLC already, is there actually a high speed timer in it? All I see in the manual is are edge timers, which I don't think will get me where I want to be.

    Thanks

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: December 08,2006

    Created by: franji1

    Here's what I do sometimes - accumulate the scan timer (which is in ms) as a binary number. Save the accumulated time for the "start " time, then when "done ", subtract the current accumulated time from the saved accumuator time, and you will get the number of milliseconds.

    I think it's tied to the real time clock (but maybe not???), test it out to make sure you get something close (maybe do a 60 second TMRAF and see if you get something around 60000 for your delta???)

    Note that due to "modulo math ", you do not need to worry about "wrap around " unless you want to time something> 65.535 seconds.

    stick this at the top of your program:

    STR SP0 // first scan

    LD K0

    OUT V2000 // accumulated scan time

    STR SP1 // every scan

    LD V7775

    BIN // convert it to binary

    ADDB V2000 // add it to what we have so far

    OUT V2000

    Whenever you want to start timing, save off V2000 in some register, say V3000, which is the Start time

    STRPD "start event " // make sure this is a one-shot of some kind!!!

    LD V2000

    OUT V3000

    Then whenever you want to calculate the total elapsed time, subtract the start time from the current accumulated time and store it in, say, V3001:

    STRPD "end event " // make sure this is a different one-shot

    LD V2000 // current acc time

    SUBB V3000 // start time

    OUT V3001 // this is the number of milliseconds in binary/decimal, NOT BCD!!!

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: December 08,2006

    Created by: franji1

    I just wrote a program to see how close the accumulated scan is to a "60.000 " second TMRF (not TMRAF), and it doesn't look good. The measured accumulated time for a 60 second timer ends up bouncing around:

    59892

    59902

    59909

    59910

    59908

    59912

    59917

    59901

    59909

    with scan times between 1-4 ms

    I was hoping to get something within +- one scan time (i.e. +/- 4 ms, 59996 to 60004)

    Here's the program - maybe someone can see something wrong???

    C1 is the "start " event

    C2 is the "stop " event.

    C0 - You must turn on C0 to "enable " the program - it's self resetting, so just keep C0 ON.

    V2000 - accumulated scan time

    TA0 - built-in 60 second TMRF timer accmulator (in hundredths of a second)

    V3000 - start time, i.e. value of accumulated scan time when "start " event occurred (i.e. C1 one-shot)

    V3001 - calculated duration of the TMRF 60 second timer in milliseconds (should be something around 60000)

    V3002 - scan time based timer accumulator (in milliseconds)

    PLC 06

    // Rung 1

    // Address 0

    STR SP0

    LD K0

    OUT V2000

    // Rung 2

    // Address 3

    STR SP1

    LD V7775

    BIN

    ADDB V2000

    OUT V2000

    // Rung 3

    // Address 8

    STR C0

    ANDN T0

    PD C1

    // Rung 4

    // Address 11

    STR T0

    PD C2

    // Rung 5

    // Address 13

    STR C0

    ANDN T0

    TMRF T0 K6000

    // Rung 6

    // Address 18

    STR C1

    LD V2000

    OUT V3000

    // Rung 7

    // Address 21

    STR C2

    LD V2000

    SUBB V3000

    OUT V3001

    // Rung 8

    // Address 25

    STR C0

    LD V2000

    SUBB V3000

    OUT V3002

    // Rung 9

    // Address 29

    END

    // Rung 10

    // Address 30

    NOP

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: December 08,2006

    Created by: allukes

    How much precision and repeatability in the measurement do you actually require? If it is to 1 ms then you need better than the ability to resolve to .001 sec. If you need a repeatable and accurate measurement to +/- 1 ms, then you need a time base of .0005 to .0002 sec. You have the counter module, find an external time base in that range and feed it to the counter. (maybe use the pulse output from the counter module in continuous run mode?) Preset the counter to that amount and use interupts when the count is reached.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: December 09,2006

    Created by: twbrock

    The problem here is not being able to see the internal clock.

    I only know of two PLC that this can be done with the AB SLC's and CTC micro 2600 both have internal clocks that run in the micro sec. and floating point math which makes high speed timing very easy. There are most likely others that I have not seen. Both the SLC and the CTC are a lot more than AD PLC's .

    franji1 thanks for the info on using the scan time I have a program that I will put it into tonight I have been using a TMRF and the extra decimal point might help me.

    Tommy W Brock

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: December 11,2006

    Created by: Malachi

    Thanks so much for your responses.

    First, Tommy, you have it completely right. If there was some way to access the internal clock, things would be a lot easier.

    Second, Roger (and franji1), according to what I have read in the manual and help file, TMRF's only go to 0.01 seconds as well, not all the way to 0.001 sec.

    Third, allukes, I really only need to be accurate within +/- 2-3 ms, which is why I figure a 1 ms timer will do.

    What I am running into is when I try to calculate percent error from a 4-5 second test, 0.01 seconds is worth about 0.23%. The tolerance is +/- 0.15%, so I need to be able to see at least a couple of points either way within this tolerance.

    Franji1, I am working with your code. I am getting the same kind of results that you are, but I'm still trying some different things with the code.

    Thanks again everyone, please don't hesitate to post if you think of anything else.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: December 11,2006

    Created by: AZRoger

    I seem to recall something from Statistics class. It goes something like "you can measure the distance between two lines with a ruler with only lines every inch. You do it by dropping the ruler randomly across the two lines and count the number of ruler lines that are between two lines being measured. Repeat this as many times as necessary to get and average that is sufficiently accurate for your purposes. "

    I don't remember the exact math, but I do remember the concept.

    The net is that you can get to 1ms +-.5ms by taking a lot of 10ms +- 5ms readings and averaging them. Exactly how many is determined by tolerance for error and confidence requirements. Unless the process you are measuring and the PLC you are using to do the measurdments share a clock, the "random " requirement should be met; your timing intervals will start and end at "random " times relative to the timed process.

    Maybe someone who's statistics skills are better than mine can tell you how many not-good-enough measurements are needed to get you one order of magnitude more accurate than a single measurement. http://forum1.automationdirect.com/board/biggrin.gif

    Roger

    Expand Post
10 of 11