uStepper S
uStepperEncoder.h
Go to the documentation of this file.
1 /********************************************************************************************
2 * File: uStepperEncoder.h *
3 * Version: 2.0.0 *
4 * Date: March 30th, 2020 *
5 * Author: Thomas Hørring Olsen *
6 * *
7 *********************************************************************************************
8 * (C) 2020 *
9 * *
10 * uStepper ApS *
11 * www.ustepper.com *
12 * administration@ustepper.com *
13 * *
14 * The code contained in this file is released under the following open source license: *
15 * *
16 * Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International *
17 * *
18 * The code in this file is provided without warranty of any kind - use at own risk! *
19 * neither uStepper ApS nor the author, can be held responsible for any damage *
20 * caused by the use of the code contained in this file ! *
21 * *
22 ********************************************************************************************/
33 #include <Arduino.h>
34 
35 #define CS PB2
36 #define DIN PB3
37 #define DO PB4
38 #define CLK PB5
40 #define ENCODERDATATOSTEP 51200.0/65536.0
41 #define ENCODERDATATOREVOLUTIONS 60.0/65536.0
42 #define ANGLETOENCODERDATA 65535.0/360.0
50 class uStepperEncoder
51 {
52  public:
56  uStepperEncoder(void);
57 
65  void init( uStepperS * _pointer );
66 
75  void setHome( float initialAngle = 0 );
76 
87  float getAngle( void );
88 
100  uint16_t getAngleRaw( void );
101 
120  float getAngleMoved( bool filtered = true);
121 
140  int32_t getAngleMovedRaw( bool filtered = true );
141 
152  float getSpeed(void);
153 
164  float getRPM(void);
165 
174  uint16_t captureAngle( void );
175 
183  uint8_t getStatus( void );
184 
195  bool detectMagnet(void);
196 
198  volatile int32_t smoothValue;
199 
201  volatile float speedSmoothValue;
202 
204  volatile uint16_t encoderOffset;
205 
208  volatile uint16_t angle;
209 
212  volatile int32_t angleMoved;
213 
214 
218  volatile uint16_t oldAngle;
219 
220 
223  volatile float curSpeed;
224 
226  volatile posFilter_t encoderFilter;
227 
229  volatile uint8_t Beta = 5;
230 
231  private:
232 
234  uStepperS * pointer;
235 
241  void chipSelect(bool state);
242 
244  uint8_t status;
245  int32_t userAngleOffset = 0;
246 
247  volatile int32_t angleMovedRaw = 0;
248 
249 };
250 
uStepperS
Prototype of class for accessing all features of the uStepper S in a single object.
Definition: uStepperS.h:272
uStepperS::chipSelect
void chipSelect(uint8_t pin, bool state)
uStepperS::uStepperEncoder
friend class uStepperEncoder
Definition: uStepperS.h:276
uStepperS::init
void init(void)
Internal function to prepare the uStepperS in the constructor.
Definition: uStepperS.cpp:57
uStepperS::angleMoved
float angleMoved(void)
Get the angle moved from reference position in degrees.
Definition: uStepperS.cpp:481
pointer
uStepperS * pointer
Definition: uStepperS.cpp:32
posFilter_t
Struct for encoder velocity estimator.
Definition: uStepperS.h:196