SimpleFOClibrary 2.4.0
Loading...
Searching...
No Matches
MagneticSensorAnalog.cpp
Go to the documentation of this file.
2
3/** MagneticSensorAnalog(uint8_t _pinAnalog, int _min, int _max)
4 * @param _pinAnalog the pin that is reading the pwm from magnetic sensor
5 * @param _min_raw_count the smallest expected reading. Whilst you might expect it to be 0 it is often ~15. Getting this wrong results in a small click once per revolution
6 * @param _max_raw_count the largest value read. whilst you might expect it to be 2^10 = 1023 it is often ~ 1020. Note: For ESP32 (with 12bit ADC the value will be nearer 4096)
7 */
8MagneticSensorAnalog::MagneticSensorAnalog(uint8_t _pinAnalog, int _min_raw_count, int _max_raw_count){
9
10 pinAnalog = _pinAnalog;
11
12 cpr = _max_raw_count - _min_raw_count;
13 min_raw_count = _min_raw_count;
14 max_raw_count = _max_raw_count;
15
17 pinMode(pinAnalog, INPUT_PULLUP);
18 }else{
19 pinMode(pinAnalog, INPUT);
20 }
21
22}
23
24
26 raw_count = getRawCount();
27
28 this->Sensor::init(); // call base class init
29}
30
31// Shaft angle calculation
32// angle is in radians [rad]
34 // raw data from the sensor
35 raw_count = getRawCount();
36 return ( (float) (raw_count) / (float)cpr) * _2PI;
37}
38
39// function reading the raw counter of the magnetic sensor
40int MagneticSensorAnalog::getRawCount(){
41 return analogRead(pinAnalog);
42}
@ USE_INTERN
Use internal pullups.
Definition Sensor.h:20
MagneticSensorAnalog(uint8_t _pinAnalog, int _min=0, int _max=0)
int pinAnalog
encoder hardware pin A
float getSensorAngle() override
virtual void init()
Definition Sensor.cpp:59
#define _2PI
Definition foc_utils.h:29