help with Timer

More
31 Jan 2014 22:13 - 31 Jan 2014 23:38 #43370 by rmattioda
help with Timer was created by rmattioda
I have a cycle timer that works fine but I noticed that someone had a accumulative type which I have enclosed a picture of.

do any of you have the coding for this and the hal pin info? and perhaps a reset to zero the timer too would be nice
Attachments:
Last edit: 31 Jan 2014 23:38 by rmattioda. Reason: add items

Please Log in or Create an account to join the conversation.

More
01 Feb 2014 00:18 #43377 by ArcEye
Replied by ArcEye on topic help with Timer

I noticed that someone had a accumulative type which I have enclosed a picture of.


Where did you see it? First place to ask?

(Your current timer is one Probotix cobbled together using classic ladder timers by the look of it - is this Probotix related too?)

Please Log in or Create an account to join the conversation.

More
01 Feb 2014 00:48 #43379 by rmattioda

Please Log in or Create an account to join the conversation.

More
01 Feb 2014 01:07 #43380 by ArcEye
Replied by ArcEye on topic help with Timer
Seems like you are in a loop, you posted on that same thread 6 months ago,
www.linuxcnc.org/index.php/english/forum...not-working?start=30
I'll leave JT to answer re his timer

The other screenshot is from pasha, may well have been when he was demo'ing the improved dial widget
Doubt you will be able to get hold of him

Please Log in or Create an account to join the conversation.

More
01 Feb 2014 07:29 #43387 by BigJohnT
Replied by BigJohnT on topic help with Timer
The timer I wrote is the cycle timer not the overall timer. Not sure what the overall timer would be tracking???

JT

Please Log in or Create an account to join the conversation.

More
01 Feb 2014 23:33 - 02 Feb 2014 17:40 #43400 by ArcEye
Replied by ArcEye on topic help with Timer
OK

Here is JT's timer, modified to show a cumulative total of cycle times for all jobs since it was launched.

The cumulative timer should hold 9942.0539213 hours, ought to be long enough!
component time2 "Time on in Hours, Minutes, Seconds with cumulative totals";

description 
"""
Time2

When the time2.N.start bit goes true the cycle timer resets and starts
to time2 until time.N.start goes false. If you connect time2.N.start to
halui.is-running as a cycle timer it will reset during a pause. See
the example connections below to keep the timer timing during a pause.

Time2 returns the hours, minutes, and seconds that time2.N.start is true.

The cumulative total is displayed by the second set of pins

Sample pyVCP code to display the hours:minutes:seconds.

<pyvcp>
  <hbox>
  <label>
    <text>"Cycle Time"</text>
    <font>("Helvetica",14)</font>
  </label>
  <u32> 
      <halpin>"time-hours"</halpin>
      <font>("Helvetica",14)</font>
      <format>"2d"</format>
  </u32>
  <label>
    <text>":"</text>
    <font>("Helvetica",14)</font>
  </label>
  <u32> 
      <halpin>"time-minutes"</halpin>
      <font>("Helvetica",14)</font>
      <format>"2d"</format>
  </u32>
  <label>
    <text>":"</text>
    <font>("Helvetica",14)</font>
  </label>
  <u32> 
      <halpin>"time-seconds"</halpin>
      <font>("Helvetica",14)</font>
      <format>"2d"</format>
  </u32>
  </hbox>

  <hbox>
  <label>
    <text>"Total Time"</text>
    <font>("Helvetica",14)</font>
  </label>
  <u32> 
      <halpin>"total-time-hours"</halpin>
      <font>("Helvetica",14)</font>
      <format>"2d"</format>
  </u32>
  <label>
    <text>":"</text>
    <font>("Helvetica",14)</font>
  </label>
  <u32> 
      <halpin>"total-time-minutes"</halpin>
      <font>("Helvetica",14)</font>
      <format>"2d"</format>
  </u32>
  <label>
    <text>":"</text>
    <font>("Helvetica",14)</font>
  </label>
  <u32> 
      <halpin>"total-time-seconds"</halpin>
      <font>("Helvetica",14)</font>
      <format>"2d"</format>
  </u32>
  </hbox>
  <hbox>
      <button>
      <halpin>"reset"</halpin>
	  <text>"Reset Total"</text> 
      <font>('Fixed',16)</font>
      <relief>RAISED</relief>
      </button>  
  </hbox>
</pyvcp>

In your post-gui.hal file you might use the following to connect it up

 loadrt time2
 loadrt not
 addf time2.0 servo-thread
 addf not.0 servo-thread
 net prog-running not.0.in <= halui.program.is-idle
 net cycle-timer time2.0.start <= not.0.out
 net cycle-seconds pyvcp.time-seconds <= time2.0.seconds
 net cycle-minutes pyvcp.time-minutes <= time2.0.minutes
 net cycle-hours pyvcp.time-hours <= time2.0.hours
 net total-cycle-seconds pyvcp.total-time-seconds <= time2.0.totalofseconds
 net total-cycle-minutes pyvcp.total-time-minutes <= time2.0.totalofminutes
 net total-cycle-hours pyvcp.total-time-hours <= time2.0.totalofhours
""";
 
