Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ATmega168, ATmega168P, and ATmega328 #179

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/build_examples_nanoatmega168.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build examples for Atmega168

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Make directories
run: bash extras/scripts/build-pio-dirs.sh
- name: Build on PlatformIO
run: bash extras/scripts/build-platformio.sh nanoatmega168

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ No issue with platformio. Check the [related issue](https://github.com/arduino/l
[![Build examples for esp32arduino @ latest](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_esp32arduinolatest.yml/badge.svg)](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_esp32arduinolatest.yml)
[![Build examples for Atmega2560](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_atmega2560.yml/badge.svg)](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_atmega2560.yml)
[![Build examples for Atmel SAM](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_atmelsam.yml/badge.svg)](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_atmelsam.yml)
[![Build examples for Atmega328](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_nanoatmega328.yml/badge.svg)](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_nanoatmega328.yml)
[![Build examples for Atmega168/328](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_nanoatmega328.yml/badge.svg)](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_nanoatmega328.yml)
[![Build examples for Atmega32U4](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_atmega32u4.yml/badge.svg)](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_nanoatmega32u4.yml)

This is a high speed alternative for the [AccelStepper library](http://www.airspayce.com/mikem/arduino/AccelStepper/).
Supported are avr (ATmega 328, ATmega2560, ATmega32u4), esp32, esp32s2, esp32s3 and atmelsam due.
Supported are avr (ATmega 168/328/P, ATmega2560, ATmega32u4), esp32, esp32s2, esp32s3 and atmelsam due.

The stepper motors should be connected via a driver IC (like A4988) with a 1, 2 or 3-wire connection:
* Step Signal
- avr atmega328p: only Pin 9 and 10.
- avr atmega168/328/p: only Pin 9 and 10.
- avr atmega32u4: only Pin 9, 10 and 11.
- avr atmega2560: only Pin 6, 7 and 8.
On platformio, this can be changed to other triples: 11/12/13 Timer 1, 5/2/3 Timer 3 or 46/45/44 Timer 5 with FAS_TIMER_MODULE setting.
Expand Down Expand Up @@ -104,7 +104,7 @@ Comments to pin sharing:
Every motor will adhere to its auto enable delay, even if other motors already have enabled the pin.
* Direction pin sharing: The direction pin will be exclusively driven by one motor. If one motor is operating, another motor will wait until the direction pin comes available

### AVR ATMega 328
### AVR ATMega 168/168P/328/328P

* allows up to 50000 generated steps per second for single stepper operation, 37000 for dual stepper
* supports up to two stepper motors using Step/Direction/Enable Control (Direction and Enable is optional)
Expand Down Expand Up @@ -224,7 +224,7 @@ Few comments to auto enable/disable:

## Behind the curtains

### AVR ATmega328 and Atmega32u4
### AVR ATmega168/328 and Atmega32u4

The timer 1 is used with prescaler 1. With the arduino nano running at 16 MHz, timer overflow interrupts are generated every ~4 ms. This timer overflow interrupt is used for adjusting the speed.

Expand Down
6 changes: 4 additions & 2 deletions examples/Issue150/Issue150.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include <avr/sleep.h>
#endif

#if defined(__AVR_ATmega328P__)
#if (defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || \
defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__))
#include "AVRStepperPins.h"
#define dirPinStepperAVR 5
#define stepPinStepperAVR stepPinStepper1A
Expand All @@ -23,7 +24,8 @@ void setup() {
engine.init();

// pins are set to outputs here automatically
#if defined(__AVR_ATmega328P__)
#if (defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || \
defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__))
stepper = engine.stepperConnectToPin(stepPinStepperAVR);
stepper->setDirectionPin(dirPinStepperAVR);
stepper->setEnablePin(enablePinStepperAVR, true);
Expand Down
6 changes: 4 additions & 2 deletions examples/Issue151/Issue151.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include <avr/sleep.h>
#endif

