Arduino based Laser Control

A forum for the Arduino based Mach4/Darwin Laser Control Panel
BobL
Global Moderator
Global Moderator
Posts: 467
Joined: Sun Sep 05, 2010 7:18 am

Re: Arduino based Laser Control

Post by BobL »

Hi Dan;

I do not have any of that information here in front of me, all of it is at Art's place. Hope you don't mind waiting until he gets back to get the answer, which should be towards the weekend sometimes? Sorry..

Cheers
Bob
>:(
Gearotic Motion
Bob
Ya-Nvr-No
Old Timer
Posts: 188
Joined: Wed Sep 08, 2010 11:15 am

Re: Arduino based Laser Control

Post by Ya-Nvr-No »


Got this from line 50
//initialize the lcd..its on a0-a6 lines in my leonardo..

this is what worked for me.
Not pretty as I can not seem to write well with a mouse. ;D

I added the pot to control the contrast
Attachments
lcd-wiring.JPG
DanL
Old Timer
Posts: 362
Joined: Wed Sep 10, 2014 1:35 pm

Re: Arduino based Laser Control

Post by DanL »

char bro I don't mind waiting at all it will be a few weeks before all the parts show up
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4643
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Arduino based Laser Control

Post by ArtF »

Thx Guys:

  Yes, those seem correct as numbers. ( Preciate it ). The call to LCDInit shows the numbers
I used and what controls them. The line in the code for
LiquidCrystal  lcd( 23,22,21,20,19,18); 

shows the init of the lcd and its settings as to pin. So looking at the call above... the pins in order are

RS pin -- 23
Enable -- 22
D4 - D7 pins 21,20,19,18

  These pin numbers correspond to A5 - A0 on the Leonardo..I suspect the pin numbering differs because
the library wasnt originally written for a leonardo so at the time I traced them by schematic as I recall..
If anyone has trouble with that usage let me know and Ill tear mine down to double check it, but I think
YaNvrNo has it right..

Art

User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4643
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Arduino based Laser Control

Post by ArtF »

Hi All:

  Schematic has been corrected as to pushbutton wiring ... the post at

http://gearotic.com/ESW/FavIcons/http:/ ... 7232#p7232

has been updated to show the fixes.

Thx
Art
DanL
Old Timer
Posts: 362
Joined: Wed Sep 10, 2014 1:35 pm

Re: Arduino based Laser Control

Post by DanL »

morning all I need some advice about what to use for a drive for a laser I will be using this is it

http://www.ebay.com/itm/2W-445nm-M140-B ... 2a2158fe9d

its a 2w 445nm Diode laser I will be running it at 2A 4.7vdc. what I need is advice on what to drive it with there is lot of info on driving a laser with a LT1121.

I Have a Schematic for it see attachment I know it is only for up to 1.5A I can get a bigger chip 2A+ for it is this schematic good enough to run with your controller art.

also I have striped back the sketch so it only has the Laser control stuff on it can someone have a look and see if I got it correct as I don't have all the parts yet so cant test it.I have disabled the LCD part as I am porting it over to run on a TI board

Code: Select all

#include <Wire.h>
#include <LiquidCrystal.h>
#include <PWM.h>

//Setup for Diags..
#define DIAGS&nbsp;  0
#define CNCMODE 1
#define NGRAVE&nbsp; 2

//frequency and pins used.
int32_t basefrequency = 5000; //5khz base freq
int8_t&nbsp; PulsePin = 9;&nbsp; &nbsp; &nbsp; &nbsp;  //Pin 9 will control the laser. 
int8_t&nbsp; BoardLED = 13;
int8_t&nbsp; FireLED&nbsp; = 12;
int8_t&nbsp; PowerLED&nbsp; = 5;
int8_t&nbsp; Pot&nbsp; = 4;
int8_t&nbsp; Buttons&nbsp; = 8;&nbsp; &nbsp; &nbsp; &nbsp; //analogue and digital are same numbers..be carefull if you use other pins..
int8_t&nbsp; Buttons1 = 10;
int8_t&nbsp; CurButton = 0;&nbsp; &nbsp; &nbsp;  //currently pressed button
int8_t&nbsp; CountMode = 0;&nbsp; &nbsp; &nbsp;  //the mode of the up/down counter..
bool&nbsp; &nbsp; WaitButtonZero = false;
int8_t&nbsp; OneMicro = 16;
int8_t&nbsp; OpMode = 0;
volatile unsigned short SerialIn = 0;
volatile unsigned short LastSerial = 0;
//volatile unsigned long SpinOnCnt = 0;
//volatile unsigned long SpinOffCnt = 0;
//volatile bool SpindleOn = false; //remote spindle command..
//volatile bool SpindlePWM = false; //remote spindle command current state..

//vars for control
bool&nbsp; &nbsp; &nbsp; PowerOn = false;
bool&nbsp; &nbsp; &nbsp; Tickle = false; // On Off Safety watchdog .. monitor the tickle for laser health
volatile int16_t Duty = OneMicro; //this is the pulse to pulse firepower during a shot.
volatile int32_t cnt = 0;&nbsp; //this is a global interrupt counter..
volatile bool FIRE = false;

//initialize the lcd..its on a0-a6 lines in my leonardo..
//LiquidCrystal&nbsp; lcd( 23,22,21,20,19,18);&nbsp; // set the LCD address to 0x27 for a 20 chars and 4 line display

// the main control variable for diags mode..
int16_t&nbsp;  Power =&nbsp; 50; //0 - 100%
unsigned long&nbsp; PWMPower = 0;//0- 100% for the incoming PWM..
int16_t&nbsp;  Freq = 5000; // frequency of pulses..
int8_t&nbsp; &nbsp; PotMode = 0;

volatile int32_t&nbsp;  FireCount = 0;&nbsp;  //number of pulses to fire in diags 
volatile int16_t&nbsp;  ReLoad = 1;

void setup()&nbsp;  
{

 // lcd.begin(20,4); // initialize the lcd 
 // lcd.setCursor(3,0);&nbsp;  
 // lcd.print("Gearotic Laser");
 // lcd.setCursor(0,2);&nbsp;  
 // lcd.print("Waiting for Unix.");

&nbsp; InitTimers();&nbsp; &nbsp; //start up the timers.
&nbsp; bool timeron = SetPinFrequency( PulsePin, basefrequency ); //set pulsepin to 5Khz
&nbsp; TIMSK1 |= (1 << TOIE1);&nbsp; // enable timer overflow interrupt, we'll use this one for fastpwm

&nbsp; attachInterrupt( 0, DUMMY, RISING ); //pulse external monitor 
&nbsp; attachInterrupt( 4, DUMMY, CHANGE ); //sets the routine to call..&nbsp; &nbsp; 

&nbsp; pwmWrite( PulsePin, 8); //set for 1us for laser tickle 
&nbsp; if( timeron ) //if the timercall worked..
&nbsp; {
&nbsp; &nbsp; pinMode( BoardLED, INPUT); // board led life
&nbsp; &nbsp; pinMode( FireLED,&nbsp; OUTPUT); // fire button led
&nbsp; &nbsp; pinMode( PowerLED, OUTPUT); //power control led & control

&nbsp; &nbsp; pinMode( 2,&nbsp;  INPUT); //inputs from breakout board
&nbsp; &nbsp; digitalWrite( 2, LOW );

&nbsp; &nbsp; pinMode( 3,&nbsp;  INPUT); //inputs from breakout board
&nbsp; &nbsp; digitalWrite( 3, LOW );

&nbsp; &nbsp; pinMode( 11,&nbsp; &nbsp; INPUT); //inputs from breakout board
&nbsp; &nbsp; digitalWrite( 11, HIGH );
&nbsp; &nbsp; digitalWrite( PowerLED, PowerOn); //turn off led for power at start
&nbsp; &nbsp; pinMode( Pot, INPUT); //pot for variable control
&nbsp; &nbsp; digitalWrite(4, HIGH); //set for a pullup resistor
&nbsp; &nbsp; pinMode( Buttons, INPUT); //Jog buttons as analogue input
&nbsp; &nbsp; digitalWrite(Buttons, HIGH); 
&nbsp; &nbsp; pinMode( Buttons1, INPUT); //Rest of buttons
&nbsp; &nbsp; digitalWrite(Buttons1, HIGH); 

&nbsp; } 
&nbsp; //SetDisplay( true ); //and draw the display mask
}

//main idle loop..

void loop() 
{
&nbsp; HeartBeat(); //flash the board led if fire isnt flashing..
&nbsp; FlashFire(); // flash the fire button if we are going to fire..
&nbsp; WatchDog();&nbsp; // ensure all is safe.
&nbsp; DiagsOut();&nbsp; //display test text if demanded..not used
&nbsp; PotControl(); //use the pot for values..
&nbsp; GetButton();&nbsp;  
&nbsp; 
&nbsp; if( OpMode == DIAGS )&nbsp; DiagFire();
&nbsp; //if( OpMode == NGRAVE)&nbsp; NGraveFire();
&nbsp; LaserOnOff();
&nbsp; DoButtonCount();&nbsp; // make freq or firecount set by button if needed.
&nbsp; //set power and other vars, then display..
&nbsp; //SetDisplay( false );
}

void DoButtonCount()
{
&nbsp; int8_t&nbsp;  Accel = 1; //this is the accel of button freq, adjust as needed.
&nbsp; static&nbsp;  int16_t&nbsp; Adder = Accel;
&nbsp; int16_t&nbsp; Freqmax&nbsp; = 200;
&nbsp; static&nbsp;  int32_t&nbsp; Bres = Freqmax;&nbsp; 
&nbsp; if( CurButton == 0)
&nbsp; {
&nbsp; &nbsp; Adder = Accel;
&nbsp; &nbsp; Bres = Freqmax; 
&nbsp; &nbsp; return;
&nbsp; }
&nbsp; int16_t oldfire = FireCount;
&nbsp; Bres += Adder;
&nbsp; while( Bres > Freqmax ) //not very ellegant, fix later. just a timer for easier button press
&nbsp; {
&nbsp; &nbsp; if( CurButton == 4 ) //left arrow, switch pot to count mode..
&nbsp; &nbsp; &nbsp; CountMode--;
&nbsp; &nbsp; if( CurButton == 6 ) //left arrow, switch pot to dutycyle..
&nbsp; &nbsp; &nbsp; CountMode++;
&nbsp; &nbsp; if( CountMode < 0) CountMode = 2; 
&nbsp; &nbsp; if( CountMode > 2) CountMode = 0;

&nbsp; &nbsp; Bres -= Freqmax;
&nbsp; &nbsp; if( CountMode == 0&nbsp; && CurButton == 5) Freq++;
&nbsp; &nbsp; if( CountMode == 2&nbsp; && CurButton == 5) FireCount++;
&nbsp; &nbsp; if( CountMode == 0&nbsp; && CurButton == 7) Freq--;
&nbsp; &nbsp; if( CountMode == 2&nbsp; && CurButton == 7) FireCount--;
&nbsp; &nbsp; if( FireCount < 0 ) FireCount = 5000;
&nbsp; &nbsp; if( FireCount >&nbsp; 5000 ) FireCount = 0;
&nbsp; &nbsp; if( Freq <= 0 ) Freq = 1;
&nbsp; &nbsp; if( Freq > 5000 ) Freq = 5000;
&nbsp; &nbsp; int oldop = OpMode;
&nbsp; &nbsp; if( CountMode == 1 && CurButton == 5 ) OpMode++;
&nbsp; &nbsp; if( CountMode == 1 && CurButton == 7 ) OpMode--;
&nbsp; &nbsp; if( OpMode > 2 ) OpMode = 0; //these two lines just make the opMode toggle up or down..
&nbsp; &nbsp; if( OpMode < 0 ) OpMode = 2;

&nbsp; &nbsp; //reopen file if required.
&nbsp; &nbsp; if( OpMode == NGRAVE && oldop != NGRAVE)
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; //detach the spindle interrupts.
&nbsp; &nbsp; &nbsp; detachInterrupt(4);
&nbsp; &nbsp; &nbsp; attachInterrupt( 1, DUMMY, RISING ); //reattach the spindle interrupt

&nbsp; &nbsp; }
&nbsp; &nbsp; if( OpMode != NGRAVE && oldop == NGRAVE )
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; attachInterrupt( 4, DUMMY, CHANGE ); //reattach the spindle interrupt
&nbsp; &nbsp; &nbsp; detachInterrupt(1);
&nbsp; &nbsp; }

&nbsp; }
&nbsp; if( oldfire != FireCount ) ReLoad = FireCount;
&nbsp; Adder += Accel;
&nbsp; //faster..damnit..faster. :)
&nbsp; if( Adder == 100 )&nbsp;  Adder *= 2;
&nbsp; if( Adder == 400)&nbsp; &nbsp; Adder *= 2;
&nbsp; if( Adder == 1000)&nbsp; Adder *= 2;
}

