Skip to content

Commit

Permalink
start with test case for issue #262
Browse files Browse the repository at this point in the history
  • Loading branch information
gin66 committed Jun 14, 2024
1 parent bc9501a commit 5348194
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ extras/tests/simavr_based/test_sd*/Makefile
extras/tests/simavr_based/test_seq*/Makefile
extras/tests/esp32_hw_based/*.log
library.properties
examples
75 changes: 75 additions & 0 deletions examples/Issue262/Issue262.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <FastAccelStepper.h>

#define stepPin 9
#define dirPin 5
#define USB_BAUD 250000

FastAccelStepperEngine engine = FastAccelStepperEngine();
FastAccelStepper *stepper = NULL;

const int32_t quickAcc = 100000 * 4;
const int32_t acc = 2000;
const int32_t minSpeed = 1;
const int32_t maxSpeed = 2000;

void memoryMix() {
delay(30);
}

void setup() {
engine.init();
stepper = engine.stepperConnectToPin(stepPin);
stepper->setDirectionPin(dirPin);
Serial.begin(USB_BAUD);
randomSeed(42);

}

void loop() {
uint32_t sp, oldSp;
int i, count;
long target;
// Serial.println("Starting");
target = random(minSpeed, maxSpeed);
stepper->setAcceleration(acc);
stepper->setSpeedInHz(target);
stepper->runForward();
while (stepper-> getCurrentSpeedInMilliHz()/1000 < target - 100)
{};
// Serial.println("Stopping");
stepper ->moveByAcceleration(-quickAcc, false);
stepper ->applySpeedAcceleration();
oldSp = stepper -> getCurrentSpeedInMilliHz();
count = 0;
while ((sp = stepper -> getCurrentSpeedInMilliHz()) != 0) {
count ++;
if (count > 20) {
Serial.print("No stop iter ");
Serial.print(count);
Serial.print(".");
if (!stepper -> isRunning())
Serial.print("isRunning() reports stopped");
Serial.println();
}
if (sp > oldSp) {
Serial.print("Speed moves wrong way ");
Serial.print(sp);
Serial.print(">");
Serial.print(oldSp);
Serial.println();
}
oldSp = sp;
memoryMix();
}
for (i =0; i< 100; i++) {
memoryMix();
sp = stepper-> getCurrentSpeedInMilliHz();
if (sp !=0) {
Serial.print("Speed error. Received value: ");
Serial.print(sp);
Serial.print(". Target speed was ");
Serial.print(target);
Serial.println();
}
}
}
1 change: 1 addition & 0 deletions extras/tests/simavr_based/test_issue262/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/
132 changes: 132 additions & 0 deletions extras/tests/simavr_based/test_issue262/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#
# In order to execute the test for one directory use:
#
# make -C test_sd_01b_328p -f ../Makefile.test

SRC=$(wildcard ../../../src/*) $(wildcard src/*)

# platformio should contain only one env section.
# This section states the dut name
# atmega168
# atmega168p
# atmega328
# atmega328p
# atmega2560_timer1
# atmega2560_timer3
# atmega2560_timer4
# atmega2560_timer5
#

DUT=$(shell gawk '/env:/{print(substr($$1,6,length($$1)-6))}' platformio.ini)

TRACES=-at StepISR=trace@0x25/0x08 # PB3
TRACES+=-at FillISR=trace@0x25/0x10 # PB4

#
ifeq ($(DUT),atmega2560_timer1)
DEVICE=atmega2560
TRACES+=-at StepA=trace@0x025/0x20 #OC1A PB5 11 ATMega2560
TRACES+=-at StepB=trace@0x025/0x40 #OC1B PB6 12 ATMega2560
TRACES+=-at StepC=trace@0x025/0x80 #OC1C PB7 13 ATMega2560
#
else ifeq ($(DUT),atmega2560_timer3)
DEVICE=atmega2560
TRACES+=-at StepA=trace@0x02e/0x08 #OC3A PE3 5 ATMega2560
TRACES+=-at StepB=trace@0x02e/0x10 #OC3B PE4 2 ATMega2560
TRACES+=-at StepC=trace@0x02e/0x20 #OC3C PE5 3 ATMega2560
#
else ifeq ($(DUT),atmega2560_timer4)
DEVICE=atmega2560
TRACES+=-at StepA=trace@0x102/0x08 #OC4A PH3 6 ATMega2560
TRACES+=-at StepB=trace@0x102/0x10 #OC4B PH4 7 ATMega2560
TRACES+=-at StepC=trace@0x102/0x20 #OC4C PH5 8 ATMega2560
#
else ifeq ($(DUT),atmega2560_timer5)
DEVICE=atmega2560
TRACES+=-at StepA=trace@0x10b/0x08 #OC5A PL3 46 ATMega2560
TRACES+=-at StepB=trace@0x10b/0x10 #OC5B PL4 45 ATMega2560
TRACES+=-at StepC=trace@0x10b/0x20 #OC5C PL5 44 ATMega2560

else ifeq ($(DUT),atmega168)
DEVICE=atmega168
TRACES+=-at StepA=trace@0x25/0x02 #OC1A PB1 9 atmega168
TRACES+=-at StepB=trace@0x25/0x04 #OC1B PB2 10 atmega168

else ifeq ($(DUT),atmega168p)
DEVICE=atmega168p
TRACES+=-at StepA=trace@0x25/0x02 #OC1A PB1 9 atmega168p
TRACES+=-at StepB=trace@0x25/0x04 #OC1B PB2 10 atmega168p

else ifeq ($(DUT),atmega328)
DEVICE=atmega328
TRACES+=-at StepA=trace@0x25/0x02 #OC1A PB1 9 ATMega328
TRACES+=-at StepB=trace@0x25/0x04 #OC1B PB2 10 ATMega328

else ifeq ($(DUT),atmega328p)
DEVICE=atmega328p
TRACES+=-at StepA=trace@0x25/0x02 #OC1A PB1 9 ATMega328p
TRACES+=-at StepB=trace@0x25/0x04 #OC1B PB2 10 ATMega328p

else ifeq ($(DUT),atmega32u4)
DEVICE=atmega32u4
TRACES+=-at StepA=trace@0x025/0x20 #OC1A PB5 11
TRACES+=-at StepB=trace@0x025/0x40 #OC1B PB6 12
#TRACES+=-at StepC=trace@0x025/0x80 #OC1C PB7 13

endif

ifeq ($(DEVICE),atmega2560)
TRACES+=-at DirA=trace@0x2b/0x01 # Pin 21 PD0
TRACES+=-at DirB=trace@0x2b/0x02 # Pin 20 PD1
TRACES+=-at DirC=trace@0x10b/0x80 # Pin 42 PL7
TRACES+=-at EnableA=trace@0x2b/0x04 # Pin 19 PD2
TRACES+=-at EnableB=trace@0x2b/0x08 # Pin 18 PD3
TRACES+=-at EnableC=trace@0x10b/0x40 # Pin 43 PL6

else ifeq ($(DEVICE),$(filter $(DEVICE),atmega168 atmega168p atmega328 atmega328p))
TRACES+=-at DirA=trace@0x2b/0x20 # Pin 5 PD5
TRACES+=-at DirB=trace@0x2b/0x80 # Pin 7 PD7
TRACES+=-at EnableA=trace@0x2b/0x40 # Pin 6 PD6
TRACES+=-at EnableB=trace@0x25/0x01 # Pin 8 PB0

else ifeq ($(DUT),atmega32u4)
TRACES+=-at DirA=trace@0x25/0x10 # Pin 26 PB4
TRACES+=-at DirB=trace@0x25/0x08 # Pin 14 PB3
#TRACES+=-at DirC=trace@0x10b/0x80 # Pin 42 PL7
TRACES+=-at EnableA=trace@0x25/0x04 # Pin 16 PB2
TRACES+=-at EnableB=trace@0x25/0x02 # Pin 15 PB1
#TRACES+=-at EnableC=trace@0x10b/0x40 # Pin 43 PL6

endif

FIRMWARE=".pio/build/$(DUT)/firmware.elf"

DIR=$(shell env pwd)

ifndef SILENCE
SILENCE=0
endif

test: .tested

.tested: result.txt expect.txt ../judge.awk
echo DUT=$(DUT)
rm -f .tested
gawk -f ../judge.awk -v DIR=$(DIR) result.txt expect.txt
test -f .tested

result.txt: x.vcd
gawk -v SILENCE=$(SILENCE) -f ../eval.awk x.vcd >/dev/null
cat expect.txt

x.vcd: $(SRC) ../run_avr platformio.ini src/Issue262.ino
~/.platformio/penv/bin/pio run -e $(DUT) || ~/.local/bin/pio run -e $(DUT) || env pio run -e $(DUT)
../run_avr $(FIRMWARE) -m $(DEVICE) -o x.vcd $(TRACES)

src/Issue262.ino:
mkdir -p src
cd src; ln -s ../../../../../examples/Issue262/Issue262.ino .

clean:
rm -fR .pio .tested x.vcd result.txt

Empty file.
31 changes: 31 additions & 0 deletions extras/tests/simavr_based/test_issue262/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]

# There should be only one env section for the DUT under test.
# One of
# atmega168p
# atmega328p
# atmega2560_timer1
# atmega2560_timer3
# atmega2560_timer4
# atmega2560_timer5
#
[common]
# This is the line input to StepperDemo:
build_flags = -D SIMULATOR -D SIMAVR_TIME_MEASUREMENT

[env:atmega328p]
platform = atmelavr
board = nanoatmega328
framework = arduino
build_flags = -Werror -Wall ${common.build_flags}
lib_extra_dirs = ../../../../..

0 comments on commit 5348194

Please sign in to comment.