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: torque_calibration_ywsim
Revision 5:4f34d26cc9e7, committed 2021-02-12
- Comitter:
- ywsim
- Date:
- Fri Feb 12 22:50:27 2021 +0000
- Parent:
- 4:d7a5cd03ed09
- Commit message:
- aa
Changed in this revision
HX711.cpp | Show annotated file Show diff for this revision Revisions of this file |
HX711.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/HX711.cpp Wed Sep 13 09:11:22 2017 +0000 +++ b/HX711.cpp Fri Feb 12 22:50:27 2021 +0000 @@ -18,84 +18,41 @@ HX711::HX711 ( PinName PD_SCK, PinName DOUT ) - : _PD_SCK ( PD_SCK ) - , _DOUT ( DOUT ) -{ - -} + : _PD_SCK( PD_SCK ) + , _DOUT( DOUT ) +{} - -HX711::~HX711() -{ -} - - +HX711::~HX711(){} /** * @brief HX711_Reset ( void ) - * * @details It performs an internal reset. - * * @param[in] NaN. - * * @param[out] NaN. - * - * * @return Status of HX711_Reset. - * - * * @author Manuel Caballero * @date 11/September/2017 * @version 11/September/2017 The ORIGIN * @pre When PD_SCK pin changes from low to high and stays at high for * longer than 60μs, HX711 enters power down mode. - * - * When PD_SCK returns to low, chip will reset and enter normal + * When PD_SCK returns to low, chip will reset and enter normal * operation mode. * @warning NaN. */ -HX711::HX711_status_t HX711::HX711_Reset ( void ) -{ +HX711::HX711_status_t HX711::HX711_Reset(void){ _PD_SCK = HX711_PIN_HIGH; - wait_us ( 120 ); // Datasheet p5. At least 60us ( Security Factor: 2*60us = 120us ) + wait_us ( 120 ); // Datasheet p5. At least 60us ( Security Factor: 2*60us = 120us ) _PD_SCK = HX711_PIN_LOW; - - if ( _DOUT == HX711_PIN_HIGH ) return HX711_SUCCESS; else return HX711_FAILURE; } - - -/** - * @brief HX711_PowerDown ( void ) - * - * @details It puts the device in power-down mode. - * - * @param[in] NaN. - * - * @param[out] NaN. - * - * - * @return Status of HX711_PowerDown. - * - * - * @author Manuel Caballero - * @date 11/September/2017 - * @version 11/September/2017 The ORIGIN - * @pre When PD_SCK pin changes from low to high and stays at high for - * longer than 60μs, HX711 enters power down mode. - * @warning NaN. - */ -HX711::HX711_status_t HX711::HX711_PowerDown ( void ) -{ +HX711::HX711_status_t HX711::HX711_PowerDown(void){ _PD_SCK = HX711_PIN_HIGH; - wait_us ( 120 ); // Datasheet p5. At least 60us ( Security Factor: 2*60us = 120us ) - - + wait_us ( 120 ); // Datasheet p5. At least 60us ( Security Factor: 2*60us = 120us ) if ( _DOUT == HX711_PIN_HIGH ) return HX711_SUCCESS; @@ -107,27 +64,16 @@ /** * @brief HX711_SetChannelAndGain ( HX711_channel_gain_t myChannel_Gain ) - * * @details It sets both the channel and the gain for the next measurement. - * * @param[in] myChannel_Gain: Channel and Gain to perform the new measurement. - * * @param[out] NaN. - * - * * @return Status of HX711_SetChannelAndGain. - * - * - * @author Manuel Caballero - * @date 11/September/2017 - * @version 11/September/2017 The ORIGIN - * @pre NaN. - * @warning NaN. */ -HX711::HX711_status_t HX711::HX711_SetChannelAndGain ( HX711_channel_gain_t myChannel_Gain ) + +HX711::HX711_status_t HX711::HX711_SetChannelAndGain( HX711_channel_gain_t myChannel_Gain ) { uint32_t myPulses = 0; - uint32_t i = 0; // Counter and timeout variable + uint32_t i = 0; // Counter and timeout variable // Select the gain/channel switch ( myChannel_Gain ) { @@ -168,68 +114,34 @@ myPulses--; } while ( myPulses > 0 ); - - - if ( _DOUT == HX711_PIN_HIGH ) return HX711_SUCCESS; else return HX711_FAILURE; } - - /** * @brief HX711_GetChannelAndGain ( void ) - * * @details It gets both the channel and the gain for the current measurement. - * * @param[in] NaN. - * * @param[out] NaN. - * - * * @return Channel and Gain. - * - * - * @author Manuel Caballero - * @date 12/September/2017 - * @version 12/September/2017 The ORIGIN - * @pre NaN. - * @warning NaN. */ HX711::HX711_channel_gain_t HX711::HX711_GetChannelAndGain ( void ) { return _HX711_CHANNEL_GAIN; } - - /** * @brief HX711_ReadRawData ( HX711_channel_gain_t myChannel_Gain, Vector_count_t*, uint32_t ) - * * @details It reads the raw data from the device according to the channel * and its gain. - * * @param[in] myChannel_Gain: Channel and Gain to perform the new read. * @param[in] myAverage: How many measurement we have to get and deliver the average. - * * @param[out] myNewRawData: The new value from the device. - * - * * @return Status of HX711_ReadRawData. - * - * - * @author Manuel Caballero - * @date 11/September/2017 - * @version 12/September/2017 Gain mode was fixed, now it gets the value - * a given gain/channel. A timeout was added to - * avoid the microcontroller gets stuck. - * 11/September/2017 The ORIGIN - * @pre NaN. - * @warning NaN. */ -HX711::HX711_status_t HX711::HX711_ReadRawData ( HX711_channel_gain_t myChannel_Gain, Vector_count_t* myNewRawData, uint32_t myAverage ) +HX711::HX711_status_t HX711::HX711_ReadRawData( HX711_channel_gain_t myChannel_Gain, Vector_count_t* myNewRawData, uint32_t myAverage ) { uint32_t i = 0; // Counter and timeout variable uint32_t ii = 0; // Counter variable @@ -341,47 +253,29 @@ * @pre NaN. * @warning NaN. */ -HX711::HX711_status_t HX711::HX711_ReadData_WithCalibratedMass ( HX711_channel_gain_t myChannel_Gain, Vector_count_t* myNewRawData, uint32_t myAverage ) -{ +HX711::HX711_status_t HX711::HX711_ReadData_WithCalibratedMass( HX711_channel_gain_t myChannel_Gain, Vector_count_t* myNewRawData, uint32_t myAverage ){ HX711_status_t aux; // Perform a new bunch of readings aux = HX711_ReadRawData ( myChannel_Gain, myNewRawData, myAverage ); - // Update the value with a calibrated mass myNewRawData->myRawValue_WithCalibratedMass = myNewRawData->myRawValue; - - - if ( aux == HX711_SUCCESS ) - return HX711_SUCCESS; - else - return HX711_FAILURE; + if ( aux == HX711_SUCCESS ) return HX711_SUCCESS; + else return HX711_FAILURE; } - /** * @brief HX711_ReadData_WithoutMass ( HX711_channel_gain_t myChannel_Gain, Vector_count_t* myNewRawData, uint32_t myAverage ) - * * @details It reads data without any mass on the load cell. - * * @param[in] myChannel_Gain: Gain/Channel to perform the new measurement. * @param[in] myAverage: How many data to read. - * * @param[out] myNewRawData: myRawValue_WithoutCalibratedMass ( ADC code taken without any mass ). - * - * * @return Status of HX711_ReadData_WithoutMass. - * - * - * @author Manuel Caballero - * @date 12/September/2017 - * @version 12/September/2017 The ORIGIN - * @pre NaN. - * @warning NaN. */ + HX711::HX711_status_t HX711::HX711_ReadData_WithoutMass ( HX711_channel_gain_t myChannel_Gain, Vector_count_t* myNewRawData, uint32_t myAverage ) { HX711_status_t aux; @@ -389,44 +283,25 @@ // Perform a new bunch of readings aux = HX711_ReadRawData ( myChannel_Gain, myNewRawData, myAverage ); - // Update the value without any mass myNewRawData->myRawValue_WithoutCalibratedMass = myNewRawData->myRawValue; - - - if ( aux == HX711_SUCCESS ) - return HX711_SUCCESS; - else - return HX711_FAILURE; + if ( aux == HX711_SUCCESS ) return HX711_SUCCESS; + else return HX711_FAILURE; } - /** * @brief HX711_CalculateMass ( Vector_count_t* myNewRawData, uint32_t myCalibratedMass, HX711_scale_t myScaleCalibratedMass ) - * * @details It calculates the mass. - * * @param[in] myNewRawData: It has myRawValue_WithCalibratedMass ( ADC code taken with calibrated mass ), * myRawValue_WithoutCalibratedMass ( ADC code taken without any mass ) and * myRawValue ( the current data taken by the system ). * @param[in] myCalibratedMass: A known value for the calibrated mass when myRawValue_WithCalibratedMass was * calculated. * @param[in] myScaleCalibratedMass: The range of the calibrated mass ( kg, g, mg or ug ). - * * @param[out] NaN. - * - * * @return The calculated mass. - * - * - * @author Manuel Caballero - * @date 12/September/2017 - * @version 13/September/2017 Adapt the scale was fixed, myFactor now works as expected. - * 12/September/2017 The ORIGIN - * @pre NaN. - * @warning NaN. */ HX711::Vector_mass_t HX711::HX711_CalculateMass ( Vector_count_t* myNewRawData, float myCalibratedMass, HX711_scale_t myScaleCalibratedMass ) { @@ -435,10 +310,8 @@ float c_zs, w_fs, c_fs, w_t; float c = 0; float myFactor = 1.0; - Vector_mass_t w; - // Adapt the scale ( kg as reference ) switch ( myScaleCalibratedMass ) { default: @@ -457,15 +330,12 @@ case HX711_SCALE_ug: myFactor /= 1000000000.0; break; - } - // Calculate the Calibration Constant ( m ) w_fs = ( myCalibratedMass / myFactor ); // User-specified calibration mass c_zs = myNewRawData->myRawValue_WithoutCalibratedMass; // ADC measurement taken with no load c_fs = myNewRawData->myRawValue_WithCalibratedMass; // ADC code taken with the calibration mass applied - m = ( float )( w_fs / ( ( c_fs ) - c_zs ) ); // The Calibration Constant
--- a/HX711.h Wed Sep 13 09:11:22 2017 +0000 +++ b/HX711.h Fri Feb 12 22:50:27 2021 +0000 @@ -2,8 +2,7 @@ * @brief HX711.h * @details 24-Bit Analog-to-Digital Converter (ADC) for Weigh Scales. * Header file. - * - * + * @return NA * * @author Manuel Caballero @@ -18,7 +17,6 @@ #include "mbed.h" - /** Example: