fix upload not working

This commit is contained in:
2021-06-29 20:23:38 +03:00
parent 4621c3db8b
commit 54c8417f9d
2 changed files with 28 additions and 21 deletions

View File

@@ -22,21 +22,24 @@ board_hardware.oscillator = external
board_hardware.uart = no_bootloader board_hardware.uart = no_bootloader
; Brown-out detection ; Brown-out detection
board_hardware.bod = 2.7v board_hardware.bod = 2.7v
build_unflags = -flto
; specify fuses because platformio burns wrong ones when uploading
; actually this doesn't help?
; for whatever reason avrdude gives an error if you don't upload
; just after flashing fuses
board_fuse.lfuse = 0xf7
board_fuse.hfuse = 0xd7
board_fuse.efuse = 0xfd
board_upload.speed = 115200 board_upload.speed = 115200
monitor_speed = 9600 monitor_speed = 9600
upload_protocol = stk500 ; Custom upload procedure
upload_port = COM3 upload_protocol = custom
upload_flags = -PCOM3 ; Avrdude upload flags
upload_flags =
-C$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
-p$BOARD_MCU
-PCOM3
-cstk500
-e
; Avrdude upload command
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i
lib_deps = 883 #Servo lib_deps = 883 #Servo

View File

@@ -20,21 +20,21 @@ int calculateDelay(float rpm, int stepsPerRevolution) {
} }
void adjustRPM() { void adjustRPM() {
eggStepperRPM = curRPM; eggStepperDelay = calculateDelay(curRPM, STEPS_PER_REVOLUTION);
servoStepperRPM = curRPM; servoStepperDelay = calculateDelay(curRPM, STEPS_PER_REVOLUTION);
if (needAdjust) { if (needAdjust) {
unsigned int stepsX = servoStepper.getRemainingSteps(); unsigned int stepsX = servoStepper.getRemainingSteps();
unsigned int stepsY = eggStepper.getRemainingSteps(); unsigned int stepsY = eggStepper.getRemainingSteps();
if (stepsX != 0 && stepsY != 0) { if (stepsX != 0 && stepsY != 0) {
if (stepsX > stepsY) { if (stepsX > stepsY) {
eggStepperRPM = (float)curRPM * (float)stepsY / (float)stepsX; eggStepperDelay =
} else if (stepsY > stepsX) { (float)servoStepperDelay * (float)stepsY / (float)stepsX;
servoStepperRPM = (float)curRPM * (float)stepsX / (float)stepsY; } else {
servoStepperDelay =
(float)eggStepperDelay * (float)stepsX / (float)stepsY;
} }
} }
} }
eggStepperDelay = calculateDelay(eggStepperRPM, STEPS_PER_REVOLUTION);
servoStepperDelay = calculateDelay(servoStepperRPM, STEPS_PER_REVOLUTION);
} }
Command command; Command command;
@@ -77,8 +77,6 @@ void requestEvent() {
sts.toBytes(txBuffer); sts.toBytes(txBuffer);
Wire.write(txBuffer, i2cStsBytes); Wire.write(txBuffer, i2cStsBytes);
wdt_reset();
} }
void execCommand(Command cmd) { void execCommand(Command cmd) {
@@ -137,6 +135,7 @@ void setup() {
} }
volatile unsigned int tick = 0; volatile unsigned int tick = 0;
volatile bool newTick = false;
void steppersRoutine() { void steppersRoutine() {
if (tick % eggStepperDelay == 0) { if (tick % eggStepperDelay == 0) {
eggStepper.doStep(); eggStepper.doStep();
@@ -155,11 +154,16 @@ We use our own timer for more precise timings
*/ */
ISR(TIMER2_COMPA_vect) { ISR(TIMER2_COMPA_vect) {
tick++; tick++;
steppersRoutine(); newTick = true;
} }
void loop() { void loop() {
if (newCommand) { if (newCommand) {
execCommand(command); execCommand(command);
} }
if (newTick) {
steppersRoutine();
newTick = false;
}
wdt_reset();
} }