Merge branch 'backlash' into software

# Conflicts:
#	main.c
pull/25/head
Patrick Felixberger 2018-12-16 20:35:50 +01:00
commit adf49524c6
16 zmienionych plików z 420 dodań i 94 usunięć

Wyświetl plik

@ -74,8 +74,8 @@
<Add option="-std=c99" /> <Add option="-std=c99" />
<Add option="-Wextra" /> <Add option="-Wextra" />
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fno-strict-aliasing" />
<Add option="-fsingle-precision-constant" /> <Add option="-fsingle-precision-constant" />
<Add option="-fno-strict-aliasing" />
<Add symbol="ARM_MATH_CM4" /> <Add symbol="ARM_MATH_CM4" />
<Add symbol="__FPU_USED" /> <Add symbol="__FPU_USED" />
<Add symbol="STM32F411RE" /> <Add symbol="STM32F411RE" />
@ -93,6 +93,11 @@
<Add option="-flto" /> <Add option="-flto" />
<Add option="-lm" /> <Add option="-lm" />
</Linker> </Linker>
<ExtraCommands>
<Add after="arm-none-eabi-objcopy -O binary ${PROJECT_DIR}${TARGET_OUTPUT_DIR}${TARGET_OUTPUT_BASENAME}.elf ${PROJECT_DIR}${TARGET_OUTPUT_DIR}${TARGET_OUTPUT_BASENAME}.bin" />
<Mode before="0" />
<Mode after="1" />
</ExtraCommands>
<Unit filename="cmsis\arm_common_tables.h" /> <Unit filename="cmsis\arm_common_tables.h" />
<Unit filename="cmsis\arm_math.h" /> <Unit filename="cmsis\arm_math.h" />
<Unit filename="cmsis\core_cm4.h" /> <Unit filename="cmsis\core_cm4.h" />

Wyświetl plik

@ -13,7 +13,7 @@
</File> </File>
<File name="cmsis\core_cmFunc.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="cmsis\core_cmFunc.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="1392" topLine="80" /> <Cursor1 position="11905" topLine="437" />
</Cursor> </Cursor>
</File> </File>
<File name="cmsis\core_cmInstr.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="cmsis\core_cmInstr.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -21,29 +21,29 @@
<Cursor1 position="1639" topLine="32" /> <Cursor1 position="1639" topLine="32" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\Config.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\Config.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="819" topLine="0" /> <Cursor1 position="8686" topLine="135" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\CoolantControl.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\CoolantControl.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="776" topLine="0" /> <Cursor1 position="959" topLine="8" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\CoolantControl.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\CoolantControl.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="767" topLine="21" /> <Cursor1 position="873" topLine="13" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\defaults.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\defaults.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="750" topLine="0" /> <Cursor1 position="2491" topLine="30" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\GCode.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\GCode.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="809" topLine="30" /> <Cursor1 position="51560" topLine="1228" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\GCode.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\GCode.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -68,7 +68,7 @@
</File> </File>
<File name="grbl\Limits.c" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\Limits.c" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="858" topLine="0" /> <Cursor1 position="10865" topLine="269" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\Limits.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\Limits.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -76,9 +76,9 @@
<Cursor1 position="858" topLine="15" /> <Cursor1 position="858" topLine="15" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\MotionControl.c" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\MotionControl.c" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="848" topLine="0" /> <Cursor1 position="1311" topLine="18" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\MotionControl.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\MotionControl.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -91,9 +91,9 @@
<Cursor1 position="896" topLine="0" /> <Cursor1 position="896" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\Planner.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\Planner.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="861" topLine="0" /> <Cursor1 position="1896" topLine="15" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\Probe.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\Probe.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -106,9 +106,9 @@
<Cursor1 position="778" topLine="0" /> <Cursor1 position="778" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\Protocol.c" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\Protocol.c" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="7298" topLine="171" /> <Cursor1 position="4480" topLine="105" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\Protocol.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\Protocol.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -116,39 +116,39 @@
<Cursor1 position="842" topLine="3" /> <Cursor1 position="842" topLine="3" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\Report.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\Report.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="776" topLine="0" /> <Cursor1 position="7133" topLine="223" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\Report.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\Report.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="776" topLine="0" /> <Cursor1 position="1255" topLine="9" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\Settings.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\Settings.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="5420" topLine="141" /> <Cursor1 position="8966" topLine="241" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\Settings.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\Settings.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="817" topLine="0" /> <Cursor1 position="3593" topLine="62" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\SpindleControl.c" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\SpindleControl.c" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="978" topLine="12" /> <Cursor1 position="2495" topLine="41" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\SpindleControl.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\SpindleControl.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="824" topLine="0" /> <Cursor1 position="1411" topLine="12" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\Stepper.c" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\Stepper.c" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="10292" topLine="204" /> <Cursor1 position="46208" topLine="1051" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\Stepper.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\Stepper.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -158,7 +158,7 @@
</File> </File>
<File name="grbl\System.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\System.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="0" topLine="0" /> <Cursor1 position="12252" topLine="135" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\util.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\util.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -166,9 +166,9 @@
<Cursor1 position="31" topLine="0" /> <Cursor1 position="31" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="grbl\util.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="grbl\util.h" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="1463" topLine="34" /> <Cursor1 position="2820" topLine="54" />
</Cursor> </Cursor>
</File> </File>
<File name="HAL\EXTI\EXTI.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="HAL\EXTI\EXTI.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -193,12 +193,12 @@
</File> </File>
<File name="HAL\GPIO\GPIO.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="HAL\GPIO\GPIO.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="583" topLine="42" /> <Cursor1 position="1238" topLine="93" />
</Cursor> </Cursor>
</File> </File>
<File name="HAL\GPIO\GPIO.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="HAL\GPIO\GPIO.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="727" topLine="78" /> <Cursor1 position="1808" topLine="38" />
</Cursor> </Cursor>
</File> </File>
<File name="HAL\SPI\SPI.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="HAL\SPI\SPI.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -218,7 +218,7 @@
</File> </File>
<File name="HAL\STM32\stm32f4xx.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="HAL\STM32\stm32f4xx.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="171145" topLine="2290" /> <Cursor1 position="79135" topLine="840" />
</Cursor> </Cursor>
</File> </File>
<File name="HAL\STM32\stm32f4xx_conf.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="HAL\STM32\stm32f4xx_conf.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -228,7 +228,7 @@
</File> </File>
<File name="HAL\STM32\stm32f4xx_it.c" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="HAL\STM32\stm32f4xx_it.c" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="4797" topLine="156" /> <Cursor1 position="5450" topLine="195" />
</Cursor> </Cursor>
</File> </File>
<File name="HAL\STM32\stm32f4xx_it.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="HAL\STM32\stm32f4xx_it.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -248,7 +248,7 @@
</File> </File>
<File name="HAL\System32.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="HAL\System32.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="1064" topLine="15" /> <Cursor1 position="1451" topLine="13" />
</Cursor> </Cursor>
</File> </File>
<File name="HAL\System32.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="HAL\System32.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -256,12 +256,12 @@
<Cursor1 position="1130" topLine="9" /> <Cursor1 position="1130" topLine="9" />
</Cursor> </Cursor>
</File> </File>
<File name="HAL\TIM\TIM.c" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="HAL\TIM\TIM.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="3181" topLine="67" /> <Cursor1 position="3237" topLine="69" />
</Cursor> </Cursor>
</File> </File>
<File name="HAL\TIM\TIM.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="HAL\TIM\TIM.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="841" topLine="0" /> <Cursor1 position="841" topLine="0" />
</Cursor> </Cursor>
@ -286,9 +286,9 @@
<Cursor1 position="781" topLine="12" /> <Cursor1 position="781" topLine="12" />
</Cursor> </Cursor>
</File> </File>
<File name="main.c" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="main.c" open="1" top="1" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="2489" topLine="35" /> <Cursor1 position="2755" topLine="52" />
</Cursor> </Cursor>
</File> </File>
<File name="SPL\inc\stm32f4xx_cryp.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="SPL\inc\stm32f4xx_cryp.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -313,7 +313,7 @@
</File> </File>
<File name="SPL\inc\stm32f4xx_tim.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="SPL\inc\stm32f4xx_tim.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="2663" topLine="56" /> <Cursor1 position="44718" topLine="1018" />
</Cursor> </Cursor>
</File> </File>
<File name="SPL\src\stm32f4xx_cryp.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="SPL\src\stm32f4xx_cryp.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -348,7 +348,7 @@
</File> </File>
<File name="Src\Print.c" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="Src\Print.c" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="118" topLine="0" /> <Cursor1 position="364" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="Src\Print.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="Src\Print.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">

Wyświetl plik

