uStepper S
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
uStepperEncoder Class Reference

Prototype of class for the AEAT8800-Q24 encoder. More...

#include <uStepperEncoder.h>

Public Member Functions

 uStepperEncoder (void)
 Constructor of uStepperEncoder class.
 
void init (uStepperS *_pointer)
 Initiation of the encoder. More...
 
void setHome (void)
 Define new reference(home) position. More...
 
float getAngle (void)
 Return the current shaft angle in degrees. More...
 
uint16_t getAngleRaw (void)
 Return the current shaft angle in raw encoder readings. More...
 
float getAngleMoved (void)
 Returns the angle moved from reference position in degrees. More...
 
int32_t getAngleMovedRaw (void)
 Returns the angle moved from reference position in raw encoder readings. More...
 
float getSpeed (void)
 Measure the current speed of the motor. More...
 
float getRPM (void)
 Measure the current speed of the motor. More...
 
uint16_t captureAngle (void)
 Capture the current shaft angle. More...
 
uint8_t getStatus (void)
 Get encoder status. More...
 
bool detectMagnet (void)
 detect magnet More...
 

Public Attributes

uint16_t encoderOffset
 
volatile uint16_t angle
 
volatile int32_t angleMoved
 
volatile uint16_t oldAngle
 
volatile int16_t revolutions
 
volatile float curSpeed
 
volatile posFilter_t encoderFilter
 

Private Member Functions

void chipSelect (bool state)
 Set the output level of the chip select pin. More...
 

Private Attributes

uStepperSpointer
 
uint8_t status
 

Detailed Description

Prototype of class for the AEAT8800-Q24 encoder.

        This class enables the user of the library to access the AEAT8800-Q24
        encoder on the uStepper S board.

Definition at line 58 of file uStepperEncoder.h.

Member Function Documentation

◆ captureAngle()

uint16_t uStepperEncoder::captureAngle ( void  )

Capture the current shaft angle.

        This function is used by the ISR to read the current angle of the motor shaft.
        The Angle is read by means of the SSI interface, using the hardware SPI port.
Returns
samples the encoder and returns the current angle reading

Definition at line 108 of file uStepperEncoder.cpp.

◆ chipSelect()

void uStepperEncoder::chipSelect ( bool  state)
private

Set the output level of the chip select pin.

Parameters
[in]state- 1 = High, 0 = low

Definition at line 170 of file uStepperEncoder.cpp.

◆ detectMagnet()

bool uStepperEncoder::detectMagnet ( void  )

detect magnet

        This function reads the current status of the encoder with regards to placement
        of the magnet.
Returns
checks if the magnet is placed in the correct distance from the encoder: 0: everything is OK 1: magnet is placed either too far away or too close to the encoder

Definition at line 92 of file uStepperEncoder.cpp.

◆ getAngle()

float uStepperEncoder::getAngle ( void  )

Return the current shaft angle in degrees.

        This function returns the last captured shaft angle.
        The resolution of the angle returned by this function is
        0.0054931640625 degrees (16 bits)
Returns
Floating point representation of the current motor shaft angle

Definition at line 133 of file uStepperEncoder.cpp.

◆ getAngleMoved()

float uStepperEncoder::getAngleMoved ( void  )

Returns the angle moved from reference position in degrees.

        This function returns the angle moved from the shaft
        reference position. When the uStepper S 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 in degrees.

Definition at line 144 of file uStepperEncoder.cpp.

◆ getAngleMovedRaw()

int32_t uStepperEncoder::getAngleMovedRaw ( void  )

Returns the angle moved from reference position in raw encoder readings.

        This function returns the angle moved from the shaft
        reference position. When the uStepper S 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 in raw encoder readings.

Definition at line 149 of file uStepperEncoder.cpp.

◆ getAngleRaw()

uint16_t uStepperEncoder::getAngleRaw ( void  )

Return the current shaft angle in raw encoder readings.

            This function returns the last captured shaft angle, as 
        output directly from the encoder.
            The resolution of the angle returned by this function is
            16 bits
Returns
raw 16 bit encoder representation of the current motor shaft angle

Definition at line 138 of file uStepperEncoder.cpp.

◆ getRPM()

float uStepperEncoder::getRPM ( void  )

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.
Returns
Current speed in RPM

Definition at line 165 of file uStepperEncoder.cpp.

◆ getSpeed()

float uStepperEncoder::getSpeed ( void  )

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.
Returns
Current speed in 1/256th steps per second

Definition at line 160 of file uStepperEncoder.cpp.

◆ getStatus()

uint8_t uStepperEncoder::getStatus ( void  )

Get encoder status.

        This function reads the current status of the encoder 
Returns
Current status register content

Definition at line 155 of file uStepperEncoder.cpp.

◆ init()

void uStepperEncoder::init ( uStepperS _pointer)

Initiation of the encoder.

        This function initiates all the registers of the encoder.
Parameters
[in]_pointer- reference to the uStepper S object

Definition at line 49 of file uStepperEncoder.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 75 of file uStepperEncoder.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 206 of file uStepperEncoder.h.

◆ angleMoved

volatile int32_t uStepperEncoder::angleMoved

Variable used to store that measured angle moved from the reference position

Definition at line 210 of file uStepperEncoder.h.

◆ curSpeed

volatile float uStepperEncoder::curSpeed

Variable used to store the last measured rotational speed of the motor shaft

Definition at line 227 of file uStepperEncoder.h.

◆ encoderFilter

volatile posFilter_t uStepperEncoder::encoderFilter

Object to hold speed filter

Definition at line 230 of file uStepperEncoder.h.

◆ encoderOffset

uint16_t uStepperEncoder::encoderOffset

Angle of the shaft at the reference position.

Definition at line 202 of file uStepperEncoder.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 216 of file uStepperEncoder.h.

◆ pointer

uStepperS* uStepperEncoder::pointer
private

Reference to the main object

Definition at line 235 of file uStepperEncoder.h.

◆ revolutions

volatile int16_t uStepperEncoder::revolutions

This variable contains the number of revolutions in either direction, since last home position was set. negative numbers corresponds to CCW turns, and positive to CW turns

Definition at line 222 of file uStepperEncoder.h.

◆ status

uint8_t uStepperEncoder::status
private

Status bits from the encoder

Definition at line 245 of file uStepperEncoder.h.


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