Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Unger committed May 1, 2022
2 parents 486b87a + 7761612 commit 9525cb3
Show file tree
Hide file tree
Showing 22 changed files with 1,114 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
- uses: actions/checkout@v2
- uses: arduino/arduino-lint-action@v1
with:
library-manager: submit
library-manager: update
project-type: library
build:
name: Test compile
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ What's here? See the sections below. Each driver or function should come with it

### Motor/Gate driver ICs

[DRV8316 driver](src/drivers/drv8316/) - SPI driver for TI's DRV8316 motor driver IC.
- [DRV8316 driver](src/drivers/drv8316/) - SPI driver for TI's DRV8316 motor driver IC.

### Encoders

- [AS5048A SPI driver](src/encoders/as5048a/) - SPI driver for the AMS AS5048A absolute position magnetic rotary encoder IC.
- [AS5047 SPI driver](src/encoders/as5047/) - SPI driver for the AMS AS5047P and AS5047D absolute position magnetic rotary encoder ICs.
- [AS5047U SPI driver](src/encoders/as5047u/) - SPI driver for the AMS AS5047U absolute position magnetic rotary encoder ICs.
- [MA730 SPI driver](src/encoders/ma730/) - SPI driver for the MPS MagAlpha MA730 absolute position magnetic rotary encoder IC.
- [MA730 SSI driver](src/encoders/ma730/) - SSI driver for the MPS MagAlpha MA730 absolute position magnetic rotary encoder IC.
- [AS5145 SSI driver](src/encoders/as5145/) - SSI driver for the AMS AS5145 and AS5045 absolute position magnetic rotary encoder ICs.
- [TLE5012B SPI driver](src/encoders/tle5012b/) - SPI (half duplex) driver for TLE5012B absolute position magnetic rotary encoder IC.
- [STM32 Hardware Encoder](src/encoders/stm32hwencoder/) - Hardware timer based encoder driver for ABI type quadrature encoders.
- [SC60228 SPI driver](src/encoders/sc60228/) - SPI driver for SemiMent SC60288 magnetic encoder IC.

### Communications

Expand Down
2 changes: 1 addition & 1 deletion library.properties
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.
Expand Down
54 changes: 54 additions & 0 deletions src/encoders/a1334/A1334.cpp
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;
};

51 changes: 51 additions & 0 deletions src/encoders/a1334/A1334.h
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
27 changes: 27 additions & 0 deletions src/encoders/a1334/MagneticSensorA1334.cpp
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;
}
24 changes: 24 additions & 0 deletions src/encoders/a1334/MagneticSensorA1334.h
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
3 changes: 2 additions & 1 deletion src/encoders/as5047/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# AS5047 SimpleFOC driver

While AS5047 absolute position magnetic rotary encoder is supported by the standard MagneticSensorSPI driver included in the base distribution, this AS5047-specific driver includes some optimisations:
While the AS5047 absolute position magnetic rotary encoder is supported by the standard MagneticSensorSPI driver included in the base distribution, this AS5047-specific driver includes some optimisations:

- access to the other registers of the AS5047, including the magnitude value which can be used to check the magnet strength, and the diagnostics register
- access to the error state of the sensor, and ability to clear errors
- it has a fastMode setting, in which the sensor is sent only 1 command per getAngle() call - the value returned will be from previous getAngle() invocation

This driver should work with AS5047P and AS5047D models. The AS5047U has it's own driver [here](../as5047u/).

## Hardware setup

Expand Down
Loading

0 comments on commit 9525cb3

Please sign in to comment.