-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathMagneticSensorMA735SSI.cpp
More file actions
34 lines (25 loc) · 1.01 KB
/
MagneticSensorMA735SSI.cpp
File metadata and controls
34 lines (25 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "./MagneticSensorMA735SSI.h"
#include "common/foc_utils.h"
#include "common/time_utils.h"
MagneticSensorMA735SSI::MagneticSensorMA735SSI(SPISettings settings) : settings(settings) {
}
MagneticSensorMA735SSI::~MagneticSensorMA735SSI() {
}
void MagneticSensorMA735SSI::init(SPIClass* _spi) {
this->spi=_spi;
this->Sensor::init();
}
// check 40us delay between each read?
float MagneticSensorMA735SSI::getSensorAngle() {
float angle_data = readRawAngleSSI();
angle_data = ( angle_data / (float)MA735_16BIT ) * _2PI;//It doesn't matter that it is divided by 65536, because the raw angle fills empty data bits with empty zeros so sensor resolution doesn't affect angle calculation
// return the shaft angle
return angle_data;
}
uint16_t MagneticSensorMA735SSI::readRawAngleSSI() {
spi->beginTransaction(settings);
uint16_t value = spi->transfer16(0x0000);
//uint16_t parity = spi->transfer(0x00);
spi->endTransaction();
return (value<<1); //>>1)&0x3FFF;
}; // 9-13bit angle value