151 #ifndef __AVR_ATmega328P__
152 #error !!This library only supports the ATmega328p MCU!!
155 #include <inttypes.h>
173 #define INTFREQ 28200.0f
179 #define ENCODERADDR 0x36
184 #define MAGNITUDE 0x1B
186 #define ENCODERINTFREQ 1000.0
187 #define ENCODERSPEEDCONSTANT ENCODERINTFREQ/10.0/360.0
199 #define REPSTART 0x10
201 #define TXADDRACK 0x18
203 #define TXDATAACK 0x28
205 #define RXADDRACK 0x40
227 #define A 0.001295752996237
228 #define B 0.000237488365866
229 #define C 0.000000083423218
232 #define BETA (1.0 - ALPHA)
235 extern "C" void INT0_vect(
void) __attribute__ ((signal));
236 extern "
C"
void INT1_vect(
void) __attribute__ ((signal));
237 extern "
C"
void TIMER2_COMPA_vect(
void) __attribute__ ((signal,naked));
238 extern "
C"
void TIMER1_COMPA_vect(
void) __attribute__ ((signal));
244 float getFloatValue(
void);
245 uint64_t getRawValue(
void);
246 void setValue(
float val);
247 float2 & operator=(
const float &value);
248 bool operator==(
const float2 &value);
249 bool operator!=(
const float2 &value);
250 bool operator>=(
const float2 &value);
251 bool operator<=(
const float2 &value);
252 bool operator<=(
const float &value);
253 bool operator<(
const float2 &value);
254 bool operator>(
const float2 &value);
255 float2 & operator*=(
const float2 &value);
256 float2 & operator-=(
const float2 &value);
257 float2 & operator+=(
const float2 &value);
258 float2 & operator+=(
const float &value);
259 float2 & operator/=(
const float2 &value);
260 const float2 operator+(
const float2 &value);
261 const float2 operator-(
const float2 &value);
262 const float2 operator*(
const float2 &value);
263 const float2 operator/(
const float2 &value);
267 friend void TIMER2_COMPA_vect(
void) __attribute__ ((signal));
415 friend void TIMER1_COMPA_vect(
void) __attribute__ ((signal));
419 volatile float angle;
470 volatile uint16_t faultStepDelay;
471 volatile float tolerance;
472 volatile float stepResolution;
475 friend void TIMER2_COMPA_vect(
void) __attribute__ ((signal,naked));
476 friend
void TIMER1_COMPA_vect(
void) __attribute__ ((signal));
620 void moveSteps(uint32_t steps,
bool dir,
bool holdMode);
657 void setup(
bool mode = NORMAL, uint8_t microStepping = SIXTEEN,
float faultSpeed = 3000.0, uint32_t faultTolerance = 20);
727 void cmd(uint8_t cmd);
750 bool readByte(
bool ack, uint8_t *data);
765 bool read(uint8_t slaveAddr, uint8_t regAddr, uint8_t numOfBytes, uint8_t *data);
779 bool start(uint8_t addr,
bool RW);
793 bool restart(uint8_t addr,
bool RW);
805 bool writeByte(uint8_t data);
820 bool write(uint8_t slaveAddr, uint8_t regAddr, uint8_t numOfBytes, uint8_t *data);
840 uint8_t getStatus(
void);
uStepperEncoder(void)
Constructor.
void setup(bool mode=NORMAL, uint8_t microStepping=SIXTEEN, float faultSpeed=3000.0, uint32_t faultTolerance=20)
Initializes the different parts of the uStepper object.
Prototype of class for the temperature sensor.
uint16_t getStrength(void)
Measure the strength of the magnet.
float getSpeed(void)
Measure the current speed of the motor.
bool getMotorState(void)
Get the current state of the motor.
Prototype of class for accessing all features of the uStepper in a single object. ...
void enableMotor(void)
Enables the stepper driver output stage.
float getMaxAcceleration(void)
Get the value of the maximum motor acceleration.
float getTemp(void)
Request a reading of current temperature.
bool getCurrentDirection(void)
Returns the direction the motor is currently configured to rotate.
float getAngleMoved(void)
Measure the angle moved from reference position.
void hardStop(bool holdMode)
Stop the motor without deceleration.
void setMaxAcceleration(float accel)
Set the maximum acceleration of the stepper motor.
void startTimer(void)
Starts timer for stepper algorithm.
void setMaxVelocity(float vel)
Sets the maximum rotational velocity of the motor.
void moveSteps(uint32_t steps, bool dir, bool holdMode)
Make the motor perform a predefined number of steps.
float getMaxVelocity(void)
Returns the maximum rotational velocity of the motor.
void softStop(bool holdMode)
Stop the motor with deceleration.
uint8_t detectMagnet(void)
Detect if magnet is present and within range.
void stopTimer(void)
Stops the timer for the stepper algorithm.
uint8_t getAgc(void)
Read the current AGC value of the encoder chip.
void runContinous(bool dir)
Make the motor rotate continuously.
Prototype of class for accessing the TWI (I2C) interface of the AVR (master mode only).
Prototype of class for the AS5600 encoder.
void setHome(void)
Define new reference(home) position.
float getAngle(void)
Measure the current shaft angle.
volatile float angleMoved
uStepperTemp(void)
Constructor.
void disableMotor(void)
Disables the stepper driver output stage.
int64_t getStepsSinceReset(void)
Get the number of steps applied since reset.
void setup(void)
Setup the encoder.
uint32_t initialDecelSteps