This repository has been archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRPMMeasure.h
73 lines (55 loc) · 1.45 KB
/
RPMMeasure.h
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef RPMMeasure_h
#define RPMMeasure_h
#include <Arduino.h>
#include <FreqMeasure.h>
#include <InterruptFreqMeasure.h>
//Assume some arbitrary defaults.
#define DEFAULT_PPR 4
#define DEFAULT_AVERAGING_DEPTH 0
//At 0 RPM there would be no pulses,
//this value determines how long we will wait for a pulse before considering it 0 RPM.
//IE: 100RPM * 2PPR = 300ms
#define DEAD_RPM_TIME 300
//This is a calibration of FreqMeasure to limit false readings.
#define FREQMEASURE_OVERFLOW_IGNORE_TICKS 0xC000
//The maximum buffer depth for averaging.
#define MAX_RPM_BUF 12
typedef int8_t measureMode_t;
class RPMMeasureMode{
public:
enum modes: measureMode_t{
None = -1,
Interrupt = 0,
Timer1 = 1
};
};
typedef uint32_t (*IntervalReader)();
class RPMMeasure{
public:
RPMMeasure(uint8_t interruptPin=2, uint8_t interruptNum=0, uint8_t timer1Pin=8);
~RPMMeasure();
void
update(void),
setPulsesPerRevolution(uint8_t ppr),
setMeasureMode(measureMode_t mode),
setAveragingDepth(uint8_t depth),
begin(),
end();
uint16_t
getRPM();
private:
uint32_t lastReading;
uint16_t rpm;
uint16_t *rpmBuffer = NULL;
uint8_t
averagingDepth,
pulsesPerRevolution,
interruptPin,
interruptNum,
timer1Pin,
bufferHead;
bool begun;
measureMode_t measureMode;
uint16_t intervalToRPM(uint32_t interval);
};
#endif