mycnc:independent_pulse_generator
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
mycnc:independent_pulse_generator [2018/09/02 11:05] – skirillov | mycnc:independent_pulse_generator [2022/02/11 15:45] (current) – ivan | ||
---|---|---|---|
Line 6: | Line 6: | ||
< | < | ||
Independent Pulse Generator was added to firmware dated July 20, 2018. | Independent Pulse Generator was added to firmware dated July 20, 2018. | ||
- | At the moment the firmware is available as the | ||
- | " | ||
</ | </ | ||
Line 17: | Line 15: | ||
^ Register Name ^ Address ^ Description ^ | ^ Register Name ^ Address ^ Description ^ | ||
- | | GVAR_GENERATOR_FRQ_RAW | 8130 | Pulse Generator RAW frequency value, [units] \\ 1 unit = | | + | | GVAR_GENERATOR_FRQ_RAW | 8130 | Pulse Generator RAW frequency value, [units] \\ 1 unit = 0.000736 Hz | |
| GVAR_GENERATOR_ACCEL | 8131 | Generator Acceleration, | | GVAR_GENERATOR_ACCEL | 8131 | Generator Acceleration, | ||
| GVAR_GENERATOR_FRQ_RATIO | 8132 | Generator Frequency Ratio | | | GVAR_GENERATOR_FRQ_RATIO | 8132 | Generator Frequency Ratio | | ||
Line 23: | Line 21: | ||
- | Originally the Pulse generator was supposed | + | Originally the Pulse generator was meant to be used as Coolant control. |
Global register GVAR_PLC_COOLANT_STATE (#7372) is used to detect the Current State of the Pulse generator. | Global register GVAR_PLC_COOLANT_STATE (#7372) is used to detect the Current State of the Pulse generator. | ||
Line 37: | Line 35: | ||
Global variable registers can be written in either Hardware or Software PLC. | Global variable registers can be written in either Hardware or Software PLC. | ||
- | < | + | < |
- | A: Internal frequency | + | A: Internal frequency |
- | to set up the ratio and has the Frequency value in a unit usable for a user. | + | to set up the ratio and has the Frequency value in a unit that would be usable for a user. |
- | Depends | + | Depending |
- | It can be [1Hz] if you need a simple frequency generator, | + | It may be [1Hz] if you need a simple frequency generator, |
or [ml/hour] for Coolant control | or [ml/hour] for Coolant control | ||
or [rpm] for Spindle speed through pulse-dir servo controller. | or [rpm] for Spindle speed through pulse-dir servo controller. | ||
Line 51: | Line 49: | ||
The first application we used the Pulse Generator was a Coolant control base on a stepper driver. | The first application we used the Pulse Generator was a Coolant control base on a stepper driver. | ||
- | |||
- | |||
- | === Pulse Generator settings in User Widget === | ||
- | We added Pulse generator settings to a User Widget of " | ||
- | |||
- | |||
- | {{mycnc: | ||
- | |||
- | The programming of Pulse the Coolant widget is shown below. | ||
- | |||
- | " | ||
- | |||
- | <code XML> | ||
- | < | ||
- | | ||
- | | ||
- | |||
- | < | ||
- | </ | ||
- | | ||
- | The lines contain " | ||
- | |||
- | " | ||
- | |||
- | <code XML user-coolant.xml> | ||
- | < | ||
- | <gitem where=" | ||
- | | ||
- | | ||
- | < | ||
- | < | ||
- | < | ||
- | </ | ||
- | |||
- | <gitem where=" | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | < | ||
- | < | ||
- | </ | ||
- | |||
- | <gitem where=" | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | < | ||
- | < | ||
- | </ | ||
- | |||
- | </ | ||
- | </ | ||
- | |||
- | The code contains 3 parts | ||
- | * the widget label set up | ||
- | * the frequency setup | ||
- | * the Ratio set up | ||
- | |||
- | It's supposed operator no need to change frequency acceleration and this setting is hidden from an operator. | ||
- | The acceleration can be set up in the Software or Hardware PLC for example. | ||
- | |||
=== Pulse Generator settings in the Software PLC === | === Pulse Generator settings in the Software PLC === | ||
- | The rate, ratio and acceleration can be set up in the Software PLC as well. | + | The rate, ratio and acceleration can be set up in the Software PLC, as well as in the User Settings widget (the Step-Dir Coolant Control section). |
- | " | + | " |
<code C HANDLER_INIT.plc> | <code C HANDLER_INIT.plc> | ||
Line 134: | Line 69: | ||
- | ==== (Coolant) Pulse Generator control through Hardware PLC ==== | + | ==== MQL (Coolant) Pulse Generator control through Hardware PLC ==== |
- | Function coolant_motor_start() is addaed | + | Function |
<code C mill-func.h> | <code C mill-func.h> | ||
Line 155: | Line 90: | ||
</ | </ | ||
- | M08.plc procedure which starts the coolant motor would be | + | '' |
<code C M08.plc> | <code C M08.plc> | ||
Line 171: | Line 106: | ||
- | A procedure M09.plc to stop a coolant motor is simpler. Just need to write " | + | A procedure |
<code C M09.plc> | <code C M09.plc> | ||
Line 190: | Line 125: | ||
</ | </ | ||
+ | ====Pulse Generator control for Spindle==== | ||
+ | It is possible to control the spindle speed through the pulse generator. This is done through the independent pulse generator implemented in myCNC, which can be "mixed into" the B axis channel. An independent generator is controlled by writing values to the global variables 8130-8133, as described in the table at the beginning of this page (Register Name / Description table). | ||
- | ==== Low level CNC registers | + | When using the GUI elements (buttons, input lines, etc.) it is convenient (and necessary) |
- | This is for records only. Users don't have to use low-level access. | + | When utilizing the Hardware PLC, you MUST use the " |
- | ^ Register Name ^ Address ^ Description ^ | + | ===Independent Pulse Generator |
- | | EXT_GENERATOR_SPEED | 225 | Generator Frequency, [units] \\ 1 unit = 0.000736 Hz | | + | |
- | | EXT_GENERATOR_ACCEL | 226 | Generator | + | |
+ | 1. Add the code that enables the generator into the Hardware PLC procedure M03.plc (spindle ON procedure). It is convenient to add code to the end of the procedure before the exit(99); line. | ||
+ | <code C> | ||
+ | // Set the acceleration of the generator | ||
+ | gvarset (8131, 100000); timer = 30; do {timer -;} while (timer> 0); // Delay for 30ms | ||
+ | // Convert spindle speed reference to frequency. | ||
+ | // The value of the coefficient is selected in such a way as to convert | ||
+ | // 12-bit spindle speed to generator frequency | ||
+ | k = 123456; | ||
+ | freq = eparam * k; // Calculate the raw value of the generator frequency | ||
+ | // Send generator frequency value | ||
+ | gvarset (8130, freq); timer = 30; do {timer -;} while (timer> 0); // Delay for 30ms | ||
+ | exit (99); // normal exit | ||
+ | </ | ||
+ | |||
+ | 2. Add the following code to to enable the generator into the Hardware PLC spindle speed adjustment procedure (SPN.plc controls the speed with which the spindle is rotating). | ||
+ | |||
+ | <code C> | ||
+ | // Set the acceleration of the generator | ||
+ | gvarset (8131, 100000); timer = 30; do {timer -;} while (timer> 0); // Delay for 30ms | ||
+ | |||
+ | // Convert reference spindle speed to frequency. | ||
+ | // The value of the coefficient k is selected in such a way as to convert | ||
+ | // 12-bit spindle speed to generator frequency | ||
+ | k = 123456; | ||
+ | freq = eparam * k; // Calculate the raw value of the generator frequency by using the multiplier k | ||
+ | |||
+ | // Send the generator frequency value | ||
+ | gvarset (8130, freq); timer = 30; do {timer -;} while (timer> 0); // Delay for 30ms | ||
+ | exit (99); // normal exit | ||
+ | </ | ||
+ | |||
+ | 3. Add the generator shutdown code to the Hardware PLC spindle shutdown procedure (M05.plc turns the spindle OFF). It is also convenient to add this code right at the end of the PLC procedure, before the exit(99); line. | ||
+ | |||
+ | <code C> | ||
+ | // Send generator frequency value | ||
+ | gvarset(8130, | ||
+ | exit (99); // normal exit | ||
+ | </ | ||
+ | |||
+ | |||
+ | {{plc: | ||
+ | |||
+ | {{plc: | ||
+ | |||
+ | {{plc: | ||
+ | |||
+ | In this implementation, | ||
+ | |||
+ | < | ||
+ | If the task is to connect both spindles at the same time and switch them during operation | ||
+ | (for example, by referencing their tool number), it is necessary to organize | ||
+ | a more complex PLC procedure, which will be checking the number of the tool, | ||
+ | the value of the global variable or input controller and by this condition | ||
+ | would include only one of the spindles. | ||
+ | </ | ||
+ | |||
+ | In this example, we are assuming that the speed of a conventional spindle is 24,000 rpm. This value, respectively, | ||
+ | |||
+ | {{plc: | ||
+ | |||
+ | At this spindle speed, a full 10V signal must be sent to the analog output, so the " | ||
+ | |||
+ | When calling the PLC procedures for turning ON the spindle (M03.plc) and changing the spindle speed (SPN.plc), the spindle speed value is stored in the **eparam** variable. | ||
+ | |||
+ | myCNC controllers have 12-bit registers for PWM and DAC at 0-10V.This means that with a maximum spindle speed of **24000 rpm** and a factor of **1**, the '' | ||
+ | |||
+ | Assume that the maximum servo spindle speed is 4,500 rpm. Then the '' | ||
+ | |||
+ | < | ||
+ | |||
+ | The Pulse-Dir input of the servo spindle is set to 10,000 pulses, i.e. the motor shaft will make a full revolution every 10,000 pulses. Then, to achieve a full speed of 4500 rpm, the following pulse rate is required: | ||
+ | |||
+ | < | ||
+ | |||
+ | The register RAW value for 750kHz (750,000Hz) will therefore be calculated as follows: | ||
+ | |||
+ | < | ||
+ | |||
+ | If the maximum speed corresponds to the '' | ||
+ | |||
+ | < | ||
+ | |||
+ | By setting these values in the M03.plc and SPN.plc procedures, we will generate the required 750 kHz frequency when the spindle speed is set to 4500, as well as smooth frequency control over the entire range from 0 to 4500 rpm. | ||
+ | |||
+ | |||
+ | ===A method for evaluating the required acceleration of a generator=== | ||
+ | |||
+ | One unit of the generator acceleration is, by a very rough approximation, | ||
+ | |||
+ | ===Test code for spindle start-up and spindle speed adjustment procedures=== | ||
+ | |||
+ | <code C M03.plc> | ||
+ | //Turn on Spindle clockwise | ||
+ | #include pins.h | ||
+ | #include vars.h | ||
+ | main() | ||
+ | { | ||
+ | command=PLC_MESSAGE_SPINDLE_SPEED_CHANGED; | ||
+ | parameter=eparam; | ||
+ | message=PLCCMD_REPLY_TO_MYCNC; | ||
+ | timer=0; | ||
+ | |||
+ | timer=0; | ||
+ | proc=plc_proc_spindle; | ||
+ | |||
+ | val=eparam; | ||
+ | if (val> | ||
+ | if (val<0) {val=0;}; | ||
+ | |||
+ | dac01=val; | ||
+ | |||
+ | portclr(OUTPUT_CCW_SPINDLE); | ||
+ | portset(OUTPUT_SPINDLE); | ||
+ | |||
+ | gvarset(7370, | ||
+ | timer=30; | ||
+ | gvarset(7371, | ||
+ | |||
+ | // | ||
+ | // | ||
+ | |||
+ | |||
+ | gvarset(8131, | ||
+ | k=671223; | ||
+ | freq=val*k; //calculate the RAW frequency | ||
+ | if (freq> | ||
+ | gvarset(8130, | ||
+ | |||
+ | |||
+ | //delay after the spindle was turned on | ||
+ | timer=spindle_on_delay; | ||
+ | do{timer--; | ||
+ | |||
+ | exit(99); | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | <code C SPN.plc> | ||
+ | #include vars.h | ||
+ | //set the Spindle Speed through DAC | ||
+ | main() | ||
+ | { | ||
+ | val=eparam; | ||
+ | dac01=val; | ||
+ | |||
+ | //Change the Spindle State | ||
+ | gvarset(7371, | ||
+ | |||
+ | s=gvarget(7370); | ||
+ | if (s!=0) //if spindle should be ON | ||
+ | { | ||
+ | k=671223; | ||
+ | freq=val*k; //calculate the RAW frequency using the multiplier | ||
+ | if (freq> | ||
+ | gvarset(8130, | ||
+ | }; | ||
+ | exit(99);// | ||
+ | }; | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Low level CNC registers to control independent pulse generator ==== | ||
+ | |||
+ | This is for records only. Users don't have to utilize these settings which can be altered only by having low-level access to the controller. | ||
+ | |||
+ | ^ Register Name ^ Address ^ Description ^ | ||
+ | | EXT_GENERATOR_SPEED | 225 | Generator Frequency, [units] \\ 1 unit = 0.000736 Hz | | ||
+ | | EXT_GENERATOR_ACCEL | 226 | Generator Acceleration, | ||
Independent pulse output can be used for - | Independent pulse output can be used for - | ||
Line 210: | Line 314: | ||
* stepper motor based coolant system. | * stepper motor based coolant system. | ||
+ | |||
+ | ==== Additional Notes ==== | ||
+ | |||
+ | ++++ Synchronization | | ||
+ | |||
+ | When using the spindle as a rotary B/C axis, synchronization will be performed automatically, | ||
+ | |||
+ | ++++ | ||
mycnc/independent_pulse_generator.txt · Last modified: 2022/02/11 15:45 by ivan