try to fix submodule

This commit is contained in:
2023-11-09 19:02:15 -05:00
parent c1d45aa443
commit deea94b076
366 changed files with 40228 additions and 2 deletions

View File

@@ -0,0 +1,34 @@
#include "./MagneticSensorAS5145.h"
#include "common/foc_utils.h"
#include "common/time_utils.h"
MagneticSensorAS5145::MagneticSensorAS5145(SPISettings settings) : settings(settings) {
}
MagneticSensorAS5145::~MagneticSensorAS5145() {
}
void MagneticSensorAS5145::init(SPIClass* _spi) {
this->spi=_spi;
this->Sensor::init();
}
// check 40us delay between each read?
float MagneticSensorAS5145::getSensorAngle() {
float angle_data = readRawAngleSSI();
angle_data = ( (float)angle_data / AS5145_CPR ) * _2PI;
// return the shaft angle
return angle_data;
}
uint16_t MagneticSensorAS5145::readRawAngleSSI() {
spi->beginTransaction(settings);
uint16_t value = spi->transfer16(0x0000);
//uint16_t parity = spi->transfer(0x00);
spi->endTransaction();
return (value>>3)&0x1FFF; // TODO this isn't what I expected from the datasheet... maybe there's a leading 0 bit?
}; // 12bit angle value

View File

@@ -0,0 +1,39 @@
#ifndef __MAGNETIC_SENSOR_AS5145_H__
#define __MAGNETIC_SENSOR_AS5145_H__
#include "Arduino.h"
#include "SPI.h"
#include "common/base_classes/Sensor.h"
#ifndef MSBFIRST
#define MSBFIRST BitOrder::MSBFIRST
#endif
#define AS5145_BITORDER MSBFIRST
#define AS5145_CPR 4096.0f
#define _2PI 6.28318530718f
static SPISettings AS5145SSISettings(1000000, AS5145_BITORDER, SPI_MODE2); // @suppress("Invalid arguments")
class MagneticSensorAS5145 : public Sensor {
public:
MagneticSensorAS5145(SPISettings settings = AS5145SSISettings);
virtual ~MagneticSensorAS5145();
virtual float getSensorAngle() override;
virtual void init(SPIClass* _spi = &SPI);
uint16_t readRawAngleSSI();
private:
SPIClass* spi;
SPISettings settings;
};
#endif

View File

@@ -0,0 +1,50 @@
# AS5145 SimpleFOC driver
SSI protocol driver for the AMS AS5145 magnetic encoder. Any of the A, B or H variants should work. AS5045 encoders should also be supported.
Only angle reading is supported, might get to the status bits at a later time.
The SSI protocol is "emulated" using the SPI peripheral.
Tested with AS5145A on STM32G491 so far.
## Hardware setup
Wire the sensor's data (DO) line to the MISO (CIPO) pin, nCS, SCK as normal. Leave the MOSI pin unconnected.
## Software setup
```
#include <Arduino.h>
#include <SimpleFOC.h>
#include <SimpleFOCDrivers.h>
#include "encoders/as5145/MagneticSensorAS5145.h"
MagneticSensorAS5145 sensor;
SPIClass spi_ssi(PB15, PB14, PB13, PB12);
long ts;
void setup() {
Serial.begin(115200);
while (!Serial) ;
delay(2000);
Serial.println("Initializing sensor...");
spi_ssi.begin();
sensor.init(&spi_ssi);
Serial.println("Sensor initialized.");
ts = millis();
}
void loop() {
sensor.update();
if (millis() - ts > 1000) {
Serial.println(sensor.getAngle(), 3);
ts = millis();
}
delay(1);
}
```