GearHeads Corner
June 02, 2020, 03:40:14 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1] 2 3 ... 14
  Print  
Author Topic: Arduino based Laser Control  (Read 61409 times)
0 Members and 2 Guests are viewing this topic.
ArtF
Administrator
Hero Member
*****
Posts: 5634



View Profile
« on: September 04, 2014, 10:17:54 AM »

Hello All:

   This board is for questions, materials, code and suggestio ns involved with the Darwin/Mach4
Arduino based Laser Control panel. With Darwin now able to create laser engraving files and
with its requireme nt that an arduino laser controlle r be used, this board will contain my original
code and its evolution, along with ( hopefully) any users code suggestio ns and improveme nts.

Soon, I will start posting photo's, build suggestio ns and the code from the original laser panel
and we'll build from there.

What the hell is that you ask? :

     Darwin ( the printer port cnc driver for Mach4 ) has been released, and as of version 1.19 of it,
it can process grey scale images ( such as those made by Gearotic of Celtic knots) and from those
create mapping files so a fast laser system can engrave them with proper power levels. Darwin also creates
GCode files to match the power mapping files. But to do all this it needed more speed and power than a
printer port alone could offer. So a laser control panel was built with an eye to ease of use, creating and low cost
of owning one. The one I ended up with is made of wood, plexiglas s and an inexpensi ve arduino. It connects to
a breakout board on 3 pins to provide the interface with Mach4 and Darwin. As such, its easy to make, inexpensi ve
and gives an amazing level of control over a DIY laser system while requiring no real knowledge of electroni cs and only basic
construct ion skills needed. In future many more cool effects could be done due to the way the power mapping is performed .
The following postings will detail the panel, provide videos and answer questions from those that would like to build
a panel or help the community improve on it, and perhaps we can all learn a lot about engraving technique s on
various materials at the same time. 


Art
 
Logged
ArtF
Administrator
Hero Member
*****
Posts: 5634



View Profile
« Reply #1 on: September 05, 2014, 03:04:30 PM »