void DiagFire()
{
&nbsp; if( CurButton == 2 ) FireCount = ReLoad;
&nbsp; //FIRE!!!!
&nbsp; if( CurButton == 1 && FireCount > 0 ) FIRE = true;
&nbsp; if( CurButton == 0 && FIRE && OpMode == DIAGS ) FIRE = false; //turn it off if no button is pressed in Diags mode.
}

void LaserOnOff()
{
&nbsp; //this controls Laser ON/OFF
&nbsp; if( CurButton == 3 ) //power call , but only once per press
&nbsp; { 
&nbsp; &nbsp; if( !WaitButtonZero) PowerOn = !PowerOn; 
&nbsp; &nbsp; digitalWrite( PowerLED, PowerOn); //Set Power condition;
&nbsp; &nbsp; WaitButtonZero = true;
&nbsp; }

}

void DUMMY()
{

}

int16_t FireLaser()
{
&nbsp; int16_t ret = OneMicro; //usually we'll return 1 microsecond.
&nbsp; static int16_t Counter = basefrequency;
&nbsp; if( FIRE )
&nbsp; {&nbsp;  
&nbsp; &nbsp; if( OpMode == DIAGS )
&nbsp; &nbsp; &nbsp; ret = Power << 5; //we'll return this power only if the counter says so..
&nbsp; &nbsp; else 
&nbsp; &nbsp; &nbsp; ret =&nbsp; PWMPower << 5; //in CNC modes we return the duty cycle power

&nbsp; &nbsp; if( ret > 3191 ) ret = 3191; //set a maximum pulse wdith here for your cpu speed
&nbsp; &nbsp; //now decide on a frequcny basis is this is a shot time..
&nbsp; &nbsp; Counter += Freq;
&nbsp; &nbsp; if( Counter >= basefrequency )
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; Counter -= basefrequency;
&nbsp; &nbsp; &nbsp; //if( SpindleOn && FireCount > 2000 ) FireCount = 2000;
&nbsp; &nbsp; &nbsp; if( FireCount != 5000) FireCount--;
&nbsp; &nbsp; &nbsp; if( FireCount <= 0 ) FIRE = false;
&nbsp; &nbsp; }
&nbsp; &nbsp; else
&nbsp; &nbsp; &nbsp; ret = OneMicro;

&nbsp; }
&nbsp; if( ret < OneMicro ) ret = OneMicro; //no msaller than 1 microsecnd
&nbsp; return ret;
}

