VoltageReference
Arduino voltage reference library
VoltageReference.h
1/*
2 VoltageReference.cpp - VoltageReference library
3 Copyright (c) 2014 Roberto Lo Giacco.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation, either version 3 of the
8 License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef VOLTAGE_REFERENCE_H_
20#define VOLTAGE_REFERENCE_H_
21
22#include "Arduino.h"
23
24#define ANALOG_MAX_VALUE 0x3FF
25#define DEFAULT_REFERENCE_CALIBRATION 1126400L
26#define INVALID_REFERENCE_CALIBRATION 0xFFFFFFL
27
28#define getHiByte(calibration) (calibration >> 16)
29#define getMidByte(calibration) (calibration >> 8)
30#define getLowByte(calibration) (calibration & 0xFF)
31#define mergeBytes(hi, mid, low) ((((long)hi) << 16) | ((mid << 8) | ((low & 0xFF) & 0xFFFF)))
32
34 private:
35 uint32_t calibration;
36
40 uint16_t readInternalRef();
41 public:
42
47 void begin(uint32_t reference = DEFAULT_REFERENCE_CALIBRATION);
48
53 void begin(uint8_t hi, uint8_t mid, uint8_t low);
54
58 uint16_t readVcc();
59
63 uint32_t calibrate(uint16_t milliVolt);
64
68 uint16_t internalValue();
69
70};
71#endif // VOLTAGE_REFERENCE_H_
Definition: VoltageReference.h:33
void begin(uint32_t reference=DEFAULT_REFERENCE_CALIBRATION)
Definition: VoltageReference.cpp:22
uint16_t readVcc()
Definition: VoltageReference.cpp:52
uint32_t calibrate(uint16_t milliVolt)
Definition: VoltageReference.cpp:61
uint16_t internalValue()
Definition: VoltageReference.cpp:56