author "John Thornton (modified by ArcEye)";

license "GPL";

// Input Pins
pin in bit start "Timer On";
pin in bit reset "Reset the cumulative timer";
// Output Pins
pin out u32 seconds "Seconds";
pin out u32 minutes "Minutes";
pin out u32 hours "Hours";

pin out u32 totalofseconds "total-Seconds";
pin out u32 totalofminutes "total-Minutes";
pin out u32 totalofhours "total-Hours";

// Global Variables
variable double totalnsec;
variable int old_start;
variable int totalseconds = 0;
variable int sumtotalseconds = 0;

function _;

;;

#include "rtapi_math.h"

FUNCTION(_) 
{
  
	if(reset)
		sumtotalseconds = 0;
		
	if(start && !old_start)
		{
		sumtotalseconds += totalseconds; 
		totalnsec = 0;
		}
    if(start)
		{
    	totalnsec = totalnsec + period;
    	totalseconds = totalnsec * 0.000000001;
	   	seconds = totalseconds % 60;
		minutes = (totalseconds / 60) % 60;
		hours = (totalseconds / 3600);
    	totalofseconds = (totalseconds + sumtotalseconds) % 60;
		totalofminutes = ((totalseconds +sumtotalseconds) / 60) % 60;
		totalofhours = ((totalseconds +sumtotalseconds) / 3600);		
		}
	old_start = start;
}

and here it is running





Instructions for compiling etc same as on the other thread

regards
Attachments:
Last edit: 02 Feb 2014 17:40 by ArcEye.
The following user(s) said Thank You: BigJohnT

Please Log in or Create an account to join the conversation.

More
02 Feb 2014 09:57 - 02 Feb 2014 13:55 #43421 by rmattioda
Replied by rmattioda on topic help with Timer
Arceye

Can you send the entire set of files, I am having trouble making this work.

I have enclosed mine if you want to see what I am doing wrong

Thanks
Attachments:
Last edit: 02 Feb 2014 13:55 by rmattioda. Reason: add

Please Log in or Create an account to join the conversation.

More
02 Feb 2014 17:46 #43426 by ArcEye
Replied by ArcEye on topic help with Timer

Arceye

Can you send the entire set of files, I am having trouble making this work.

I have enclosed mine if you want to see what I am doing wrong

Thanks


There is no 'entire set of files' . All the info you need is in the header of the comp file

Cut and paste the whole file and save as time2.comp

Compile with sudo comp --install time2.comp

Add the pyvcp xml bit from the header to your pyvcp xml file, whatever it is called

Add the hal section of the header to your postgui.hal file ( you have not done this, it is still the old code)

(NB This component is called time2, not time, make sure you are loading the right component)

Please Log in or Create an account to join the conversation.

More
02 Feb 2014 20:30 #43429 by BigJohnT
Replied by BigJohnT on topic help with Timer
I wonder if we can update master with this modified timer? It doesn't seem to break any old configs and adds total time to the component.

JT

Please Log in or Create an account to join the conversation.

More
02 Feb 2014 21:57 #43435 by ArcEye
Replied by ArcEye on topic help with Timer
Entirely down to you JT, it is your component, I just tinkered with it.
Certainly if you name it back to timer, it is backwardly compatible with the existing component.

I think the first test needs changing to
if(reset)
    {
    sumtotalseconds = 0;
    totalofseconds = totalofminutes = totalofhours = 0;
    }

That way the counters will zero if there is no program running, which is probably what the user would expect.

If there is a program running, they will momentarily zero and then sync with the cycle counter.

regards

Please Log in or Create an account to join the conversation.

Time to create page: 0.651 seconds
Powered by Kunena Forum