//display the text
/////&nbsp; Text Blockout

////////////////////////
//&nbsp; &nbsp; &nbsp; &nbsp; Pwr&nbsp; &nbsp; &nbsp; &nbsp;  //
//Frq-hz&nbsp; 100&nbsp; Pulses //
//&nbsp; 5000 <--->&nbsp; 5000&nbsp; //
////////////////////////
//void SetDisplay( bool clear )
//{
 // if( clear ) 
 // {
&nbsp; //&nbsp; lcd.clear(); //x,y
&nbsp; //&nbsp; lcd.setCursor(8, 0);&nbsp; &nbsp; 
&nbsp; //&nbsp; lcd.print("Pwr");
&nbsp; //&nbsp; lcd.setCursor(0, 1);&nbsp; &nbsp; 
&nbsp; //&nbsp; lcd.print("Frq-hz");
&nbsp; //&nbsp; lcd.setCursor(14,1);&nbsp; &nbsp; 
&nbsp; //&nbsp; lcd.print("Pulses");
 // }
 // static int8_t slw = 0;
 // slw++;
 // if( slw % 8 )
 //&nbsp;  if( SpindleOn && OpMode == CNCMODE ) //display of remote power setting..
&nbsp; //&nbsp; {
&nbsp;  //&nbsp;  lcd.setCursor(11, 0);&nbsp; &nbsp; 
&nbsp;  //&nbsp;  lcd.print("-Rem:");
&nbsp; &nbsp; //&nbsp; lcd.setCursor(16, 0);&nbsp; &nbsp; 
&nbsp;  //&nbsp;  lcd.print("&nbsp; &nbsp;  ");
&nbsp;  //&nbsp;  lcd.setCursor(16, 0);&nbsp; &nbsp; 
&nbsp; &nbsp; //&nbsp; lcd.print(PWMPower,10);
&nbsp;  // }
&nbsp; //&nbsp; else
&nbsp; //&nbsp; &nbsp; if( OpMode == NGRAVE )
&nbsp; //&nbsp; &nbsp; {
&nbsp;  //&nbsp; &nbsp;  lcd.setCursor(11, 0);&nbsp; &nbsp; 
&nbsp;  //&nbsp; &nbsp;  lcd.print("-Rem:");
&nbsp; &nbsp; //&nbsp; &nbsp; lcd.setCursor(16, 0);&nbsp; &nbsp; 
&nbsp; &nbsp; //&nbsp; &nbsp; lcd.print("&nbsp; &nbsp;  ");
&nbsp; &nbsp; //&nbsp; &nbsp; lcd.setCursor(16, 0);&nbsp; &nbsp; 
&nbsp;  //&nbsp; &nbsp;  lcd.print(LastSerial,10);
&nbsp;  //&nbsp;  }
&nbsp;  //&nbsp;  else
&nbsp;  //&nbsp;  {&nbsp;  
&nbsp;  //&nbsp; &nbsp;  lcd.setCursor(11, 0);&nbsp;  
&nbsp;  //&nbsp; &nbsp;  lcd.print("&nbsp; &nbsp; &nbsp; &nbsp; ");
&nbsp;  //&nbsp; &nbsp;  lcd.setCursor(16, 0);&nbsp;  
&nbsp;  //&nbsp; &nbsp;  lcd.print("&nbsp; &nbsp;  ");
&nbsp;  //&nbsp;  }

