-
Notifications
You must be signed in to change notification settings - Fork 2
User Commands
This is for generic I/O control. These could be for cooling fans, clamping, valves, etc. These could be digital (on/off) or analog (PWM). This allows you to do gcode rather than special coding.
- Digital I/O
- Analog (PWM)
Commands
- M62 Synchronized Digital Output On
- M63 Synchronized Digital Output Off
- M64 Immediate Digital Output On
- M65 Immediate Digital Output Off
Use P word to indicate digital output number (0-3)
Examples:
M62 P0
M63 P0
- M67 Synchronized Set Analog Value
- M68 Immediate Set Analog Value
Use E word for analog output number (0-3) Use Q word for analog value in percent duty.
Examples
M67 E1 Q23.87 (set set output#1 to 23.87% duty)
M67 E1 Q0 (to turn off the pin. 0% duty)
Each pin will be given a number starting at 0. The numbers for the digital and analog are independent. If you use one of each, they should both be 0.
Synchronized means all steps in the buffers must complete before the I/O is changed. Immediate does not wait. With streaming gcode, you should use the synchronized commands. There is no timing guarantee with immediate versions of the commands.
- Power On - All pins will be set to the off state
- Reset - All pins will be set to the off state
- Alarm Mode - No change in pin state
- Error - No change in pins state
- End of File - No change in pins state
#define USER_DIGITAL_PIN_0 GPIO_NUM_xx
#define USER_DIGITAL_PIN_1 GPIO_NUM_xx
#define USER_DIGITAL_PIN_2 GPIO_NUM_xx
#define USER_DIGITAL_PIN_3 GPIO_NUM_xx
#define USER_ANALOG_PIN_0 GPIO_NUM_xx
#define USER_ANALOG_PIN_1 GPIO_NUM_xx
#define USER_ANALOG_PIN_2 GPIO_NUM_xx
#define USER_ANALOG_PIN_3 GPIO_NUM_xx
#define USER_ANALOG_PIN_1_FREQ 50 // Hz
Defining a frequency is optional. If you do not define one for a pin the default of 5000 will be used.
The resolution is dependent on the frequency used. The PWM is based on a 80MHz timer. If you have a 10KHz frequency, 80,000,000 / 10,000 gives you a maximum of an 8,000 count resolution. The resolution is based on bits so you need to round down to the nearest bit value which would be 12 bit or 4096. The highest bit value allowed is 13 bits.
This is all done behind the scenes, you only have to provide the frequency and duty.
The duty is a percentage of the period. It you are looking for a specific pulse width, you need to determine the period, which is 1/freq. If your frequency is 100Hz your period is 10ms. If you want a 1ms pulse, you would set the duty to 0.10%. Duty is a floating point number. A value of XX.XX will get you the highest resolution. Values above 100% are set at 100%. Negative numbers are set to 0%.