Hello Everyone.

  So this thread is about a control panel for a laser. But more broadly its about ways to get signals
  from a printer port Mach4 to other devices for things youd like to experimen t with. ITs probably best
  to go at this as a "This is the problem I had..and this is what I did" type of discussio n as not everyone
  who reads this thread will be thinking of running a laser. An impact needle for engraving tombstone s, or
  a unit to apply a known unit of glue to a particula r spot, or even perhaps a UV diode to cure 3d liquids
  in various positions at various power may be your thing. All of these things have common features.
  
     My problem was simply to get laser power to a laser, but at the same time I had to control a very accurate
  tickle pulse, Perhaps software could have done it all, but it occured to me that these things called arduino's
  may be able to help and make the solution to my problem acceptabl e for other problems.
  
    I may as well admit now that this was my first arduino project, and my first arduino program. So dont expect
  any fancy programmi ng skills to be shown. BUT, the fact I could code this arduino very quicky to do what its doing
  should clue you in that you could do such a project to use the same data for many other things. (Or just simply
  copy my code and build a laser panel..sh ould you have a laser. Smiley )
  
   Here attached is a photo of an arduino leonardo. I use a Arduino Yun, which is basically a leonardo, but with
   a unix system attached running at 400mhz with wireless. I use that part only to allow me to program it wirelessl y,
   you can use a normal leonardo if you dont mind having to plug in to usb to reprogram it. I like the fact I can just
   boot up a compiler and send updates to mine but if your not a programme r, than just usb is enough to program it from
   my files.
  
     A leonardo is about 20 bucks each. The total laser panel as I built mine, comprises
    
     1) Leonardo  : $21.00        (Yun: $79.00)
     2) 6 buttons : $2.00 total
     3) 1 led ring button for fire:  $2.00
     4) about 6 1k resistors          $1.00  ( 10k or even 100k resistors should work fine.)
     5) 4x20 LCD display              $6.00
     6) 5k pot for laser power control
     7) A box to put it in..
    
     I built my box from scrap wood, and used plexi on the front as a faceplate . So the whole things is worth about $30.00
     or so without wiress and around a hundred with. ( Although chinese Yun's on ebay are abotu 13.00 each.. dont know
     how they work..
    
       A leonardo is a 16mhz processor . Its pins are analogue, digital and in/out on pretty much all of them. You tell it
       the pins function as you program it. Some are limited to digital, others have PWM others are both, and some have interrupt
       capabilit y.
      
    As I stated, this is my first Arduino project, so Im hopefull people will come along and help me make it better, over
    time perhaps Ill learn more arduino programmi ng, but if a beginner can do it, so can you.
    
    Basic Theory of the device:
    
       OK, so I'm using a synrad laser. This laser is RF based and needs no water cooling or high voltage which is why Im
    using it. With modificat ions though this project will run a chineese laser or any laser. This laser , like most rf/co2 lasers
    needs a "tickle" pulse every 200us. You can damage the laser if you dont use this AND it has to be fairly accurate
    as if the pulse exceeds 3us, the laser will lase. It wants a 1us width. From 3us to 199us will give a power range of 0-100%
    of power output for that 200us period. High end Laser engravers like the epilog brand use these lasers using two main variables,
    they set power and frequency . SO you tell it for example to do 50%power at 4Khz. To understan d this imagine you set 25% power
    at 2500hz, this means the laser should be given a 50us pulse every 400us. ( 1/4 power = 50us. and skipping the next 200us
    period gives you 2.5khz output. ). Its powerfull to combine these two variables . Instead of burning and charing plywood
    when you cut it, having the ability to use a set power at a lower frequency allows the spot to cool before being hit again
    thus reducing charing of material.
    
       Since all that was fairly new to me, I decided this panel I was building had to have a diagnosti cs mode where I could
    dial up a pulse count, power level, and set a frequency , and then, by pressing a flashing button I could shoot that
    exact amount of energy at that frequency to measure accuratel y laser's affects on various materials . This is all much
    too complex to do from a printer port accuratel y...so enter the arduino. Never having used one before, I had heard it should
    have enough power to do what I needed done. BUT , I really dont want to redo my breakout board on my robotic arm, so it
    was decided to build an arduino that simply hooked to 3 spots on the cnc's breakout baord. From those pins we'd make
    sure the tickle was accurate, and photos could be engraved as well as vectors..
    
   <End of Part 1>


* Leonardo.jpg (11.13 KB, 252x200 - viewed 675 times.)
« Last Edit: October 01, 2014, 10:15:38 AM by ArtF » Logged
tweakie
Full Member
***
Posts: 182


Super Kitty


View Profile WWW
« Reply #2 on: September 06, 2014, 07:35:08 AM »

Hi Art,

Excellent work.
Have a tremendou s nice time on your holiday, please make a few notes whilst away so we can have Part II ... upon your return.  Grin  Grin

Tweakie.
Logged
ArtF
Administrator
Hero Member
*****
Posts: 5634



View Profile
« Reply #3 on: September 06, 2014, 10:47:41 AM »

Hi Tweak:

  I dont leave till later in the month.. so Ill be adding as much as I can till then. Smiley

Art
Logged
Mooselake
Hero Member
*****
Posts: 633



View Profile
« Reply #4 on: September 06, 2014, 12:19:17 PM »

You're awfully busy for a retired guy Smiley

Maybe in your spare time you could figure out how to use Tweakie's jet engine to build a really high power laser.

Kirk
Logged
SkyMoBot
Jr. Member
**
Posts: 83


View Profile
« Reply #5 on: September 06, 2014, 03:02:04 PM »

Am following this thread with a great deal of interest as I have a Epilog Summit laser engraver with a burnt out control board.  It uses the same Synrad laser tube that you all have.   I converted it over to use Gecko's and Mach3 for the motion control.   I have a modified version of Tweakie's control panel and I was just about to convert over to his version that uses the parallel port breakout board.

I tried getting an Arduino to output the tickle pulse and could never get the pulse down to under 4 msec,  I do a lot of laser cutting and being able to change the pulse width and speed on the fly would be very very handy.

Since you are doing low level parallel port stuff, why not have Darwin output the tickle pulse?

Regardles s, whatever you get working, I'm bound to try and replicate .   I have a full time regular job and 4 kids so my free time is somewhat limited so I have to let you all do my experimen tation.
Logged
ArtF
Administrator
Hero Member
*****
Posts: 5634



View Profile
« Reply #6 on: September 06, 2014, 03:37:19 PM »

Hi:

  Darwin is incapable of timing to the requireme nts of the laser. The Arduino though finds it trivial. It tickles with exactly 1us every 200us religious ly, and each pulse is adjustabl e form 1 to 199us in 5000 discrete steps. Darwin uses only 100 steps of about 50 in that range. Darwin , as was mach3, was also limited in that it couldnt do pwm at 5khz, but had to use much lower.

  So this panel has 3 modes, diags mode where you manually shoot what you wish.. CNC mode where it accepts pwm and fires on each step, and NGrave where speed is also taken into account to stop charing or burning in corners, all things Darwin on its own cannot do.

  Now Im sure in the future Smoothste ppers and the like WILL do all that, but till then I needed it from a printer port,so the arduino was the obvious choice for tight control pulse to pulse..

Thx
Art
Logged
ArtF
Administrator
Hero Member
*****
Posts: 5634



View Profile
« Reply #7 on: September 06, 2014, 07:05:08 PM »

Hi Guys:

  Here is a video on how the panel operates.

 https://www.youtube.com/watch?v=o6MbP672xzY


Art
Logged
ArtF
Administrator
Hero Member
*****
Posts: 5634



View Profile
« Reply #8 on: September 07, 2014, 05:42:28 PM »

What the arduino does internall y::

Well, as the video in the last post shows the panel itself,before building one we just need
to know what its doing internall y. Let me point out that the point here is to make a device that can take
power and fire commands from mach4 with a time dependenc y that allows a laser or impactor or whatever
to do its job. There's a lot of microproc essors available to do that kind of thing, TI's launchpad,
Arduino's, beagleboa rds..etc, and I woudlnt rule out building another panel with another micro at
some point. Hopefully by that point more a few of us will be getting commands from Darwin.

  The software in the arduino isnt very complex, as my first arduino experimen t you can imagine that
it wont be up to a knowledga ble arduino programme rs level. One of my hopes here is we attract such
people or we learn together how to do this better. Also worth noting is that while it was important
to me to have a diagnosti cs panel at the machine for testing and calibrati ng future engraving s to the
material at hand, you may not want a diagnosti cs mode at all, and if so, just a simple arduino with
no box, buttons or LCD display would work fine, the program would simply require a bit of recoding
and you could hot glue the arduino into your cnc control box to permanent ly control your laser power
with no interacti on. Point is.. there's lots of room for altering what we're doing here.

So.. that having been said, whatever controlle r we use,  (a leonardo in this case) has the
primary job of supplying PWM to the laser. Synrads require ( as do many others) a 5khz base
tickle frequency at 1us. The leonardo has a complex timer chip in it with envelope outputs, this allows
us to program that chip to do 5khz pwn with 1us pulses as tickles.
 
   To make any specific pulse longer than 1us ( up to the full 200us of the 5khz period..)
you simple change a register.  In our case thats OCR1A , a register that sets the duty
cycle of the pwm. this is all really hardware so its very accurate and controlla ble. 

So we then need to change it on the fly. SO I turned on an interrupt that the timer can generate
 at the beginning of every period. In that interrupt call, we calculate based on current condition s
 what length (duty cycle) this upcoming pulse should be. If we leave it at 1us, the laser will
 not fire, but from 3.5us to 199us the laser will fire fully for that time frame. This then is what
 we consider varying power, in reality the power is always at 100% but at varying lengths of time.
 
 As the video shows,I didnt want the laser to fire all the time. SO a second interrupt is hooked up
 to the StepFlag output of Darwin which gives a pulse whenever a step pulse is put out to any motor.
 We have then, two interrupt s going on so far, a timer interrupt that triggers at the start of each pwm
 pulse, and a Step interrupt that happens whenever a step is taken. Now the diag mode has a fire button
 which when pressed fires off a set number of pulses depending on what one selects for count.
 So in NGrave mode, the interrupt on the step flag reloads the pulse count( usually set at one) and
 internall y presses the button. This makes it fire one pulse. As the CNC unit moves, each pulse
 resets the counter to its setpoint and tells it to fire. The laser fires once and does nothing until the
 next step pulse. Youd set higher pulse count numbers to cut materials and can use frequency and pulse count
settings on the panel to control charring or overburn in various materials .
 
   So that leaves us with just needing a way to get the power of each shot. For that Darwin now has a clock
 and a data output. When Darwin sees your in Laser mode, it will constantl y send a stream of power
 data, if the spindle is off it sends zero's.. if spindle is on it sends the last SWord.. ( 0-100%),
 and if a photo is linked to Darwin, it sends the grey scale of the photo point in the spot
 the axis is at currently ..otherwi se zero. The Data clock runs at full kernal speed, so 30khz on my system,
 so to be sure the arduino doesnt miss it, it uses another interrupt . This means we have 3 interrupt s
 running constantl y in the arduino to sync output to whatever Darwin is doing. This leaves most of the
complexit y on the PC side in Darwin. If not doing a photo, Darwin calculate s a TOF(Time of flight)
for your vector line, calculati ng a power level for each set of steps to maintain a level amount of power
throughou t your motions.
 
  So thats it really, not very complex, and from a programmi ng standpoin t not very hard to implement
  so far. Ive cut many photo's and each is an interesti ng lesson in power vs speed vs output. Smiley
 
  Ill post the arduino code here later this week, Im happy to help as well if anyone has questions
  about how this all works, or has ideas for other ways to make it all work better.
 
 
  Art
Logged
SkyMoBot
Jr. Member
**
Posts: 83


View Profile
« Reply #9 on: September 07, 2014, 11:15:42 PM »

That makes a lot more sense to me now.    I never did more than a set of digitalOn/DigitalOff and sleep for a few us to get the pulse.  I never fooled around with the OCR1A register.

How about posting a snippet of code that does just the tickle so I can try it for myself while I wait for the rest of it?
Logged
ArtF
Administrator
Hero Member
*****
Posts: 5634



View Profile
« Reply #10 on: September 08, 2014, 06:35:34 AM »

Hi Sky:

  TO do that Im using a PWM library for the leonardo. .but.. it was set to do only phase correct
PWM, in that mode if you change duty on the fly it creates a double pulse... so I modified the
library by changing the control bit to be FastPWM.. So if you use the library the following code
will allow one to control the PWM duty cycle on a pulse by pulse basis.

(I include the PWM library as the one I modified). Ive modified a coupdl fo the system files for
this project.. so just be aware when I post a library it may or may not match with the Arduino libraries
as released.  


#define PulsePin 9

setup()
{
   bool timeron = SetPinFre quency( PulsePin, 5000 ); //set pulsepin to 5Khz, modified for fast pwm mode
 //this turns on the timer interrupt so that duty cycle can be set pulse by pulse..
  TIMSK1 |= (1 << TOIE1);  // enable timer overflow interrupt, we'll use this one for firing the laser if a fire is called for.
  //this is the slow way of setting the pwm duty cycle..
  pwmWrite( PulsePin, 16); //set for 1us for laser tickle , never go below this and tickle will be all good.
}

//this is a decalarat ion of an interrupt to be called at the start of every PWM period..

ISR(TIMER1_OV F_vect)
{
  //I keep track of the PWM periods as a way of coordinat ing power in other code
  cnt++;
  Duty = FireLaser();   //find the next power level..    
  OCR1A = Duty;       //this is the fast way fo changing the upcoming duty cycle period.     
}


* PWMlib.zip (15.93 KB - downloaded 277 times.)
« Last Edit: September 08, 2014, 09:00:44 AM by ArtF » Logged
ArtF
Administrator
Hero Member
*****
Posts: 5634



View Profile
« Reply #11 on: September 08, 2014, 08:31:27 PM »

Hi All:

  I dont normally draw schematic s, so forgive the poor quality. Here is the wiring of the laser
panel, as you can see its pretty simple, just a few buttons, an led and a few wires. Not shown is the
5vdc and 0vdc wires connected to a breakout baord or external 5vdc power supply. You also need to hook
the negative of the 5vdc t0 the ground of the breakout board..

(Schematic Modified Oct 1/2014)

Art


* LaserPanel4.png (15.78 KB, 1495x1060 - viewed 1227 times.)
« Last Edit: October 01, 2014, 02:37:00 PM by ArtF » Logged
Richard Cullin
Full Member
***
Posts: 152


View Profile
« Reply #12 on: September 08, 2014, 10:47:40 PM »

do you think it might be "safer" to put 47k pull down resistors on your analog button reading pins ?   . I'm assuming you have weak pullpowns turned on but a noise spike on the fire button could be nasty.
Logged
ArtF
Administrator
Hero Member
*****
Posts: 5634



View Profile
« Reply #13 on: September 09, 2014, 06:47:03 AM »

Hi Richard:

  Noise spikes typically have very little current capabilit y behind them, but with 1k to ground as worst case
button press we get about 5 ma in normal operation, the pin will only source about 50 ma I think.. so even if the voltage
on a noise spike got to 50 volts, you'd still be at max about 50ma and even then for so small a period that actual power
dissipati on would be too small to care about. Induction of enough power to hurt the arduino would be near impossibl e
on the button lines, so 1k is likely more than enough. Feel free though to use pretty much any resistanc e you like as
its truly not critical in this type of circuit. Its more about the ratio than the actual values.. I would worry about too high
a value making the circuit a bit more susceptib le to noise.
 (All just my opinion of course, I make no pretence at an engineeri ng degree. :-) ). All that having been said, those are
