当前位置：网站首页>Grbl learning (I)
Grbl learning (I)
2022-04-23 15:55:00 【Sola_ Ex】
Grbl Is used for CNC The motion control of milling based on parallel port is absolutely , High performance , Low cost alternatives . Just run Atmega 328, It will be Arduino（Duemillanove / Uno） Up operation .
The controller is highly optimized C Language writing , utilize AVR All the ingenious functions of the chip to realize accurate timing and asynchronous operation . It can last up to 30kHz The stability of the , Jitter free control pulse .
It accepts... That meets the standards g Code , And has passed a variety of CAM The output of the tool is tested , No problem . Fully support arc , Circular and helical motion , And all other major g Code command . Macro functions are not supported , Variables and most fixed loops , But we think that GUI They can be better converted into direct g Code .
Just from GitHub Downloaded grbl after , It can be used directly vscode Open the whole folder , remove git Some documents and readme outside , In fact, only 3 A folder ：
In fact, it seems to know ,build and doc It has nothing to do with the source code , They will only include some files stored after compilation or some description documents, or some dependent scripts that need to be downloaded during compilation . about Arduino Come on , Not all source files or dependent files will appear in the project , More time , After selecting some chips , By writing in advance py Script , Automatically link and download the corresponding chip dependency file , So as to reduce the capacity of the whole project .
The focus of the whole warehouse is grbl This folder .
As you can see from the diagram ,grbl In the folder of , contain ：
- Related driver files
from cpu_map You can see , It contains two header files , namely ：
That's what I've just introduced GRBL Described when , Support 328P and 2560 Two AVR chip . These two are also Arduino The classic of development board （ It is estimated that foreigners like Arduino, After all, it's easy to use ）.
If you want to transplant, of course, you must know what's inside , After opening it, it's like this ：
Analyze it bit by bit ：
#define GRBL_PLATFORM "Atmega328p"
Here is used to define the name of the chip , It's easy to understand .
// Define serial port pins and interrupt vectors. #define SERIAL_RX USART_RX_vect #define SERIAL_UDRE USART_UDRE_vect
This place , It is used to define the pin and interrupt vector of the serial port .
// Define step pulse output pins. NOTE: All step bit pins must be on the same port. #define STEP_DDR DDRD #define STEP_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 STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits // Define step direction output pins. NOTE: All direction pins must be on the same port. #define DIRECTION_DDR DDRD #define DIRECTION_PORT PORTD #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 DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits // Define stepper driver enable/disable output pin. #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 homing/hard limit switch input pins and limit interrupt vectors. // NOTE: All limit bit pins must be on the same port, but not on a port with other input pins (CONTROL). #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 #ifdef VARIABLE_SPINDLE // Z Limit pin and spindle enabled swapped to access hardware PWM on Pin 11. #define Z_LIMIT_BIT 4 // Uno Digital Pin 12 #else #define Z_LIMIT_BIT 3 // Uno Digital Pin 11 #endif #define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits #define LIMIT_INT PCIE0 // Pin change interrupt enable pin #define LIMIT_INT_vect PCINT0_vect #define LIMIT_PCMSK PCMSK0 // Pin change interrupt register
Is this paragraph very long ？ But take a closer look , Nothing ,GRBL In fact, printing is realized by controlling the motor , Similar to 3D Printer i3 Structure . So we need to define ：
- X/Y/Z Direction control pin , This pin is used to control the operation direction of the motor .
- Stepper motor enable pin , That is to control whether the stepping motor can move through this pin .
- Limit switch detection pin , That is, the motor is moving to 0 A.m. , After triggering the limit switch , Need to stop right now , Otherwise, it is easy to damage the machine structure .
Analyze it like this , It's easy .
// Define probe switch input pin. #define PROBE_DDR DDRC #define PROBE_PIN PINC #define PROBE_PORT PORTC #define PROBE_BIT 5 // Uno Analog Pin 5 #define PROBE_MASK (1<<PROBE_BIT) // Start of PWM & Stepper Enabled Spindle #ifdef VARIABLE_SPINDLE // Advanced Configuration Below You should not need to touch these variables #define PWM_MAX_VALUE 255.0 #define TCCRA_REGISTER TCCR2A #define TCCRB_REGISTER TCCR2B #define OCR_REGISTER OCR2A #define COMB_BIT COM2A1 #define WAVE0_REGISTER WGM20 #define WAVE1_REGISTER WGM21 #define WAVE2_REGISTER WGM22 #define WAVE3_REGISTER WGM23 // NOTE: On the 328p, these must be the same as the SPINDLE_ENABLE settings. #define SPINDLE_PWM_DDR DDRB #define SPINDLE_PWM_PORT PORTB #define SPINDLE_PWM_BIT 3 // Uno Digital Pin 11
about GRBL for , Use CNC Words , With the function of laser head , The laser head uses PWM Control mode control , Of course, it also has a probe .
There are so many general analysis , In fact, you can go and see 2560 The header file , You'll find it's basically the same . Therefore, these two header files directly indicate , Use it normally GRBL Words ,MCU What function pins need to be provided . So we can also start the first step of transplantation ------ Pin assignments .
After entering , See several defaults Header file starting with name , Careful can be found on the name , This should be an adaptive configuration according to different models .
You can open any file to see ：
you 're right , The file is extremely simple , It's just a configuration file ！ Used to configure CNC Related parameters of , For example, the number of pulses of the motor and so on . Specific configuration , When transplanting later, if you encounter , Let's go into more detail .
This folder is useless , It's in there Arduino Engineering documents of . because GRBL Is based on Arduino It's done , So the compiler will use Arduino To compile .
For this GRBL Transplantation , I intend to transplant it to two chips ：
- i.MX RT1010 EVK （ I applied to ！ Happy ！）
One is M4 One of the kernel is M7 The kernel of , because GRBL The motion has a computational complement algorithm , Choosing a chip with floating-point operation will feel very good .
… Development board design …ing！
- C, calculation method and source program of bell number
- Codejock Suite Pro v20. three
- 一刷312-简单重复set-剑指 Offer 03. 数组中重复的数字（e）
- Load Balancer
- Date date calculation in shell script
- C language self compiled string processing function - string segmentation, string filling, etc
- JS regular détermine si le nom de domaine ou le chemin de port IP est correct
IronPDF for .NET 2022.4.5455
Unity shader learning
C, calculation method and source program of bell number
IronPDF for . NET 2022.4.5455
Implement default page
Codejock Suite Pro v20.3.0
Filter usage of spark operator
MySQL Cluster Mode and application scenario
[AI weekly] NVIDIA designs chips with AI; The imperfect transformer needs to overcome the theoretical defect of self attention
Neodynamic Barcode Professional for WPF V11. 0
[split of recursive number] n points K, split of limited range
One brush 313 sword finger offer 06 Print linked list from end to end (E)
Import address table analysis (calculated according to the library file name: number of imported functions, function serial number and function name)
Read the meaning of serial port and various level signals
Function summary of drawing object arrangement in R language