Search Results (Searched for: )
- blazini36
- blazini36
22 Jan 2025 23:05 - 22 Jan 2025 23:07
Replied by blazini36 on topic Rando hal component collections
Rando hal component collections
Category: HAL
Here's a good one.....
The control panel I'm working on uses 1 button for (cycle) start/pause and another button for (cycle) stop. I made it that way before I bothered figuring out how to do the hal programming. Now that I look at halui, it doesn't really like that setup. I searched and this came up before...
forum.linuxcnc.org/47-hal-examples/13201...-hold-resume-buttons
Writing HAL lines like that I find confusing when there's alot of logic involved. I started to break it down like I write them, to "look" like a terminal block. I'm sure it works but that's alot of HAL to do something like this. I reworked the toggle2nist component to add 2 more outputs to set resume and pause directly and another input to take the opposing state of what was "is-on". I just named the component and the pins as a specialized component since it's probably not as generally useful. It works perfectly without extra hal components. My flash component is also used here to switch an LED on/flashing when program is running, and on/solid when it is paused. It's off when stopped.
This is all the HAL lines for this setup:
And this is the component:
I'll submit this when I'm done testing it but so far so good.
The control panel I'm working on uses 1 button for (cycle) start/pause and another button for (cycle) stop. I made it that way before I bothered figuring out how to do the hal programming. Now that I look at halui, it doesn't really like that setup. I searched and this came up before...
forum.linuxcnc.org/47-hal-examples/13201...-hold-resume-buttons
Writing HAL lines like that I find confusing when there's alot of logic involved. I started to break it down like I write them, to "look" like a terminal block. I'm sure it works but that's alot of HAL to do something like this. I reworked the toggle2nist component to add 2 more outputs to set resume and pause directly and another input to take the opposing state of what was "is-on". I just named the component and the pins as a specialized component since it's probably not as generally useful. It works perfectly without extra hal components. My flash component is also used here to switch an LED on/flashing when program is running, and on/solid when it is paused. It's off when stopped.
This is all the HAL lines for this setup:
#program-run,pause,stop
net program-btn => run_pause.program.in
net program-toggle-run <= run_pause.program.run
net program-toggle-run => halui.program.run
net program-toggle-pause <= run_pause.program.pause
net program-toggle-pause => halui.program.pause
net program-is-running <= halui.program.is-running
net program-is-running => run_pause.program.running
net program-is-running => or2.program.in0
net program-resume <= run_pause.program.resume
net program-resume => halui.program.resume
net program-is-paused <= halui.program.is-paused
net program-is-paused => run_pause.program.paused
net program-is-paused => or2.program.in1
net program-run-or-pause <= or2.program.out
net program-run-or-pause => flash.program.enable
net program-is-paused => flash.program.hold
net program-led <= flash.program.out
net program-stop-btn => halui.program.stop
setp flash.program.hold-prec false
setp flash.program.hold-prec-inv false
setp flash.program.flash-rate-ms 250And this is the component:
component run_pause "Run-Pause, component for controlling halui program pins with 2 momentary pushbuttons";
description
"""
Run_Pause is based on the component toggle2nist. It has been specialized to work with halui program pins controlled with only 2 pushbuttons, start/resume and stop without adding a bunch of external logic.
""";
pin in bit in "momentary button for run/pause input";
pin in bit running "running state input";
pin in bit paused "paused state input";
pin in unsigned debounce = 2 "debounce delay for 'in'-pin in cycles";
pin out bit run "run output, activates on in=true when paused=false and running=false";
pin out bit pause "pause output, activates on in=true when paused=false and running=true";
pin out bit resume "resume output, activates on in=true when paused=true and running=false";
variable int debounce_cntr;
variable unsigned debounce_set;
variable int state;
function _ nofp;
license "GPL";
author "Shade Technik";
author "Anders Wallin, David Mueller"; //Authors or toggle2nist
;;
FUNCTION(_) {
if (( debounce < 1 ) || ( debounce > 10000 )) {
debounce_set = 2; /* set a sane value */
} else {
debounce_set = debounce;
}
if (in && state == 0 ) { /* input has changed from debounced 0 -> 1 */
debounce_cntr++;
if ( debounce_cntr >= debounce_set ) {
if (!running && paused) { /* turn ON if it's paused */
resume = 1;
pause = 0;
} else if (running && !paused) { /* turn OFF if it's running */
resume = 0;
pause = 1;
}
state = 1;
debounce_cntr = 0;
}
} else if (!in && state == 1) { /* input has changed from debounced 1 -> 0 */
debounce_cntr++;
if ( debounce_cntr >= debounce_set ) {
state = 0;
debounce_cntr = 0;
}
} else if ((!running && pause) || (running && run)) { /* reset outputs once device has switched */
run = 0;
pause = 0;
debounce_cntr = 0;
} else {
debounce_cntr = 0;
}
/* Set resume output while in is true and neither running nor paused is active */
if (in && !running && !paused) {
run = 1;
} else {
run = 0;
}
}I'll submit this when I'm done testing it but so far so good.
Time to create page: 0.357 seconds