Skip to content

Commit

Permalink
Small improvements; Updated docs
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Felixberger <[email protected]>
  • Loading branch information
Schildkroet committed Feb 19, 2024
1 parent c6916ce commit 48b6766
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 43 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
bin/*
obj/*
build/*
*.depend
*.layout
grbl-master
*.hex
*.bin
*.elf
*.lst
*.map
7 changes: 4 additions & 3 deletions HAL/GPIO/GPIO.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* D12: Z_LIMIT_BIT: PA6
* D13: SPINDLE_DIRECTION_BIT: PA5
* D14: SPINDLE_ENABLE_BIT: PB7
* D15: SAFETY_DOOR_ENABLE_BIT: PB8
* D15: SAFETY_DOOR_ENABLE_BIT: PC2
*
* A0: CONTROL_RESET_BIT: PA0
* A1: CONTROL_FEED_HOLD_BIT: PA1
Expand Down Expand Up @@ -195,6 +195,7 @@ static void GPIO_InitSystem(void)
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// Safety door
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
4 changes: 2 additions & 2 deletions HAL/GPIO/GPIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
#define GPIO_SPINDLE_ENA_PIN GPIO_Pin_7

// Safety door
#define GPIO_DOOR_PORT GPIOB
#define GPIO_DOOR_PIN GPIO_Pin_8
#define GPIO_DOOR_PORT GPIOC
#define GPIO_DOOR_PIN GPIO_Pin_2

// Control pins
#define GPIO_CTRL_RST_PORT GPIOA
Expand Down
4 changes: 2 additions & 2 deletions HAL/STM32/stm32f4xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void SysTick_Handler(void)
MC_UpdateSyncMove();
}

if(gMillis%25 == 0)
if(gMillis%32 == 0)
{
// 25ms Task (min 7 RPM)
uint16_t cnt = (uint16_t)Encoder_GetValue();
Expand All @@ -299,7 +299,7 @@ void SysTick_Handler(void)
}

// Calculate RPM and smooth it
float rpm = ((cnt_diff * 40.0) / PULSES_PER_REV) * 60.0;
float rpm = ((cnt_diff * 31.25) / PULSES_PER_REV) * 60.0;
rpm_arr[rpm_idx++] = (uint32_t)rpm;
if(rpm_idx > (RPM_FILTER_NUM-1))
{
Expand Down
24 changes: 18 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,22 @@ SOURCES := ./ ARM/cmsis/ grbl/ HAL/ HAL/EXTI HAL/FLASH HAL/GPIO HAL/I2C HAL/SPI

INCLUDES := $(SOURCES) ARM/SPL/inc

LD_FILE = stm32f411re_flash.ld
DEFINES = -DSTM32F411xE -DSTM32F411RE

#LD_FILE = stm32f446re_flash.ld
#DEFINES = -DSTM32F446xx -DSTM32F446RE
# STM32 F446
ifeq ($(target),F446)
LD_FILE = stm32f446re_flash.ld
DEFINES = -DSTM32F446xx -DSTM32F446RE
TARGET_STR = "STM32 F446"
# STM32 F411
else ifeq ($(target),F411)
LD_FILE = stm32f411re_flash.ld
DEFINES = -DSTM32F411xE -DSTM32F411RE
TARGET_STR = "STM32 F411"
else
# Default Target
LD_FILE = stm32f446re_flash.ld
DEFINES = -DSTM32F446xx -DSTM32F446RE
TARGET_STR = "STM32 F446"
endif

#---------------------------------------------------------------------------------
# options for code generation
Expand Down Expand Up @@ -110,8 +121,9 @@ export OUTPUT := $(CURDIR)/$(TARGET)

#---------------------------------------------------------------------------------
all:
@echo "Building "$(TARGET_STR)"..."
@[ -d $(BUILD) ] || mkdir -p $(BUILD)
@make --no-print-directory -C $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(OUTPUT).hex $(OUTPUT).lst -f $(CURDIR)/Makefile -j3
@make --no-print-directory -C $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(OUTPUT).hex $(OUTPUT).lst -f $(CURDIR)/Makefile -j4
@$(SIZE) $(OUTPUT).elf

#---------------------------------------------------------------------------------
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ sudo apt install build-essential stlink-tools
* Clone repository and run following commands:
```
make clean
make all flash
# Choose a target
make target=F446
make target=F411
make flash
```

***
Expand Down
2 changes: 1 addition & 1 deletion grbl/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define CONFIG_H


#define GRBL_VERSION "1.1i"
#define GRBL_VERSION "1.1j"
#define GRBL_VERSION_BUILD __DATE__


Expand Down
2 changes: 1 addition & 1 deletion grbl/GCode.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC
Copyright (c) 2009-2011 Simen Svale Skogsrud
Copyright (c) 2018-2020 Patrick F.
Copyright (c) 2018-2024 Patrick F.
Grbl-Advanced is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
26 changes: 6 additions & 20 deletions grbl/MotionControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC
Copyright (c) 2009-2011 Simen Svale Skogsrud
Copyright (c) 2017-2020 Patrick F.
Copyright (c) 2017-2024 Patrick F.
Grbl-Advanced is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -48,15 +48,15 @@ static uint8_t dir_negative[N_AXIS] = {DIR_NEGATIV};
static uint8_t backlash_enable = 0;

// Sync move
int32_t pos_z = 0;
static int32_t pos_z = 0;
static volatile uint8_t wait_spindle = 0;
static uint8_t start_sync = 0;
static uint16_t enc_cnt_prev = 0;
static uint32_t EncValue = 0;
static float sync_pitch = 0.0;

float in = 0.0, out = 0.0, set = 0.0;
PID_t pid;
static float in = 0.0, out = 0.0, set = 0.0;
static PID_t pid;


void MC_Init(void)
Expand All @@ -78,7 +78,7 @@ void MC_Init(void)
}

PID_Create(&pid, &in, &out, &set, 1.8, 22, 0.08);
PID_Limits(&pid, -0.4, 0.4);
PID_Limits(&pid, -0.7, 0.7);
PID_EnableAuto(&pid);

pos_z = 0;
Expand Down Expand Up @@ -262,18 +262,7 @@ void MC_LineSync(float *target, Planner_LineData_t *pl_data, float pitch)

sync_pitch = pitch;

if(pitch < 1.1)
{
PID_Tune(&pid, 1.8, 22, 0.08);
}
else if(pitch < 1.6)
{
PID_Tune(&pid, 1.6, 18, 0.06);
}
else
{
PID_Tune(&pid, 1.4, 15, 0.04);
}
PID_Tune(&pid, 20, 130.0, 0.0);

// Disable feed override
sys.f_override = DEFAULT_FEED_OVERRIDE;
Expand Down Expand Up @@ -395,9 +384,6 @@ void MC_UpdateSyncMove(void)

// Apply
Stepper_Ovr(out);

/*Printf("err %d\r\n", (int)(1000*in));
Printf_Flush();*/
}
}
}
Expand Down
18 changes: 12 additions & 6 deletions grbl/Stepper.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@
// Level 1 cutoff frequency and up to as fast as the CPU allows (over 30kHz in limited testing).
// NOTE: AMASS cutoff frequency multiplied by ISR overdrive factor must not exceed maximum step frequency.
// NOTE: Current settings are set to overdrive the ISR to no more than 16kHz, balancing CPU overhead
// and timer accuracy. Do not alter these settings unless you know what you are doing.
#define MAX_AMASS_LEVEL 3
// and timer accuracy. Do not alter these settings unless you know what you are doing.
#define MAX_AMASS_LEVEL 4
// AMASS_LEVEL0: Normal operation. No AMASS. No upper cutoff frequency. Starts at LEVEL1 cutoff frequency.
#define AMASS_LEVEL1 (uint32_t)(F_TIMER_STEPPER/8000) // Over-drives ISR (x2). Defined as F_CPU/(Cutoff frequency in Hz)
#define AMASS_LEVEL2 (uint32_t)(F_TIMER_STEPPER/4000) // Over-drives ISR (x4)
#define AMASS_LEVEL3 (uint32_t)(F_TIMER_STEPPER/2000) // Over-drives ISR (x8)
#define AMASS_LEVEL1 (uint32_t)(F_TIMER_STEPPER / 8000) // Over-drives ISR (x2). Defined as F_CPU/(Cutoff frequency in Hz)
#define AMASS_LEVEL2 (uint32_t)(F_TIMER_STEPPER / 4000) // Over-drives ISR (x4)
#define AMASS_LEVEL3 (uint32_t)(F_TIMER_STEPPER / 2000) // Over-drives ISR (x8)
#define AMASS_LEVEL4 (uint32_t)(F_TIMER_STEPPER / 1000) // Over-drives ISR (x16)

#if MAX_AMASS_LEVEL <= 0
error "AMASS must have 1 or more levels to operate correctly."
Expand All @@ -71,6 +72,7 @@
#define STEP_TIMER_MIN (uint16_t)(F_TIMER_STEPPER / MAX_STEP_RATE_HZ)
#else
#define STEP_TIMER_MIN (uint16_t)((F_TIMER_STEPPER / 120000))
#pragma message("Max stepper rate: 120KHz")
#endif

#define G96_UPDATE_CNT 20
Expand Down Expand Up @@ -1363,10 +1365,14 @@ void Stepper_PrepareBuffer(void)
{
prep_segment->amass_level = 2;
}
else
else if (cycles < AMASS_LEVEL4)
{
prep_segment->amass_level = 3;
}
else
{
prep_segment->amass_level = 4;
}

cycles >>= prep_segment->amass_level;
prep_segment->n_step <<= prep_segment->amass_level;
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC
Copyright (c) 2009-2011 Simen Svale Skogsrud
Copyright (c) 2018-2020 Patrick F.
Copyright (c) 2018-2024 Patrick F.
Grbl-Advanced is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down

0 comments on commit 48b6766

Please sign in to comment.