#if defined(__AVR_ATmega328P__)
#if (defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || \
defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__))
#include "AVRStepperPins.h"
#define dirPinStepperAVR 5
#define stepPinStepperAVR stepPinStepper1A
Expand All @@ -23,7 +24,8 @@ void setup() {
engine.init();

// pins are set to outputs here automatically
#if defined(__AVR_ATmega328P__)
#if (defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || \
defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__))
stepper = engine.stepperConnectToPin(stepPinStepperAVR);
stepper->setDirectionPin(dirPinStepperAVR);
stepper->setEnablePin(enablePinStepperAVR, true);
Expand Down
6 changes: 4 additions & 2 deletions examples/Issue152/Issue152.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include <avr/sleep.h>
#endif

#if defined(__AVR_ATmega328P__)
#if (defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || \
defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__))
#include "AVRStepperPins.h"
#define dirPinStepperAVR 5
#define stepPinStepperAVR stepPinStepper1A
Expand All @@ -23,7 +24,8 @@ void setup() {
engine.init();

// pins are set to outputs here automatically
#if defined(__AVR_ATmega328P__)
#if (defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || \
defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__))
stepper = engine.stepperConnectToPin(stepPinStepperAVR);
stepper->setDirectionPin(dirPinStepperAVR);
stepper->setEnablePin(enablePinStepperAVR, true);
Expand Down
6 changes: 4 additions & 2 deletions examples/Issue172/Issue172.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include <avr/sleep.h>
#endif

#if defined(__AVR_ATmega328P__)
#if (defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || \
defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__))
#include "AVRStepperPins.h"
#define dirPinStepperAVR 5
#define stepPinStepperAVR stepPinStepper1A
Expand All @@ -23,7 +24,8 @@ void setup() {
engine.init();

// pins are set to outputs here automatically
#if defined(__AVR_ATmega328P__)
#if (defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || \
defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__))
stepper = engine.stepperConnectToPin(stepPinStepperAVR);
stepper->setDirectionPin(dirPinStepperAVR);
stepper->setEnablePin(enablePinStepperAVR, true);
Expand Down
6 changes: 4 additions & 2 deletions examples/Issue173/Issue173.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include <avr/sleep.h>
#endif

#if defined(__AVR_ATmega328P__)
#if (defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || \
defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__))
#include "AVRStepperPins.h"
#define dirPinStepperAVR 5
#define stepPinStepperAVR stepPinStepper1A
Expand All @@ -24,7 +25,8 @@ void setup() {
engine.init();

// pins are set to outputs here automatically
#if defined(__AVR_ATmega328P__)
#if (defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || \
defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__))
stepper = engine.stepperConnectToPin(stepPinStepperAVR);
stepper->setDirectionPin(dirPinStepperAVR);
stepper->setEnablePin(enablePinStepperAVR, true);
Expand Down
3 changes: 2 additions & 1 deletion examples/StepperDemo/StepperDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ struct stepper_config_s {
};

#if defined(ARDUINO_ARCH_AVR)
#if defined(__AVR_ATmega328P__)
#if (defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || \
defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__))
// Example hardware configuration for Arduino Nano
// Please adapt to your configuration
const uint8_t led_pin = 13; // turn off with PIN_UNDEFINED
Expand Down
7 changes: 7 additions & 0 deletions extras/ci/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ build_flags = -Werror -Wall -Wno-deprecated-declarations -Wno-error=incompatible
board_build.f_cpu = 240000000L
lib_extra_dirs = ../../..

[env:nanoatmega168]
platform = atmelavr
board = nanoatmega168
framework = arduino
build_flags = -Werror -Wall -Wno-deprecated-declarations
lib_extra_dirs = ../../..

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
Expand Down
18 changes: 9 additions & 9 deletions extras/doc/FastAccelStepper_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

FastAccelStepper is a high speed alternative for the
[AccelStepper library](http:www.airspayce.com/mikem/arduino/AccelStepper/).
Supported are avr (ATmega 328, ATmega2560), esp32 and atmelsam due.
Supported are avr (ATmega 168/328/P, ATmega2560), esp32 and atmelsam due.

