SimpleFOClibrary 2.4.0
Loading...
Searching...
No Matches
MagneticSensorSPI.h
Go to the documentation of this file.
1#ifndef MAGNETICSENSORSPI_LIB_H
2#define MAGNETICSENSORSPI_LIB_H
3
4
5#include "Arduino.h"
6#include <SPI.h>
7#include "../common/base_classes/Sensor.h"
8#include "../common/foc_utils.h"
9#include "../common/time_utils.h"
10
11#define DEF_ANGLE_REGISTER 0x3FFF
12
22// typical configuration structures
24
26 public:
27 /**
28 * MagneticSensorSPI class constructor
29 * @param cs SPI chip select pin
30 * @param bit_resolution sensor resolution bit number
31 * @param angle_register (optional) angle read register - default 0x3FFF
32 * @param clock_speed (optional) SPI clock speed
33 */
34 MagneticSensorSPI(int cs, int bit_resolution, int angle_register = 0, long clock_speed = NOT_SET);
35
36 /**
37 * MagneticSensorSPI class constructor
38 /**
39 * MagneticSensorSPI class constructor
40 * @param config SPI config
41 * @param cs SPI chip select pin
42 * @param clock_speed (optional) SPI clock speed
43 */
45
46 /** sensor initialise pins */
47 void init(SPIClass* _spi = &SPI);
48
49 // implementation of abstract functions of the Sensor class
50 /** get current angle (rad) */
51 float getSensorAngle() override;
52
53 // returns the spi mode (phase/polarity of read/writes) i.e one of SPI_MODE0 | SPI_MODE1 | SPI_MODE2 | SPI_MODE3
55
56 /* returns the speed of the SPI clock signal */
58
59
60 private:
61 float cpr; //!< Maximum range of the magnetic sensor
62 // spi variables
63 int angle_register; //!< SPI angle register to read
64 int chip_select_pin; //!< SPI chip select pin
65 SPISettings settings; //!< SPI settings variable
66 // spi functions
67 /** Stop SPI communication */
68 void close();
69 /** Read one SPI register value */
70 word read(word angle_register);
71 /** Calculate parity value */
72 byte spiCalcEvenParity(word value);
73
74 /**
75 * Function getting current angle register value
76 * it uses angle_register variable
77 */
78 int getRawCount();
79
80 int bit_resolution; //!< the number of bites of angle data
81 int command_parity_bit; //!< the bit where parity flag is stored in command
82 int command_rw_bit; //!< the bit where read/write flag is stored in command
83 int data_start_bit; //!< the the position of first bit
84
85 SPIClass* spi;
86};
87
88
89#endif
MagneticSensorSPIConfig_s MA730_SPI
MagneticSensorSPIConfig_s AS5047_SPI
MagneticSensorSPIConfig_s AS5048_SPI
MagneticSensorSPIConfig_s AS5147_SPI
float getSensorAngle() override
virtual void init()
Definition Sensor.cpp:59
#define NOT_SET
Definition foc_utils.h:34