uStepper
Classes | Macros | Functions | Variables
uStepper.h File Reference

Function prototypes and definitions for the uStepper library. More...

#include <inttypes.h>
#include <avr/io.h>
#include <avr/delay.h>
#include <Arduino.h>
#include <uStepperServo.h>

Go to the source code of this file.

Classes

class  float2
 
class  uStepperTemp
 Prototype of class for the temperature sensor. More...
 
class  uStepperEncoder
 Prototype of class for the AS5600 encoder. More...
 
class  uStepper
 Prototype of class for accessing all features of the uStepper in a single object. More...
 
class  i2cMaster
 Prototype of class for accessing the TWI (I2C) interface of the AVR (master mode only). More...
 

Macros

#define FULL   1
 
#define HALF   2
 
#define QUARTER   4
 
#define EIGHT   8
 
#define SIXTEEN   16
 
#define NORMAL   0
 
#define PWM   1
 
#define DROPIN   1
 
#define PID   2
 
#define STOP   1
 
#define ACCEL   2
 
#define CRUISE   4
 
#define DECEL   8
 
#define INITDECEL   16
 
#define INTFREQ   28200.0f
 
#define INTPERIOD   1000000.0/INTFREQ
 
#define INTPIDDELAYCONSTANT   0.028199994
 
#define CW   0
 
#define CCW   1
 
#define HARD   1
 
#define SOFT   0
 
#define ENCODERINTFREQ   1000.0
 
#define ENCODERSPEEDCONSTANT   ENCODERINTFREQ/10.0/4096.0
 
#define ENCODERADDR   0x36
 
#define ANGLE   0x0E
 
#define STATUS   0x0B
 
#define AGC   0x1A
 
#define MAGNITUDE   0x1B
 
#define R   4700.0
 
#define I2CFREE   0
 
#define READ   1
 
#define WRITE   0
 
#define START   0x08
 
#define REPSTART   0x10
 
#define TXADDRACK   0x18
 
#define TXDATAACK   0x28
 
#define RXADDRACK   0x40
 
#define ACK   1
 
#define NACK   0
 
#define A   0.001295752996237
 
#define B   0.000237488365866
 
#define C   0.000000083423218
 

Functions

void interrupt0 (void)
 Used by dropin feature to take in step pulses. More...
 
void interrupt1 (void)
 Used by dropin feature to take in enable signal. More...
 
