Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ACS712.h
00001 #ifndef ACS712_H 00002 #define ACS712_H 00003 00004 #define WAIT 5.0 00005 #include "mbed.h" 00006 00007 /** 00008 @file ACS712.h 00009 * @brief Library for interfacing ACS712 Hall Effect Current sensor 00010 * 00011 * @author Josh Marshall 00012 * 00013 * @date July 2019 00014 */ 00015 00016 00017 namespace mbed 00018 { 00019 class AnalogIn; 00020 } 00021 00022 class ACS712 00023 { 00024 00025 private: 00026 00027 mbed::AnalogIn *_aInPin; 00028 00029 public: 00030 00031 /** Constructor */ 00032 ACS712(PinName const outpin); 00033 00034 /** Destructor */ 00035 ~ACS712(); 00036 00037 /** 00038 * Initialise all peripherals and configure interrupts 00039 * @author Josh Marshall 00040 * @date July 2019 00041 */ 00042 void init(); 00043 00044 00045 /** 00046 * Reads current sensor 00047 * @returns current sensor value in range 0.0 to 1.0 00048 * @author Josh Marshall 00049 * @date July 2019 00050 */ 00051 double read_current_sensor(); 00052 00053 00054 /** 00055 * Read current sensor 00056 * @returns current sensor value in range 0 to 65535 (2^16-1) 00057 * K64F High‐speed 16‐bit ADC with configurable resolution 00058 * LPC1768 12-bit Analog-to-Digital Converter (ADC) with input multiplexing among 00059 * eight pins, conversion rates up to 200 kHz, and multiple result registers. 00060 * @author Josh Marshall 00061 * @date July 2019 00062 */ 00063 00064 00065 int read_ain_uint_16(); 00066 00067 /** 00068 * Read current sensor and convert to amps 00069 * @param acs_ffset the value that the current sensor outputs at 0 amps 00070 * @param gain from potential divider to map 5v out put of sensor onto 3.3v input 00071 * @param sensor type 5,20, or 30 amp 00072 * @author Josh Marshall 00073 * @date July 2019 00074 */ 00075 void convert_to_amps(float acs_offset, float gain, int type); 00076 00077 /** 00078 * If current spike (>1.1*operating current) from motor is detected it returns true flag 00079 * @param value of current from ACS712 Hall Effect Current Sensor 00080 * @prarm typical operating current 00081 * @author Josh Marshall 00082 * @date July 2019 00083 */ 00084 00085 bool over_current_detection(double operating_current); 00086 00087 /** 00088 * Returns the value frrom the current sensor 00089 * @author Josh Marshall 00090 * @date July 2019 00091 */ 00092 00093 float get_current_amps(); 00094 00095 private: 00096 00097 double _current; 00098 00099 }; 00100 00101 #endif
Generated on Wed Jul 13 2022 00:00:33 by
1.7.2