SimpleFOClibrary  2.1
MagneticSensorSPI.h
Go to the documentation of this file.
1 #ifndef MAGNETICSENSORSPI_LIB_H
2 #define MAGNETICSENSORSPI_LIB_H
3 
4 #include "Arduino.h"
5 #include <SPI.h>
6 #include "../common/base_classes/Sensor.h"
7 #include "../common/foc_utils.h"
8 #include "../common/time_utils.h"
9 
10 #define DEF_ANGLE_REGISTER 0x3FFF
11 
13  int spi_mode;
20 };
21 // typical configuration structures
23 
24 class MagneticSensorSPI: public Sensor{
25  public:
32  MagneticSensorSPI(int cs, float bit_resolution, int angle_register = 0);
39 
41  void init(SPIClass* _spi = &SPI);
42 
43  // implementation of abstract functions of the Sensor class
45  float getAngle() override;
47  float getVelocity() override;
48 
49  // returns the spi mode (phase/polarity of read/writes) i.e one of SPI_MODE0 | SPI_MODE1 | SPI_MODE2 | SPI_MODE3
50  int spi_mode;
51 
52  /* returns the speed of the SPI clock signal */
54 
55 
56  private:
57  float cpr;
58  // spi variables
59  int angle_register;
60  int chip_select_pin;
61  SPISettings settings;
62  // spi functions
64  void close();
66  word read(word angle_register);
68  byte spiCalcEvenParity(word value);
69 
74  int getRawCount();
75 
76  // total angle tracking variables
77  float full_rotation_offset;
78  float angle_data_prev;
79 
80  // velocity calculation variables
81  float angle_prev;
82  long velocity_calc_timestamp;
83 
84  int bit_resolution;
85  int command_parity_bit;
86  int command_rw_bit;
87  int data_start_bit;
88 
89  SPIClass* spi;
90 };
91 
92 
93 #endif
MagneticSensorSPI::getVelocity
float getVelocity() override
Definition: MagneticSensorSPI.cpp:114
MagneticSensorSPIConfig_s::bit_resolution
int bit_resolution
Definition: MagneticSensorSPI.h:15
AS5047_SPI
MagneticSensorSPIConfig_s AS5047_SPI
Definition: MagneticSensorSPI.h:22
MagneticSensorSPI
Definition: MagneticSensorSPI.h:24
MagneticSensorSPIConfig_s::clock_speed
long clock_speed
Definition: MagneticSensorSPI.h:14
MagneticSensorSPIConfig_s::command_rw_bit
int command_rw_bit
Definition: MagneticSensorSPI.h:18
AS5048_SPI
MagneticSensorSPIConfig_s AS5048_SPI
Definition: MagneticSensorSPI.h:22
MagneticSensorSPIConfig_s::spi_mode
int spi_mode
Definition: MagneticSensorSPI.h:13
MagneticSensorSPI::spi_mode
int spi_mode
Definition: MagneticSensorSPI.h:50
MagneticSensorSPIConfig_s::angle_register
int angle_register
Definition: MagneticSensorSPI.h:16
MagneticSensorSPI::getAngle
float getAngle() override
Definition: MagneticSensorSPI.cpp:94
MagneticSensorSPI::MagneticSensorSPI
MagneticSensorSPI(int cs, float bit_resolution, int angle_register=0)
Definition: MagneticSensorSPI.cpp:33
MagneticSensorSPI::init
void init(SPIClass *_spi=&SPI)
Definition: MagneticSensorSPI.cpp:64
MagneticSensorSPIConfig_s
Definition: MagneticSensorSPI.h:12
MagneticSensorSPIConfig_s::command_parity_bit
int command_parity_bit
Definition: MagneticSensorSPI.h:19
MagneticSensorSPIConfig_s::data_start_bit
int data_start_bit
Definition: MagneticSensorSPI.h:17
AS5147_SPI
MagneticSensorSPIConfig_s AS5147_SPI
Definition: MagneticSensorSPI.cpp:4
MA730_SPI
MagneticSensorSPIConfig_s MA730_SPI
Definition: MagneticSensorSPI.h:22
MagneticSensorSPI::clock_speed
long clock_speed
Definition: MagneticSensorSPI.h:53
Sensor
Definition: Sensor.h:26