@ -1,4 +1,6 @@
#include "SPI.h" #include "SPI.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
void Spi_Init(SPI_TypeDef *SPIx, SPI_Mode mode) void Spi_Init(SPI_TypeDef *SPIx, SPI_Mode mode)
@ -163,3 +165,84 @@ uint8_t Spi_WriteByte(SPI_TypeDef *SPIx, uint8_t _data)
return (uint8_t)SPI_I2S_ReceiveData(SPIx); return (uint8_t)SPI_I2S_ReceiveData(SPIx);
} }
void Spi_ReadByteArray(SPI_TypeDef *SPIx, uint8_t *_buffer, uint8_t _len)
{
uint8_t i = 0;
for(i = 0; i < _len; ++i)
{
// Loop while DR register is not empty
while(SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_TXE) == RESET);
// Send byte through the SPIx peripheral
SPI_I2S_SendData(SPIx, 0xFF);
while(SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_RXNE) == RESET);
_buffer[i] = (uint8_t)SPI_I2S_ReceiveData(SPIx);
}
}
void Spi_WriteDataArray(SPI_TypeDef *SPIx, uint8_t *_data, uint8_t _len)
{
uint8_t i = 0;
for(i = 0; i < _len; ++i)
{
// Loop while DR register is not empty
while(SPI_I2S_GetFlagStatus(SPIx, SPI_I2S_FLAG_TXE) == RESET);
// Send byte through the SPIx peripheral
SPI_I2S_SendData(SPIx, _data[i]);
}
}
void Spi_SetPrescaler(SPI_TypeDef *SPIx, uint16_t prescaler)
{
SPI_Cmd(SPIx, DISABLE);
uint16_t tmpreg = SPIx->CR1;
tmpreg |= prescaler;
SPIx->CR1 = tmpreg;
SPI_Cmd(SPIx, ENABLE);
}
void Spi_ChipSelect(SPI_TypeDef *SPIx, bool select)
{
if(select)
{
if(SPIx == SPI1)
{
GPIO_ResetBits(SPI1_CS_GPIO_PORT, SPI1_CS_PIN);
}
else if(SPIx == SPI2)
{
GPIO_ResetBits(SPI2_CS_GPIO_PORT, SPI2_CS_PIN);
}
else if(SPIx == SPI3)
{
GPIO_ResetBits(SPI3_CS_GPIO_PORT, SPI3_CS_PIN);
}
}
else
{
if(SPIx == SPI1)
{
GPIO_SetBits(SPI1_CS_GPIO_PORT, SPI1_CS_PIN);
}
else if(SPIx == SPI2)
{
GPIO_SetBits(SPI2_CS_GPIO_PORT, SPI2_CS_PIN);
}
else if(SPIx == SPI3)
{
GPIO_SetBits(SPI3_CS_GPIO_PORT, SPI3_CS_PIN);
}
}
}

Wyświetl plik

@ -3,12 +3,35 @@
#include <stdint.h> #include <stdint.h>
#include "stm32f4xx_conf.h" #include <stdbool.h>
#include "stm32f4xx_spi.h"
typedef enum { // CS Pin Configuration
SPI_MODE0, SPI_MODE1, SPI_MODE2, SPI_MODE3 // Default SPI1 CS Pins: PA4, PA15(Remap)
} SPI_Mode; #define SPI1_CS_PIN GPIO_Pin_6
#define SPI1_CS_GPIO_PORT GPIOB
#define SPI1_CS_GPIO_CLK RCC_APB2Periph_GPIOB
// Default SPI2 CS Pins: PB12, PB9(AF)
#define SPI2_CS_PIN GPIO_Pin_12
#define SPI2_CS_GPIO_PORT GPIOB
#define SPI2_CS_GPIO_CLK RCC_APB2Periph_GPIOB
// Default SPI3 CS Pins: PA15, PA4(AF)
#define SPI3_CS_PIN GPIO_Pin_15
#define SPI3_CS_GPIO_PORT GPIOA
#define SPI3_CS_GPIO_CLK RCC_APB2Periph_GPIOA
#define SPI_PRESCALER_2 0x0000
#define SPI_PRESCALER_4 0x0008
#define SPI_PRESCALER_8 0x0010
#define SPI_PRESCALER_16 0x0018
#define SPI_PRESCALER_32 0x0020
#define SPI_PRESCALER_64 0x0028
#define SPI_PRESCALER_128 0x0030
#define SPI_PRESCALER_256 0x0038
#ifdef __cplusplus #ifdef __cplusplus
@ -16,11 +39,22 @@ typedef enum {
#endif #endif
typedef enum {
SPI_MODE0, SPI_MODE1, SPI_MODE2, SPI_MODE3
} SPI_Mode;
void Spi_Init(SPI_TypeDef *SPIx, SPI_Mode mode); void Spi_Init(SPI_TypeDef *SPIx, SPI_Mode mode);
uint8_t Spi_ReadByte(SPI_TypeDef *SPIx); uint8_t Spi_ReadByte(SPI_TypeDef *SPIx);
uint8_t Spi_WriteByte(SPI_TypeDef *SPIx, uint8_t _data); uint8_t Spi_WriteByte(SPI_TypeDef *SPIx, uint8_t _data);
void Spi_ReadByteArray(SPI_TypeDef *SPIx, uint8_t *_buffer, uint8_t _len);
void Spi_WriteDataArray(SPI_TypeDef *SPIx, uint8_t *_data, uint8_t _len);
void Spi_SetPrescaler(SPI_TypeDef *SPIx, uint16_t prescaler);
void Spi_ChipSelect(SPI_TypeDef *SPIx, bool select);
#ifdef __cplusplus #ifdef __cplusplus
} }

Wyświetl plik

