Dan:
If Diag mode works, then its time for the CNC mode test.. in that you setup Mach4 for a pwm spindle.. 50hz and dont turn on laser. The laser should fire when a g1 move is done whlie the spindle is turned on and a SWord is set. By the way, for all uses of the laser in MAch4, you need to set the spindle range from 0 - 100, and the SWord to use then must be 0-100 for the desired power. Its made this way on all modes to make it easier to pick power. I think the next logical test to make is to see if we can get CNC mode working.. and debug it till we know why it isnt if it wont..
Art
Arduino based Laser Control
-
ArtF
- Global Moderator

- Posts: 4557
- Joined: Sun Sep 05, 2010 5:14 pm
- Contact:
-
DanL
- Site Admin
- Posts: 357
- Joined: Thu Sep 11, 2014 12:35 am
Re: Arduino based Laser Control
that's what I was doing wrong I was turning the laser on so it would of been turning it off what a dork lol
I will test now
I will test now
-
DanL
- Site Admin
- Posts: 357
- Joined: Thu Sep 11, 2014 12:35 am
Re: Arduino based Laser Control
tried but cant get it working in cnc mode.
tried doing a engrave did not seem to work ever
and diag mode does work I will play some more tommorow
tried doing a engrave did not seem to work ever
and diag mode does work I will play some more tommorow
-
ArtF
- Global Moderator

- Posts: 4557
- Joined: Sun Sep 05, 2010 5:14 pm
- Contact:
Re: Arduino based Laser Control
Dan:
For cnc mode to work, the box must sense a PWM signal coming in... for NGrave mode to work, it must sense the serial clk and data
properly. So probably best to troubleshoot one or the other based on the way it works. Take NGRave... when its on, there is a "REM:"
in the top right hand corner that shows the power the box is recieving from Darwin. It will normally show REM:0 , but when actually cutting a photo
the REM :xx will show a number from 0-100 as a power beign recieved. (It toggles quickly as the axis scans across the photo..)
What kernal speed are you set to in Darwin? Id advise you slow it down to 25 - 35K for testing to make sure the serial process works..
Also, here is the latest code I use for mine , Im using the latest published Darwin and the attached LAser box code..
Art
For cnc mode to work, the box must sense a PWM signal coming in... for NGrave mode to work, it must sense the serial clk and data
properly. So probably best to troubleshoot one or the other based on the way it works. Take NGRave... when its on, there is a "REM:"
in the top right hand corner that shows the power the box is recieving from Darwin. It will normally show REM:0 , but when actually cutting a photo
the REM :xx will show a number from 0-100 as a power beign recieved. (It toggles quickly as the axis scans across the photo..)
What kernal speed are you set to in Darwin? Id advise you slow it down to 25 - 35K for testing to make sure the serial process works..
Also, here is the latest code I use for mine , Im using the latest published Darwin and the attached LAser box code..
Art
You do not have the required permissions to view the files attached to this post.
-
ArtF
- Global Moderator

- Posts: 4557
- Joined: Sun Sep 05, 2010 5:14 pm
- Contact:
Re: Arduino based Laser Control
Dan:
If you wish to debug the CNC mode first, since its the easiest..
look to the code at the end of the above code..
//and finally a pwm spindle interrupt, basically Reads incoming PWM signal
at 50hz..
ISR(INT6_vect)
{
if( PINE & ( 1<<6))
{
SpinOnCnt = cnt;
SpindleOn = true;
}
else
SpinOffCnt = cnt;
return;
}
This small fragment reads the pin7 PWM incoming signal, and determins the
laser's output power, if it see's any signal
it turns on the laser power ( which would then fireon the next step flag).
SO perhaps in the display section adding a lcd output
of the state of the "SpindleOn" variable will show you if the PWM
conversation with Darwin is working. SpindleOn, once set
will remain on until it senses no further PWMs for at least 200us.. So its
a great signal to track to troubleshoot the boxes
communication with Darwin..
TO make it easier on your head, Id add such a display message and make
sure you can get it to show the pwm is
being seen as on or off when you turn the spindle on or off in mach4....
once we get that far you wont be far off from
making it work..
Art
Thanks,
Art
www.gearotic.com
If you wish to debug the CNC mode first, since its the easiest..
look to the code at the end of the above code..
//and finally a pwm spindle interrupt, basically Reads incoming PWM signal
at 50hz..
ISR(INT6_vect)
{
if( PINE & ( 1<<6))
{
SpinOnCnt = cnt;
SpindleOn = true;
}
else
SpinOffCnt = cnt;
return;
}
This small fragment reads the pin7 PWM incoming signal, and determins the
laser's output power, if it see's any signal
it turns on the laser power ( which would then fireon the next step flag).
SO perhaps in the display section adding a lcd output
of the state of the "SpindleOn" variable will show you if the PWM
conversation with Darwin is working. SpindleOn, once set
will remain on until it senses no further PWMs for at least 200us.. So its
a great signal to track to troubleshoot the boxes
communication with Darwin..
TO make it easier on your head, Id add such a display message and make
sure you can get it to show the pwm is
being seen as on or off when you turn the spindle on or off in mach4....
once we get that far you wont be far off from
making it work..
Art
Thanks,
Art
www.gearotic.com
- tweakie
- Site Admin
- Posts: 171
- Joined: Wed Dec 01, 2010 11:58 am
Re: Arduino based Laser Control
Hi Art,
I am a bit confused here - in the previous post you said;
"This small fragment reads the pin7 PWM incoming signal, and determins the
laser's output power, if it see's any signal".
Pin 7 ??
Is that the 'Serial Data' on Arduino Pin 11 or are you using another input on Arduino Pin7 for the spindle PWM ??
Tweakie.
I am a bit confused here - in the previous post you said;
"This small fragment reads the pin7 PWM incoming signal, and determins the
laser's output power, if it see's any signal".
Pin 7 ??
Is that the 'Serial Data' on Arduino Pin 11 or are you using another input on Arduino Pin7 for the spindle PWM ??
Tweakie.
-
ArtF
- Global Moderator