&nbsp; //power
 // lcd.setCursor(8,1);
 // lcd.print( Power , 10 );
 // lcd.print( "%&nbsp; " );
&nbsp; //frequency
 // lcd.setCursor(3,3);
 // lcd.print( Freq , 10 );&nbsp; &nbsp; &nbsp; 
 // lcd.print("&nbsp;  ");
&nbsp; //fire count
 // lcd.setCursor(15,3);

 // if( FireCount != 5000)
 // { 
 //&nbsp;  lcd.print( FireCount , 10 ); 
 //&nbsp;  lcd.print("&nbsp;  "); 
 // }
 // else
 //&nbsp;  lcd.print(" CW&nbsp;  ");

&nbsp; //and count mode
&nbsp; //lcd.setCursor(8,3);
 // switch( CountMode )
 // {
 //&nbsp;  case (0) : 
&nbsp; //&nbsp; lcd.print("<<---"); 
 //&nbsp;  break;
 //&nbsp;  case (1) : 
 //&nbsp;  lcd.print(" ^^^ "); 
 //&nbsp;  break;
 //&nbsp;  case (2) : 
&nbsp; //&nbsp; lcd.print("--->>"); 
&nbsp; //&nbsp; break;
 // }

&nbsp; //static int toggle = 0;
 // static bool twinkle = true;
 // toggle++;
 // if( toggle > 20 )
 // {
 //&nbsp;  toggle = 0;
