Skip to content

Commit 48b6766

Browse files
committed
Small improvements; Updated docs
Signed-off-by: Patrick Felixberger <[email protected]>
1 parent c6916ce commit 48b6766

File tree

11 files changed

+59
-43
lines changed

11 files changed

+59
-43
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
bin/*
22
obj/*
3+
build/*
34
*.depend
45
*.layout
56
grbl-master
7+
*.hex
8+
*.bin
9+
*.elf
10+
*.lst
11+
*.map

HAL/GPIO/GPIO.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* D12: Z_LIMIT_BIT: PA6
1313
* D13: SPINDLE_DIRECTION_BIT: PA5
1414
* D14: SPINDLE_ENABLE_BIT: PB7
15-
* D15: SAFETY_DOOR_ENABLE_BIT: PB8
15+
* D15: SAFETY_DOOR_ENABLE_BIT: PC2
1616
*
1717
* A0: CONTROL_RESET_BIT: PA0
1818
* A1: CONTROL_FEED_HOLD_BIT: PA1
@@ -195,6 +195,7 @@ static void GPIO_InitSystem(void)
195195
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
196196
GPIO_Init(GPIOA, &GPIO_InitStructure);
197197

198-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
199-
GPIO_Init(GPIOB, &GPIO_InitStructure);
198+
// Safety door
199+
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
200+
GPIO_Init(GPIOC, &GPIO_InitStructure);
200201
}

HAL/GPIO/GPIO.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
#define GPIO_SPINDLE_ENA_PIN GPIO_Pin_7
6868

6969
// Safety door
70-
#define GPIO_DOOR_PORT GPIOB
71-
#define GPIO_DOOR_PIN GPIO_Pin_8
70+
#define GPIO_DOOR_PORT GPIOC
71+
#define GPIO_DOOR_PIN GPIO_Pin_2
7272

7373
// Control pins
7474
#define GPIO_CTRL_RST_PORT GPIOA

HAL/STM32/stm32f4xx_it.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void SysTick_Handler(void)
281281
MC_UpdateSyncMove();
282282
}
283283

284-
if(gMillis%25 == 0)
284+
if(gMillis%32 == 0)
285285
{
286286
// 25ms Task (min 7 RPM)
287287
uint16_t cnt = (uint16_t)Encoder_GetValue();
@@ -299,7 +299,7 @@ void SysTick_Handler(void)
299299
}
300300

301301
// Calculate RPM and smooth it
302-
float rpm = ((cnt_diff * 40.0) / PULSES_PER_REV) * 60.0;
302+
float rpm = ((cnt_diff * 31.25) / PULSES_PER_REV) * 60.0;
303303
rpm_arr[rpm_idx++] = (uint32_t)rpm;
304304
if(rpm_idx > (RPM_FILTER_NUM-1))
305305
{

Makefile

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,22 @@ SOURCES := ./ ARM/cmsis/ grbl/ HAL/ HAL/EXTI HAL/FLASH HAL/GPIO HAL/I2C HAL/SPI
3232

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

35-
LD_FILE = stm32f411re_flash.ld
36-
DEFINES = -DSTM32F411xE -DSTM32F411RE
37-
38-
#LD_FILE = stm32f446re_flash.ld
39-
#DEFINES = -DSTM32F446xx -DSTM32F446RE
35+
# STM32 F446
36+
ifeq ($(target),F446)
37+
LD_FILE = stm32f446re_flash.ld
38+
DEFINES = -DSTM32F446xx -DSTM32F446RE
39+
TARGET_STR = "STM32 F446"
40+
# STM32 F411
41+
else ifeq ($(target),F411)
42+
LD_FILE = stm32f411re_flash.ld
43+
DEFINES = -DSTM32F411xE -DSTM32F411RE
44+
TARGET_STR = "STM32 F411"
45+
else
46+
# Default Target
47+
LD_FILE = stm32f446re_flash.ld
48+
DEFINES = -DSTM32F446xx -DSTM32F446RE
49+
TARGET_STR = "STM32 F446"
50+
endif
4051

4152
#---------------------------------------------------------------------------------
4253
# options for code generation
@@ -110,8 +121,9 @@ export OUTPUT := $(CURDIR)/$(TARGET)
110121

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

117129
#---------------------------------------------------------------------------------

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ sudo apt install build-essential stlink-tools
9898
* Clone repository and run following commands:
9999
```
100100
make clean
101-
make all flash
101+
102+
# Choose a target
103+
make target=F446
104+
make target=F411
105+
106+
make flash
102107
```
103108

104109
***

grbl/Config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#define CONFIG_H
2929

3030

31-
#define GRBL_VERSION "1.1i"
31+
#define GRBL_VERSION "1.1j"
3232
#define GRBL_VERSION_BUILD __DATE__
3333

3434

grbl/GCode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC
66
Copyright (c) 2009-2011 Simen Svale Skogsrud
7-
Copyright (c) 2018-2020 Patrick F.
7+
Copyright (c) 2018-2024 Patrick F.
88
99
Grbl-Advanced is free software: you can redistribute it and/or modify
1010
it under the terms of the GNU General Public License as published by

grbl/MotionControl.c

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC
66
Copyright (c) 2009-2011 Simen Svale Skogsrud
7-
Copyright (c) 2017-2020 Patrick F.
7+
Copyright (c) 2017-2024 Patrick F.
88
99
Grbl-Advanced is free software: you can redistribute it and/or modify
1010
it under the terms of the GNU General Public License as published by
@@ -48,15 +48,15 @@ static uint8_t dir_negative[N_AXIS] = {DIR_NEGATIV};
4848
static uint8_t backlash_enable = 0;
4949

5050
// Sync move
51-
int32_t pos_z = 0;
51+
static int32_t pos_z = 0;
5252
static volatile uint8_t wait_spindle = 0;
5353
static uint8_t start_sync = 0;
5454
static uint16_t enc_cnt_prev = 0;
5555
static uint32_t EncValue = 0;
5656
static float sync_pitch = 0.0;
5757

58-
float in = 0.0, out = 0.0, set = 0.0;
59-
PID_t pid;
58+
static float in = 0.0, out = 0.0, set = 0.0;
59+
static PID_t pid;
6060

6161

6262
void MC_Init(void)
@@ -78,7 +78,7 @@ void MC_Init(void)
7878
}
7979

8080
PID_Create(&pid, &in, &out, &set, 1.8, 22, 0.08);
81-
PID_Limits(&pid, -0.4, 0.4);
81+
PID_Limits(&pid, -0.7, 0.7);
8282
PID_EnableAuto(&pid);
8383

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

263263
sync_pitch = pitch;
264264

265-
if(pitch < 1.1)
266-
{
267-
PID_Tune(&pid, 1.8, 22, 0.08);
268-
}
269-
else if(pitch < 1.6)
270-
{
271-
PID_Tune(&pid, 1.6, 18, 0.06);
272-
}
273-
else
274-
{
275-
PID_Tune(&pid, 1.4, 15, 0.04);
276-
}
265+
PID_Tune(&pid, 20, 130.0, 0.0);
277266

278267
// Disable feed override
279268
sys.f_override = DEFAULT_FEED_OVERRIDE;
@@ -395,9 +384,6 @@ void MC_UpdateSyncMove(void)
395384

396385
// Apply
397386
Stepper_Ovr(out);
398-
399-
/*Printf("err %d\r\n", (int)(1000*in));
400-
Printf_Flush();*/
401387
}
402388
}
403389
}

