===== Lathe/Turning Set up Tips ===== ==== Lathe Low/High Gears ==== Codes to switch Lathe gears M41, M42 ^ Code ^ Name ^ Description ^ | M41 | G_M41_LATHE_LOW_GEARS | Switch to Low Gears transmission | | M42 | G_M42_LATHE_HIGH_GEARS | Switch to high gears transmission | Global Variables to test Current transmission state ^ Number ^ Name ^ Description ^ | 5715 | GVAR_LATHE_GEARS | Show current transmission status. \ 0 - High gears \ 1 - Low gears | | 5716 | GVAR_LATHE_LOW_GEARS_RATIO | Current Low gears ratio stored in the register | | 5717 | GVAR_LATHE_LOW_GEARS_1024RATIO | Current Low gears ratio multiplied by 1024 (for integer operations) stored in the register | The registers described above store the low gears ratio, as well as the current state (regular/high gears versus low gears). If the value of the global variable #5715 is equal to 1, then turning the spindle ON or changing the spindle speed will result in the spindle speed value being multiplied by the factor stored in global variable #5716. For example, if the gear ratio (#5716) is equal to 2 and the current transmission status (#5715) is set to 1, or Low Gears, then the DAC value will be twice its usual value to maintain the same speed. The M41/M42 commands can then be used to switch between the two gear transmissions, by writing a 0 or a 1 into global variable #5715 and turning the necessary ports on and off. M41.plc example //Lathe Low gears #include pins.h #include vars.h //#define input_lathe_low_gears 6 //#define input_lathe_high_gears 7 //#define output_lath_gears_low 3 //#define output_lath_gears_high 4 main() { gvarset(9159,0); a=portget(input_lathe_low_gears); b=portget(input_lathe_high_gears); a_b=a^b; if (a_b==0) { gvarset(9159,1); //display error message message=PLCCMD_MOTION_BREAK; exit(99); }; portclr(output_lathe_gears_high);// if (a!=0) { //change gears gvarset(5715,1);//GVAR_LATHE_GEARS 5715 timer=30; do { timer--; } while (timer>0); exit(99); }; if (is_modbus!=0) { message=PLCCMD_MODBUS_SPINDLE_SPEED; command=spindle_low_speed; parameter=spindle_low_speed; timeout=timer+10; do { timer++; } while (timer0); a0=gvarget(spindle_encoder);//Encoder#7; 9048+7=9055 timer=10; do { timer--; } while (timer>0); ready=0; do { a1=gvarget(spindle_encoder);//Encoder#7; 9048+7=9055 ad=a1-a0; a0=a1; timer=10; do { timer--; } while (timer>0); gvarset(7255,ad); if (ad>30) { if (ad<70) { ready=1; }; }; } while (ready==0); portset(output_lathe_gears_low);//3 ready=0; wait_time=0; do{ a=portget(input_lathe_low_gears); b=portget(input_lathe_high_gears); if (a!=0) { if (b==0) { ready=1; }; }; wait_time++; if (wait_time>5000) { ready=1; }; } while (ready==0); //portclr(output_lathe_gears_low);//3 message=PLCCMD_MODBUS_SPINDLE_CMD; command=spindle_off_reg_value; parameter=spindle_off_reg_value; timer=10; do { timer--; } while (timer>0); if (wait_time>5000) { gvarset(9159,1); timer=30;do{timer--;}while(timer>0); message=PLCCMD_MOTION_BREAK; exit(99); }; //change gears gvarset(5715,1);//GVAR_LATHE_GEARS 5715 timer=30; do { timer--; } while (timer>0); exit(99); //normal exit }; A simple M41.plc example //Lathe Low gears #include pins.h #include vars.h main() { portclr(output_lathe_gears_high);// portset(output_lathe_gears_low);//3 //change gears gvarset(5715,1);//GVAR_LATHE_GEARS 5715 timer=30; do { timer--; } while (timer>0); exit(99); //normal exit }; A simple M42.plc example //Lathe High gears #include pins.h #include vars.h main() { portset(output_lathe_gears_high);// portclr(output_lathe_gears_low);//3 //change gears gvarset(5715,0);//GVAR_LATHE_GEARS 5715 timer=30; do { timer--; } while (timer>0); exit(99); //normal exit }; 1. Select Basic profile as "Lathe" in **Cfg** - **Preferences** - **Common** dialog {{turning:mycnc-setup-turning-01.png}} 2. Select "Lathe Visualisation" in **Cfg** - **Preferences** - **3D visualisation** configuration dialog 3. Select axes **X, Z** for visualisation and deselect the rest axes. {{turning:mycnc-setup-turning-02.png}} 4. Check G-code settings related to Lathe operations in **Cfg** - **Preferences** - **G-codes settings** configuration dialog {{turning:mycnc-setup-turning-04.png}} 5. Goto **Cfg** - **Technology** - **Lathe** configuration dialog and setup appropriate settings {{turning:mycnc-setup-turning-03.png}}