&nbsp; //&nbsp; twinkle = !twinkle;
&nbsp; //&nbsp; lcd.setCursor( 0,4 ); 
 //&nbsp;  if( twinkle ) lcd.print("*"); 
&nbsp; //&nbsp; else lcd.print("#");
 // }

&nbsp; //erase the mopde line..
 // lcd.setCursor( 0,2 );
 // lcd.print("&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ");

//&nbsp; if( SpindleOn && OpMode == DIAGS)
&nbsp; //&nbsp; OpMode = CNCMODE; //auto switch from Diags

 // switch (OpMode)
 // {
 //&nbsp;  case(0): 
 //&nbsp;  lcd.setCursor( 8,2 );&nbsp; 
 //&nbsp;  lcd.print("Diag"); 
 //&nbsp;  break;
&nbsp; //&nbsp; case(1): 
 //&nbsp;  lcd.setCursor( 7,2 ); 
&nbsp; //&nbsp; lcd.print("CNC-CW"); 
&nbsp; //&nbsp; break;
&nbsp; //&nbsp; case(2): 
&nbsp; //&nbsp; lcd.setCursor( 7,2 ); 
&nbsp; //&nbsp; lcd.print("NGRAVE"); 
&nbsp; //&nbsp; break;
&nbsp; //}
//}

