Skip to content

Commit 9525cb3

Browse files
author
Richard Unger
committed
Merge branch 'dev'
2 parents 486b87a + 7761612 commit 9525cb3

22 files changed

+1114
-4
lines changed

.github/workflows/ccpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
- uses: actions/checkout@v2
88
- uses: arduino/arduino-lint-action@v1
99
with:
10-
library-manager: submit
10+
library-manager: update
1111
project-type: library
1212
build:
1313
name: Test compile

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ What's here? See the sections below. Each driver or function should come with it
1414

1515
### Motor/Gate driver ICs
1616

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

1919
### Encoders
2020

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

2931
### Communications
3032

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SimpleFOCDrivers
2-
version=1.0.0
2+
version=1.0.1
33
author=Simplefoc <[email protected]>
44
maintainer=Simplefoc <[email protected]>
55
sentence=A library of supporting drivers for SimpleFOC. Motor drivers chips, encoder chips, current sensing and supporting code.

src/encoders/a1334/A1334.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
#include "./A1334.h"
3+
4+
5+
6+
A1334::A1334(SPISettings settings, int nCS) : settings(settings), nCS(nCS) {
7+
// nix
8+
};
9+
10+
11+
12+
A1334::~A1334() {
13+
};
14+
15+
16+
17+
18+
void A1334::init(SPIClass* _spi) {
19+
spi = _spi;
20+
if (nCS>=0)
21+
pinMode(nCS, OUTPUT);
22+
digitalWrite(nCS, HIGH);
23+
//SPI has an internal SPI-device counter, it is possible to call "begin()" from different devices
24+
spi->begin();
25+
readRawAngle(); // read an angle
26+
};
27+
28+
29+
30+
31+
A1334Angle A1334::readRawAngle() {
32+
uint16_t command = A1334_REG_ANG;
33+
uint16_t cmdResult = spi_transfer16(command); // TODO fast mode
34+
cmdResult = spi_transfer16(command);
35+
A1334Angle result = { .reg = cmdResult };
36+
// TODO check parity
37+
// errorflag = result.ef;
38+
return result;
39+
};
40+
41+
42+
43+
44+
uint16_t A1334::spi_transfer16(uint16_t outdata) {
45+
if (nCS>=0)
46+
digitalWrite(nCS, 0);
47+
spi->beginTransaction(settings);
48+
uint16_t result = spi->transfer16(outdata);
49+
spi->endTransaction();
50+
if (nCS>=0)
51+
digitalWrite(nCS, 1);
52+
return result;
53+
};
54+

src/encoders/a1334/A1334.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
3+
#ifndef __A1334_H__
4+
#define __A1334_H__
5+
6+
#include <Arduino.h>
7+
#include <SPI.h>
8+
9+
10+
#define A1334_CPR 4096
11+
#define A1334_BITORDER MSBFIRST
12+
13+
static SPISettings A1334SPISettings(8000000, A1334_BITORDER, SPI_MODE3); // @suppress("Invalid arguments")
14+
15+
16+
typedef union {
17+
struct {
18+
uint16_t angle:12;
19+
uint16_t p:1;
20+
uint16_t nf:1;
21+
uint16_t ef:1;
22+
uint16_t ridc:1;
23+
};
24+
uint16_t reg;
25+
} A1334Angle;
26+
27+
28+
#define A1334_REG_ANG 0x2000
29+
30+
31+
32+
33+
class A1334 {
34+
public:
35+
A1334(SPISettings settings = A1334SPISettings, int nCS = -1);
36+
virtual ~A1334();
37+
38+
virtual void init(SPIClass* _spi = &SPI);
39+
A1334Angle readRawAngle(); // 10 or 12 bit angle value
40+
protected:
41+
uint16_t spi_transfer16(uint16_t outdata);
42+
SPIClass* spi;
43+
SPISettings settings;
44+
int nCS = -1;
45+
};
46+
47+
48+
49+
50+
51+
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
#include "./MagneticSensorA1334.h"
3+
#include "common/foc_utils.h"
4+
#include "common/time_utils.h"
5+
6+
MagneticSensorA1334::MagneticSensorA1334(int nCS, SPISettings settings) : A1334(settings, nCS) {
7+
8+
}
9+
10+
11+
MagneticSensorA1334::~MagneticSensorA1334(){
12+
13+
}
14+
15+
16+
void MagneticSensorA1334::init(SPIClass* _spi) {
17+
this->A1334::init(_spi);
18+
this->Sensor::init();
19+
}
20+
21+
22+
float MagneticSensorA1334::getSensorAngle() {
23+
A1334Angle angle_data = readRawAngle();
24+
float result = ( angle_data.angle / (float)A1334_CPR) * _2PI;
25+
// return the shaft angle
26+
return result;
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
#ifndef __MAGNETIC_SENSOR_A1334_H__
3+
#define __MAGNETIC_SENSOR_A1334_H__
4+
5+
#include "common/base_classes/Sensor.h"
6+
#include "./A1334.h"
7+
8+
9+
10+
class MagneticSensorA1334 : public Sensor, public A1334 {
11+
public:
12+
MagneticSensorA1334(int nCS = -1, SPISettings settings = A1334SPISettings);
13+
virtual ~MagneticSensorA1334();
14+
15+
virtual float getSensorAngle() override;
16+
17+
virtual void init(SPIClass* _spi = &SPI);
18+
private:
19+
};
20+
21+
22+
23+
24+
#endif

src/encoders/as5047/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# AS5047 SimpleFOC driver
22

3-
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:
3+
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:
44

55
- 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
66
- access to the error state of the sensor, and ability to clear errors
77
- 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
88

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

1011
## Hardware setup
1112

0 commit comments

Comments
 (0)