CN0216 weigh scale sensor library
Dependencies: AD7791
For additional information check out the mbed page of the Analog Devices wiki: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
CN0216.h@2:ea269fe29bab, 2016-08-18 (annotated)
- Committer:
- adisuciu
- Date:
- Thu Aug 18 12:36:12 2016 +0000
- Revision:
- 2:ea269fe29bab
- Parent:
- 0:afcb81077332
Implemented missing doxygen tags
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
adisuciu | 0:afcb81077332 | 1 | /** |
adisuciu | 0:afcb81077332 | 2 | * @file cn0216.h |
adisuciu | 0:afcb81077332 | 3 | * @brief Header file for CN0216 |
adisuciu | 0:afcb81077332 | 4 | * @author Analog Devices Inc. |
adisuciu | 0:afcb81077332 | 5 | * |
adisuciu | 0:afcb81077332 | 6 | * For support please go to: |
adisuciu | 0:afcb81077332 | 7 | * Github: https://github.com/analogdevicesinc/mbed-adi |
adisuciu | 0:afcb81077332 | 8 | * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers |
adisuciu | 0:afcb81077332 | 9 | * Product: www.analog.com/EVAL-CN0216-ARDZ |
adisuciu | 0:afcb81077332 | 10 | * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all |
adisuciu | 0:afcb81077332 | 11 | |
adisuciu | 0:afcb81077332 | 12 | ******************************************************************************** |
adisuciu | 0:afcb81077332 | 13 | * Copyright 2016(c) Analog Devices, Inc. |
adisuciu | 0:afcb81077332 | 14 | * |
adisuciu | 0:afcb81077332 | 15 | * All rights reserved. |
adisuciu | 0:afcb81077332 | 16 | * |
adisuciu | 0:afcb81077332 | 17 | * Redistribution and use in source and binary forms, with or without |
adisuciu | 0:afcb81077332 | 18 | * modification, are permitted provided that the following conditions are met: |
adisuciu | 0:afcb81077332 | 19 | * - Redistributions of source code must retain the above copyright |
adisuciu | 0:afcb81077332 | 20 | * notice, this list of conditions and the following disclaimer. |
adisuciu | 0:afcb81077332 | 21 | * - Redistributions in binary form must reproduce the above copyright |
adisuciu | 0:afcb81077332 | 22 | * notice, this list of conditions and the following disclaimer in |
adisuciu | 0:afcb81077332 | 23 | * the documentation and/or other materials provided with the |
adisuciu | 0:afcb81077332 | 24 | * distribution. |
adisuciu | 0:afcb81077332 | 25 | * - Neither the name of Analog Devices, Inc. nor the names of its |
adisuciu | 0:afcb81077332 | 26 | * contributors may be used to endorse or promote products derived |
adisuciu | 0:afcb81077332 | 27 | * from this software without specific prior written permission. |
adisuciu | 0:afcb81077332 | 28 | * - The use of this software may or may not infringe the patent rights |
adisuciu | 0:afcb81077332 | 29 | * of one or more patent holders. This license does not release you |
adisuciu | 0:afcb81077332 | 30 | * from the requirement that you obtain separate licenses from these |
adisuciu | 0:afcb81077332 | 31 | * patent holders to use this software. |
adisuciu | 0:afcb81077332 | 32 | * - Use of the software either in source or binary form, must be run |
adisuciu | 0:afcb81077332 | 33 | * on or directly connected to an Analog Devices Inc. component. |
adisuciu | 0:afcb81077332 | 34 | * |
adisuciu | 0:afcb81077332 | 35 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
adisuciu | 0:afcb81077332 | 36 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
adisuciu | 0:afcb81077332 | 37 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
adisuciu | 0:afcb81077332 | 38 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
adisuciu | 0:afcb81077332 | 39 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
adisuciu | 0:afcb81077332 | 40 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
adisuciu | 0:afcb81077332 | 41 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
adisuciu | 0:afcb81077332 | 42 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
adisuciu | 0:afcb81077332 | 43 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
adisuciu | 0:afcb81077332 | 44 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
adisuciu | 0:afcb81077332 | 45 | * |
adisuciu | 0:afcb81077332 | 46 | ********************************************************************************/ |
adisuciu | 0:afcb81077332 | 47 | |
adisuciu | 0:afcb81077332 | 48 | #include "mbed.h" |
adisuciu | 0:afcb81077332 | 49 | #include "AD7791.h" |
adisuciu | 0:afcb81077332 | 50 | |
adisuciu | 0:afcb81077332 | 51 | #ifndef CN0216_H_ |
adisuciu | 0:afcb81077332 | 52 | #define CN0216_H_ |
adisuciu | 0:afcb81077332 | 53 | |
adisuciu | 2:ea269fe29bab | 54 | |
adisuciu | 2:ea269fe29bab | 55 | /** |
adisuciu | 2:ea269fe29bab | 56 | * @brief EVAL-CN0216 weigh scale measurement shield |
adisuciu | 2:ea269fe29bab | 57 | */ |
adisuciu | 0:afcb81077332 | 58 | class CN0216 |
adisuciu | 0:afcb81077332 | 59 | { |
adisuciu | 0:afcb81077332 | 60 | public: |
adisuciu | 0:afcb81077332 | 61 | typedef enum { |
adisuciu | 0:afcb81077332 | 62 | ZERO_SCALE_CALIBRATION, ///< Calibration of the zero scale value |
adisuciu | 0:afcb81077332 | 63 | FULL_SCALE_CALIBRATION, ///< Calibration of the full scale value |
adisuciu | 0:afcb81077332 | 64 | COMPUTE_UNITS_PER_BIT ///< Units per LSB computation |
adisuciu | 0:afcb81077332 | 65 | } CalibrationStep_t; |
adisuciu | 0:afcb81077332 | 66 | |
adisuciu | 0:afcb81077332 | 67 | CN0216(PinName CSAD7791 = D8, PinName MOSI = SPI_MOSI, PinName MISO = SPI_MISO, PinName SCK = SPI_SCK); |
adisuciu | 0:afcb81077332 | 68 | void init(float cal_weight = _DEFAULT_CAL_WEIGHT, uint8_t mode_val = _DEFAULT_MODE_VAL, uint8_t filter_val = _DEFAULT_FILTER_VAL); |
adisuciu | 0:afcb81077332 | 69 | void calibrate(CalibrationStep_t cal); |
adisuciu | 0:afcb81077332 | 70 | float compute_weight(uint32_t data); |
adisuciu | 0:afcb81077332 | 71 | uint32_t read_u32(); |
adisuciu | 0:afcb81077332 | 72 | float read_weight(); |
adisuciu | 0:afcb81077332 | 73 | |
adisuciu | 0:afcb81077332 | 74 | private: |
adisuciu | 0:afcb81077332 | 75 | |
adisuciu | 0:afcb81077332 | 76 | const static int _NUMBER_OF_SAMPLES = 20; ///< Number of samples used in calibration |
adisuciu | 0:afcb81077332 | 77 | const static int _DEFAULT_MODE_VAL = AD7791::MD1 | AD7791::MD0; // POWERDOWN MODE |
adisuciu | 0:afcb81077332 | 78 | const static int _DEFAULT_FILTER_VAL = AD7791::FS0 | AD7791::FS1 | AD7791::FS2; |
adisuciu | 0:afcb81077332 | 79 | const static int _DEFAULT_CAL_WEIGHT = 1000.0; |
adisuciu | 0:afcb81077332 | 80 | |
adisuciu | 0:afcb81077332 | 81 | AD7791 ad7791; |
adisuciu | 0:afcb81077332 | 82 | float _cal_weight; |
adisuciu | 0:afcb81077332 | 83 | uint32_t _zero_scale_value; |
adisuciu | 0:afcb81077332 | 84 | uint32_t _full_scale_value; |
adisuciu | 0:afcb81077332 | 85 | float _weight_units_per_bit; |
adisuciu | 0:afcb81077332 | 86 | |
adisuciu | 0:afcb81077332 | 87 | }; |
adisuciu | 0:afcb81077332 | 88 | |
adisuciu | 0:afcb81077332 | 89 | #endif |