Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CPR configuration option to SC60228 Encoder #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/encoders/sc60228/MagneticSensorSC60228.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "common/foc_utils.h"
#include "common/time_utils.h"

MagneticSensorSC60228::MagneticSensorSC60228(int nCS, SPISettings settings) : SC60228(settings, nCS){
MagneticSensorSC60228::MagneticSensorSC60228(int nCS, uint32_t cpr, SPISettings settings) : SC60228(settings, nCS), cpr_(cpr){
// nix
};
MagneticSensorSC60228::~MagneticSensorSC60228(){ };
Expand All @@ -12,7 +12,7 @@ MagneticSensorSC60228::~MagneticSensorSC60228(){ };

float MagneticSensorSC60228::getSensorAngle(){
SC60228Angle angle_data = readRawAngle();
float result = ( angle_data.angle / (float)SC60228_CPR ) * _2PI;
float result = ( angle_data.angle / (float)cpr_ ) * _2PI;
return result;
};

Expand Down
3 changes: 2 additions & 1 deletion src/encoders/sc60228/MagneticSensorSC60228.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

class MagneticSensorSC60228 : public Sensor, public SC60228 {
public:
MagneticSensorSC60228(int nCS = -1, SPISettings settings = SC60228SPISettings);
MagneticSensorSC60228(int nCS = -1, uint32_t cpr=4096, SPISettings settings = SC60228SPISettings);
virtual ~MagneticSensorSC60228();

virtual float getSensorAngle() override;

virtual void init(SPIClass* _spi = &SPI) override;
uint32_t cpr_;
};


Expand Down
5 changes: 4 additions & 1 deletion src/encoders/sc60228/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ void setup() {
Set some options:

```c++
MagneticSensorSC60228 sensor1(SENSOR1_CS, mySPISettings);
// set counts_per_revolution (which should be the default 4096, but one some hardware appears to be 2048), and spi settings
MagneticSensorSC60228 sensor1(SENSOR1_CS, 4096, mySPISettings);
// or with default SPI settings, just override cpr to a non-default value
MagneticSensorSC60228 sensor1(SENSOR1_CS, 2048);
```

Use another SPI bus:
Expand Down
1 change: 0 additions & 1 deletion src/encoders/sc60228/SC60228.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ typedef union {
} SC60228Angle;


#define SC60228_CPR 4096
#define SC60228_BITORDER MSBFIRST

static SPISettings SC60228SPISettings(8000000, SC60228_BITORDER, SPI_MODE1); // @suppress("Invalid arguments")
Expand Down