//helper functions

void FlashFire() 
{
&nbsp; static int8_t Flashtime = 0;
&nbsp; static bool&nbsp;  fireledstate;
&nbsp; if( FireCount == 0 ) 
&nbsp; &nbsp; fireledstate = false;
&nbsp; if( Flashtime++ > 10 ) //this 10 should be change for a pleasant flash tempo..
&nbsp; {
&nbsp; &nbsp; digitalWrite( FireLED, fireledstate ); 
&nbsp; &nbsp; fireledstate = !fireledstate;
&nbsp; &nbsp; Flashtime = 0;
&nbsp; }
}

//flash the board led to show we're alive
void HeartBeat() 
{
&nbsp; static int8_t Beat = 0;
&nbsp; static bool&nbsp;  beatstate;
&nbsp; if( FireCount != 0 ) return; 

&nbsp; if( Beat++ > 10 ) //this 10 should be change for a pleasant flash tempo..
&nbsp; {
&nbsp; &nbsp; //digitalWrite( BoardLED, beatstate ); 
&nbsp; &nbsp; beatstate = !beatstate;
&nbsp; &nbsp; Beat&nbsp; = 0;
&nbsp; }
}

//watchdog function, kill laser power if tickle stops..
//or other checks all of which can be put here..
void WatchDog()
{
&nbsp; static int lastcnt = cnt; //activity monitor
&nbsp; if( lastcnt != cnt ) Tickle = true; 
&nbsp; else&nbsp; Tickle = false;
&nbsp; lastcnt = cnt;

&nbsp; //set other checks here... too long a shot maybe...

&nbsp; if( !Tickle )
&nbsp; {
&nbsp; &nbsp; PowerOn = false;
&nbsp; &nbsp; digitalWrite( PowerLED, PowerOn); //turn off led for power at start
&nbsp; }
}
//use of the pot for duty or frequency.
void PotControl()
{
&nbsp; int32_t val = analogRead( Pot + 2 ); //the analogue for the pot pin
&nbsp; if( PotMode == 0 ) // duty cycle.. only mode at present..
&nbsp; {
&nbsp; &nbsp; Power =&nbsp; val / 10.23;
&nbsp; &nbsp; if( Power < 1 ) Power = 1;
&nbsp; &nbsp; if( Power > 100) Power = 100;
&nbsp; &nbsp; Power = 101 - Power;
&nbsp; }

}

