try to fix submodule
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#include "./MagneticSensorMT6701SSI.h"
|
||||
#include "common/foc_utils.h"
|
||||
#include "common/time_utils.h"
|
||||
|
||||
MagneticSensorMT6701SSI::MagneticSensorMT6701SSI(int nCS, SPISettings settings) : settings(settings), nCS(nCS) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
MagneticSensorMT6701SSI::~MagneticSensorMT6701SSI() {
|
||||
|
||||
}
|
||||
|
||||
void MagneticSensorMT6701SSI::init(SPIClass* _spi) {
|
||||
this->spi=_spi;
|
||||
if (nCS >= 0) {
|
||||
pinMode(nCS, OUTPUT);
|
||||
digitalWrite(nCS, HIGH);
|
||||
}
|
||||
this->spi->begin();
|
||||
this->Sensor::init();
|
||||
}
|
||||
|
||||
// check 40us delay between each read?
|
||||
float MagneticSensorMT6701SSI::getSensorAngle() {
|
||||
float angle_data = readRawAngleSSI();
|
||||
angle_data = ( angle_data / (float)MT6701_CPR ) * _2PI;
|
||||
// return the shaft angle
|
||||
return angle_data;
|
||||
}
|
||||
|
||||
|
||||
uint16_t MagneticSensorMT6701SSI::readRawAngleSSI() {
|
||||
if (nCS >= 0)
|
||||
digitalWrite(nCS, LOW);
|
||||
spi->beginTransaction(settings);
|
||||
uint16_t value = spi->transfer16(0x0000);
|
||||
spi->endTransaction();
|
||||
if (nCS >= 0)
|
||||
digitalWrite(nCS, HIGH);
|
||||
return (value>>MT6701_DATA_POS)&0x3FFF;
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef __MAGNETIC_SENSOR_MT6701_SSI_H__
|
||||
#define __MAGNETIC_SENSOR_MT6701_SSI_H__
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "SPI.h"
|
||||
#include "common/base_classes/Sensor.h"
|
||||
|
||||
|
||||
#define MT6701_CPR 16384.0f
|
||||
|
||||
#define MT6701_BITORDER MSBFIRST
|
||||
|
||||
#if defined(TARGET_RP2040)||defined(ESP_H)||defined(CORE_TEENSY)
|
||||
#define MT6701_DATA_POS 1
|
||||
#else
|
||||
#define MT6701_DATA_POS 2
|
||||
#endif
|
||||
|
||||
// Use SPI mode 2, capture on falling edge. First bit is not valid data, so have to read 25 bits to get a full SSI frame.
|
||||
// SSI frame is 1 bit ignore, 14 bits angle, 4 bit status and 6 bit CRC.
|
||||
static SPISettings MT6701SSISettings(1000000, MT6701_BITORDER, SPI_MODE2); // @suppress("Invalid arguments")
|
||||
|
||||
|
||||
|
||||
class MagneticSensorMT6701SSI : public Sensor {
|
||||
public:
|
||||
MagneticSensorMT6701SSI(int nCS = -1, SPISettings settings = MT6701SSISettings);
|
||||
virtual ~MagneticSensorMT6701SSI();
|
||||
|
||||
virtual void init(SPIClass* _spi = &SPI);
|
||||
|
||||
float getSensorAngle() override; // angle in radians, return current value
|
||||
|
||||
protected:
|
||||
uint16_t readRawAngleSSI();
|
||||
|
||||
SPISettings settings;
|
||||
SPIClass* spi;
|
||||
int nCS = -1;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,82 @@
|
||||
# MT6701 SimpleFOC driver
|
||||
|
||||
:warning: work in progress... SSI driver is working. I2C not yet complete.
|
||||
|
||||
Due to the peculiarities of its interfaces, this very versatile sensor is not directly supported by SimpleFOC's SPI or I2C magnetic sensor implementations. This folder contains dedicated SimpleFOC sensor drivers for the MT6701 for I2C and SSI.
|
||||
|
||||
Note: the ABZ, UVW and Analog outputs of this sensor are supported by the standard SimpleFOC encoder, hall-sensor or analog sensor classes respectively.
|
||||
|
||||
:warning: Note: the I2C output of this sensor is probably too slow for high performance motor control, but could be useful to program the sensor IC, and to read the absolute angle values for intializing ABZ or UVW modes.
|
||||
|
||||
## Hardware setup
|
||||
|
||||
For I2C, connect the sensor as normal for I2C, using the SDA and SCL lines.
|
||||
|
||||
:warning: Note: to program the sensor via I2C, it has to be operated at 5V.
|
||||
|
||||
For SSI, connect the CSN line to the nCS output of your MCU, the CLK line to the SCLK output of the MCU, and the DO line to the CIPO (MISO) input of the MCU.
|
||||
|
||||
In my tests, the sensor was not able to work correctly together with other SPI devices on the same bus, but your experience might differ from mine.
|
||||
|
||||
## Software setup
|
||||
|
||||
### SSI code sample
|
||||
|
||||
```c++
|
||||
#include "Arduino.h"
|
||||
#include "SPI.h"
|
||||
#include "SimpleFOC.h"
|
||||
#include "SimpleFOCDrivers.h"
|
||||
#include "encoders/MT6701/MagneticSensorMT6701SSI.h"
|
||||
|
||||
|
||||
#define SENSOR1_CS 5 // some digital pin that you're using as the nCS pin
|
||||
MagneticSensorMT6701SSI sensor1(SENSOR1_CS);
|
||||
|
||||
|
||||
void setup() {
|
||||
sensor1.init();
|
||||
}
|
||||
```
|
||||
|
||||
To use a custom SPI bus:
|
||||
|
||||
```c++
|
||||
void setup() {
|
||||
sensor1.init(&SPI2);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
### I2C code sample
|
||||
|
||||
I2C usage is quite simple:
|
||||
|
||||
```c++
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
#include "SimpleFOC.h"
|
||||
#include "SimpleFOCDrivers.h"
|
||||
#include "encoders/MT6701/MagneticSensorMT6701I2C.h"
|
||||
|
||||
MagneticSensorMT6701I2C sensor1();
|
||||
|
||||
|
||||
void setup() {
|
||||
sensor1.init();
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
If you've programmed a different I2C address or want to use a different I2C bus you can:
|
||||
|
||||
```c++
|
||||
#define I2C_ADDR 0x70
|
||||
MagneticSensorMT6701I2C sensor1(I2C_ADDR);
|
||||
|
||||
|
||||
void setup() {
|
||||
sensor1.init(&Wire2);
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user