Git Product home page Git Product logo

turbostepper's Introduction

TurboStepper

An Arduino library for controlling stepper motors and RC servo motors with Interrupt Service Routines (ISR). Unlike the AccelStepper library, using ISRs does not require periodic calls to the stepper.run() function in the main loop. Since ISRs are quick interruptions of the main loop execution, this also guaranty that steps will be done in time, even if the program is executing a slow operation like an analogRead() or a Serial.read().

The library is designed around templates to be:

  • Versatile: You can easily add implement your own timers, profiles and steppers interfaces.
  • Efficient: Constants known at compile time are optimized to make the ISRs as quick as possible.
  • Easy-to-use: Hardware details are encapsulated within classes while still triggering errors when incompatible parameters are detected.

The provided implementations allows using 2 steppers per timer so up to 6 steppers on an Arduino Nano with a maximum safe steps/s of about 10k, the bottleneck being the end of the accelerating phase.

Generic badge

Dependencies

Uses the library digitalWriteFast.

Code examples

#include <TurboStepper.hpp>

// step pin = 2
// dir pin = 3
// steps/turn = 800
// max speed = 2 (turns/sec)
// max acceleration = 4 (turns/sec/sec)
using Stepper1 = Stepper<2, 3, 800, 2, 4>;
// use Timer1 with 2MHz clock
using Timer = ATMEGA328P::Timer1<C2MHz>;
using Profile = TrapezoidalProfile<Stepper1, Timer::CounterA>;

ISR(TIMER1_COMPA_vect) { Profile::DoStep(); }

void setup() {
    Stepper1::Setup();
    Timer::Setup();
    Profile::Setup();
}

void loop() {
    Profile::MoveForward(4000);
    while(Profile::IsMoving());
    Profile::MoveBackward(4000);
    while(Profile::IsMoving());
}
#include <TurboStepper.hpp>

// use Timer2 with 15_625Hz clock
using Timer2 = ATMEGA328P::Timer2<C15_625Hz>;
// PWM pin = 4
using Servo1 = Servo<4, Timer2::CounterA>;

ISR(TIMER2_COMPA_vect) { Servo1::DoPulse(); }

void setup() {
    Timer2::Setup();
    Servo1::Setup();
}

void loop() {
    Servo1::MoveTo(0);
    delay(2000);
    Servo1::MoveTo(180.0);
    delay(2000);
}

turbostepper's People

Contributors

fhamonic avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.