the reason I picked those values, and since you ( or anyone) may know better than I, please use any values you might
calculate and let us know. Id worry on 47K though ( if used on all pins ) that youd then max out at around 200K for one of the
button presses and with that low a current flow noise could give wrong indicatio ns. ( 4.7K perhaps though)

    The reason I state ratio's are more important than values is simply the code gets easier if all values are the same.
Button code such as this:

int16_t val = analogRea d(Buttons); //read the jog buttons.
thisbut = (val >> Cool;

  So too high a value could in theory make the buttons a bit less responsiv e or error prone, and with a fire button as one
of the buttons in the loop I figured Id keep it as reliably set as I could in terms of returned analogue count.     
 

Art
Logged
ArtF
Administrator
Hero Member
*****
Posts: 5634



View Profile
« Reply #14 on: September 09, 2014, 07:19:47 AM »

Hi All:

   Here is the code for the Arduino Im currently using. With it comes a few pointers about why it is what it is. ( Again, please keep
in mind this is my first arduino project, so its messy , poorly written but works fine so far, hopefully together we can make it better
and more fireproof . Its the result of several recodes as I discovere d limitatio ns in the arduino's capabilit ies.

So lets discuss whats here.

  Firstly, its just a few routines, BUT I did a change to the systems Winterrup ts.c file that you will have to duplicate
for this to compile. Find the WInterrup ts.c file and comment out the following lines

//ISR(INT0_vect) {
//   if(intFunc[EXTERNAL_INT_0])
//      intFunc[EXTERNAL_INT_0]();
//}

//ISR(INT1_vect) {
//   if(intFunc[EXTERNAL_INT_1])
//      intFunc[EXTERNAL_INT_1]();
//}
//ISR(INT6_vect) {
//    if(intFunc[EXTERNAL_INT_4])
//      intFunc[EXTERNAL_INT_4]();
//}

     This was necessary because I found the interrupt time with AttachInt errupt(..) was too slow. The library was attemptin g
to figure out too much and wasted over 25us as a result, by recoding to direct calls and giving Attach() a dummy process in
its call while providing the actual interrupt routine I was able to get much better responce at higher speeds. So the interrupt
calls may look a bit weird to you.

attachInt errupt( 0, DUMMY, RISING ); //pulse external monitor

 The above sets up the interrupt but the routine DUMMY isnt used, the routine
is directly set by the use of  ISR(INT0_vect)  further down in the code.

 the program uses three interrupt s, though really only 2 at once. The Int6 routine is used only for PWM
sensing and gives me a number of 0-100 as a current PWM setting at 50hz. It does this by
counting the 5Khz laser base and reporting how many "ticks" of that occur between PWM rise and fall
(thus at 50hz PWM you get a values of 0-100 which is a good slick way of getting pwm in this case. )

 PWM though is used only in CNC mode which is the worst mode. In NGrave mode we user a power value
sent via serial by interrupt #1, this is a raw serial clock/data pulsing at kernal frequency . I use very noisy
servo's so to eliminate as much error as I could, I frame the power level in between hex f's, so the power is
sent as 0xfppf where pp is 8 bits of power. In addition the 8 power bits must be less than 100 else
the system will reject it as noise. As further noise reduction the same value is always sent twice and must
match, or its rejected as well.

   This is not a great serial routine, we could probably do much better but I came up with it in frustrati on
at the level of noise I was getting from my servos.  ( I shouldn't have put them in  my breakout board
cabinet as they have their own AC/DC conversio n which makes them very noisy.

  SO the power once received is used as the next duty cycle to be used when a "stepflag" is seen, this is
on Interrupt 0.

if( (OpMode != DIAGS && SpindleOn))
   {
      FireCount = ReLoad;
      FIRE = true;
   }
 
  Its code simple fires the laser if we're in NGrave or CNC mode and the spindle
is known to be running.

  SO just keep in mind the code is pretty badly coded as a result of many many attempts
with various theories, text comments may be totally wrong from cut and pastes
during its developme nt, but that as it stands it does engraving very well and with high
repetitio n rates. Changes to make it better as we have more testers will be great so
once anyone has a unit working, please let us know what changes you do and what their effect
is. I'm very willing to revise Darwin to comply with what any users feel would work better.
   I suspect changes in theory that makes for good engraving will evolve to other hardware
like the smoothste pper in future, so ideas here are good for everyone. 


Have fun
Art




* LaserControlCode.zip (5.1 KB - downloaded 374 times.)
Logged
Pages: [1] 2 3 ... 14
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!