GY-63_MS5611/libraries/ACS712/ACS712.h

69 lines
1.8 KiB
C
Raw Normal View History

2020-03-19 10:16:52 -04:00
#pragma once
//
// FILE: ACS712.h
// AUTHOR: Rob Tillaart
2021-01-29 06:31:58 -05:00
// VERSION: 0.2.1
2020-11-27 05:10:47 -05:00
// DATE: 2020-08-02
2020-03-19 10:16:52 -04:00
// PURPOSE: ACS712 library - current measurement
//
// Tested with a RobotDyn ACS712 20A breakout + UNO.
//
#include "Arduino.h"
2021-01-29 06:31:58 -05:00
#define ACS712_LIB_VERSION "0.2.1"
2020-03-19 10:16:52 -04:00
class ACS712
{
public:
// NOTE:
// One can quite precisely tune the value of the sensor
// (1) the milliVolt per Ampere and
// (2) the volts parameter.
//
// TYPE mV per Ampere
// 5A 185
// 20A 100
// 30A 66
ACS712(uint8_t analogPin, float volts = 5.0, uint16_t maxADC = 1023, uint8_t mVperA = 100);
// returns mA
2020-11-27 05:10:47 -05:00
// blocks 20-21 ms to sample a whole 50 or 60 Hz period.
int mA_AC(uint8_t freq = 50);
2020-03-19 10:16:52 -04:00
// returns mA
// blocks < 1 ms
int mA_DC();
// midpoint ADC for DC only
2021-01-29 06:31:58 -05:00
inline void setMidPoint(uint16_t mp) { _midPoint = mp; };
2020-03-19 10:16:52 -04:00
inline uint16_t getMidPoint() { return _midPoint; };
inline void incMidPoint() { _midPoint++; };
inline void decMidPoint() { _midPoint--; };
2020-11-27 05:10:47 -05:00
// Auto midPoint, assuming zero DC current or any AC current
void autoMidPoint(uint8_t freq = 50);
2020-03-19 10:16:52 -04:00
// also known as crest factor; affects AC only
inline void setFormFactor(float ff) { _formFactor = ff; };
inline float getFormFactor() { return _formFactor; };
2020-11-27 05:10:47 -05:00
// noise
inline void setNoisemV(uint8_t noisemV) { _noisemV = noisemV; };
inline uint8_t getNoisemV() { return _noisemV; };
2020-03-19 10:16:52 -04:00
// AC and DC
inline void setmVperAmp(uint8_t mva) { _mVperAmpere = mva; };
inline uint8_t getmVperAmp() { return _mVperAmpere; };
private:
uint8_t _pin;
2021-01-29 06:31:58 -05:00
float _mVpstep; // millivolt per step
float _formFactor; // point2point -> RMS
2020-03-19 10:16:52 -04:00
uint8_t _mVperAmpere;
uint16_t _midPoint;
2020-11-27 05:10:47 -05:00
uint8_t _noisemV;
2020-03-19 10:16:52 -04:00
};
// END OF FILE