//diags text for testing and debugging..
void DiagsOut()
{
&nbsp; //just for testing pins..
&nbsp; return; //only use if we demand it in setup..

&nbsp; int16_t&nbsp; d1 = 0, d2 = 0, d3 = 0;
&nbsp; if( cnt > 2000)
&nbsp; {
&nbsp; &nbsp; cnt = 0;
&nbsp; &nbsp; d1 = analogRead(Pot + 2);
&nbsp; &nbsp; d2 = analogRead(8);
&nbsp; &nbsp; d3 = analogRead(10);

&nbsp; &nbsp; //Console.print("pins 6,8,10 --- " );
&nbsp; &nbsp; //Console.print(" "); 
&nbsp;  // Console.print( d1 );
&nbsp; &nbsp; //Console.print(" "); 
&nbsp; &nbsp; //Console.print( d2 );
&nbsp; &nbsp; //Console.print(" "); 
&nbsp; &nbsp; //Console.print( d3 );
&nbsp; &nbsp; //Console.print(" "); 
&nbsp; &nbsp; //Console.print( CurButton );
&nbsp; &nbsp; //Console.println();

&nbsp; }
}
//figure out a button press, only one button 
//at any time with noise rejection. This uses 2 analogue pins
//which multiplexes many buttons on each pin.
void GetButton()
{
&nbsp; int8_t setbounce = 4; //set a debounce here..
&nbsp; static int8_t debounce = setbounce;
&nbsp; static int8_t LastButton = 0;
&nbsp; int8_t thisbut = 0;

&nbsp; int16_t val = analogRead(Buttons); //fire,reload and laser
&nbsp; if( val < 900 )
&nbsp; {

&nbsp; &nbsp; thisbut = 3 - (val >> 8);
&nbsp; }
&nbsp; val = analogRead(Buttons1); //ok, read the fire buttons then..
&nbsp; if( val < 900 )
&nbsp; {
&nbsp; &nbsp; //figure out the button in the fire group
&nbsp; &nbsp; thisbut = (val >> 8) + 4;
&nbsp; }

&nbsp; if( LastButton == thisbut ) debounce--;
&nbsp; else&nbsp;  debounce = setbounce;&nbsp; &nbsp; 
&nbsp; if( debounce == 0 )
&nbsp; {
&nbsp; &nbsp; CurButton = thisbut;
&nbsp; &nbsp; debounce = setbounce;
&nbsp; }

&nbsp; if( WaitButtonZero && CurButton == 0)
&nbsp; &nbsp; WaitButtonZero = false;

&nbsp; LastButton = thisbut;
}

//make the frerq and count registers count by button.

//this gets called at timer reset time..
ISR(TIMER1_OVF_vect)
{
&nbsp; cnt++;
&nbsp; Duty = FireLaser();&nbsp;  //find the next power level..&nbsp; &nbsp; 
&nbsp; OCR1A = Duty;&nbsp; &nbsp; &nbsp; &nbsp;  
}

//these three interrupts are for step/dir and spindle pwm. 
//used as direct vectors to get the speed required..
//this interrupt is for the step pulses..any step pulses, to 
//set a firepulse..

ISR(INT0_vect) 
{
&nbsp; //step interrupt...very fast
&nbsp; //if( (OpMode != DIAGS && SpindleOn)) 
&nbsp; {
&nbsp; &nbsp; FireCount = ReLoad;
&nbsp; &nbsp; FIRE = true;
&nbsp; }

}

//this is for recieving serial data power 
//for 16 slice sequences.
ISR(INT1_vect) 
{
&nbsp; //count the X steps as well for future use
&nbsp; if( PINB & ( 1 << 7))
&nbsp; &nbsp; SerialIn |= 0x8000;
&nbsp; if( (SerialIn & 0xf00f ) == 0xf00f)
&nbsp; {
&nbsp; &nbsp; // LastSerial = SerialIn & 0x0ff0;
&nbsp; &nbsp; LastSerial = (SerialIn >> 4) & 0xff;
&nbsp; &nbsp; SerialIn = 0;
&nbsp; &nbsp; if( LastSerial < 100 )
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; static unsigned short prev = 0;
&nbsp; &nbsp; &nbsp; if( prev == LastSerial )&nbsp; //must be a repeated power..
&nbsp; &nbsp; &nbsp; &nbsp; PWMPower = LastSerial;
&nbsp; &nbsp; &nbsp; prev = LastSerial;
&nbsp; &nbsp; }
&nbsp; &nbsp; 
&nbsp; SerialIn = SerialIn >>&nbsp; 1; //we got a clock, so shift it..
}

}
Attachments
LT1121.png
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4643
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Arduino based Laser Control

