uStepper S
uStepperEncoder.h
Go to the documentation of this file.
1 /********************************************************************************************
2 * File: uStepperEncoder.h *
3 * Version: 2.2.0 *
4 * Date: September 22nd, 2020 *
5 * Authors: Thomas Hørring Olsen *
6 * Emil Jacobsen *
7 * *
8 *********************************************************************************************
9 * (C) 2020 *
10 * *
11 * uStepper ApS *
12 * www.ustepper.com *
13 * administration@ustepper.com *
14 * *
15 * The code contained in this file is released under the following open source license: *
16 * *
17 * Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International *
18 * *
19 * The code in this file is provided without warranty of any kind - use at own risk! *
20 * neither uStepper ApS nor the author, can be held responsible for any damage *
21 * caused by the use of the code contained in this file ! *
22 * *
23 ********************************************************************************************/
34 #include <Arduino.h>
35 
36 #define CS PB2
37 #define DIN PB3
38 #define DO PB4
39 #define CLK PB5
41 #define ENCODERDATATOSTEP 51200.0/65536.0
42 #define ENCODERDATATOREVOLUTIONS 60.0/65536.0
43 #define ANGLETOENCODERDATA 65535.0/360.0
51 class uStepperEncoder
52 {
53  public:
57  uStepperEncoder(void);
58 
66  void init( uStepperS * _pointer );
67 
76  void setHome( float initialAngle = 0 );
77 
88  float getAngle( void );
89 
101  uint16_t getAngleRaw( void );
102 
121  float getAngleMoved( bool filtered = true);
122 
141  int32_t getAngleMovedRaw( bool filtered = true );
142 
153  float getSpeed(void);
154 
165  float getRPM(void);
166 
175  uint16_t captureAngle( void );
176 
184  uint8_t getStatus( void );
185 
196  bool detectMagnet(void);
197 
199  volatile int32_t smoothValue;
200 
202  volatile float speedSmoothValue;
203 
205  volatile uint16_t encoderOffset;
206 
209  volatile uint16_t angle;
210 
213  volatile int32_t angleMoved;
214 
215 
219  volatile uint16_t oldAngle;
220 
221 
224  volatile float curSpeed;
225 
228 
230  volatile uint8_t Beta = 5;
231 
232  private:
233 
236 
242  void chipSelect(bool state);
243 
245  uint8_t status;
246  int32_t userAngleOffset = 0;
247 
248  volatile int32_t angleMovedRaw = 0;
249 
250 };
251 
uStepperS
Prototype of class for accessing all features of the uStepper S in a single object.
Definition: uStepperS.h:279
uStepperEncoder::angle
volatile uint16_t angle
Definition: uStepperEncoder.h:209
uStepperS::chipSelect
void chipSelect(uint8_t pin, bool state)
uStepperEncoder::angleMoved
volatile int32_t angleMoved
Definition: uStepperEncoder.h:213
uStepperEncoder::status
uint8_t status
Definition: uStepperEncoder.h:245
uStepperEncoder::oldAngle
volatile uint16_t oldAngle
Definition: uStepperEncoder.h:219
uStepperS::uStepperEncoder
friend class uStepperEncoder
Definition: uStepperS.h:282
uStepperEncoder::encoderFilter
volatile posFilter_t encoderFilter
Definition: uStepperEncoder.h:227
uStepperEncoder::smoothValue
volatile int32_t smoothValue
Definition: uStepperEncoder.h:199
uStepperEncoder::speedSmoothValue
volatile float speedSmoothValue
Definition: uStepperEncoder.h:202
uStepperS::init
void init(void)
Internal function to prepare the uStepperS in the constructor.
Definition: uStepperS.cpp:59
uStepperEncoder::curSpeed
volatile float curSpeed
Definition: uStepperEncoder.h:224
uStepperEncoder::pointer
uStepperS * pointer
Definition: uStepperEncoder.h:235
uStepperEncoder::encoderOffset
volatile uint16_t encoderOffset
Definition: uStepperEncoder.h:205
posFilter_t
Struct for encoder velocity estimator.
Definition: uStepperS.h:203