GRBL学习
coolant_control.c/.h
这个文件比较简单,从名字上看是控制冷却,但冷却这个在GRBL上显得格外奇怪。事实上在3D打印上冷却会听得比较多,因为挤出头在不挤出时候,还在高温的话,容易造成挤出头损坏。但CNC不一样,它不是加热的,他是激光类型的。
从源码上简单看:
void coolant_init()
{
COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT);
#ifdef ENABLE_M7
COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT);
#endif
coolant_stop();
}
void coolant_stop()
{
COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT);
#ifdef ENABLE_M7
COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT);
#endif
}
void coolant_set_state(uint8_t mode)
{
if (mode == COOLANT_FLOOD_ENABLE) {
COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT);
#ifdef ENABLE_M7
} else if (mode == COOLANT_MIST_ENABLE) {
COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT);
#endif
} else {
coolant_stop();
}
}
void coolant_run(uint8_t mode)
{
if (sys.state == STATE_CHECK_MODE) {
return; }
protocol_buffer_synchronize(); // Ensure coolant turns on when specified in program.
coolant_set_state(mode);
}
这几个函数基本上就是控制GPIO的高低电平,来控制是否使能。
使用
coolant_set_state
可以切换状态。
头文件只有对函数的声明
#ifndef coolant_control_h
#define coolant_control_h
void coolant_init();
void coolant_stop();
void coolant_set_state(uint8_t mode);
void coolant_run(uint8_t mode);
#endif
cpu_map.h
这个文件,基本就是根据不同的板卡进行选择的,可以直接看源码:
#ifndef cpu_map_h
#define cpu_map_h
#ifdef CPU_MAP_ATMEGA328P // (Arduino Uno) Officially supported by Grbl.
#include "cpu_map/cpu_map_atmega328p.h"
#endif
#ifdef CPU_MAP_ATMEGA2560 // (Arduino Mega 2560) Working @EliteEng
#include "cpu_map/cpu_map_atmega2560.h"
#endif
/*
#ifdef CPU_MAP_CUSTOM_PROC
// For a custom pin map or different processor, copy and edit one of the available cpu
// map files and modify it to your needs. Make sure the defined name is also changed in
// the config.h file.
#endif
*/
#endif
选择不同的板卡,来包含不同的头文件。
defaults.h
这个文件名,跟前面的一个宏:
#define DEFAULTS_GENERIC
是有关系的。事实上这个文件是用来选择针对不同的机器类型,包含不一样的头文件处理用的。可以看下图:
一般来说,初期不改动的情况下,我会直接默认选择默认的机器类型。但在产品上不一样,CNC在针对不同场景,会有不一样的应用类型,也有不一样的结构、或使用不一样的电机。此时这个文件就显得格外重要,因为它可以很方便地用户直接修改机型,甚至自己添加新的机型。
eeprom.c/.h
这个应该是极其简单了,由文件名上看,就知道是eeprom的实现。在移植之前,是不是应该搞清楚,这个eeprom到底需要一些什么样的接口呢?
此处可以自定义EEPROM的名字,当然不管也行
#ifndef EEPE
#define EEPE EEWE //!< EEPROM program/write enable.
#define EEMPE EEMWE //!< EEPROM master program/write enable.
#endif
这里实际要看你的eeprom的类型
/* These two are unfortunately not defined in the device include files. */
#define EEPM1 5 //!< EEPROM Programming Mode Bit 1.
#define EEPM0 4 //!< EEPROM Programming Mode Bit 0.
此处需要实现一个读取一个字节的函数,还有一个写的函数
unsigned char eeprom_get_char( unsigned int addr )
void eeprom_put_char( unsigned int addr, unsigned char new_value )
这里需要实现EEPROM的校验
void memcpy_to_eeprom_with_checksum(unsigned int destination, char *source, unsigned int size)
int memcpy_from_eeprom_with_checksum(char *destination, unsigned int source, unsigned int size)
没错就只有这些,似乎看上去很简单?当然这是因为当前的芯片速度不够快,如果想让EEPROM更快?或者需要存储更多的东西?那读写的方式以及校验的方式是不是应该改一下?