Here is a basic example to run a stepper from position 0 to 1000 and back
again to 0.
Expand Down Expand Up @@ -79,14 +79,14 @@ This call allows to select the respective driver
```
Comments to valid pins:

| Device | Comment |
|:-----------|:--------------------------------------------------------------------------------------------------|
| ESP32  | Every output capable GPIO can be used |
| ESP32S2  | Every output capable GPIO can be used |
| Atmega328p | Only the pins connected to OC1A and OC1B are allowed |
| Atmega2560 | Only the pins connected to OC4A, OC4B and OC4C are allowed. |
| Atmega32u4 | Only the pins connected to OC1A, OC1B and OC1C are allowed |
| Atmel SAM | This can be one of each group of pins: 34/67/74/35, 17/36/72/37/42, 40/64/69/41, 9, 8/44, 7/45, 6 |
| Device | Comment |
|:----------------|:--------------------------------------------------------------------------------------------------|
| ESP32   | Every output capable GPIO can be used |
| ESP32S2   | Every output capable GPIO can be used |
| Atmega168/328/p | Only the pins connected to OC1A and OC1B are allowed |
| Atmega2560 | Only the pins connected to OC4A, OC4B and OC4C are allowed. |
| Atmega32u4 | Only the pins connected to OC1A, OC1B and OC1C are allowed |
| Atmel SAM | This can be one of each group of pins: 34/67/74/35, 17/36/72/37/42, 40/64/69/41, 9, 8/44, 7/45, 6 |
## External Pins

If the direction/enable pins are e.g. connected via external HW (shift
Expand Down
6 changes: 5 additions & 1 deletion extras/scripts/build-platformio.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

TARGETS=${1:-nanoatmega328 atmega2560 esp32 esp32s2 esp32c3 atmelsam atmega32u4}
TARGETS=${1:-nanoatmega168 nanoatmega328 atmega2560 esp32 esp32s2 esp32c3 atmelsam atmega32u4}
echo "execute for ${TARGETS}"

if [ "$GITHUB_WORKSPACE" != "" ]
Expand Down Expand Up @@ -33,6 +33,10 @@ for i in pio_dirs/*
do
for p in ${TARGETS}
do
if [ "$p" = "nanoatmega168" ] && [ "$i" = "pio_dirs/StepperDemo" ]; then
echo $p: Skipping $i for $p due to space constraints
continue
fi
echo $p: $i
(cd $i;pio run -s -e $p)
done
Expand Down
20 changes: 19 additions & 1 deletion extras/tests/simavr_based/Makefile.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ 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
Expand Down Expand Up @@ -44,6 +47,21 @@ 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
Expand All @@ -65,7 +83,7 @@ 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),atmega328p)
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
Expand Down
2 changes: 1 addition & 1 deletion extras/tests/simavr_based/Raw/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# There should be only one env section for the DUT under test.
# One of
# atmega168p
# atmega328p
# atmega2560_timer1
# atmega2560_timer3
Expand All @@ -28,4 +29,3 @@ board = nanoatmega328
framework = arduino
build_flags = -Werror -Wall ${common.build_flags}
lib_extra_dirs = ../../../../..

1 change: 1 addition & 0 deletions extras/tests/simavr_based/off_test_timing/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# There should be only one env section for the DUT under test.
# One of
# atmega168p
# atmega328p
# atmega2560_timer1
# atmega2560_timer3
Expand Down
20 changes: 19 additions & 1 deletion extras/tests/simavr_based/test_externalCall/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ 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
Expand Down Expand Up @@ -44,6 +47,21 @@ 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
Expand All @@ -65,7 +83,7 @@ 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),atmega328p)
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
Expand Down
2 changes: 1 addition & 1 deletion extras/tests/simavr_based/test_externalCall/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# There should be only one env section for the DUT under test.
# One of
# atmega168p
# atmega328p
# atmega2560_timer1
# atmega2560_timer3
Expand All @@ -28,4 +29,3 @@ board = nanoatmega328
framework = arduino
build_flags = -Werror -Wall ${common.build_flags}
lib_extra_dirs = ../../../../..

20 changes: 19 additions & 1 deletion extras/tests/simavr_based/test_issue150/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ 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
Expand Down Expand Up @@ -44,6 +47,21 @@ 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
Expand All @@ -65,7 +83,7 @@ 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),atmega328p)
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
Expand Down
Loading