Subroutine to wait for input using M66

More
03 Sep 2011 07:08 #12923 by automata
I had this problem to wait for an input before executing the next line of gcode. like a punching machine / drilling mahcine.

This is a subroutine to to do that.
O<wait_for_input_fall> sub
  M66 P0 L2 Q1
  O<loop> while [#5399 EQ -1]
    M66 P0 L2 Q1
  O<loop> endwhile
O<wait_for_input_fall> endsub

Put this subrouting at the start of your Gcode file and call it as:
O<wait_for_input_fall> call

This will wait for input 0 to go low and keep re-checking the input at every 1s.

The changes made to the HAL file are to link motion.digital-in-00 to the input pin. In my case I am using the MESA 7i43 card and I want a time delay after the input is received..

HAL File....
#use halui to configure estop... and machine on
#
net estop-in <= hm2_7i43.0.gpio.047.in_not
net estop-in => iocontrol.0.emc-enable-in
#load a time delay...
loadrt timedelay count=2
#add the time delay function to the servo-thread
addf timedelay.0 servo-thread
#set the on-delays and offselays in seconds
setp timedelay.0.on-delay 0.25
setp timedelay.0.off-delay 0.0
net estop-in => timedelay.0.in
net machineon <= timedelay.0.out 
net machineon => halui.machine.on


# start the program...


# and step-program-input with mode auto
loadrt and2 count=2
loadrt edge count=1
addf and2.0 servo-thread
addf and2.1 servo-thread
addf timedelay.1 servo-thread
setp timedelay.1.on-delay 0.4
setp timedelay.1.off-delay 0.0
#connect andgate to step program edge
net step-program-input hm2_7i43.0.gpio.046.in => and2.0.in0
#and the input with machine on signal
net machineon => and2.0.in1
net step-and-machine and2.0.out => and2.1.in0
net modeauto halui.mode.is-auto => and2.1.in1
net step-program and2.1.out => timedelay.1.in
net progstep timedelay.1.out => motion.digital-in-00 

PLEASE USE ABOVE AT YOUR OWN DISCRETION and after understanding what it does... This is what works for me. Ofcourse I will also be changing this to make it better and am very open to suggestion to that same effect.

Regards,

automata
The following user(s) said Thank You: nkp

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

More
03 Sep 2011 22:49 #12939 by andypugh
automata wrote:

I had this problem to wait for an input before executing the next line of gcode. like a punching machine / drilling mahcine.

This is a subroutine to to do that.

O<wait_for_input_fall> sub
  M66 P0 L2 Q1
  O<loop> while [#5399 EQ -1]
    M66 P0 L2 Q1
  O<loop> endwhile
O<wait_for_input_fall> endsub


I am a bit confused. Are you saying that M66 P0 L2 doesn't work properly?
M66 L2 is meant to wait P seconds for a falling edge on input Q. There shouldn't be any need for the rest of the subroutine.

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

More
04 Sep 2011 06:51 #12946 by automata
Hi Andy,

I am not saying the M66 does not work. Infact it works perfectly.

The routine is to wait indefinitely for an input or stop / abort being pressed.

Although this routine keeps writing to the disk at 1s intervals (to the .var file). So it is a problem if you want to minimize disk writes (if you are using SSD's or Flash based devices with finite write cycles and hve not implemented read-only root file systems).

regards,

automata
The following user(s) said Thank You: nkp

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

Time to create page: 0.076 seconds
Powered by Kunena Forum