In this topic, you can present and discuss of solutions and ideas about the use of interrupts or polling techniques to manage the limit switches.
Until now, I controlled the limit switches (LS) by using the arduino interrupts and they work fine because they make the code more lightweight but the solution has a drawback: the number of limit switches that the firmware can manage. I conceived eCNC to use up to two LSs per axis (up and down) and even if their use is optional, the problem appears already with three axes. With three axis I should manage six LSs and the arduino mega 2560 has only six external interrupts (EI); it means that I cannot use any other EI to control any other button and I am also tied to use only the pins associated to the EIs. Moreover, one of the main goal of the next version of the firmware (FW) is the capability to manage a configurable number of axes, up to 5 axes. It make the issue of the number of EIs relevant.
I would adopt a solution that keeps the advantages of the EI but it gives also the flexibility to chose any pins that I want.
I report a solution proposed by Meir:
...
This is the way I envision the usaage of the controller:
1) you start the controller.
2)connect to CNC ( I would use it for my milling and my laser machines)
3) set Home (in Marlin this is G28) In my own firmware it is G30 and G28 does G01 X0 Y0 without hitting the micro switches.
4) load gcode
5) optionally do another job or jog the machine.
The important thing is that I hit the microswitch only once when setting the machine.
In the firmware(it can be modified by Mcode) I set the size of the machine and I keep track of my position.
If I try to go more than the limit of the machine, the machine will reset to the limits. so I am always protected.
...
The solution is interesting because you prevent the issue with a software check and in extreme cases, you reset the machine if the LS is triggered.
How do you manage the reset by LS?
Last edit: Hawk 2015-06-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you Meir. I opened another topic to talk about the laser power control. It is an relevant topic for me, because I am using a continue current laser that is switched on/off by a relè. The relè is too slow to be controlled with a PWM signal, thus the laser goes to the max power when is switched on.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In this topic, you can present and discuss of solutions and ideas about the use of interrupts or polling techniques to manage the limit switches.
Until now, I controlled the limit switches (LS) by using the arduino interrupts and they work fine because they make the code more lightweight but the solution has a drawback: the number of limit switches that the firmware can manage. I conceived eCNC to use up to two LSs per axis (up and down) and even if their use is optional, the problem appears already with three axes. With three axis I should manage six LSs and the arduino mega 2560 has only six external interrupts (EI); it means that I cannot use any other EI to control any other button and I am also tied to use only the pins associated to the EIs. Moreover, one of the main goal of the next version of the firmware (FW) is the capability to manage a configurable number of axes, up to 5 axes. It make the issue of the number of EIs relevant.
I would adopt a solution that keeps the advantages of the EI but it gives also the flexibility to chose any pins that I want.
I report a solution proposed by Meir:
The solution is interesting because you prevent the issue with a software check and in extreme cases, you reset the machine if the LS is triggered.
How do you manage the reset by LS?
Last edit: Hawk 2015-06-15
I just made public the changes in my current firmware. Please feel free to use it as inspiration or comparative exercise.
https://github.com/meirm/laseramp/tree/master/firmware
Thank you Meir. I opened another topic to talk about the laser power control. It is an relevant topic for me, because I am using a continue current laser that is switched on/off by a relè. The relè is too slow to be controlled with a PWM signal, thus the laser goes to the max power when is switched on.