Post by ArtF »

Hi DanL:

&nbsp; Wow, nice diode. Being blue it could also harden oxalic acid infused fibreglass resin ... nice thing to play with..


&nbsp; Schematic looks like it could be used, take not of just how important cooling is with such devices, I have a few lower
power ones that I run for small periods at times and cooling is really very very important as you get up to 2 watts. A blue 2 watt is quite powerfull really, be interesting to see how you make out..

Id change the line in the code at
pwmWrite( PulsePin, 8); //set for 1us for laser tickle
&nbsp; to 0, as you dont want 1us tickles, you want 0us as a tickle and only want the
PWM to be on when the laser is. Set the variable OneMicro to 0 as well, it defines the PWM timer's
one microsecond setting. That will then make the laser only fire when given a power from Dariwn greater
than 0%. Probably take some fudging about in the rest of the code but those two changes should
make it run as youd expect, making the PWM really into a TTL trigger in PWM form..

&nbsp; Ill be interested in how you make out, feel free to ask questions if you run into trouble
as you test. Hard to say without testing what trouble youll run into , youll probably want
to use some sort of console messaging for feedback to tell you whats up during testing...

Art



Richard Cullin
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

Re: Arduino based Laser Control

Post by Richard Cullin »

the datasheet for a LT1121 indicates ~&nbsp; max output current is&nbsp; 150 mA&nbsp; &nbsp; (0.15 amps) that won't even warm up a 2w laser .
Richard Cullin
Old Timer
Posts: 152
Joined: Sat Jun 02, 2012 5:45 am

Re: Arduino based Laser Control

Post by Richard Cullin »

User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4643
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Arduino based Laser Control

Post by ArtF »

Good point...&nbsp; 150ma wont cut it..

Art
DanL
Old Timer
Posts: 362
Joined: Wed Sep 10, 2014 1:35 pm

Re: Arduino based Laser Control

Post by DanL »

I will bring the console back in, its like that as arduino ide went mental yesterday I had to delete all the copy's and temp files to do with this, that's the copy I am using for porting over to Ti`s ide I am striping it back in the arduino ide so when I know its working properly with arduino I will move it over and change it to work with TI`s MSP430 boards then do it again to there C2000 boards.

Ill will be making a head for the laser to go into so I can run air through it so it keeps the smoke away from the lens and cools it at the same time, it will be a pieces of bronze what I will cut fins into it and fit it into a aluminium block what I more than likely will add a fan onto it as-well. or run water though it or forced air.

the forced air idea comes from a diy mister I made for my big router, when I run water though it the temp of the housing drop by quite a bit &nbsp;

I have a big computer coiling fan and block what I will be using to keep the driver cool.

quite a few of the parts I will be using are recycled from computers and a machinists junk box I was given what had quite a few good bits of metals in it.
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4643
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Arduino based Laser Control

Post by ArtF »

DanL
Old Timer
Posts: 362
Joined: Wed Sep 10, 2014 1:35 pm

Re: Arduino based Laser Control

Post by DanL »

I know its not enough to run a 2W laser that's why I said I can get a 2W+ driver its just checking the circuit is correct to use with this project. or I might use a LT1764A - 3A, Fast Transient Response, Low Noise, LDO Regulators or the Ti equivalent.

or just buy something that will work
User avatar
tweakie
Old Timer
Posts: 183
Joined: Wed Dec 01, 2010 12:58 am

Re: Arduino based Laser Control

Post by tweakie »

Hi Dan,

A group of us have been working with diode lasers for some time now and something you may wish to consider is fitting a Lasorb (or similar) across your laser diode terminals. When you consider the cost of replacing the diode these little devices are a pretty good insurance policy against the unexpected. http://www.lasorb.com

Tweakie.
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4643
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Arduino based Laser Control

Post by ArtF »

Tweakie:

&nbsp; Thx, I hadnt heard of those... happy to read up on that one..

Art
Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests