Project practice: DIY optical drive laser engraving machine - laser cutting machine
After a period of study of 51 single chip computer, I made a laser engraving machine and laser cutting machine by referring to the information of the previous generation and using the waste optical drive. Here is my production process. I want to share with you the successful new one. Thank you again for the information of the previous generation
1.First disassemble the old optical drive
2.Take out the stepper motor bracket
3.Fold the optical drive shell into this shape
4.Fix the screw rod and the stepping motor in this way, and the small iron bar is the position of the laser
5.This iron bar is to make it vertical
6.Start welding DuPont line
7.Basic forming
8.accomplish
Component list
Desktop optical drive x2
L298n motor drive module x2
51 Minimum system x1
Usb-ttl module x1
Uln2003 module x1
250mw laser module x1
Several conductors
Refer to C procedure
/*Z Address definition
50 1=x+,2=x-,3=y+,4=y-
51 High number of forward and backward steps
52 Low number of forward and backward steps
fifty-three
54/55 word width
fifty-six
57 Low light switch
58/59 Laser intensity
60 x axis speed
61 y-axis speed
62 Start printing 0,57
63 Suspension
64 Stop flag
sixty-five
66 Left and right marks
100 Grayscale data at the beginning
*/
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
#Define N z [60]//X speed
#Define M z [61]//Y speed
sbit a=P1^3;// Stepper motor wiring definition moving laser head
sbit a_= P1^2;
sbit b=P1^1;
sbit b_= P1^0;
sbit xa=P1^4;
sbit xa_= P1^5;
sbit xb=P1^6;
sbit xb_= P1^7;
/*sbit a=P1^4;// Stepper motor wiring definition moving base plate
sbit a_= P1^5;
sbit b=P1^6;
sbit b_= P1^7;
sbit xa=P1^3;
sbit xa_= P1^2;
sbit xb=P1^1;
sbit xb_= P1^0; */
sbit jg=P2^0;
sbit led=P2^1;// indicator light
uchar xdata z[500]={0};// cache
uchar buff[3];// Serial port cache
uchar x1,x0,y1,y0,cont2=0;
uchar xfb=4,yfb=4;// Walk sign
unsigned char HighRH = 0; // High byte of high level overload value
unsigned char HighRL = 0; // Low byte of high level overload value
unsigned char LowRH = 0; // High byte of low-level overload value
unsigned char LowRL = 0; // Low byte of low level overload value
void delayms(uint xms)
{
uint i,j;
For (i=xms; i>0; i –)//i=xms, that is, the delay is about xms milliseconds
for(j=110;j>0;j–);
}
/*Configure and start PWM, fr-frequency, dc-duty ratio*/
void ConfigPWM(unsigned int fr, unsigned char dc)
{
unsigned int high, low;
unsigned long tmp;
tmp = (11059200/12) / fr; // Calculate the count value required for a cycle
high = (tmpdc) / 100; // Calculate the count value required for high level
low = tmp - high; // Calculate the count value required for low level
high = 65536 - high + 12; // Calculate the high level overload value and compensate the interrupt delay
low = 65536 - low + 12; // Calculate the overload value of low level and compensate the interruption delay
HighRH = (unsigned char)(high>>8); // High level overload value is divided into high and low bytes
HighRL = (unsigned char)high;
LowRH = (unsigned char)(low>>8); // Low level overload value is divided into high and low bytes
LowRL = (unsigned char)low;
TMOD &= 0xF0; // Clear the control bit of T0
TMOD |= 0x01; // Configure T0 as mode 1
TH0 = HighRH; // Load T0 overload value
TL0 = HighRL;
ET0 = 1; // Enable T0 interrupt
TR0 = 1; // Start T0
jg = 1; // Output low level, turn off the laser
}
/Turn off PWM/
void ClosePWM()
{
TR0 = 0; // Stop timer 0
ET0 = 0; // Disable timer 0 interrupt
jg = 1; // Output low level, turn off the laser
}
/T0 interrupts the service function and generates PWM output*/
void InterruptTimer0() interrupt 1
{
If (jg==1)//The current output is low level, load the high level value and output the high level
{
TH0 = LowRH;
TL0 = LowRL;
jg = 0;
}
Else//The current output is high level, load the low level value and output the low level
{
TH0 = HighRH;
TL0 = HighRL;
jg = 1;
}
}
Void xfor (uint i)//x-axis advance function, how many steps forward
{
while(1)
{
if(xfb4)
{
xa=xb=1;
xb_= xa_= 0
xfb=1;
i–;
delayms(N);
if(i0){xa=xb=0; break;}
}
if(xfb1)
{
xb=xa_= 1;
xa=xb_= 0
xfb=2;
i–;
delayms(N);
if(i0){xa_=xb=0; break;}
}
if(xfb2)
{
xa_= xb_= 1;
xb=xa=0;
xfb=3; // Walk sign
i–;
delayms(N);
if(i0){xa_=xb_=0; break;}
}
if(xfb3)
{
xa_= xb=0;
xb_= xa=1;
xfb=4;
i–;
delayms(N);
if(i0){xa=xb_=0; break;}
}
}
one
}
Void xbac (uint i)//xxx fallback function
{
while(1)
{
if(xfb1)
{
xa_= xb=0;
xb_= xa=1;
xfb=4;
i–; // Walk sign
delayms(N);
if(i0){xa=xb_=0; break;}
}
if(xfb4)
{
xa_= xb_= 1;
xb=xa=0;
xfb=3;
i–;
delayms(N);
if(i0){xa_=xb_=0; break;}
}
if(xfb3)
{
xb=xa_= 1;
xa=xb_= 0
xfb=2; // Walk sign
i–;
delayms(N);
if(i0){xa_=xb=0; break;}
}
if(xfb2)
{
xa=xb=1;
xb_= xa_= 0
xfb=1;
i–;
delayms(N);
if(i0){xa=xb=0; break;}
}
}
}
Void yfor (uint i)//y-axis advance function
{
while(1)
{
switch(yfb)
{
case 4:{a=b=1; b_=a_=0; yfb=1; i–; delayms(M); if(i0){a=b=0;break;}}
case 1:{b=a_=1; a=b_=0; yfb=2; i–; delayms(M); if(i0){a_=b=0;break;}}
case 2:{a_=b_=1; b=a=0; yfb=3; i–; delayms(M); if(i0){a_=b_=0;break;}}
case 3:{b_=a=1; a_=b=0; yfb=4; i–; delayms(M); if(i0){a=b_=0;break;}}
}
if(i==0) break;
}
}
Void ybac (uint i)//yy fallback function
{
while(1)
{
switch(yfb)
{
case 1:{a=b_=1; b=a_=0; yfb=4; i–; delayms(M); if(i0){a=b_=0;break;}}
case 4:{b_=a_=1; a=b=0; yfb=3; i–; delayms(M); if(i0){a_=b_=0;break;}}
case 3:{a_=b=1; b_=a=0; yfb=2; i–; delayms(M); if(i0){a_=b=0;break;}}
case 2:{b=a=1; a_=b_=0; yfb=1; i–; delayms(M); if(i0){a=b=0;break;}}
}
if(i==0) break;
}
}
Void dazi (uint zik)//Print function Print function changed
{
uint x;
jg=0;
For (x=0; x<zik; x++)//Execute zik cycles, and move the x-axis right zik steps
{
while(z[63]); // Pause waiting
if(z[64]==1) break;// Stop flag jumps out of the loop
SBUF=255; // Each time a point is printed, 255 is sent to the upper computer, and the upper computer progress display is used
jg=0; // Laser on
delayms((z[99+x]*(z[58]*256+z[59]))/100);
jg=1; // Turn off the laser
if(z[66]1)
{
xbac(1);
}
else
{
xfor(1);
}
}
if(z[641]) z[64]=0;
Else {yfor (1);}//The y-axis enters a line
z[62]=0; // One-line printing completed
SBUF=1; // Send a message to indicate that one line is printed
}
/*Serial port configuration function, baud communication baud rate*/
void ConfigUART(unsigned int baud)
{
SCON = 0x50; // Configure the serial port as mode 1
TMOD &= 0x0F; // Clear the control bit of T1
TMOD |= 0x20; // Configure T1 as mode 2
TH1 = 256 - (11059200/12/32)/baud; // Calculate T1 overload value
TL1 = TH1; // Initial value is equal to overload value
ET1 = 0; // T1 interrupt prohibited
ES = 1; // Enable serial port interrupt
TR1 = 1; // Start T1
}
void chuanlo() interrupt 4
{
if(RI)
{
buff[cont2]=SBUF;// 3 bytes each time, address high, address low, data,,
cont2++;
If (cont2==3)//Write the data into the address every 3 bytes received
{
z[(buff[0]256)+buff[1]]=buff[2];
cont2=0;
SBUF=0; // Add this line of code here to test it*************
}
RI=0;
}
if(TI)
{
TI=0;
}
}
Due to space limitation, only part of the code can be written
Finally, if you have any comments or suggestions, please leave me a message. Let's learn and make progress together,
- 2023-02-02
- 2022-11-16