1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
component time "Time on in Hours, Minutes, Seconds";
description
"""
Time
When either the time.N.start or time.N.pause bits goes true the cycle
timer resets and starts to time until time.N.start AND time.N.pause go
false. When the time.N.pause bit goes true timing is paused until
time.N.pause goes false. If you connect time.N.start to
halui.program.is-running and leave time.N.pause unconnected the timer
will reset during a pause. See the example connections below for more
information.
Time returns the hours, minutes, and seconds that time.N.start is true.
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>
</pyvcp>
In your post-gui.hal file you might use one of the following to connect
this timer:
For a new config:
loadrt time
addf time.0 servo-thread
net cycle-timer time.0.start <= halui.program.is-running
net cycle-timer-pause time.0.pause <= halui.program.is-paused
net cycle-seconds pyvcp.time-seconds <= time.0.seconds
net cycle-minutes pyvcp.time-minutes <= time.0.minutes
net cycle-hours pyvcp.time-hours <= time.0.hours
Previous to this version if you wanted the timer to continue running
during a pause instead of resetting, you had to use a HAL NOT component
to invert the halui.program.is-idle pin and connect to time.N.start as
shown below:
loadrt time
loadrt not
addf time.0 servo-thread
addf not.0 servo-thread
net prog-running not.0.in <= halui.program.is-idle
net cycle-timer time.0.start <= not.0.out
net cycle-seconds pyvcp.time-seconds <= time.0.seconds
net cycle-minutes pyvcp.time-minutes <= time.0.minutes
net cycle-hours pyvcp.time-hours <= time.0.hours
For those who have this setup already, you can simply add a net connecting
time.N.pause to halui.program.is-paused:
net cycle-timer-pause time.0.pause <= halui.program.is-paused
""";
author "John Thornton, itaib, Moses McKnight";
license "GPL";
// Input Pins
pin in bit start "Timer On";
pin in bit pause = 0 "Pause";
// Output Pins
pin out u32 seconds "Seconds";
pin out u32 minutes "Minutes";
pin out u32 hours "Hours";
// Global Variables
variable double totalnsec;
variable int old_start;
function _;
;;
#include "rtapi_math.h"
FUNCTION(_) {
rtapi_u32 totalseconds;
int running = start | pause;
if(running && !old_start) totalnsec = 0;
if(start && !pause){
totalnsec = totalnsec + period;
totalseconds = totalnsec * 0.000000001;
seconds = totalseconds % 60;
minutes = (totalseconds / 60) % 60;
hours = (totalseconds / 3600);
}
old_start = running;
}
|