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

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

#include <uStepper.h>

Public Member Functions

 uStepperEncoder (void)
 Constructor. More...
 
float getAngle (void)
 Measure the current shaft angle. More...
 
float getSpeed (void)
 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 (uint8_t mode)
 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 int16_t revolutions
 
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 board. This class can be instantiated as a standalone object if all the features of the uStepper is not needed by the programmers specific application.

Definition at line 448 of file uStepper.h.

Constructor & Destructor Documentation

◆ uStepperEncoder()

uStepperEncoder::uStepperEncoder ( void  )

Constructor.

This is the constructor of the uStepperEncoder class.

Definition at line 680 of file uStepper.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 755 of file uStepper.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 746 of file uStepper.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 732 of file uStepper.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 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 685 of file uStepper.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 revolutions per second (RPS)

Definition at line 690 of file uStepper.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 737 of file uStepper.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 717 of file uStepper.cpp.

◆ setup()

void uStepperEncoder::setup ( uint8_t  mode)

Setup the encoder.

This function initializes all the encoder features.

Parameters
[in]modeVariable to indicate if the uStepper is in normal or drop-in mode

Definition at line 695 of file uStepper.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. 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.

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 465 of file uStepper.h.

◆ angleMoved

volatile int32_t uStepperEncoder::angleMoved

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

Definition at line 453 of file uStepper.h.

◆ curSpeed

volatile float uStepperEncoder::curSpeed

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

Definition at line 474 of file uStepper.h.

◆ encoderOffset

uint16_t uStepperEncoder::encoderOffset

Angle of the shaft at the reference position.

Definition at line 456 of file uStepper.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 461 of file uStepper.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 470 of file uStepper.h.


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