Skip to content

Commit 48489e2

Browse files
committed
Documentation
1 parent e2ec9a7 commit 48489e2

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ An EMA (**Exponential Moving Average**) filter behaves like an RC lowpass filter
5555
An EMA filter is implemented by e.g. the following statement:
5656

5757
```c++
58-
int16_t Lowpass5 += ((InputValue - Lowpass5) >> 5;
58+
int16_t sLowpass3;
59+
int16_t Lowpass5;
60+
...
61+
sLowpass3 += ((aInputValue - sLowpass3) + (1 << 2)) >> 3; // 1.8 us, alpha = 0.125, cutoff frequency 22.7 Hz @1kHz
62+
sLowpass5 += ((aInputValue - sLowpass5) + (1 << 4)) >> 5; // 2.5 us, alpha = 1/32 0.03125, cutoff frequency 5.13 Hz @1kHz
5963
```
6064
which takes **2.5 &micro;s on a 16 MHz Arduino Uno**.
6165

src/ADCUtils.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ void readAndPrintVCCVoltageMillivolt(Print *aSerial) {
481481
void readVCCVoltageSimple(void) {
482482
// use AVCC with (optional) external capacitor at AREF pin as reference
483483
float tVCC = readADCChannelWithReferenceMultiSamples(ADC_1_1_VOLT_CHANNEL_MUX, DEFAULT, 4);
484-
sVCCVoltage = (1023 * 1.1 * 4) / tVCC;
484+
sVCCVoltage = (1023 * (((float) ADC_INTERNAL_REFERENCE_MILLIVOLT) / 1000) * 4) / tVCC;
485485
}
486486

487487
/*

src/HCSR04.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
#include <stdint.h>
3636

3737
#define DISTANCE_TIMEOUT_RESULT 0
38-
#define US_DISTANCE_DEFAULT_TIMEOUT_MICROS 20000
39-
#define US_DISTANCE_DEFAULT_TIMEOUT_CENTIMETER 343 // Timeout of 20000L is 3.43 meter
38+
#define US_DISTANCE_DEFAULT_TIMEOUT_MICROS 20000 // Timeout of 20000L is 3.43 meter
39+
#define US_DISTANCE_DEFAULT_TIMEOUT_CENTIMETER 343 // Timeout of 20000L is 3.43 meter
4040

41-
#define US_DISTANCE_TIMEOUT_MICROS_FOR_1_METER 5825 // Timeout of 5825 is 1 meter
41+
#define US_DISTANCE_TIMEOUT_MICROS_FOR_1_METER 5825 // Timeout of 5825 is 1 meter
4242
#define US_DISTANCE_TIMEOUT_MICROS_FOR_2_METER 11650 // Timeout of 11650 is 2 meter
4343
#define US_DISTANCE_TIMEOUT_MICROS_FOR_3_METER 17475 // Timeout of 17475 is 3 meter
4444

src/HCSR04.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void initUSDistancePin(uint8_t aTriggerOutEchoInPin) {
137137

138138
/*
139139
* Start of standard blocking implementation using pulseInLong() since PulseIn gives wrong (too small) results :-(
140-
* @param aTimeoutMicros timeout of 5825 micros is equivalent to 1 meter, default timeout of 20000 micro seconds is 3.43 meter
140+
* @param aTimeoutMicros timeout of 5825 micros is equivalent to 1 meter, default timeout of 20000 micros is 3.43 meter
141141
* @return 0 / DISTANCE_TIMEOUT_RESULT if uninitialized or timeout happened
142142
*/
143143
unsigned int getUSDistance(unsigned int aTimeoutMicros) {

0 commit comments

Comments
 (0)