@ -54,11 +54,19 @@ extern void Limit_PinChangeISR(void);
extern void System_PinChangeISR(void); extern void System_PinChangeISR(void);
// Counter for milliseconds
static volatile uint32_t gMillis = 0;
/******************************************************************************/ /******************************************************************************/
/* Cortex-M4 Processor Exceptions Handlers */ /* Cortex-M4 Processor Exceptions Handlers */
/******************************************************************************/ /******************************************************************************/
uint32_t millis(void)
{
return gMillis;
}
/** /**
* @brief This function handles NMI exception. * @brief This function handles NMI exception.
* @param None * @param None
@ -191,6 +199,8 @@ void SysTick_Handler(void)
if(DebounceCounterControl && !controls) { if(DebounceCounterControl && !controls) {
DebounceCounterControl--; DebounceCounterControl--;
} }
gMillis++;
} }

Wyświetl plik

@ -16,6 +16,7 @@ void Print_Init(void)
Usart_Init(STDOUT, BAUD_RATE); Usart_Init(STDOUT, BAUD_RATE);
} }
int Printf(const char *str, ...) int Printf(const char *str, ...)
{ {
char buffer[MAX_BUFFER_SIZE]; char buffer[MAX_BUFFER_SIZE];
@ -30,17 +31,30 @@ int Printf(const char *str, ...)
i = MAX_BUFFER_SIZE; i = MAX_BUFFER_SIZE;
} }
#ifdef BUFFERD_OUTPUT
while(i) while(i)
{ {
while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET); FifoUsart_Insert(STDOUT_NUM, 1, buffer[idx++]);
USART_SendData(USART2, buffer[idx++]);
i--; i--;
} }
va_end(vl); va_end(vl);
return 0; // Enable sending via interrupt
Usart_TxInt(STDOUT, true);
#else
while(i)
{
while(USART_GetFlagStatus(STDOUT, USART_FLAG_TC) == RESET);
USART_SendData(STDOUT, buffer[idx++]);
i--;
}
va_end(vl);
#endif
// Return number of sent bytes
return idx;
} }
// Convert float to string by immediately converting to a long integer, which contains // Convert float to string by immediately converting to a long integer, which contains
@ -105,8 +119,15 @@ int8_t Getc(char *c)
int Putc(const char c) int Putc(const char c)
{ {
#ifdef BUFFERD_OUTPUT
FifoUsart_Insert(STDOUT_NUM, 1, c);
// Enable sending via interrupt
Usart_TxInt(STDOUT, true);
#else
while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET); while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
USART_SendData(USART2, c); USART_SendData(USART2, c);
#endif
return 0; return 0;
} }

Wyświetl plik

@ -38,8 +38,11 @@
// If doing so, simply comment out these two defines and see instructions below. // If doing so, simply comment out these two defines and see instructions below.
#define DEFAULTS_GENERIC #define DEFAULTS_GENERIC
// Serial baud rate // Serial baud rate
#define BAUD_RATE 115200 #define BAUD_RATE 115200
//#define BAUD_RATE 230400
// Define realtime command special characters. These characters are 'picked-off' directly from the // Define realtime command special characters. These characters are 'picked-off' directly from the
// serial read data stream and are not passed to the grbl line execution parser. Select characters // serial read data stream and are not passed to the grbl line execution parser. Select characters
@ -47,12 +50,12 @@
// used, if they are available per user setup. Also, extended ASCII codes (>127), which are never in // used, if they are available per user setup. Also, extended ASCII codes (>127), which are never in
// g-code programs, maybe selected for interface programs. // g-code programs, maybe selected for interface programs.
// NOTE: If changed, manually update help message in report.c. // NOTE: If changed, manually update help message in report.c.
#define CMD_RESET 0x18 // ctrl-x. #define CMD_RESET 0x18 // ctrl-x.
#define CMD_STATUS_REPORT '?' #define CMD_STATUS_REPORT '?'
#define CMD_CYCLE_START '~' #define CMD_CYCLE_START '~'
#define CMD_FEED_HOLD '!' #define CMD_FEED_HOLD '!'
// NOTE: All override realtime commands must be in the extended ASCII character set, starting // NOTE: All override realtime commands must be in the extended ASCII character set, starting
// at character value 128 (0x80) and up to 255 (0xFF). If the normal set of realtime commands, // at character value 128 (0x80) and up to 255 (0xFF). If the normal set of realtime commands,
// such as status reports, feed hold, reset, and cycle start, are moved to the extended set // such as status reports, feed hold, reset, and cycle start, are moved to the extended set
@ -82,11 +85,13 @@
#define CMD_COOLANT_FLOOD_OVR_TOGGLE 0xA0 #define CMD_COOLANT_FLOOD_OVR_TOGGLE 0xA0
#define CMD_COOLANT_MIST_OVR_TOGGLE 0xA1 #define CMD_COOLANT_MIST_OVR_TOGGLE 0xA1
// If homing is enabled, homing init lock sets Grbl into an alarm state upon power up. This forces // If homing is enabled, homing init lock sets Grbl into an alarm state upon power up. This forces
// the user to perform the homing cycle (or override the locks) before doing anything else. This is // the user to perform the homing cycle (or override the locks) before doing anything else. This is
// mainly a safety feature to remind the user to home, since position is unknown to Grbl. // mainly a safety feature to remind the user to home, since position is unknown to Grbl.
#define HOMING_INIT_LOCK // Comment to disable #define HOMING_INIT_LOCK // Comment to disable
// Define the homing cycle patterns with bitmasks. The homing cycle first performs a search mode // Define the homing cycle patterns with bitmasks. The homing cycle first performs a search mode
// to quickly engage the limit switches, followed by a slower locate mode, and finished by a short // to quickly engage the limit switches, followed by a slower locate mode, and finished by a short
// pull-off motion to disengage the limit switches. The following HOMING_CYCLE_x defines are executed // pull-off motion to disengage the limit switches. The following HOMING_CYCLE_x defines are executed
@ -112,11 +117,13 @@
//#define HOMING_CYCLE_0 (1<<X_AXIS) // COREXY COMPATIBLE: First home X //#define HOMING_CYCLE_0 (1<<X_AXIS) // COREXY COMPATIBLE: First home X
//#define HOMING_CYCLE_1 (1<<Y_AXIS) // COREXY COMPATIBLE: Then home Y //#define HOMING_CYCLE_1 (1<<Y_AXIS) // COREXY COMPATIBLE: Then home Y
// Number of homing cycles performed after when the machine initially jogs to limit switches. // Number of homing cycles performed after when the machine initially jogs to limit switches.
// This help in preventing overshoot and should improve repeatability. This value should be one or // This help in preventing overshoot and should improve repeatability. This value should be one or
// greater. // greater.
#define N_HOMING_LOCATE_CYCLE 1 // Integer (1-128) #define N_HOMING_LOCATE_CYCLE 1 // Integer (1-128)
// Enables single axis homing commands. $HX, $HY, and $HZ for X, Y, and Z-axis homing. The full homing // Enables single axis homing commands. $HX, $HY, and $HZ for X, Y, and Z-axis homing. The full homing
// cycle is still invoked by the $H command. This is disabled by default. It's here only to address // cycle is still invoked by the $H command. This is disabled by default. It's here only to address
// users that need to switch between a two-axis and three-axis machine. This is actually very rare. // users that need to switch between a two-axis and three-axis machine. This is actually very rare.
@ -134,6 +141,7 @@
// parser state depending on user preferences. // parser state depending on user preferences.
#define N_STARTUP_LINE 0 // Integer (1-2) #define N_STARTUP_LINE 0 // Integer (1-2)
// Number of floating decimal points printed by Grbl for certain value types. These settings are // Number of floating decimal points printed by Grbl for certain value types. These settings are
// determined by realistic and commonly observed values in CNC machines. For example, position // determined by realistic and commonly observed values in CNC machines. For example, position
// values cannot be less than 0.001mm or 0.0001in, because machines can not be physically more // values cannot be less than 0.001mm or 0.0001in, because machines can not be physically more
@ -146,6 +154,7 @@
#define N_DECIMAL_SETTINGVALUE 3 // Decimals for floating point setting values #define N_DECIMAL_SETTINGVALUE 3 // Decimals for floating point setting values
#define N_DECIMAL_RPMVALUE 0 // RPM value in rotations per min. #define N_DECIMAL_RPMVALUE 0 // RPM value in rotations per min.
// If your machine has two limits switches wired in parallel to one axis, you will need to enable // If your machine has two limits switches wired in parallel to one axis, you will need to enable
// this feature. Since the two switches are sharing a single pin, there is no way for Grbl to tell // this feature. Since the two switches are sharing a single pin, there is no way for Grbl to tell
// which one is enabled. This option only effects homing, where if a limit is engaged, Grbl will // which one is enabled. This option only effects homing, where if a limit is engaged, Grbl will
@ -154,21 +163,25 @@
// homing cycle while on the limit switch and not have to move the machine off of it. // homing cycle while on the limit switch and not have to move the machine off of it.
// #define LIMITS_TWO_SWITCHES_ON_AXES // #define LIMITS_TWO_SWITCHES_ON_AXES
// Upon a successful probe cycle, this option provides immediately feedback of the probe coordinates // Upon a successful probe cycle, this option provides immediately feedback of the probe coordinates
// through an automatically generated message. If disabled, users can still access the last probe // through an automatically generated message. If disabled, users can still access the last probe
// coordinates through Grbl '$#' print parameters. // coordinates through Grbl '$#' print parameters.
#define MESSAGE_PROBE_COORDINATES // Enabled by default. Comment to disable. #define MESSAGE_PROBE_COORDINATES // Enabled by default. Comment to disable.
// Enables a second coolant control pin via the mist coolant g-code command M7 on the Arduino Uno // Enables a second coolant control pin via the mist coolant g-code command M7 on the Arduino Uno
// analog pin 4. Only use this option if you require a second coolant control pin. // analog pin 4. Only use this option if you require a second coolant control pin.
// NOTE: The M8 flood coolant control pin on analog pin 3 will still be functional regardless. // NOTE: The M8 flood coolant control pin on analog pin 3 will still be functional regardless.
//#define ENABLE_M7 // Disabled by default. Uncomment to enable. //#define ENABLE_M7 // Disabled by default. Uncomment to enable.
// After the safety door switch has been toggled and restored, this setting sets the power-up delay // After the safety door switch has been toggled and restored, this setting sets the power-up delay
// between restoring the spindle and coolant and resuming the cycle. // between restoring the spindle and coolant and resuming the cycle.
#define SAFETY_DOOR_SPINDLE_DELAY 2.0 // Float (seconds) #define SAFETY_DOOR_SPINDLE_DELAY 2.0 // Float (seconds)
#define SAFETY_DOOR_COOLANT_DELAY 1.0 // Float (seconds) #define SAFETY_DOOR_COOLANT_DELAY 1.0 // Float (seconds)
// Enable CoreXY kinematics. Use ONLY with CoreXY machines. // Enable CoreXY kinematics. Use ONLY with CoreXY machines.
// IMPORTANT: If homing is enabled, you must reconfigure the homing cycle #defines above to // IMPORTANT: If homing is enabled, you must reconfigure the homing cycle #defines above to
// #define HOMING_CYCLE_0 (1<<X_AXIS) and #define HOMING_CYCLE_1 (1<<Y_AXIS) // #define HOMING_CYCLE_0 (1<<X_AXIS) and #define HOMING_CYCLE_1 (1<<Y_AXIS)
@ -178,6 +191,7 @@
// have the same steps per mm internally. // have the same steps per mm internally.
// #define COREXY // Default disabled. Uncomment to enable. // #define COREXY // Default disabled. Uncomment to enable.
// Inverts select limit pin states based on the following mask. This effects all limit pin functions, // Inverts select limit pin states based on the following mask. This effects all limit pin functions,
// such as hard limits and homing. However, this is different from overall invert limits setting. // such as hard limits and homing. However, this is different from overall invert limits setting.
// This build option will invert only the limit pins defined here, and then the invert limits setting // This build option will invert only the limit pins defined here, and then the invert limits setting
@ -186,6 +200,7 @@
// NOTE: PLEASE DO NOT USE THIS, unless you have a situation that needs it. // NOTE: PLEASE DO NOT USE THIS, unless you have a situation that needs it.
//#define INVERT_LIMIT_PIN_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)) // Default disabled. Uncomment to enable. //#define INVERT_LIMIT_PIN_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)) // Default disabled. Uncomment to enable.
// Inverts the spindle enable pin from low-disabled/high-enabled to low-enabled/high-disabled. Useful // Inverts the spindle enable pin from low-disabled/high-enabled to low-enabled/high-disabled. Useful
// for some pre-built electronic boards. // for some pre-built electronic boards.
// NOTE: If VARIABLE_SPINDLE is enabled(default), this option has no effect as the PWM output and // NOTE: If VARIABLE_SPINDLE is enabled(default), this option has no effect as the PWM output and
@ -193,11 +208,13 @@
// uncomment the config option USE_SPINDLE_DIR_AS_ENABLE_PIN below. // uncomment the config option USE_SPINDLE_DIR_AS_ENABLE_PIN below.
//#define INVERT_SPINDLE_ENABLE_PIN // Default disabled. Uncomment to enable. //#define INVERT_SPINDLE_ENABLE_PIN // Default disabled. Uncomment to enable.
// Inverts the selected coolant pin from low-disabled/high-enabled to low-enabled/high-disabled. Useful // Inverts the selected coolant pin from low-disabled/high-enabled to low-enabled/high-disabled. Useful
// for some pre-built electronic boards. // for some pre-built electronic boards.
//#define INVERT_COOLANT_FLOOD_PIN // Default disabled. Uncomment to enable. //#define INVERT_COOLANT_FLOOD_PIN // Default disabled. Uncomment to enable.
//#define INVERT_COOLANT_MIST_PIN // Default disabled. Note: Enable M7 mist coolant in Config.h //#define INVERT_COOLANT_MIST_PIN // Default disabled. Note: Enable M7 mist coolant in Config.h
// When Grbl powers-cycles or is hard reset with the Arduino reset button, Grbl boots up with no ALARM // When Grbl powers-cycles or is hard reset with the Arduino reset button, Grbl boots up with no ALARM
// by default. This is to make it as simple as possible for new users to start using Grbl. When homing // by default. This is to make it as simple as possible for new users to start using Grbl. When homing
// is enabled and a user has installed limit switches, Grbl will boot up in an ALARM state to indicate // is enabled and a user has installed limit switches, Grbl will boot up in an ALARM state to indicate
@ -206,12 +223,14 @@
// OEMs and LinuxCNC users that would like this power-cycle behavior. // OEMs and LinuxCNC users that would like this power-cycle behavior.
//#define FORCE_INITIALIZATION_ALARM // Default disabled. Uncomment to enable. //#define FORCE_INITIALIZATION_ALARM // Default disabled. Uncomment to enable.
// At power-up or a reset, Grbl will check the limit switch states to ensure they are not active // At power-up or a reset, Grbl will check the limit switch states to ensure they are not active
// before initialization. If it detects a problem and the hard limits setting is enabled, Grbl will // before initialization. If it detects a problem and the hard limits setting is enabled, Grbl will
// simply message the user to check the limits and enter an alarm state, rather than idle. Grbl will // simply message the user to check the limits and enter an alarm state, rather than idle. Grbl will
// not throw an alarm message. // not throw an alarm message.
#define CHECK_LIMITS_AT_INIT #define CHECK_LIMITS_AT_INIT
// --------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------
// ADVANCED CONFIGURATION OPTIONS: // ADVANCED CONFIGURATION OPTIONS:
@ -235,11 +254,13 @@
#define SPINDLE_OVERRIDE_COARSE_INCREMENT 10 // (1-99). Usually 10%. #define SPINDLE_OVERRIDE_COARSE_INCREMENT 10 // (1-99). Usually 10%.
#define SPINDLE_OVERRIDE_FINE_INCREMENT 1 // (1-99). Usually 1%. #define SPINDLE_OVERRIDE_FINE_INCREMENT 1 // (1-99). Usually 1%.
// When a M2 or M30 program end command is executed, most g-code states are restored to their defaults. // When a M2 or M30 program end command is executed, most g-code states are restored to their defaults.
// This compile-time option includes the restoring of the feed, rapid, and spindle speed override values // This compile-time option includes the restoring of the feed, rapid, and spindle speed override values
// to their default values at program end. // to their default values at program end.
#define RESTORE_OVERRIDES_AFTER_PROGRAM_END // Default enabled. Comment to disable. #define RESTORE_OVERRIDES_AFTER_PROGRAM_END // Default enabled. Comment to disable.
// The status report change for Grbl v1.1 and after also removed the ability to disable/enable most data // The status report change for Grbl v1.1 and after also removed the ability to disable/enable most data
// fields from the report. This caused issues for GUI developers, who've had to manage several scenarios // fields from the report. This caused issues for GUI developers, who've had to manage several scenarios
// and configurations. The increased efficiency of the new reporting style allows for all data fields to // and configurations. The increased efficiency of the new reporting style allows for all data fields to
@ -253,6 +274,7 @@
#define REPORT_FIELD_OVERRIDES // Default enabled. Comment to disable. #define REPORT_FIELD_OVERRIDES // Default enabled. Comment to disable.
#define REPORT_FIELD_LINE_NUMBERS // Default enabled. Comment to disable. #define REPORT_FIELD_LINE_NUMBERS // Default enabled. Comment to disable.
// Some status report data isn't necessary for realtime, only intermittently, because the values don't // Some status report data isn't necessary for realtime, only intermittently, because the values don't
// change often. The following macros configures how many times a status report needs to be called before // change often. The following macros configures how many times a status report needs to be called before
// the associated data is refreshed and included in the status report. However, if one of these value // the associated data is refreshed and included in the status report. However, if one of these value
@ -267,6 +289,7 @@
#define REPORT_WCO_REFRESH_BUSY_COUNT 30 // (2-255) #define REPORT_WCO_REFRESH_BUSY_COUNT 30 // (2-255)
#define REPORT_WCO_REFRESH_IDLE_COUNT 10 // (2-255) Must be less than or equal to the busy count #define REPORT_WCO_REFRESH_IDLE_COUNT 10 // (2-255) Must be less than or equal to the busy count
// The temporal resolution of the acceleration management subsystem. A higher number gives smoother // The temporal resolution of the acceleration management subsystem. A higher number gives smoother
// acceleration, particularly noticeable on machines that run at very high feedrates, but may negatively // acceleration, particularly noticeable on machines that run at very high feedrates, but may negatively
// impact performance. The correct value for this parameter is machine dependent, so it's advised to // impact performance. The correct value for this parameter is machine dependent, so it's advised to
@ -274,14 +297,16 @@
// NOTE: Changing this value also changes the execution time of a segment in the step segment buffer. // NOTE: Changing this value also changes the execution time of a segment in the step segment buffer.
// When increasing this value, this stores less overall time in the segment buffer and vice versa. Make // When increasing this value, this stores less overall time in the segment buffer and vice versa. Make
// certain the step segment buffer is increased/decreased to account for these changes. // certain the step segment buffer is increased/decreased to account for these changes.
#define ACCELERATION_TICKS_PER_SECOND 220 #define ACCELERATION_TICKS_PER_SECOND 210
// Sets the maximum step rate allowed to be written as a Grbl setting. This option enables an error // Sets the maximum step rate allowed to be written as a Grbl setting. This option enables an error
// check in the settings module to prevent settings values that will exceed this limitation. The maximum // check in the settings module to prevent settings values that will exceed this limitation. The maximum
// step rate is strictly limited by the CPU speed and will change if something other than an AVR running // step rate is strictly limited by the CPU speed and will change if something other than an AVR running
// at 16MHz is used. // at 16MHz is used.
// NOTE: For now disabled, will enable if flash space permits. // NOTE: For now disabled, will enable if flash space permits.
#define MAX_STEP_RATE_HZ 50000 // Hz #define MAX_STEP_RATE_HZ 50000 // Hz
// By default, Grbl sets all input pins to normal-high operation with their internal pull-up resistors // By default, Grbl sets all input pins to normal-high operation with their internal pull-up resistors
// enabled. This simplifies the wiring for users by requiring only a switch connected to ground, // enabled. This simplifies the wiring for users by requiring only a switch connected to ground,
@ -300,17 +325,20 @@
//#define DISABLE_PROBE_PIN_PULL_UP //#define DISABLE_PROBE_PIN_PULL_UP
//#define DISABLE_CONTROL_PIN_PULL_UP //#define DISABLE_CONTROL_PIN_PULL_UP
// Sets which axis the tool length offset is applied. Assumes the spindle is always parallel with // Sets which axis the tool length offset is applied. Assumes the spindle is always parallel with
// the selected axis with the tool oriented toward the negative direction. In other words, a positive // the selected axis with the tool oriented toward the negative direction. In other words, a positive
// tool length offset value is subtracted from the current location. // tool length offset value is subtracted from the current location.
#define TOOL_LENGTH_OFFSET_AXIS Z_AXIS // Default z-axis. Valid values are X_AXIS, Y_AXIS, or Z_AXIS. #define TOOL_LENGTH_OFFSET_AXIS Z_AXIS // Default z-axis. Valid values are X_AXIS, Y_AXIS, or Z_AXIS.
// Enables variable spindle output voltage for different RPM values. On the Arduino Uno, the spindle // Enables variable spindle output voltage for different RPM values. On the Arduino Uno, the spindle
// enable pin will output 5V for maximum RPM with 256 intermediate levels and 0V when disabled. // enable pin will output 5V for maximum RPM with 256 intermediate levels and 0V when disabled.
// NOTE: IMPORTANT for Arduino Unos! When enabled, the Z-limit pin D11 and spindle enable pin D12 switch! // NOTE: IMPORTANT for Arduino Unos! When enabled, the Z-limit pin D11 and spindle enable pin D12 switch!
// The hardware PWM output on pin D11 is required for variable spindle output voltages. // The hardware PWM output on pin D11 is required for variable spindle output voltages.
#define VARIABLE_SPINDLE // Default enabled. Comment to disable. #define VARIABLE_SPINDLE // Default enabled. Comment to disable.
// Used by variable spindle output only. This forces the PWM output to a minimum duty cycle when enabled. // Used by variable spindle output only. This forces the PWM output to a minimum duty cycle when enabled.
// The PWM pin will still read 0V when the spindle is disabled. Most users will not need this option, but // The PWM pin will still read 0V when the spindle is disabled. Most users will not need this option, but
// it may be useful in certain scenarios. This minimum PWM settings coincides with the spindle rpm minimum // it may be useful in certain scenarios. This minimum PWM settings coincides with the spindle rpm minimum
@ -322,6 +350,7 @@
// NOTE: Compute duty cycle at the minimum PWM by this equation: (% duty cycle)=(SPINDLE_PWM_MIN_VALUE/255)*100 // NOTE: Compute duty cycle at the minimum PWM by this equation: (% duty cycle)=(SPINDLE_PWM_MIN_VALUE/255)*100
//#define SPINDLE_PWM_MIN_VALUE 5 // Default disabled. Uncomment to enable. Must be greater than zero. Integer (1-255). //#define SPINDLE_PWM_MIN_VALUE 5 // Default disabled. Uncomment to enable. Must be greater than zero. Integer (1-255).
// Alters the behavior of the spindle enable pin with the USE_SPINDLE_DIR_AS_ENABLE_PIN option . By default, // Alters the behavior of the spindle enable pin with the USE_SPINDLE_DIR_AS_ENABLE_PIN option . By default,
// Grbl will not disable the enable pin if spindle speed is zero and M3/4 is active, but still sets the PWM // Grbl will not disable the enable pin if spindle speed is zero and M3/4 is active, but still sets the PWM
// output to zero. This allows the users to know if the spindle is active and use it as an additional control // output to zero. This allows the users to know if the spindle is active and use it as an additional control
@ -330,6 +359,7 @@
// NOTE: Requires USE_SPINDLE_DIR_AS_ENABLE_PIN to be enabled. // NOTE: Requires USE_SPINDLE_DIR_AS_ENABLE_PIN to be enabled.
//#define SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED // Default disabled. Uncomment to enable. //#define SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED // Default disabled. Uncomment to enable.
// With this enabled, Grbl sends back an echo of the line it has received, which has been pre-parsed (spaces // With this enabled, Grbl sends back an echo of the line it has received, which has been pre-parsed (spaces
// removed, capitalized letters, no comments) and is to be immediately executed by Grbl. Echoes will not be // removed, capitalized letters, no comments) and is to be immediately executed by Grbl. Echoes will not be
// sent upon a line buffer overflow, but should for all normal lines sent to Grbl. For example, if a user // sent upon a line buffer overflow, but should for all normal lines sent to Grbl. For example, if a user
@ -339,6 +369,7 @@
// to help minimize transmission waiting within the serial write protocol. // to help minimize transmission waiting within the serial write protocol.
//#define REPORT_ECHO_LINE_RECEIVED // Default disabled. Uncomment to enable. //#define REPORT_ECHO_LINE_RECEIVED // Default disabled. Uncomment to enable.
// Minimum planner junction speed. Sets the default minimum junction speed the planner plans to at // Minimum planner junction speed. Sets the default minimum junction speed the planner plans to at
// every buffer block junction, except for starting from rest and end of the buffer, which are always // every buffer block junction, except for starting from rest and end of the buffer, which are always
// zero. This value controls how fast the machine moves through junctions with no regard for acceleration // zero. This value controls how fast the machine moves through junctions with no regard for acceleration
@ -347,17 +378,20 @@
// should not be much greater than zero or to the minimum value necessary for the machine to work. // should not be much greater than zero or to the minimum value necessary for the machine to work.
#define MINIMUM_JUNCTION_SPEED 0.0 // (mm/min) #define MINIMUM_JUNCTION_SPEED 0.0 // (mm/min)
// Sets the minimum feed rate the planner will allow. Any value below it will be set to this minimum // Sets the minimum feed rate the planner will allow. Any value below it will be set to this minimum
// value. This also ensures that a planned motion always completes and accounts for any floating-point // value. This also ensures that a planned motion always completes and accounts for any floating-point
// round-off errors. Although not recommended, a lower value than 1.0 mm/min will likely work in smaller // round-off errors. Although not recommended, a lower value than 1.0 mm/min will likely work in smaller
// machines, perhaps to 0.1mm/min, but your success may vary based on multiple factors. // machines, perhaps to 0.1mm/min, but your success may vary based on multiple factors.
#define MINIMUM_FEED_RATE 1.0 // (mm/min) #define MINIMUM_FEED_RATE 1.0 // (mm/min)
// Number of arc generation iterations by small angle approximation before exact arc trajectory // Number of arc generation iterations by small angle approximation before exact arc trajectory
// correction with expensive sin() and cos() calcualtions. This parameter maybe decreased if there // correction with expensive sin() and cos() calcualtions. This parameter maybe decreased if there
// are issues with the accuracy of the arc generations, or increased if arc execution is getting // are issues with the accuracy of the arc generations, or increased if arc execution is getting
// bogged down by too many trig calculations. // bogged down by too many trig calculations.
#define N_ARC_CORRECTION 8 // Integer (1-255) #define N_ARC_CORRECTION 6 // Integer (1-255)
// The arc G2/3 g-code standard is problematic by definition. Radius-based arcs have horrible numerical // The arc G2/3 g-code standard is problematic by definition. Radius-based arcs have horrible numerical
// errors when arc at semi-circles(pi) or full-circles(2*pi). Offset-based arcs are much more accurate // errors when arc at semi-circles(pi) or full-circles(2*pi). Offset-based arcs are much more accurate
@ -369,6 +403,7 @@
// much greater than this. The default setting should capture most, if not all, full arc error situations. // much greater than this. The default setting should capture most, if not all, full arc error situations.
#define ARC_ANGULAR_TRAVEL_EPSILON 5E-7 // Float (radians) #define ARC_ANGULAR_TRAVEL_EPSILON 5E-7 // Float (radians)
// Time delay increments performed during a dwell. The default value is set at 50ms, which provides // Time delay increments performed during a dwell. The default value is set at 50ms, which provides
// a maximum time delay of roughly 55 minutes, more than enough for most any application. Increasing // a maximum time delay of roughly 55 minutes, more than enough for most any application. Increasing
// this delay will increase the maximum dwell time linearly, but also reduces the responsiveness of // this delay will increase the maximum dwell time linearly, but also reduces the responsiveness of
@ -376,6 +411,7 @@
// time step. Also, keep in mind that the Arduino delay timer is not very accurate for long delays. // time step. Also, keep in mind that the Arduino delay timer is not very accurate for long delays.
#define DWELL_TIME_STEP 50 // Integer (1-255) (milliseconds) #define DWELL_TIME_STEP 50 // Integer (1-255) (milliseconds)
// The number of linear motions in the planner buffer to be planned at any give time. The vast // The number of linear motions in the planner buffer to be planned at any give time. The vast
// majority of RAM that Grbl uses is based on this buffer size. Only increase if there is extra // majority of RAM that Grbl uses is based on this buffer size. Only increase if there is extra
// available RAM, like when re-compiling for a Mega2560. Or decrease if the Arduino begins to // available RAM, like when re-compiling for a Mega2560. Or decrease if the Arduino begins to
@ -383,6 +419,7 @@
// new incoming motions as they are executed. // new incoming motions as they are executed.
#define BLOCK_BUFFER_SIZE 64 // Uncomment to override default in planner.h. #define BLOCK_BUFFER_SIZE 64 // Uncomment to override default in planner.h.
// Governs the size of the intermediary step segment buffer between the step execution algorithm // Governs the size of the intermediary step segment buffer between the step execution algorithm
// and the planner blocks. Each segment is set of steps executed at a constant velocity over a // and the planner blocks. Each segment is set of steps executed at a constant velocity over a
// fixed time defined by ACCELERATION_TICKS_PER_SECOND. They are computed such that the planner // fixed time defined by ACCELERATION_TICKS_PER_SECOND. They are computed such that the planner
@ -391,6 +428,7 @@
// before having to come back and refill this buffer, currently at ~50msec of step moves. // before having to come back and refill this buffer, currently at ~50msec of step moves.
#define SEGMENT_BUFFER_SIZE 32 // Uncomment to override default in stepper.h. #define SEGMENT_BUFFER_SIZE 32 // Uncomment to override default in stepper.h.
// Line buffer size from the serial input stream to be executed. Also, governs the size of // Line buffer size from the serial input stream to be executed. Also, governs the size of
// each of the startup blocks, as they are each stored as a string of this size. Make sure // each of the startup blocks, as they are each stored as a string of this size. Make sure
// to account for the available EEPROM at the defined memory address in settings.h and for // to account for the available EEPROM at the defined memory address in settings.h and for
@ -401,6 +439,7 @@
// we know how much extra memory space we can re-invest into this. // we know how much extra memory space we can re-invest into this.
#define LINE_BUFFER_SIZE 200 // Uncomment to override default in protocol.h #define LINE_BUFFER_SIZE 200 // Uncomment to override default in protocol.h
// Serial send and receive buffer size. The receive buffer is often used as another streaming // Serial send and receive buffer size. The receive buffer is often used as another streaming
// buffer to store incoming blocks to be processed by Grbl when its ready. Most streaming // buffer to store incoming blocks to be processed by Grbl when its ready. Most streaming
// interfaces will character count and track each block send to each block response. So, // interfaces will character count and track each block send to each block response. So,
@ -408,16 +447,18 @@
// memory allows. The send buffer primarily handles messages in Grbl. Only increase if large // memory allows. The send buffer primarily handles messages in Grbl. Only increase if large
// messages are sent and Grbl begins to stall, waiting to send the rest of the message. // messages are sent and Grbl begins to stall, waiting to send the rest of the message.
// NOTE: Grbl generates an average status report in about 0.5msec, but the serial TX stream at // NOTE: Grbl generates an average status report in about 0.5msec, but the serial TX stream at
// 115200 baud will take 5 msec to transmit a typical 55 character report. Worst case reports are // 115200 will take 5 msec to transmit a typical 55 character report. Worst case reports are
// around 90-100 characters. As long as the serial TX buffer doesn't get continually maxed, Grbl // around 90-100 characters. As long as the serial TX buffer doesn't get continually maxed, Grbl
// will continue operating efficiently. Size the TX buffer around the size of a worst-case report. // will continue operating efficiently. Size the TX buffer around the size of a worst-case report.
//#define RX_BUFFER_SIZE 128 // (1-254) Uncomment to override defaults in serial.h //#define RX_BUFFER_SIZE 128 // (1-254) Uncomment to override defaults in serial.h
//#define TX_BUFFER_SIZE 100 // (1-254) //#define TX_BUFFER_SIZE 100 // (1-254)
// Configures the position after a probing cycle during Grbl's check mode. Disabled sets // Configures the position after a probing cycle during Grbl's check mode. Disabled sets
// the position to the probe target, when enabled sets the position to the start position. // the position to the probe target, when enabled sets the position to the start position.
//#define SET_CHECK_MODE_PROBE_TO_START // Default disabled. Uncomment to enable. //#define SET_CHECK_MODE_PROBE_TO_START // Default disabled. Uncomment to enable.
// Force Grbl to check the state of the hard limit switches when the processor detects a pin // Force Grbl to check the state of the hard limit switches when the processor detects a pin
// change inside the hard limit ISR routine. By default, Grbl will trigger the hard limits // change inside the hard limit ISR routine. By default, Grbl will trigger the hard limits
// alarm upon any pin change, since bouncing switches can cause a state check like this to // alarm upon any pin change, since bouncing switches can cause a state check like this to
@ -428,6 +469,7 @@
// NOTE: This option has no effect if SOFTWARE_DEBOUNCE is enabled. // NOTE: This option has no effect if SOFTWARE_DEBOUNCE is enabled.
//#define HARD_LIMIT_FORCE_STATE_CHECK // Default disabled. Uncomment to enable. //#define HARD_LIMIT_FORCE_STATE_CHECK // Default disabled. Uncomment to enable.
// Adjusts homing cycle search and locate scalars. These are the multipliers used by Grbl's // Adjusts homing cycle search and locate scalars. These are the multipliers used by Grbl's
// homing cycle to ensure the limit switches are engaged and cleared through each phase of // homing cycle to ensure the limit switches are engaged and cleared through each phase of
// the cycle. The search phase uses the axes max-travel setting times the SEARCH_SCALAR to // the cycle. The search phase uses the axes max-travel setting times the SEARCH_SCALAR to
@ -438,6 +480,7 @@
//#define HOMING_AXIS_SEARCH_SCALAR 1.5 // Uncomment to override defaults in limits.c. //#define HOMING_AXIS_SEARCH_SCALAR 1.5 // Uncomment to override defaults in limits.c.
//#define HOMING_AXIS_LOCATE_SCALAR 10.0 // Uncomment to override defaults in limits.c. //#define HOMING_AXIS_LOCATE_SCALAR 10.0 // Uncomment to override defaults in limits.c.
// Enable the '$RST=*', '$RST=$', and '$RST=#' eeprom restore commands. There are cases where // Enable the '$RST=*', '$RST=$', and '$RST=#' eeprom restore commands. There are cases where
// these commands may be undesirable. Simply comment the desired macro to disable it. // these commands may be undesirable. Simply comment the desired macro to disable it.
// NOTE: See SETTINGS_RESTORE_ALL macro for customizing the `$RST=*` command. // NOTE: See SETTINGS_RESTORE_ALL macro for customizing the `$RST=*` command.
@ -445,6 +488,7 @@
#define ENABLE_RESTORE_EEPROM_DEFAULT_SETTINGS // '$RST=$' Default enabled. Comment to disable. #define ENABLE_RESTORE_EEPROM_DEFAULT_SETTINGS // '$RST=$' Default enabled. Comment to disable.
#define ENABLE_RESTORE_EEPROM_CLEAR_PARAMETERS // '$RST=#' Default enabled. Comment to disable. #define ENABLE_RESTORE_EEPROM_CLEAR_PARAMETERS // '$RST=#' Default enabled. Comment to disable.
// Defines the EEPROM data restored upon a settings version change and `$RST=*` command. Whenever the // Defines the EEPROM data restored upon a settings version change and `$RST=*` command. Whenever the
// the settings or other EEPROM data structure changes between Grbl versions, Grbl will automatically // the settings or other EEPROM data structure changes between Grbl versions, Grbl will automatically
// wipe and restore the EEPROM. This macro controls what data is wiped and restored. This is useful // wipe and restore the EEPROM. This macro controls what data is wiped and restored. This is useful
@ -454,6 +498,7 @@
// NOTE: Uncomment to override defaults in settings.h // NOTE: Uncomment to override defaults in settings.h
//#define SETTINGS_RESTORE_ALL (SETTINGS_RESTORE_DEFAULTS | SETTINGS_RESTORE_PARAMETERS | SETTINGS_RESTORE_STARTUP_LINES | SETTINGS_RESTORE_BUILD_INFO) //#define SETTINGS_RESTORE_ALL (SETTINGS_RESTORE_DEFAULTS | SETTINGS_RESTORE_PARAMETERS | SETTINGS_RESTORE_STARTUP_LINES | SETTINGS_RESTORE_BUILD_INFO)
// Enable the '$I=(string)' build info write command. If disabled, any existing build info data must // Enable the '$I=(string)' build info write command. If disabled, any existing build info data must
// be placed into EEPROM via external means with a valid checksum value. This macro option is useful // be placed into EEPROM via external means with a valid checksum value. This macro option is useful
// to prevent this data from being over-written by a user, when used to store OEM product data. // to prevent this data from being over-written by a user, when used to store OEM product data.
@ -462,6 +507,7 @@
// NOTE: See the included grblWrite_BuildInfo.ino example file to write this string seperately. // NOTE: See the included grblWrite_BuildInfo.ino example file to write this string seperately.
#define ENABLE_BUILD_INFO_WRITE_COMMAND // '$I=' Default enabled. Comment to disable. #define ENABLE_BUILD_INFO_WRITE_COMMAND // '$I=' Default enabled. Comment to disable.
// AVR processors require all interrupts to be disabled during an EEPROM write. This includes both // AVR processors require all interrupts to be disabled during an EEPROM write. This includes both
// the stepper ISRs and serial comm ISRs. In the event of a long EEPROM write, this ISR pause can // the stepper ISRs and serial comm ISRs. In the event of a long EEPROM write, this ISR pause can
// cause active stepping to lose position and serial receive data to be lost. This configuration // cause active stepping to lose position and serial receive data to be lost. This configuration
@ -476,6 +522,7 @@
// job. At this time, this option only forces a planner buffer sync with these g-code commands. // job. At this time, this option only forces a planner buffer sync with these g-code commands.
#define FORCE_BUFFER_SYNC_DURING_EEPROM_WRITE // Default enabled. Comment to disable. #define FORCE_BUFFER_SYNC_DURING_EEPROM_WRITE // Default enabled. Comment to disable.
// In Grbl v0.9 and prior, there is an old outstanding bug where the `WPos:` work position reported // In Grbl v0.9 and prior, there is an old outstanding bug where the `WPos:` work position reported
// may not correlate to what is executing, because `WPos:` is based on the g-code parser state, which // may not correlate to what is executing, because `WPos:` is based on the g-code parser state, which
// can be several motions behind. This option forces the planner buffer to empty, sync, and stop // can be several motions behind. This option forces the planner buffer to empty, sync, and stop
@ -484,6 +531,7 @@
// that any of these commands are used need continuous motions through them. // that any of these commands are used need continuous motions through them.
#define FORCE_BUFFER_SYNC_DURING_WCO_CHANGE // Default enabled. Comment to disable. #define FORCE_BUFFER_SYNC_DURING_WCO_CHANGE // Default enabled. Comment to disable.
// By default, Grbl disables feed rate overrides for all G38.x probe cycle commands. Although this // By default, Grbl disables feed rate overrides for all G38.x probe cycle commands. Although this
// may be different than some pro-class machine control, it's arguable that it should be this way. // may be different than some pro-class machine control, it's arguable that it should be this way.
// Most probe sensors produce different levels of error that is dependent on rate of speed. By // Most probe sensors produce different levels of error that is dependent on rate of speed. By
@ -491,6 +539,7 @@
// repeatable. If needed, you can disable this behavior by uncommenting the define below. // repeatable. If needed, you can disable this behavior by uncommenting the define below.
//#define ALLOW_FEED_OVERRIDE_DURING_PROBE_CYCLES // Default disabled. Uncomment to enable. //#define ALLOW_FEED_OVERRIDE_DURING_PROBE_CYCLES // Default disabled. Uncomment to enable.
// Enables and configures parking motion methods upon a safety door state. Primarily for OEMs // Enables and configures parking motion methods upon a safety door state. Primarily for OEMs
// that desire this feature for their integrated machines. At the moment, Grbl assumes that // that desire this feature for their integrated machines. At the moment, Grbl assumes that
// the parking motion only involves one axis, although the parking implementation was written // the parking motion only involves one axis, although the parking implementation was written
@ -506,6 +555,7 @@
// positive direction. // positive direction.
//#define PARKING_ENABLE // Default disabled. Uncomment to enable //#define PARKING_ENABLE // Default disabled. Uncomment to enable
// Configure options for the parking motion, if enabled. // Configure options for the parking motion, if enabled.
#define PARKING_AXIS Z_AXIS // Define which axis that performs the parking motion #define PARKING_AXIS Z_AXIS // Define which axis that performs the parking motion
#define PARKING_TARGET -5.0 // Parking axis target. In mm, as machine coordinate [-max_travel,0]. #define PARKING_TARGET -5.0 // Parking axis target. In mm, as machine coordinate [-max_travel,0].
@ -514,6 +564,7 @@
#define PARKING_PULLOUT_INCREMENT 5.0 // Spindle pull-out and plunge distance in mm. Incremental distance. #define PARKING_PULLOUT_INCREMENT 5.0 // Spindle pull-out and plunge distance in mm. Incremental distance.
// Must be positive value or equal to zero. // Must be positive value or equal to zero.
// Enables a special set of M-code commands that enables and disables the parking motion. // Enables a special set of M-code commands that enables and disables the parking motion.
// These are controlled by `M56`, `M56 P1`, or `M56 Px` to enable and `M56 P0` to disable. // These are controlled by `M56`, `M56 P1`, or `M56 Px` to enable and `M56 P0` to disable.
// The command is modal and will be set after a planner sync. Since it is g-code, it is // The command is modal and will be set after a planner sync. Since it is g-code, it is
@ -523,12 +574,18 @@
//#define ENABLE_PARKING_OVERRIDE_CONTROL // Default disabled. Uncomment to enable //#define ENABLE_PARKING_OVERRIDE_CONTROL // Default disabled. Uncomment to enable
//#define DEACTIVATE_PARKING_UPON_INIT // Default disabled. Uncomment to enable. //#define DEACTIVATE_PARKING_UPON_INIT // Default disabled. Uncomment to enable.
// This option will automatically disable the laser during a feed hold by invoking a spindle stop // This option will automatically disable the laser during a feed hold by invoking a spindle stop
// override immediately after coming to a stop. However, this also means that the laser still may // override immediately after coming to a stop. However, this also means that the laser still may
// be reenabled by disabling the spindle stop override, if needed. This is purely a safety feature // be reenabled by disabling the spindle stop override, if needed. This is purely a safety feature
// to ensure the laser doesn't inadvertently remain powered while at a stop and cause a fire. // to ensure the laser doesn't inadvertently remain powered while at a stop and cause a fire.
#define DISABLE_LASER_DURING_HOLD // Default enabled. Comment to disable. #define DISABLE_LASER_DURING_HOLD // Default enabled. Comment to disable.
// Backlash Compensation
#define ENABLE_BACKLASH_COMPENSATION
/* --------------------------------------------------------------------------------------- /* ---------------------------------------------------------------------------------------
OEM Single File Configuration Option OEM Single File Configuration Option

Wyświetl plik

@ -32,6 +32,11 @@
#include "Report.h" #include "Report.h"
#include "CoolantControl.h" #include "CoolantControl.h"
#include "MotionControl.h" #include "MotionControl.h"
#include "defaults.h"
static float target_prev[N_AXIS] = {0.0};
static uint8_t dir_negative[N_AXIS] = {0};
// Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second // Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second
@ -43,6 +48,15 @@
// in the planner and to let backlash compensation or canned cycle integration simple and direct. // in the planner and to let backlash compensation or canned cycle integration simple and direct.
void MC_Line(float *target, Planner_LineData_t *pl_data) void MC_Line(float *target, Planner_LineData_t *pl_data)
{ {
Planner_LineData_t pl_backlash = {0};
uint8_t backlash_update = 0;
pl_backlash.spindle_speed = pl_data->spindle_speed;
pl_backlash.line_number = pl_data->line_number;
pl_backlash.feed_rate = pl_data->feed_rate;
// If enabled, check for soft limit violations. Placed here all line motions are picked up // If enabled, check for soft limit violations. Placed here all line motions are picked up
// from everywhere in Grbl. // from everywhere in Grbl.
if(BIT_IS_TRUE(settings.flags, BITFLAG_SOFT_LIMIT_ENABLE)) { if(BIT_IS_TRUE(settings.flags, BITFLAG_SOFT_LIMIT_ENABLE)) {
@ -71,6 +85,7 @@ void MC_Line(float *target, Planner_LineData_t *pl_data)
// doesn't update the machine position values. Since the position values used by the g-code // doesn't update the machine position values. Since the position values used by the g-code
// parser and planner are separate from the system machine positions, this is doable. // parser and planner are separate from the system machine positions, this is doable.
// If the buffer is full: good! That means we are well ahead of the robot. // If the buffer is full: good! That means we are well ahead of the robot.
// Remain in this loop until there is room in the buffer. // Remain in this loop until there is room in the buffer.
do { do {
@ -90,6 +105,66 @@ void MC_Line(float *target, Planner_LineData_t *pl_data)
} }
} while(1); } while(1);
#ifdef ENABLE_BACKLASH_COMPENSATION
pl_backlash.backlash_motion = 1;
pl_backlash.condition = PL_COND_FLAG_RAPID_MOTION; // Set rapid motion condition flag.
// Backlash compensation
for(uint8_t i = 0; i < N_AXIS; i++)
{
// Move positive?
if(target[i] > target_prev[i])
{
// Last move negative?
if(dir_negative[i] == 1)
{
dir_negative[i] = 0;
target_prev[i] += settings.backlash[i];
backlash_update = 1;
}
}
// Move negative?
else if(target[i] < target_prev[i])
{
// Last move positive?
if(dir_negative[i] == 0)
{
dir_negative[i] = 1;
target_prev[i] -= settings.backlash[i];
backlash_update = 1;
}
}
}
if(backlash_update)
{
// Perform backlash move if necessary
Planner_BufferLine(target_prev, &pl_backlash);
}
memcpy(target_prev, target, N_AXIS*sizeof(float));
// Backlash move needs a slot in planner buffer, so we have to check again, if planner is free
do {
Protocol_ExecuteRealtime(); // Check for any run-time commands
if(sys.abort) {
// Bail, if system abort.
return;
}
if(Planner_CheckBufferFull()) {
// Auto-cycle start when buffer is full.
Protocol_AutoCycleStart();
}
else {
break;
}
} while(1);
#endif
// Plan and queue motion into planner buffer // Plan and queue motion into planner buffer
if(Planner_BufferLine(target, pl_data) == PLAN_EMPTY_BLOCK) { if(Planner_BufferLine(target, pl_data) == PLAN_EMPTY_BLOCK) {
if(BIT_IS_TRUE(settings.flags, BITFLAG_LASER_MODE)) { if(BIT_IS_TRUE(settings.flags, BITFLAG_LASER_MODE)) {

Wyświetl plik

@ -94,10 +94,11 @@ uint8_t Planner_BufferLine(float *target, Planner_LineData_t *pl_data)
{ {
// Prepare and initialize new block. Copy relevant pl_data for block execution. // Prepare and initialize new block. Copy relevant pl_data for block execution.
Planner_Block_t *block = &block_buffer[block_buffer_head]; Planner_Block_t *block = &block_buffer[block_buffer_head];
memset(block,0,sizeof(Planner_Block_t)); // Zero all block values. memset(block, 0, sizeof(Planner_Block_t)); // Zero all block values.
block->condition = pl_data->condition; block->condition = pl_data->condition;
block->spindle_speed = pl_data->spindle_speed; block->spindle_speed = pl_data->spindle_speed;
block->line_number = pl_data->line_number; block->line_number = pl_data->line_number;
block->backlash_motion = pl_data->backlash_motion;
// Compute and store initial move distance data. // Compute and store initial move distance data.
int32_t target_steps[N_AXIS], position_steps[N_AXIS]; int32_t target_steps[N_AXIS], position_steps[N_AXIS];
@ -247,9 +248,12 @@ uint8_t Planner_BufferLine(float *target, Planner_LineData_t *pl_data)
Planner_ComputeProfileParams(block, nominal_speed, planner.previous_nominal_speed); Planner_ComputeProfileParams(block, nominal_speed, planner.previous_nominal_speed);
planner.previous_nominal_speed = nominal_speed; planner.previous_nominal_speed = nominal_speed;
// Update previous path unit_vector and planner position. if(block->backlash_motion == 0)
memcpy(planner.previous_unit_vec, unit_vec, sizeof(unit_vec)); // pl.previous_unit_vec[] = unit_vec[] {
memcpy(planner.position, target_steps, sizeof(target_steps)); // pl.position[] = target_steps[] // Update previous path unit_vector and planner position.
memcpy(planner.previous_unit_vec, unit_vec, sizeof(unit_vec)); // pl.previous_unit_vec[] = unit_vec[]
memcpy(planner.position, target_steps, sizeof(target_steps)); // pl.position[] = target_steps[]
}
// New block is all set. Update buffer head and next buffer head indices. // New block is all set. Update buffer head and next buffer head indices.
block_buffer_head = next_buffer_head; block_buffer_head = next_buffer_head;

Wyświetl plik

@ -73,6 +73,8 @@ typedef struct {
// Stored spindle speed data used by spindle overrides and resuming methods. // Stored spindle speed data used by spindle overrides and resuming methods.
float spindle_speed; // Block spindle speed. Copied from pl_line_data. float spindle_speed; // Block spindle speed. Copied from pl_line_data.
uint8_t backlash_motion;
} Planner_Block_t; } Planner_Block_t;
@ -82,6 +84,8 @@ typedef struct {
float spindle_speed; // Desired spindle speed through line motion. float spindle_speed; // Desired spindle speed through line motion.
uint8_t condition; // Bitflag variable to indicate planner conditions. See defines above. uint8_t condition; // Bitflag variable to indicate planner conditions. See defines above.
int32_t line_number; // Desired line number to report when executing. int32_t line_number; // Desired line number to report when executing.
uint8_t backlash_motion;
} Planner_LineData_t; } Planner_LineData_t;

Wyświetl plik

@ -96,6 +96,7 @@ void Protocol_MainLoop(void)
uint8_t char_counter = 0; uint8_t char_counter = 0;
char c; char c;
for(;;) { for(;;) {
// Process one line of incoming serial data, as the data becomes available. Performs an // Process one line of incoming serial data, as the data becomes available. Performs an
// initial filtering by removing spaces and comments and capitalizing all letters. // initial filtering by removing spaces and comments and capitalizing all letters.

Wyświetl plik

@ -250,9 +250,12 @@ void Report_GrblSettings(void) {
uint8_t idx, set_idx; uint8_t idx, set_idx;
uint8_t val = AXIS_SETTINGS_START_VAL; uint8_t val = AXIS_SETTINGS_START_VAL;
for(set_idx = 0; set_idx < AXIS_N_SETTINGS; set_idx++) { for(set_idx = 0; set_idx < AXIS_N_SETTINGS; set_idx++)
for(idx = 0; idx < N_AXIS; idx++) { {
switch(set_idx) { for(idx = 0; idx < N_AXIS; idx++)
{
switch(set_idx)
{
case 0: case 0:
report_util_float_setting(val+idx,settings.steps_per_mm[idx],N_DECIMAL_SETTINGVALUE); report_util_float_setting(val+idx,settings.steps_per_mm[idx],N_DECIMAL_SETTINGVALUE);
break; break;
@ -269,6 +272,10 @@ void Report_GrblSettings(void) {
report_util_float_setting(val+idx,-settings.max_travel[idx],N_DECIMAL_SETTINGVALUE); report_util_float_setting(val+idx,-settings.max_travel[idx],N_DECIMAL_SETTINGVALUE);
break; break;
case 4:
report_util_float_setting(val+idx,settings.backlash[idx],N_DECIMAL_SETTINGVALUE);
break;
default: default:
break; break;
} }

Wyświetl plik

@ -129,6 +129,10 @@ void Settings_Restore(uint8_t restore_flag) {
settings.max_travel[Y_AXIS] = (-DEFAULT_Y_MAX_TRAVEL); settings.max_travel[Y_AXIS] = (-DEFAULT_Y_MAX_TRAVEL);
settings.max_travel[Z_AXIS] = (-DEFAULT_Z_MAX_TRAVEL); settings.max_travel[Z_AXIS] = (-DEFAULT_Z_MAX_TRAVEL);
settings.backlash[X_AXIS] = DEFAULT_X_BACKLASH;
settings.backlash[Y_AXIS] = DEFAULT_Y_BACKLASH;
settings.backlash[Z_AXIS] = DEFAULT_Z_BACKLASH;
WriteGlobalSettings(); WriteGlobalSettings();
} }
@ -261,6 +265,7 @@ uint8_t Settings_StoreGlobalSetting(uint8_t parameter, float value) {
case 2: settings.acceleration[parameter] = value*60*60; break; // Convert to mm/min^2 for grbl internal use. case 2: settings.acceleration[parameter] = value*60*60; break; // Convert to mm/min^2 for grbl internal use.
case 3: settings.max_travel[parameter] = -value; break; // Store as negative for grbl internal use. case 3: settings.max_travel[parameter] = -value; break; // Store as negative for grbl internal use.
case 4: settings.backlash[parameter] = value; break;
} }
break; // Exit while-loop after setting has been configured and proceed to the EEPROM write call. break; // Exit while-loop after setting has been configured and proceed to the EEPROM write call.
} }

Wyświetl plik

@ -28,7 +28,7 @@
// Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl // Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl
// when firmware is upgraded. Always stored in byte 0 of eeprom // when firmware is upgraded. Always stored in byte 0 of eeprom
#define SETTINGS_VERSION 2 // NOTE: Check settings_reset() when moving to next version. #define SETTINGS_VERSION 3 // NOTE: Check settings_reset() when moving to next version.
// Define bit flag masks for the boolean settings in settings.system_flags // Define bit flag masks for the boolean settings in settings.system_flags
@ -78,7 +78,7 @@
// #define SETTING_INDEX_G92 N_COORDINATE_SYSTEM+2 // Coordinate offset (G92.2,G92.3 not supported) // #define SETTING_INDEX_G92 N_COORDINATE_SYSTEM+2 // Coordinate offset (G92.2,G92.3 not supported)
// Define Grbl axis settings numbering scheme. Starts at START_VAL, every INCREMENT, over N_SETTINGS. // Define Grbl axis settings numbering scheme. Starts at START_VAL, every INCREMENT, over N_SETTINGS.
#define AXIS_N_SETTINGS 4 #define AXIS_N_SETTINGS 5
#define AXIS_SETTINGS_START_VAL 100 // NOTE: Reserving settings values >= 100 for axis settings. Up to 255. #define AXIS_SETTINGS_START_VAL 100 // NOTE: Reserving settings values >= 100 for axis settings. Up to 255.
#define AXIS_SETTINGS_INCREMENT 10 // Must be greater than the number of axis settings #define AXIS_SETTINGS_INCREMENT 10 // Must be greater than the number of axis settings
@ -95,6 +95,8 @@ typedef struct {
float acceleration[N_AXIS]; float acceleration[N_AXIS];
float max_travel[N_AXIS]; float max_travel[N_AXIS];
float backlash[N_AXIS];
// Remaining Grbl settings // Remaining Grbl settings
// TODO: document system_flags // TODO: document system_flags
uint8_t system_flags; uint8_t system_flags;

Wyświetl plik

@ -97,6 +97,8 @@ typedef struct {
uint8_t st_block_index; // Stepper block data index. Uses this information to execute this segment. uint8_t st_block_index; // Stepper block data index. Uses this information to execute this segment.
uint8_t amass_level; // Indicates AMASS level for the ISR to execute this segment uint8_t amass_level; // Indicates AMASS level for the ISR to execute this segment
uint8_t spindle_pwm; uint8_t spindle_pwm;
uint8_t backlash_motion;
} Stepper_Segment_t; } Stepper_Segment_t;
@ -222,6 +224,7 @@ void Stepper_Init(void)
TIM9_Init(); TIM9_Init();
} }
// Stepper state initialization. Cycle should only start if the st.cycle_start flag is // Stepper state initialization. Cycle should only start if the st.cycle_start flag is
// enabled. Startup init and limits call this function but shouldn't start the cycle. // enabled. Startup init and limits call this function but shouldn't start the cycle.
void Stepper_WakeUp(void) void Stepper_WakeUp(void)
@ -444,12 +447,15 @@ void Stepper_MainISR(void)
st.step_outbits |= (1<<X_STEP_BIT); st.step_outbits |= (1<<X_STEP_BIT);
st.counter_x -= st.exec_block->step_event_count; st.counter_x -= st.exec_block->step_event_count;
if(st.exec_block->direction_bits & (1<<X_DIRECTION_BIT)) { if(st.exec_segment->backlash_motion == 0)
sys_position[X_AXIS]--; {
} if(st.exec_block->direction_bits & (1<<X_DIRECTION_BIT)) {
else { sys_position[X_AXIS]--;
sys_position[X_AXIS]++; }
} else {
sys_position[X_AXIS]++;
}
}
} }
st.counter_y += st.steps[Y_AXIS]; st.counter_y += st.steps[Y_AXIS];
@ -458,12 +464,15 @@ void Stepper_MainISR(void)
st.step_outbits |= (1<<Y_STEP_BIT); st.step_outbits |= (1<<Y_STEP_BIT);
st.counter_y -= st.exec_block->step_event_count; st.counter_y -= st.exec_block->step_event_count;
if(st.exec_block->direction_bits & (1<<Y_DIRECTION_BIT)) { if(st.exec_segment->backlash_motion == 0)
sys_position[Y_AXIS]--; {
} if(st.exec_block->direction_bits & (1<<Y_DIRECTION_BIT)) {
else { sys_position[Y_AXIS]--;
sys_position[Y_AXIS]++; }
} else {
sys_position[Y_AXIS]++;
}
}
} }
st.counter_z += st.steps[Z_AXIS]; st.counter_z += st.steps[Z_AXIS];
@ -472,12 +481,15 @@ void Stepper_MainISR(void)
st.step_outbits |= (1<<Z_STEP_BIT); st.step_outbits |= (1<<Z_STEP_BIT);
st.counter_z -= st.exec_block->step_event_count; st.counter_z -= st.exec_block->step_event_count;
if(st.exec_block->direction_bits & (1<<Z_DIRECTION_BIT)) { if(st.exec_segment->backlash_motion == 0)
sys_position[Z_AXIS]--; {
} if(st.exec_block->direction_bits & (1<<Z_DIRECTION_BIT)) {
else { sys_position[Z_AXIS]--;
sys_position[Z_AXIS]++; }
} else {
sys_position[Z_AXIS]++;
}
}
} }
// During a homing cycle, lock out and prevent desired axes from moving. // During a homing cycle, lock out and prevent desired axes from moving.
@ -859,6 +871,8 @@ void Stepper_PrepareBuffer(void)
// Set new segment to point to the current segment data block. // Set new segment to point to the current segment data block.
prep_segment->st_block_index = prep.st_block_index; prep_segment->st_block_index = prep.st_block_index;
prep_segment->backlash_motion = pl_block->backlash_motion;
/*------------------------------------------------------------------------------------ /*------------------------------------------------------------------------------------
Compute the average velocity of this new segment by determining the total distance Compute the average velocity of this new segment by determining the total distance
traveled over the segment time DT_SEGMENT. The following code first attempts to create traveled over the segment time DT_SEGMENT. The following code first attempts to create

Wyświetl plik

@ -33,22 +33,26 @@
#define DEFAULT_X_STEPS_PER_MM 400.0 #define DEFAULT_X_STEPS_PER_MM 400.0
#define DEFAULT_Y_STEPS_PER_MM 400.0 #define DEFAULT_Y_STEPS_PER_MM 400.0
#define DEFAULT_Z_STEPS_PER_MM 400.0 #define DEFAULT_Z_STEPS_PER_MM 400.0
#define DEFAULT_X_MAX_RATE 1000.0 // mm/min #define DEFAULT_X_MAX_RATE 2000.0 // mm/min
#define DEFAULT_Y_MAX_RATE 1000.0 // mm/min #define DEFAULT_Y_MAX_RATE 2000.0 // mm/min
#define DEFAULT_Z_MAX_RATE 1000.0 // mm/min #define DEFAULT_Z_MAX_RATE 2000.0 // mm/min
#define DEFAULT_X_ACCELERATION (20.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 #define DEFAULT_X_ACCELERATION (30.0*60*60) // 30*60*60 mm/min^2 = 30 mm/sec^2
#define DEFAULT_Y_ACCELERATION (20.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 #define DEFAULT_Y_ACCELERATION (30.0*60*60) // 30*60*60 mm/min^2 = 30 mm/sec^2
#define DEFAULT_Z_ACCELERATION (20.0*60*60) // 10*60*60 mm/min^2 = 10 mm/sec^2 #define DEFAULT_Z_ACCELERATION (30.0*60*60) // 30*60*60 mm/min^2 = 30 mm/sec^2
#define DEFAULT_X_MAX_TRAVEL 400.0 // mm NOTE: Must be a positive value. #define DEFAULT_X_MAX_TRAVEL 600.0 // mm NOTE: Must be a positive value.
#define DEFAULT_Y_MAX_TRAVEL 400.0 // mm NOTE: Must be a positive value. #define DEFAULT_Y_MAX_TRAVEL 400.0 // mm NOTE: Must be a positive value.
#define DEFAULT_Z_MAX_TRAVEL 400.0 // mm NOTE: Must be a positive value. #define DEFAULT_Z_MAX_TRAVEL 600.0 // mm NOTE: Must be a positive value.
#define DEFAULT_SPINDLE_RPM_MAX 1000.0 // rpm #define DEFAULT_SPINDLE_RPM_MAX 3000.0 // rpm
#define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm #define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm
#define DEFAULT_X_BACKLASH 0.05 // mm
#define DEFAULT_Y_BACKLASH 0.05 // mm
#define DEFAULT_Z_BACKLASH 0.05 // mm
#define DEFAULT_SYSTEM_INVERT_MASK 0 #define DEFAULT_SYSTEM_INVERT_MASK 0
#define DEFAULT_STEPPING_INVERT_MASK 0 #define DEFAULT_STEPPING_INVERT_MASK 0
#define DEFAULT_DIRECTION_INVERT_MASK 4 // Invert Z-Axis #define DEFAULT_DIRECTION_INVERT_MASK 4 // Invert Z-Axis
#define DEFAULT_STEPPER_IDLE_LOCK_TIME 25 // msec (0-254, 255 keeps steppers enabled) #define DEFAULT_STEPPER_IDLE_LOCK_TIME 50 // msec (0-254, 255 keeps steppers enabled)
#define DEFAULT_STATUS_REPORT_MASK 1 // MPos enabled #define DEFAULT_STATUS_REPORT_MASK 1 // MPos enabled
#define DEFAULT_JUNCTION_DEVIATION 0.01 // mm #define DEFAULT_JUNCTION_DEVIATION 0.01 // mm
#define DEFAULT_ARC_TOLERANCE 0.001 // mm #define DEFAULT_ARC_TOLERANCE 0.001 // mm
@ -59,7 +63,7 @@
#define DEFAULT_HARD_LIMIT_ENABLE 1 // false #define DEFAULT_HARD_LIMIT_ENABLE 1 // false
#define DEFAULT_INVERT_PROBE_PIN 0 // false #define DEFAULT_INVERT_PROBE_PIN 0 // false
#define DEFAULT_LASER_MODE 0 // false #define DEFAULT_LASER_MODE 0 // false
#define DEFAULT_HOMING_ENABLE 0 // false #define DEFAULT_HOMING_ENABLE 1 // false
#define DEFAULT_HOMING_DIR_MASK 0 // move positive dir #define DEFAULT_HOMING_DIR_MASK 0 // move positive dir
#define DEFAULT_HOMING_FEED_RATE 50.0 // mm/min #define DEFAULT_HOMING_FEED_RATE 50.0 // mm/min
#define DEFAULT_HOMING_SEEK_RATE 500.0 // mm/min #define DEFAULT_HOMING_SEEK_RATE 500.0 // mm/min