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.
Dependents: weightscale Projet-BTS-balance Programme_Final_V6
ADS1231.h
00001 /** 00002 * @brief ADS1231.h 00003 * @details 24-Bit Analog-to-Digital Converter for Bridge Sensors. 00004 * Header file. 00005 * 00006 * 00007 * @return NA 00008 * 00009 * @author Manuel Caballero 00010 * @date 18/September/2017 00011 * @version 18/September/2017 The ORIGIN 00012 * @pre NaN. 00013 * @warning NaN 00014 * @pre This code belongs to Nimbus Centre ( http://www.nimbus.cit.ie ). 00015 */ 00016 #ifndef ADS1231_H 00017 #define ADS1231_H 00018 00019 #include "mbed.h" 00020 00021 00022 /** 00023 Example: 00024 00025 #include "mbed.h" 00026 #include "ADS1231.h" 00027 00028 ADS1231 myWeightSensor ( p5, p6 ); 00029 Serial pc ( USBTX, USBRX ); 00030 00031 Ticker newReading; 00032 DigitalOut myled1 ( LED1 ); 00033 DigitalOut myled2 ( LED2 ); 00034 DigitalOut myled3 ( LED3 ); 00035 DigitalOut myled4 ( LED4 ); 00036 00037 ADS1231::ADS1231_status_t aux; 00038 ADS1231::Vector_count_t myData; 00039 ADS1231::Vector_mass_t myCalculatedMass; 00040 ADS1231::Vector_voltage_t myCalculatedVoltage; 00041 00042 00043 void readDATA ( void ) 00044 { 00045 myled4 = 1; 00046 00047 aux = myWeightSensor.ADS1231_ReadRawData ( &myData, 4 ); 00048 myCalculatedMass = myWeightSensor.ADS1231_CalculateMass ( &myData, 1.0, ADS1231::ADS1231_SCALE_kg ); 00049 myCalculatedVoltage = myWeightSensor.ADS1231_CalculateVoltage ( &myData, 5.0 ); 00050 00051 pc.printf( "Raw Data: %ld Mass: %0.5f kg Voltage: %0.5f mV\r\n", (uint32_t)myData.myRawValue, myCalculatedMass.myMass, 1000*myCalculatedVoltage.myVoltage ); 00052 00053 myled4 = 0; 00054 } 00055 00056 00057 int main() 00058 { 00059 pc.baud ( 115200 ); 00060 00061 00062 // Reset and wake the device up 00063 aux = myWeightSensor.ADS1231_PowerDown (); 00064 aux = myWeightSensor.ADS1231_Reset (); 00065 wait(1); 00066 00067 00068 // CALIBRATION time start! 00069 // 1. REMOVE THE MASS ON THE LOAD CELL ( ALL LEDs OFF ). Read data without any mass on the load cell 00070 aux = myWeightSensor.ADS1231_ReadData_WithoutMass ( &myData, 4 ); 00071 00072 myled1 = 1; 00073 wait(3); 00074 00075 00076 // 2. PUT A KNOWN MASS ON THE LOAD CELL ( JUST LED1 ON ). Read data with an user-specified calibration mass 00077 aux = myWeightSensor.ADS1231_ReadData_WithCalibratedMass ( &myData, 4 ); 00078 // CALIBRATION time end! 00079 00080 00081 // [ OPTIONAL ] REMOVE THE MASS ON THE LOAD CELL ( JUST LED2 ON ). Read the device without any mass to calculate the tare weight for 5 seconds 00082 myled1 = 0; 00083 myled2 = 1; 00084 wait(3); 00085 myled2 = 0; 00086 00087 // Calculating the tare weight ( JUST LED3 ON ) 00088 myled3 = 1; 00089 aux = myWeightSensor.ADS1231_SetAutoTare ( ADS1231::ADS1231_SCALE_kg, &myData, 5 ); 00090 myled3 = 0; 00091 00092 00093 newReading.attach( &readDATA, 0.5 ); // the address of the function to be attached ( readDATA ) and the interval ( 0.5s ) ( JUST LED4 BLINKING ) 00094 00095 // Let the callbacks take care of everything 00096 while(1) 00097 { 00098 sleep(); 00099 } 00100 } 00101 00102 */ 00103 00104 00105 /*! 00106 Library for the ADS1231 24-Bit Analog-to-Digital Converter for Bridge Sensors. 00107 */ 00108 class ADS1231 00109 { 00110 public: 00111 /** 00112 * @brief READY/BUSY DATA 00113 */ 00114 typedef enum { 00115 ADS1231_DATA_BUSY = 0, /*!< ADS1231 data is NOT ready to be read. */ 00116 ADS1231_DATA_READY = 1 /*!< ADS1231 data is ready to be read. */ 00117 } ADS1231_data_output_status_t; 00118 00119 00120 00121 /** 00122 * @brief SCALE 00123 */ 00124 typedef enum { 00125 ADS1231_SCALE_kg = 0, /*!< ADS1231 Scale in kg. */ 00126 ADS1231_SCALE_g = 1, /*!< ADS1231 Scale in g. */ 00127 ADS1231_SCALE_mg = 2, /*!< ADS1231 Scale in mg. */ 00128 ADS1231_SCALE_ug = 3 /*!< ADS1231 Scale in ug. */ 00129 } ADS1231_scale_t; 00130 00131 00132 00133 00134 #ifndef VECTOR_STRUCT_H 00135 #define VECTOR_STRUCT_H 00136 typedef struct { 00137 float myRawValue_WithCalibratedMass; 00138 float myRawValue_WithoutCalibratedMass; 00139 float myRawValue_TareWeight; 00140 uint32_t myRawValue; 00141 } Vector_count_t; 00142 00143 typedef struct { 00144 float myMass; 00145 } Vector_mass_t; 00146 00147 typedef struct { 00148 float myVoltage; 00149 } Vector_voltage_t; 00150 #endif 00151 00152 00153 00154 /** 00155 * @brief INTERNAL CONSTANTS 00156 */ 00157 #define ADS1231_PIN_HIGH 0x01 /*!< Pin 'HIGH' */ 00158 #define ADS1231_PIN_LOW 0x00 /*!< Pin 'LOW' */ 00159 00160 typedef enum { 00161 ADS1231_SUCCESS = 0, 00162 ADS1231_FAILURE = 1, 00163 } ADS1231_status_t; 00164 00165 00166 00167 00168 /** Create an ADS1231 object connected to the specified pins. 00169 * 00170 * @param sclk ADS1231 Power down control (high active) and serial clock input 00171 * @param dout ADS1231 Serial data output 00172 */ 00173 ADS1231 ( PinName SCLK, PinName DOUT ); 00174 00175 /** Delete ADS1231 object. 00176 */ 00177 ~ADS1231(); 00178 00179 /** It performs an internal reset. 00180 */ 00181 ADS1231_status_t ADS1231_Reset ( void ); 00182 00183 /** It puts the device into power-down mode. 00184 */ 00185 ADS1231_status_t ADS1231_PowerDown ( void ); 00186 00187 /** It reads raw data from the device. 00188 */ 00189 ADS1231_status_t ADS1231_ReadRawData ( Vector_count_t* myNewRawData, uint32_t myAverage ); 00190 00191 /** It reads raw data with an user-specified calibrated mass. 00192 */ 00193 ADS1231_status_t ADS1231_ReadData_WithCalibratedMass ( Vector_count_t* myNewRawData, uint32_t myAverage ); 00194 00195 /** It reads raw data without any mass. 00196 */ 00197 ADS1231_status_t ADS1231_ReadData_WithoutMass ( Vector_count_t* myNewRawData, uint32_t myAverage ); 00198 00199 /** It reads raw data without any mass after the system is calibrated. 00200 */ 00201 ADS1231_status_t ADS1231_SetAutoTare ( float myCalibratedMass, ADS1231_scale_t myScaleCalibratedMass, Vector_count_t* myNewRawData, float myTime ); 00202 00203 /** It sets a tare weight manually. 00204 */ 00205 Vector_count_t ADS1231_SetManualTare ( float myTareWeight ); 00206 00207 /** It calculates scaled data. 00208 */ 00209 Vector_mass_t ADS1231_CalculateMass ( Vector_count_t* myNewRawData, float myCalibratedMass, ADS1231_scale_t myScaleCalibratedMass ); 00210 00211 /** It calculates voltage data. 00212 */ 00213 Vector_voltage_t ADS1231_CalculateVoltage ( Vector_count_t* myNewRawData, float myVoltageReference ); 00214 00215 00216 00217 00218 private: 00219 DigitalOut _SCLK; 00220 DigitalIn _DOUT; 00221 ADS1231_scale_t _ADS1231_SCALE; 00222 float _ADS1231_USER_CALIBATED_MASS; 00223 }; 00224 00225 #endif
Generated on Wed Jul 13 2022 10:48:14 by
1.7.2