try to fix submodule
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
|
||||
#include "./MagneticSensorSC60228.h"
|
||||
#include "common/foc_utils.h"
|
||||
#include "common/time_utils.h"
|
||||
|
||||
MagneticSensorSC60228::MagneticSensorSC60228(int nCS, SPISettings settings) : SC60228(settings, nCS){
|
||||
// nix
|
||||
};
|
||||
MagneticSensorSC60228::~MagneticSensorSC60228(){ };
|
||||
|
||||
|
||||
|
||||
float MagneticSensorSC60228::getSensorAngle(){
|
||||
SC60228Angle angle_data = readRawAngle();
|
||||
float result = ( angle_data.angle / (float)SC60228_CPR ) * _2PI;
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
|
||||
void MagneticSensorSC60228::init(SPIClass* _spi){
|
||||
this->SC60228::init(_spi);
|
||||
this->Sensor::init();
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef __MAGNETICSENSORSC60228_H__
|
||||
#define __MAGNETICSENSORSC60228_H__
|
||||
|
||||
|
||||
#include "common/base_classes/Sensor.h"
|
||||
#include "./SC60228.h"
|
||||
|
||||
|
||||
class MagneticSensorSC60228 : public Sensor, public SC60228 {
|
||||
public:
|
||||
MagneticSensorSC60228(int nCS = -1, SPISettings settings = SC60228SPISettings);
|
||||
virtual ~MagneticSensorSC60228();
|
||||
|
||||
virtual float getSensorAngle() override;
|
||||
|
||||
virtual void init(SPIClass* _spi = &SPI) override;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
# SC60228 SimpleFOC driver
|
||||
|
||||
Driver for the Semiment 12bit magnetic encoder IC SC60288. According to specs it should support 12 bit accuracy, 10 bit effective accuracy and up to 20kRPM.
|
||||
|
||||
Link to [Datasheet](https://semiment.com/wp-content/uploads/2021/04/SC60228_EN-VA1.0.pdf)
|
||||
|
||||
The encoder and this driver were tested with a small gimbal motor and MKR1000 (SAMD21 MCU).
|
||||
|
||||
## Hardware setup
|
||||
|
||||
Connect as per normal for your SPI bus. No special hardware setup is needed to use this driver.
|
||||
|
||||
## Software setup
|
||||
|
||||
Its actually easier to use than the standard SPI sensor class, because it is less generic:
|
||||
|
||||
```c++
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
#include "SPI.h"
|
||||
#include "SimpleFOC.h"
|
||||
#include "SimpleFOCDrivers.h"
|
||||
#include "encoders/sc60228/MagneticSensorSC60228.h"
|
||||
|
||||
#define SENSOR1_CS 5 // some digital pin that you're using as the nCS pin
|
||||
MagneticSensorSC60228 sensor1(SENSOR1_CS);
|
||||
|
||||
|
||||
void setup() {
|
||||
sensor1.init();
|
||||
}
|
||||
```
|
||||
|
||||
Set some SPI options:
|
||||
|
||||
```c++
|
||||
SPISettings mySPISettings(1000000, SC60228_BITORDER, SPI_MODE0); // lower speed to 1Mhz
|
||||
MagneticSensorSC60228 sensor1(SENSOR1_CS, mySPISettings);
|
||||
```
|
||||
|
||||
Use another SPI bus:
|
||||
|
||||
```c++
|
||||
void setup() {
|
||||
sensor1.init(SPI2);
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,57 @@
|
||||
|
||||
#include "./SC60228.h"
|
||||
|
||||
|
||||
SC60228::SC60228(SPISettings settings, int nCS) : settings(settings), nCS(nCS) {
|
||||
// nix
|
||||
};
|
||||
|
||||
SC60228::~SC60228() { };
|
||||
|
||||
void SC60228::init(SPIClass* _spi) {
|
||||
spi = _spi;
|
||||
if (nCS>=0)
|
||||
pinMode(nCS, OUTPUT);
|
||||
digitalWrite(nCS, HIGH);
|
||||
spi->begin();
|
||||
readRawAngle();
|
||||
};
|
||||
|
||||
|
||||
|
||||
SC60228Angle SC60228::readRawAngle(){
|
||||
SC60228Angle result;
|
||||
result.reg = spi_transfer16(0x0000);
|
||||
errorflag = (result.err==1);
|
||||
// TODO check parity
|
||||
// Serial.print("0x");
|
||||
// Serial.print(result.angle, HEX);
|
||||
// Serial.print(" - 0x");
|
||||
// Serial.println(result.reg, HEX);
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
|
||||
bool SC60228::isError() {
|
||||
return errorflag;
|
||||
};
|
||||
|
||||
|
||||
|
||||
uint16_t SC60228::spi_transfer16(uint16_t outdata){
|
||||
uint16_t result;
|
||||
if (nCS>=0)
|
||||
digitalWrite(nCS, LOW);
|
||||
// min delay here: 250ns
|
||||
spi->beginTransaction(settings);
|
||||
result = spi->transfer16(outdata);
|
||||
// min delay here: clock period / 2
|
||||
spi->endTransaction();
|
||||
if (nCS>=0)
|
||||
digitalWrite(nCS, HIGH);
|
||||
// min delay until next read: 250ns
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
#ifndef __SC60228_H__
|
||||
#define __SC60228_H__
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "SPI.h"
|
||||
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint16_t parity:1;
|
||||
uint16_t df2:1;
|
||||
uint16_t df1:1;
|
||||
uint16_t err:1;
|
||||
uint16_t angle:12;
|
||||
};
|
||||
uint16_t reg;
|
||||
} SC60228Angle;
|
||||
|
||||
|
||||
#define SC60228_CPR 4096
|
||||
#define SC60228_BITORDER MSBFIRST
|
||||
|
||||
static SPISettings SC60228SPISettings(8000000, SC60228_BITORDER, SPI_MODE0); // @suppress("Invalid arguments")
|
||||
|
||||
|
||||
|
||||
class SC60228 {
|
||||
public:
|
||||
SC60228(SPISettings settings = SC60228SPISettings, int nCS = -1);
|
||||
virtual ~SC60228();
|
||||
|
||||
virtual void init(SPIClass* _spi = &SPI);
|
||||
|
||||
SC60228Angle readRawAngle(); // 12bit angle value + error flag
|
||||
bool isError(); // true if the last call to readRawAngle() returned an error
|
||||
|
||||
protected:
|
||||
uint16_t spi_transfer16(uint16_t outdata);
|
||||
|
||||
SPIClass* spi;
|
||||
SPISettings settings;
|
||||
bool errorflag = false;
|
||||
int nCS = -1;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user