uStepper S-lite
Public Member Functions | Public Attributes | Friends | List of all members
uStepperEncoder Class Reference

Prototype of class for the AS5600 encoder. More...

#include <uStepperSLite.h>

Public Member Functions

 uStepperEncoder (void)
 Constructor. More...
 
float getAngle (void)
 Measure the current shaft angle. More...
 
float getSpeed (bool unit=SPS)
 Measure the current speed of the motor. More...
 
uint16_t getStrength (void)
 Measure the strength of the magnet. More...
 
uint8_t getAgc (void)
 Read the current AGC value of the encoder chip. More...
 
uint8_t detectMagnet (void)
 Detect if magnet is present and within range. More...
 
float getAngleMoved (void)
 Measure the angle moved from reference position. More...
 
void setup (void)
 Setup the encoder. More...
 
void setHome (void)
 Define new reference(home) position. More...
 

Public Attributes

volatile int32_t angleMoved
 
uint16_t encoderOffset
 
volatile uint16_t oldAngle
 
volatile uint16_t angle
 
volatile float curSpeed
 

Friends

void used
 
void TIMER1_COMPA_vect (void) __attribute__((signal
 Measures angle and speed of motor. More...
 

Detailed Description

Prototype of class for the AS5600 encoder.

        This class enables the user of the library to access the AS5600
        encoder on the uStepper S-lite board. This class can be instantiated as
        a standalone object if all the features of the uStepper S-lite is not
        needed by the programmers specific application.

Definition at line 303 of file uStepperSLite.h.

Constructor & Destructor Documentation

◆ uStepperEncoder()

uStepperEncoder::uStepperEncoder ( void  )

Constructor.

        This is the constructor of the uStepperEncoder class.

Definition at line 419 of file uStepperSLite.cpp.

Member Function Documentation

◆ detectMagnet()

uint8_t uStepperEncoder::detectMagnet ( void  )

Detect if magnet is present and within range.

        This function detects whether the magnet is present, too
        strong or too weak.
Returns
0 - Magnet detected and within limits
1 - Magnet too strong
2 - Magnet too weak

Definition at line 494 of file uStepperSLite.cpp.

◆ getAgc()

uint8_t uStepperEncoder::getAgc ( void  )

Read the current AGC value of the encoder chip.

        This function returns the current value of the AGC register
        in the encoder chip (AS5600). This value ranges between 0 and
        255, and should preferably be as close to 128 as possible.
Returns
current AGC value

Definition at line 485 of file uStepperSLite.cpp.

◆ getAngle()

float uStepperEncoder::getAngle ( void  )

Measure the current shaft angle.

        This function reads the current angle of the motor shaft. The
        resolution of the angle returned by this function is
        0.087890625 degrees (12 bits) The Angle is read by means of
        the I2C interface, using the I2C interface implemented in
        this library.
Returns
Floating point representation of the current motor shaft angle

Definition at line 469 of file uStepperSLite.cpp.

◆ getAngleMoved()

float uStepperEncoder::getAngleMoved ( void  )

Measure the angle moved from reference position.

        This function measures the angle moved from the shaft
        reference position. When the uStepper S-lite is first powered on,
        the reference position is reset to the current shaft
        position, meaning that this function will return the angle
        rotated with respect to the angle the motor initially had. It
        should be noted that this function is absolute to an
        arbitrary number of revolutions !

        The reference position can be reset at any point in time, by
        use of the setHome() function.
Returns
The angle moved.

Definition at line 424 of file uStepperSLite.cpp.

◆ getSpeed()

float uStepperEncoder::getSpeed ( bool  unit = SPS)

Measure the current speed of the motor.

        This function returns the current speed of the motor. The
        speed is not calculated in this function, it is merely
        returning a variable. The speed is calculated in the
        interrupt routine associated with timer1.
Parameters
unit- Return unit for speed, set to either "SPS" Steps Per Second (default) or "RPM" (without the quotes).
Returns
Current speed in revolutions per minute (RPM)

Definition at line 429 of file uStepperSLite.cpp.

◆ getStrength()

uint16_t uStepperEncoder::getStrength ( void  )

Measure the strength of the magnet.

        This function returns the strength of the magnet.
Returns
Strength of magnet

Definition at line 474 of file uStepperSLite.cpp.

◆ setHome()

void uStepperEncoder::setHome ( void  )

Define new reference(home) position.

        This function redefines the reference position to the current
        angle of the shaft

Definition at line 451 of file uStepperSLite.cpp.

◆ setup()

void uStepperEncoder::setup ( void  )

Setup the encoder.

        This function initializes all the encoder features.

Definition at line 441 of file uStepperSLite.cpp.

Friends And Related Function Documentation

◆ TIMER1_COMPA_vect

void TIMER1_COMPA_vect ( void  )
friend

Measures angle and speed of motor.

        This interrupt routine is in charge of sampling the encoder and
        measure the current speed of the motor. 

Definition at line 139 of file uStepperSLite.cpp.

Member Data Documentation

◆ angle

volatile uint16_t uStepperEncoder::angle

This variable always contain the current rotor angle, relative to a single revolution

Definition at line 320 of file uStepperSLite.h.

◆ angleMoved

volatile int32_t uStepperEncoder::angleMoved

Variable used to store the angle moved from the reference position

Definition at line 308 of file uStepperSLite.h.

◆ curSpeed

volatile float uStepperEncoder::curSpeed

Variable used to store the current rotational speed of the motor shaft

Definition at line 324 of file uStepperSLite.h.

◆ encoderOffset

uint16_t uStepperEncoder::encoderOffset

Angle of the shaft at the reference position.

Definition at line 311 of file uStepperSLite.h.

◆ oldAngle

volatile uint16_t uStepperEncoder::oldAngle

Used to stored the previous measured angle for the speed measurement, and the calculation of angle moved from reference position

Definition at line 316 of file uStepperSLite.h.


The documentation for this class was generated from the following files: