FIXME **Эта страница пока что не переведена полностью. Пожалуйста, помогите завершить перевод.**\\ //(Сотрите это сообщение по окончании перевода.)// ==== Примеры использования PLC ==== * [[plc:Управление шпинделем, подключенным через PULSE-DIR]] * [[plc:Работа с расширителями портов Modbus через Hardware PLC]] * [[plc:M07 Mist Coolant ON]] * [[plc:M03 Simple Spindle ON procedure]] * [[plc:plc_height_map|Getting a Height Map]] === Spindle Speed control for DAC === #define command var00 #define parameter var01 //set Spindle speed control via DAC channel #1 //Spindle Speed is given in **eparam** register main() { value=eparam; if (value>0xFFF) {value=0xFFF;}; //fix if given value is out of range 0...0xfff if (value<0) {value=0;}; dac01=value; //setup DAC value //**Set Spindle Speed** is asynchronous operation. //It's better to inform myCNC Software New Spindle Speed applied. //Send information about new Spindle Speed to myCNC Software message=PLCCMD_REPLY_TO_MYCNC; //Command code to send to myCNC software command=PLC_MESSAGE_SPINDLE_SPEED_CHANGED; //Message code parameter=eparam; //New Spindle Speed information timeout=timer+10; do { timer++; } while (timer === Spindle Speed control for ET10_DAC === #define command var00 #define parameter var01 //set Spindle speed control via ET10 DAC channel #1 //Spindle Speed is given in **eparam** register main() { command=0x32; //EXT_ET10_DAC_OFFSET; set ADC offset register address parameter=0x800-(eparam/2)+(1<<12); //0x800 - is the middle of 12bits range - represents 0V //Eparam contains 12bits DAC value in 0V range, ET10 DAC setup in +10V...-10V range, so need to /2 //Encoder channel number is given in high 12 bits of 16bit word. message=PLCCMD_SET_CNC_EXTVAR; //setup Message register with command for access to [[External CNC Variables]] texit=timer+2;do{timer++;}while(timer === M03, Spindle On, Relay and ET10 DAC === //Turn on Spindle clockwise //set Spindle speed control ET10 DAC channel #2 #include pins.h //defines for pins numbers #include vars.h //defines for variable names main() { timer=0; value=eparam; command=0x32;//EXT_ET5_DAC_OFFSET parameter=0x800-(eparam/2)+(2<<12);//channel #2 message=PLCCMD_SET_CNC_EXTVAR; texit=timer+2;do{timer++;}while(timer === Water Fill and Drain control === Procedure M240 is used in [[mycnc:mycnc_setup#add_buttons_with_led_display_that_runs_plc_procedures_and_shows_output_pin_state|some plasma cutting machines to control Water Table Fill & Drain]]. Running procedure with parameter "1" toggles Water Filling, running with parameter "0" toggles Water Draining. If try to ON both Fill & Drain, the procedure will turn off the previous relay to prevent conflicts. #define OUTPUT_FILL 13 #define OUTPUT_DRAIN 12 main() { o=gvarget(7184); //read OUTPUT PORT 0 state (pins 0...31) drain_state=o&(1< ==== Gantry Alignment Procedure (with Homing) ==== G10 L80 P5521 Q1 G10 L80 P5525 Q1 M146 P0 L1028 M88 L0 P5(Soft stop when sensor triggered) G91 G0 Y -300.0000 F 600.00 G04 P0.1 M89 L1 P5(Quick stop when sensor triggered) G91 G0 Y 300.0000 F 30.00 G04 P0.1 M135 G10 L80 P5521 Q1 G10 L80 P5525 Q1 M146 P0 L1028 M144 G91 G0 Y100 F30 G04 P0.1 G90 G10 L70 P0 Y0 G04 P0.1 M145 P0 L1028 G90 G10 L193 P97 Q5531 debug #98 G90 G10 L192 P98 Q7525 debug #98 debug #97 G90 G10 L190 P97 Q98 debug #97 G90 G28.9 Y97 F200 M146 P0 L1028 G90 G10 L70 P0 Y0 G90 G10 L80 P5521 Q0 G90 G10 L80 P5525 Q0 G90 G10 L80 P7395 Q0 (Homing Flag) //Look after input1 & input2 sensors, remember position, when triggered main() { timer=0; message=PLCCMD_MOTION_CONTINUE; texit=timer+2;do{timer++;}while(timer25000) { b=50000-b; }; c=0-25000; if (b #define var_address var00 #define var_value var01 main() { timer=0; lparam=eparam>>16; axis=1; // n=gvarget(7230); channel=0xff; if (n==1) {channel=0;}; if (n==2) {channel=1;}; if (n==4) {channel=2;}; if (n==8) {channel=3;}; if (channel>8) { message=PLCCMD_MOTION_ABORT; texit=timer+2;do{timer++;}while(timer #define var_address var00 #define var_value var01 main() { timer=0; dir=0; axis=1; channel=0; var_address=112+channel;//channel 0 set up var_value=axis; if (dir!=0) { var_value=16+axis; }; message=PLCCMD_SET_CNC_VAR; texit=timer+10;do{timer++;}while(timer