Author Topic: High Speed Timer  (Read 8577 times)

Taranabas

  • Newbie
  • Posts: 10
    • View Profile
High Speed Timer
« on: December 17, 2013, 01:54:13 PM »
Hello, I would like to use a Nano-10 to determine how long it takes for a large relay to drop out. It typically takes 50-200 milliseconds for this to occur. As far as I know, the timer function only offers 0.01s resolution. Is there another way I could accomplish this?

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:High Speed Timer
« Reply #1 on: December 17, 2013, 05:49:30 PM »
I have measured the ladder logic scan time on my Nano-10 and have found that it is about 100us for  very short ladder logic programs.  

If you set up your Nano-10 with an INPUT that is connected to the relay coil and an INPUT controlled by the relay contact.  You should be able to measure the time it takes for the relay to drop out.

You will need to write a ladder logic program that invokes a custom function when the relay coil is de-energized.  This custom function should simple issues the STATUS(21) function to return the current CPU counter.  The value returned by STATUS(21) is a 32 value with a resolution of 0.1us  (0.0000001 seconds).

Your ladder logic will need to invoke a second custom function when the relay contact changes.  The second custom function uses the STATUS(21) function to get the CPU counter value.  You should be able to compute the difference between the two calls to STATUS(21) and get the elapsed time.

Because this measurement is done in ladder logic it is possible that measured times will be in error by 0 to 300 us. (0 to 3 scan times).

There are other approaches that use interrupts that may be able to reduce the uncertainty of the time measurements.  

You should measure the drop out time with conventional test equipment and compare the results to the PLC measurements.

Gary D.

Taranabas

  • Newbie
  • Posts: 10
    • View Profile
Re:High Speed Timer
« Reply #2 on: December 17, 2013, 06:31:42 PM »
That is an interesting approach, does the status(21) fn return the number of CPU scans or an actual time value in microseconds?  I am using the plc to energize the contactor as well, would it be sufficient to use the de-energization of that output to trigger the cusfn, or is there a special reason you suggest using an input for this?


support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:High Speed Timer
« Reply #3 on: December 17, 2013, 09:39:52 PM »
That is the right approach suggested by Gary (thanks!).

STATUS(21) returns the value of a 10MHz free running counter in the system so every 0.1us the free running counter will increment by one. What you are interested is not the absolute values of STATUS(21) but the difference between two snap shot of the counter value returned by STATUS(21) function. The differences is typically used to measure the estimated time a statement or a function takes to complete the task, but certainly can also be used to measure the time differences between two interrupt events.

You can use the de-activation of the output as an event to trigger the first STATUS(21) and then when the output actually drops off the signal can be used to trigger a falling edge interrupt input and capture the STATUS(21) and compute the differences between the two.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:High Speed Timer
« Reply #4 on: December 17, 2013, 10:23:14 PM »
I believe that the STATUS(21) returns a running time value in 0.1us units.  

This is how it is documented in "i-TRiLOGI Ladder+BASIC Programmers Reference" Revision 3.0, i-TRiLOGI V6.45:

Return CPU Counter Value
Can be used to measure execution time.
This function returns the 32-bit value of a 10MHz free running counter in the CPU. The difference between the values from two STATUS(21) gives the elapse time of a process in 0.1us.
E.g:
A = STATUS(21)
CALL [somefunction]
B = STATUS(21) - A
B is the execution time of [somefunction] in 0.1 microseconds. (i.e. if B = 10000 => 1 ms)
Note: only for PLCs with firmware r78 or above


I would probably use 2 OUTPUTs.  One connected to the contactor and a second OUPUT that is connected to an INPUT.  I am a worried about the inductive nature of the contactor.  If you fail to add the protection diodes to the contactor coil you could easily destroy a PLC input and possibly damage the OUTPUT circuity.

The reason behind suggestion 2 INPUTs is that the PLC physical outputs are not updated until the ladder logic scan is completed. Physical inputs are sampled and stored before the beginning of each ladder logic scan.  I think that using 2 INPUTS would help minimize the possible errors in the measurement system.

The only way to figure out what will give you the most predictable results is to test the system.  

Gary D

Taranabas

  • Newbie
  • Posts: 10
    • View Profile
Re:High Speed Timer
« Reply #5 on: December 17, 2013, 11:13:31 PM »
Excellent, thank you for the suggestions! My initial thought was to use a pulse width measurement, but the more I thought about it the more convoluted it seemed it would be. On a side note, I am interfacing the 24v output with a solid state relay to energize the contactor. Any caveats with that?

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:High Speed Timer
« Reply #6 on: December 18, 2013, 10:25:42 AM »
If you are using a SSR (solid state relay) because your contactor is designed for AC voltages then I may have a concern.  

Nearly all SSRs turn off only when the AC voltage is at about 0 volts.  This means that there can be a turn off delay of 0.. to 8.3ms (assuming 60Hz AC) from when the PLC OUTPUT goes "off" until the next zero crossing of the AC.

If you are OK with a measurement error of up to 8.3ms, then no worries.

Gary D.

Taranabas

  • Newbie
  • Posts: 10
    • View Profile
Re:High Speed Timer
« Reply #7 on: December 18, 2013, 11:20:48 AM »
Ahh, I seem to recall learning that in school now that you mention it. It may be a necessary evil, as this is a 2400v carriage contactor, the coil has a rather large inrush and hold in current. I can't imagine a mechanical relay would be much faster than an ssr.

Taranabas

  • Newbie
  • Posts: 10
    • View Profile
Re:High Speed Timer
« Reply #8 on: December 23, 2013, 06:32:20 AM »
I just attempted to implement this, but I just found that my PLC firmware is r74. What are my options here? Are there any other ways to obtain precise timing such as this or will I have to have r78 or greater? Can the firmware be upgraded?

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3171
    • View Profile
    • Internet Programmable PLCs
Re:High Speed Timer
« Reply #9 on: December 23, 2013, 09:04:47 AM »
The STATUS(21) function only works on the PLC with correct firmware version.

The firmware can only be upgraded at the factory. You can arrange with your seller to ship the unit back to us for firmware upgrade.  However, since Nano-10 is pretty low cost device it may make sense to purchase a new unit and keep the older unit for other projects that don't need this function.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Taranabas

  • Newbie
  • Posts: 10
    • View Profile
Re:High Speed Timer
« Reply #10 on: January 14, 2014, 09:41:29 PM »
Just wanted to follow up on this thread. The STATUS(21) Solution worked beautifully. We are seeing consistent test results within 2-3 milliseconds from some of the better contactors. This little guy can even measure the time it takes to open a small 4 pole control relay, which is about 14ms. The SSR does not appear to be causing any noticeable error in the measurements, although we will have to verify this with a scope before we can put the timer into full-fledged use. Thanks guys!