-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,114 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=SimpleFOCDrivers | ||
version=1.0.0 | ||
version=1.0.1 | ||
author=Simplefoc <[email protected]> | ||
maintainer=Simplefoc <[email protected]> | ||
sentence=A library of supporting drivers for SimpleFOC. Motor drivers chips, encoder chips, current sensing and supporting code. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
#include "./A1334.h" | ||
|
||
|
||
|
||
A1334::A1334(SPISettings settings, int nCS) : settings(settings), nCS(nCS) { | ||
// nix | ||
}; | ||
|
||
|
||
|
||
A1334::~A1334() { | ||
}; | ||
|
||
|
||
|
||
|
||
void A1334::init(SPIClass* _spi) { | ||
spi = _spi; | ||
if (nCS>=0) | ||
pinMode(nCS, OUTPUT); | ||
digitalWrite(nCS, HIGH); | ||
//SPI has an internal SPI-device counter, it is possible to call "begin()" from different devices | ||
spi->begin(); | ||
readRawAngle(); // read an angle | ||
}; | ||
|
||
|
||
|
||
|
||
A1334Angle A1334::readRawAngle() { | ||
uint16_t command = A1334_REG_ANG; | ||
uint16_t cmdResult = spi_transfer16(command); // TODO fast mode | ||
cmdResult = spi_transfer16(command); | ||
A1334Angle result = { .reg = cmdResult }; | ||
// TODO check parity | ||
// errorflag = result.ef; | ||
return result; | ||
}; | ||
|
||
|
||
|
||
|
||
uint16_t A1334::spi_transfer16(uint16_t outdata) { | ||
if (nCS>=0) | ||
digitalWrite(nCS, 0); | ||
spi->beginTransaction(settings); | ||
uint16_t result = spi->transfer16(outdata); | ||
spi->endTransaction(); | ||
if (nCS>=0) | ||
digitalWrite(nCS, 1); | ||
return result; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
|
||
#ifndef __A1334_H__ | ||
#define __A1334_H__ | ||
|
||
#include <Arduino.h> | ||
#include <SPI.h> | ||
|
||
|
||
#define A1334_CPR 4096 | ||
#define A1334_BITORDER MSBFIRST | ||
|
||
static SPISettings A1334SPISettings(8000000, A1334_BITORDER, SPI_MODE3); // @suppress("Invalid arguments") | ||
|
||
|
||
typedef union { | ||
struct { | ||
uint16_t angle:12; | ||
uint16_t p:1; | ||
uint16_t nf:1; | ||
uint16_t ef:1; | ||
uint16_t ridc:1; | ||
}; | ||
uint16_t reg; | ||
} A1334Angle; | ||
|
||
|
||
#define A1334_REG_ANG 0x2000 | ||
|
||
|
||
|
||
|
||
class A1334 { | ||
public: | ||
A1334(SPISettings settings = A1334SPISettings, int nCS = -1); | ||
virtual ~A1334(); | ||
|
||
virtual void init(SPIClass* _spi = &SPI); | ||
A1334Angle readRawAngle(); // 10 or 12 bit angle value | ||
protected: | ||
uint16_t spi_transfer16(uint16_t outdata); | ||
SPIClass* spi; | ||
SPISettings settings; | ||
int nCS = -1; | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
#include "./MagneticSensorA1334.h" | ||
#include "common/foc_utils.h" | ||
#include "common/time_utils.h" | ||
|
||
MagneticSensorA1334::MagneticSensorA1334(int nCS, SPISettings settings) : A1334(settings, nCS) { | ||
|
||
} | ||
|
||
|
||
MagneticSensorA1334::~MagneticSensorA1334(){ | ||
|
||
} | ||
|
||
|
||
void MagneticSensorA1334::init(SPIClass* _spi) { | ||
this->A1334::init(_spi); | ||
this->Sensor::init(); | ||
} | ||
|
||
|
||
float MagneticSensorA1334::getSensorAngle() { | ||
A1334Angle angle_data = readRawAngle(); | ||
float result = ( angle_data.angle / (float)A1334_CPR) * _2PI; | ||
// return the shaft angle | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
#ifndef __MAGNETIC_SENSOR_A1334_H__ | ||
#define __MAGNETIC_SENSOR_A1334_H__ | ||
|
||
#include "common/base_classes/Sensor.h" | ||
#include "./A1334.h" | ||
|
||
|
||
|
||
class MagneticSensorA1334 : public Sensor, public A1334 { | ||
public: | ||
MagneticSensorA1334(int nCS = -1, SPISettings settings = A1334SPISettings); | ||
virtual ~MagneticSensorA1334(); | ||
|
||
virtual float getSensorAngle() override; | ||
|
||
virtual void init(SPIClass* _spi = &SPI); | ||
private: | ||
}; | ||
|
||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.