激光雕刻机的原理是这样的通过读取从上位机上下载下来存在闪存里的G代码,分析以后再控制步进电机驱动板,步进电机驱动板easydriver控制步进电机转相应的步数以及方向。在网上看到大家大多使用的是GRBL的程序,抑或G-code,GRBL怎么说呢非常好使,也有专门的上位机发送G代码,但是问题是只能作用于ATMega328系列的开发板,其他mega系列使用不了,让人好郁闷。G-code可以改引脚,可以说G-code是通用的,但是有一个问题是它没有上位机,也就是说没有办法朝里面发送G代码,你自己还得写上位机。
怎么办呢?改程序呗既然GRBL好用,那咱就改嘛。还好改动不大,只需要稍做改动即可。
[mw_shl_code=c,true]#define STEPPING_DDR DDRD
#define STEPPING_PORT PORTD
#define X_STEP_BIT 2 // Uno Digital Pin 2
#define Y_STEP_BIT 3 // Uno Digital Pin 3
#define Z_STEP_BIT 4 // Uno Digital Pin 4
#define X_DIRECTION_BIT 5 // Uno Digital Pin 5
#define Y_DIRECTION_BIT 6 // Uno Digital Pin 6
#define Z_DIRECTION_BIT 7 // Uno Digital Pin 7
#define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits
#define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits
#define STEPPING_MASK (STEP_MASK | DIRECTION_MASK)
#define STEPPERS_DISABLE_DDR DDRB
#define STEPPERS_DISABLE_PORT PORTB
#define STEPPERS_DISABLE_BIT 0 // Uno Digital Pin 8
#define STEPPERS_DISABLE_MASK (1<<STEPPERS_DISABLE_BIT)
#define LIMIT_DDR DDRB
#define LIMIT_PIN PINB
#define LIMIT_PORT PORTB
#define X_LIMIT_BIT 1 // Uno Digital Pin 9
#define Y_LIMIT_BIT 2 // Uno Digital Pin 10
#define Z_LIMIT_BIT 3 // Uno Digital Pin 11
#define LIMIT_INT PCIE0 // Pin change interrupt enable pin
#define LIMIT_INT_vect PCINT0_vect
#define LIMIT_PCMSK PCMSK0 // Pin change interrupt register
#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits
#define SPINDLE_ENABLE_DDR DDRB
#define SPINDLE_ENABLE_PORT PORTB
#define SPINDLE_ENABLE_BIT 4 // Uno Digital Pin 12
#define SPINDLE_DIRECTION_DDR DDRB
#define SPINDLE_DIRECTION_PORT PORTB
#define SPINDLE_DIRECTION_BIT 5
#define COOLANT_FLOOD_DDR DDRC
#define COOLANT_FLOOD_PORT PORTC
#define COOLANT_FLOOD_BIT 3 // Uno Analog Pin 3
[/mw_shl_code]
[mw_shl_code=c,true]#ifdef ENABLE_M7
#define COOLANT_MIST_DDR DDRC
#define COOLANT_MIST_PORT   ORTC
#define COOLANT_MIST_BIT 4 // Uno Analog Pin 4
#endif
// NOTE: All pinouts pins must be on the same port
#define PINOUT_DDR DDRC
#define PINOUT_PIN PINC
#define PINOUT_PORT   ORTC
#define PIN_RESET 0 // Uno Analog Pin 0
#define PIN_FEED_HOLD 1 // Uno Analog Pin 1
#define PIN_CYCLE_START 2 // Uno Analog Pin 2[/mw_shl_code]
[mw_shl_code=c,true]
#define PINOUT_INT PCIE1 // Pin change interrupt enable pin
#define PINOUT_INT_vect   CINT1_vect
#define PINOUT_PCMSK PCMSK1 // Pin change interrupt register
#define PINOUT_MASK ((1<< IN_RESET)|(1<< IN_FEED_HOLD)|(1<< IN_CYCLE_START))
#define CMD_STATUS_REPORT '?'
#define CMD_FEED_HOLD '!'
#define CMD_CYCLE_START '~'
#define CMD_RESET 0x18 // ctrl-x
[/mw_shl_code]
这是GRBL里面config.h里面相关引脚的定义当然这是328的,我用的是mega2560的开发板,下面我们稍微改一下,使程序在2560上也可以用。
[mw_shl_code=c,true] #define STEPING_DDR DDRA
#define STEPING_PORT PORTA
#define STEPING_PIN PINA
#define X_STEP_BIT 2 //24
#define Y_STEP_BIT 3 //25
#define Z_STEP_BIT 4 //26[/mw_shl_code]
[mw_shl_code=c,true] #define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT))
[/mw_shl_code]
[mw_shl_code=c,true] #define DIRECTION_DDR DDRC
#define DIRECTION_PORT  ORTC
#define DIRECTION_PIN PINC
#define X_DIRECTION_BIT 7 //30
#define Y_DIRECTION_BIT 6 //31
#define Z_DIRECTION_BIT 5 //32[/mw_shl_code]
[mw_shl_code=c,true] #define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) #define STEPPING_MASK (STEP_MASK | DIRECTION_MASK)[/mw_shl_code]
[mw_shl_code=c,true] #define STEPPERS_DISABLE_DDR DDRB
#define STEPPERS_DISABLE_PORT  ORTB
#define STEPPERS_DISABLE_BIT 7 //13
#define STEPPERS_DISABLE_MASK (1<<STEPPERS_DISABLE_BIT)[/mw_shl_code]
[mw_shl_code=c,true] #define LIMIT_DDR DDRB
#define LIMIT_PORT  ORTB
#define LIMIT_PIN PINB
#define X_LIMIT_BIT 4 //10
#define Y_LIMIT_BIT 5 //11
#define Z_LIMIT_BIT 6 //12
#define LIMIT_INT PCIE0
#define LIMIT_INT_vect  CINT0_vect
#define LIMIT_PCMSK PCMSK0
#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT))
#define SPINDLE_ENABLE_DDR DDRH
#define SPINDLE_ENABLE_PORT PORTH
#define SPINDLE_ENABLE_BIT 3 //6
#define SPINDLE_DIRECTION_DDR DDRE
#define SPINDLE_DIRECTION_PORT PORTE
#define SPINDLE_DIRECTION_BIT 3 //5
#define COOLANT_FLOOD_DDR DDRH
#define COOLANT_FLOOD_PORT PORTH
#define COOLANT_FLOOD_BIT 5 //8
#ifdef ENABLE_M7
#define COOLANT_MIST_DDR DDRH
#define COOLANT_MIST_PORT PORTH
#define COOLANT_MIST_BIT 6 //9
#endif
#define PINOUT_DDR DDRK
#define PINOUT_PIN PINK
#define PINOUT_PORT PORTK
#define PIN_RESET 0 //Analog 8
#define PIN_FEED_HOLD 1 //Analog 9 #define PIN_CYCLE_START 2 //Analog 10
#define PINOUT_INT PCIE2
#define PINOUT_INT_vect PCINT2_vect
#define PINOUT_PCMSK PCMSK2
#define PINOUT_MASK ((1<<PIN_RESET)|(1<<PIN_FEED_HOLD)|(1<<PIN_CYCLE_START))
[/mw_shl_code]
[mw_shl_code=c,true] #define CMD_STATUS_REPORT '?'
#define CMD_FEED_HOLD '!'
#define CMD_CYCLE_START '~'
#define CMD_RESET 0x24 [/mw_shl_code]
[mw_shl_code=c,true] [/mw_shl_code]
改完了将这一段定义引脚的代码覆盖以后,在将程序烧写到开发板里以后,就应该可以使用了。 |