grbl/Stepper.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@
5656
// Level 1 cutoff frequency and up to as fast as the CPU allows (over 30kHz in limited testing).
5757
// NOTE: AMASS cutoff frequency multiplied by ISR overdrive factor must not exceed maximum step frequency.
5858
// NOTE: Current settings are set to overdrive the ISR to no more than 16kHz, balancing CPU overhead
59-
// and timer accuracy. Do not alter these settings unless you know what you are doing.
60-
#define MAX_AMASS_LEVEL 3
59+
// and timer accuracy. Do not alter these settings unless you know what you are doing.
60+
#define MAX_AMASS_LEVEL 4
6161
// AMASS_LEVEL0: Normal operation. No AMASS. No upper cutoff frequency. Starts at LEVEL1 cutoff frequency.
62-
#define AMASS_LEVEL1 (uint32_t)(F_TIMER_STEPPER/8000) // Over-drives ISR (x2). Defined as F_CPU/(Cutoff frequency in Hz)
63-
#define AMASS_LEVEL2 (uint32_t)(F_TIMER_STEPPER/4000) // Over-drives ISR (x4)
64-
#define AMASS_LEVEL3 (uint32_t)(F_TIMER_STEPPER/2000) // Over-drives ISR (x8)
62+
#define AMASS_LEVEL1 (uint32_t)(F_TIMER_STEPPER / 8000) // Over-drives ISR (x2). Defined as F_CPU/(Cutoff frequency in Hz)
63+
#define AMASS_LEVEL2 (uint32_t)(F_TIMER_STEPPER / 4000) // Over-drives ISR (x4)
64+
#define AMASS_LEVEL3 (uint32_t)(F_TIMER_STEPPER / 2000) // Over-drives ISR (x8)
65+
#define AMASS_LEVEL4 (uint32_t)(F_TIMER_STEPPER / 1000) // Over-drives ISR (x16)
6566

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

7678
#define G96_UPDATE_CNT 20
@@ -1363,10 +1365,14 @@ void Stepper_PrepareBuffer(void)
13631365
{
13641366
prep_segment->amass_level = 2;
13651367
}
1366-
else
1368+
else if (cycles < AMASS_LEVEL4)
13671369
{
13681370
prep_segment->amass_level = 3;
13691371
}
1372+
else
1373+
{
1374+
prep_segment->amass_level = 4;
1375+
}
13701376

13711377
cycles >>= prep_segment->amass_level;
13721378
prep_segment->n_step <<= prep_segment->amass_level;

0 commit comments

Comments
 (0)