void TIMER2_COMPA_vect (void) __attribute__((signal
 Used to apply step pulses to the motor. More...
 
void TIMER1_COMPA_vect (void) __attribute__((signal
 Measures angle and speed of motor. More...
 

Variables

void naked
 
void used
 
i2cMaster I2C
 

Detailed Description

Function prototypes and definitions for the uStepper library.

This file contains class and function prototypes for the library, as well as necessary constants and global variables.

Author
Thomas Hørring Olsen (thoma.nosp@m.s@us.nosp@m.teppe.nosp@m.r.co.nosp@m.m)

Definition in file uStepper.h.

Macro Definition Documentation

◆ A

#define A   0.001295752996237

Coefficients needed by the Steinhart-hart equation in order to find the temperature of the NTC (and hereby the temperature of the motor driver) from the current resistance of the NTC resistor. The coefficients are calculated for the following 3 operating points:

A: T = 5 degree Celsius

B: T = 50 degree Celsius

C: T = 105 degree Celsius

The Steinhart-Hart equation is described at the following link:

https://en.wikipedia.org/wiki/Steinhart%E2%80%93Hart_equation#Developers_of_the_equation

Definition at line 321 of file uStepper.h.

◆ ACCEL

#define ACCEL   2

Value to put in state variable in order to indicate that the motor should be accelerating

Definition at line 234 of file uStepper.h.

◆ ACK

#define ACK   1

value to indicate ACK for i2c transmission

Definition at line 299 of file uStepper.h.

◆ AGC

#define AGC   0x1A

Address of the register, in the encoder chip, containing information about the current gain value used in the encoder chip. This value should preferably be around 127 (Ideal case!)

Definition at line 267 of file uStepper.h.

◆ ANGLE

#define ANGLE   0x0E

Address of the register, in the encoder chip, containing the 8 least significant bits of the stepper shaft angle

Definition at line 263 of file uStepper.h.

◆ B

#define B   0.000237488365866

See description of A

Definition at line 323 of file uStepper.h.

◆ C

#define C   0.000000083423218

See description of A

Definition at line 325 of file uStepper.h.

◆ CCW

#define CCW   1

Value to put in direction variable in order for the stepper to turn counterclockwise

Definition at line 250 of file uStepper.h.

◆ CRUISE

#define CRUISE   4

Value to put in state variable in order to indicate that the motor should be decelerating

Definition at line 236 of file uStepper.h.

◆ CW

#define CW   0

Value to put in direction variable in order for the stepper to turn clockwise

Definition at line 248 of file uStepper.h.

◆ DECEL

#define DECEL   8

Value to put in state variable in order to indicate that the motor should be cruising at constant speed with no acceleration

Definition at line 238 of file uStepper.h.

◆ DROPIN

#define DROPIN   1

Value defining dropin mode for 3d printer/CNC controller boards

Definition at line 227 of file uStepper.h.

◆ EIGHT

#define EIGHT   8

Eighth step definition

Definition at line 219 of file uStepper.h.

◆ ENCODERADDR

#define ENCODERADDR   0x36

I2C address of the encoder chip

Definition at line 261 of file uStepper.h.

◆ ENCODERINTFREQ

#define ENCODERINTFREQ   1000.0

Frequency at which the encoder is sampled, for keeping track of angle moved and current speed

Definition at line 257 of file uStepper.h.

◆ ENCODERSPEEDCONSTANT

#define ENCODERSPEEDCONSTANT   ENCODERINTFREQ/10.0/4096.0

Constant to convert angle difference between two interrupts to speed in revolutions per second

Definition at line 259 of file uStepper.h.

◆ FULL

#define FULL   1

Full step definition

Definition at line 213 of file uStepper.h.

◆ HALF

#define HALF   2

Half step definition

Definition at line 215 of file uStepper.h.

◆ HARD

#define HARD   1

Value to put in hold variable in order for the motor to block when it is not running

Definition at line 252 of file uStepper.h.

◆ I2CFREE

#define I2CFREE   0

I2C bus is not currently in use

Definition at line 275 of file uStepper.h.

◆ INITDECEL

#define INITDECEL   16

Value to put in state variable in order to indicate that the motor should be decelerating to full stop before changing direction

Definition at line 240 of file uStepper.h.

◆ INTFREQ

#define INTFREQ   28200.0f

Frequency of interrupt routine, in which the delays for the stepper algorithm are calculated

Definition at line 242 of file uStepper.h.

◆ INTPERIOD

#define INTPERIOD   1000000.0/INTFREQ

Period of interrupt routine for stepper algortihm

Definition at line 244 of file uStepper.h.

◆ INTPIDDELAYCONSTANT

#define INTPIDDELAYCONSTANT   0.028199994

constant to calculate the amount of interrupts TIMER2 has to wait with generating new pulse, during PID error correction

Definition at line 246 of file uStepper.h.

◆ MAGNITUDE

#define MAGNITUDE   0x1B

Address of the register, in the encoder chip, containing the 8 least significant bits of magnetic field strength measured by the encoder chip

Definition at line 269 of file uStepper.h.

◆ NACK

#define NACK   0

value to indicate NACK for i2c transmission

Definition at line 302 of file uStepper.h.

◆ NORMAL

#define NORMAL   0

Value defining normal mode

Definition at line 223 of file uStepper.h.

◆ PID

#define PID   2

Value defining PID mode for normal library functions

Definition at line 229 of file uStepper.h.

◆ PWM

#define PWM   1

Value defining PWM mode of corresponding IO pin. Used to switch pin D3 and D8 between pwm or normal IO mode

Definition at line 225 of file uStepper.h.

◆ QUARTER

#define QUARTER   4

Quarter step definition

Definition at line 217 of file uStepper.h.

◆ R

#define R   4700.0

The NTC resistor used for measuring temperature, is placed in series with a 4.7 kohm resistor. This is used to calculate the temperature

Definition at line 272 of file uStepper.h.

◆ READ

#define READ   1

Value for RW bit in address field, to request a read

Definition at line 278 of file uStepper.h.

◆ REPSTART

#define REPSTART   0x10

repeated start condition transmitted

Definition at line 287 of file uStepper.h.

◆ RXADDRACK

#define RXADDRACK   0x40

slave address plus read bit transmitted, ACK received

Definition at line 296 of file uStepper.h.

◆ SIXTEEN

#define SIXTEEN   16

Sixteenth step definition

Definition at line 221 of file uStepper.h.

◆ SOFT

#define SOFT   0

Value to put in hold variable in order for the motor to not block when it is not running

Definition at line 254 of file uStepper.h.

◆ START

#define START   0x08

start condition transmitted

Definition at line 284 of file uStepper.h.

◆ STATUS

#define STATUS   0x0B

Address of the register, in the encoder chip, containing information about whether a magnet has been detected or not

Definition at line 265 of file uStepper.h.

◆ STOP

#define STOP   1

Value to put in state variable in order to indicate that the motor should not be running

Definition at line 232 of file uStepper.h.

◆ TXADDRACK

#define TXADDRACK   0x18

slave address plus write bit transmitted, ACK received

Definition at line 290 of file uStepper.h.

◆ TXDATAACK

#define TXDATAACK   0x28

data transmitted, ACK received

Definition at line 293 of file uStepper.h.

◆ WRITE

#define WRITE   0

Value for RW bit in address field, to request a write

Definition at line 281 of file uStepper.h.

Function Documentation

◆ interrupt0()

void interrupt0 ( void  )

Used by dropin feature to take in step pulses.

This interrupt routine is used by the dropin feature to keep track of step and direction pulses from main controller

Definition at line 115 of file uStepper.cpp.

◆ interrupt1()

void interrupt1 ( void  )

Used by dropin feature to take in enable signal.

This interrupt routine is used by the dropin feature to keep track of enable signal from main controller

Definition at line 82 of file uStepper.cpp.

◆ TIMER1_COMPA_vect()

void TIMER1_COMPA_vect ( void  )

Measures angle and speed of motor.

This interrupt routine is in charge of sampling the encoder and measure the current speed of the motor. In case of Dropin or PID feature this routine runs at a frequency of 500Hz while during normal operation it runs at a frequency of 1kHz.

Definition at line 271 of file uStepper.cpp.

◆ TIMER2_COMPA_vect()

void TIMER2_COMPA_vect ( void  )

Used to apply step pulses to the motor.

This interrupt routine is in charge of applying step pulses to the motor. The routine runs at a frequency of 28.2kHz, and handles acceleration algorithm calculations, as well as applying step pulses during compensation for missed steps, while either dropin or PID feature are enabled.

Definition at line 128 of file uStepper.cpp.

Variable Documentation

◆ I2C

i2cMaster I2C

Global definition of I2C object for use in arduino sketch

Definition at line 78 of file uStepper.cpp.