- Posts: 4557
- Joined: Sun Sep 05, 2010 5:14 pm
- Contact:
Re: Arduino based Laser Control
Tweakie..
Now Im confused.. I wrote that from reading the code at the top where I commented pin7 is the PWM pin..
Ill check this and reply..
Art
Now Im confused.. I wrote that from reading the code at the top where I commented pin7 is the PWM pin..
Ill check this and reply..
Art
-
ArtF
- Global Moderator

- Posts: 4557
- Joined: Sun Sep 05, 2010 5:14 pm
- Contact:
Re: Arduino based Laser Control
Tweakie:
Its as I remembered. I use 4 pins to my breakout board. I use serial clk, serial data, and step flag. These are all used for
engraving or realtime control of fire and power. Thats NGrave mode.
Then I have Diags that uses no signals, purely manual.
Finally there is CNC mode, where I use a Spindle PWM and StepFlag. Stepflag still controls firing, but the PWM spindle
sets the power. It also determines if the laser is on or off whan a step flag occurs. Further, it looks to speed and corrects
power for the speed its running at. This is to correct for acceleration times. Spindle PWM comes in pin7 which is the interrupt vector 6.
There is a spot in the code when you switch out of NGrave code that the PWM interrupt gets turned on and the serial data interrupt switched off..
attachInterrupt( 4, DUMMY, CHANGE ); //reattach the spindle interrupt
detachInterrupt(1);
There is a reverse of that when you switch to NGrave mode. ( The number is interrupt 4 but really translates to 6 as a vector..).
Also noteworthy, if your in Diags mode, and the PWM input see's that PWM spindle has turned on, youll automaticallt switch out of diags
and into CNC mode. That happens because of this line...
if( SpindleOn && OpMode == DIAGS)
OpMode = CNCMODE; //auto switch from Diags
So one can test the PWM input just by turning on M4's spindle and giving it an SWord.. An M3S50 should
make the laser control swap to CNC mode..
Art
Its as I remembered. I use 4 pins to my breakout board. I use serial clk, serial data, and step flag. These are all used for
engraving or realtime control of fire and power. Thats NGrave mode.
Then I have Diags that uses no signals, purely manual.
Finally there is CNC mode, where I use a Spindle PWM and StepFlag. Stepflag still controls firing, but the PWM spindle
sets the power. It also determines if the laser is on or off whan a step flag occurs. Further, it looks to speed and corrects
power for the speed its running at. This is to correct for acceleration times. Spindle PWM comes in pin7 which is the interrupt vector 6.
There is a spot in the code when you switch out of NGrave code that the PWM interrupt gets turned on and the serial data interrupt switched off..
attachInterrupt( 4, DUMMY, CHANGE ); //reattach the spindle interrupt
detachInterrupt(1);
There is a reverse of that when you switch to NGrave mode. ( The number is interrupt 4 but really translates to 6 as a vector..).
Also noteworthy, if your in Diags mode, and the PWM input see's that PWM spindle has turned on, youll automaticallt switch out of diags
and into CNC mode. That happens because of this line...
if( SpindleOn && OpMode == DIAGS)
OpMode = CNCMODE; //auto switch from Diags
So one can test the PWM input just by turning on M4's spindle and giving it an SWord.. An M3S50 should
make the laser control swap to CNC mode..
Art
- tweakie
- Site Admin
- Posts: 171
- Joined: Wed Dec 01, 2010 11:58 am
Re: Arduino based Laser Control
Thanks Art, that explains it.
Tweakie.
Tweakie.
-
DanL
- Site Admin
- Posts: 357
- Joined: Thu Sep 11, 2014 12:35 am
Re: Arduino based Laser Control
So one can test the PWM input just by turning on M4's spindle and giving it an SWord.. An M3S50 should
make the laser control swap to CNC mode..
that will make it easer to test to see if I can get cnc mode working.
its the signals where the problem will be not the arduino code I will try old code first then try new code
make the laser control swap to CNC mode..
that will make it easer to test to see if I can get cnc mode working.
its the signals where the problem will be not the arduino code I will try old code first then try new code