CN0357 toxic gas measurement sensor

Dependencies:   AD5270 AD7790

Dependents:   CN0357-helloworld

For additional information check out the mbed page of the Analog Devices wiki: https://wiki.analog.com/resources/tools-software/mbed-drivers-all

Committer:
adisuciu
Date:
Thu May 19 08:46:59 2016 +0000
Revision:
1:19e1bf69dc75
Parent:
0:db2cdeb6928a
Added library dependencies

Who changed what in which revision?

UserRevisionLine numberNew contents of line
adisuciu 0:db2cdeb6928a 1 /**
adisuciu 0:db2cdeb6928a 2 * @file cn0357.h
adisuciu 0:db2cdeb6928a 3 * @brief Header file for CN0357
adisuciu 0:db2cdeb6928a 4 * @author Analog Devices Inc.
adisuciu 0:db2cdeb6928a 5 *
adisuciu 0:db2cdeb6928a 6 * For support please go to:
adisuciu 0:db2cdeb6928a 7 * Github: https://github.com/analogdevicesinc/mbed-adi
adisuciu 0:db2cdeb6928a 8 * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
adisuciu 0:db2cdeb6928a 9 * Product: www.analog.com/EVAL-CN0357-ARDZ
adisuciu 0:db2cdeb6928a 10 * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
adisuciu 0:db2cdeb6928a 11
adisuciu 0:db2cdeb6928a 12 ********************************************************************************
adisuciu 0:db2cdeb6928a 13 * Copyright 2016(c) Analog Devices, Inc.
adisuciu 0:db2cdeb6928a 14 *
adisuciu 0:db2cdeb6928a 15 * All rights reserved.
adisuciu 0:db2cdeb6928a 16 *
adisuciu 0:db2cdeb6928a 17 * Redistribution and use in source and binary forms, with or without
adisuciu 0:db2cdeb6928a 18 * modification, are permitted provided that the following conditions are met:
adisuciu 0:db2cdeb6928a 19 * - Redistributions of source code must retain the above copyright
adisuciu 0:db2cdeb6928a 20 * notice, this list of conditions and the following disclaimer.
adisuciu 0:db2cdeb6928a 21 * - Redistributions in binary form must reproduce the above copyright
adisuciu 0:db2cdeb6928a 22 * notice, this list of conditions and the following disclaimer in
adisuciu 0:db2cdeb6928a 23 * the documentation and/or other materials provided with the
adisuciu 0:db2cdeb6928a 24 * distribution.
adisuciu 0:db2cdeb6928a 25 * - Neither the name of Analog Devices, Inc. nor the names of its
adisuciu 0:db2cdeb6928a 26 * contributors may be used to endorse or promote products derived
adisuciu 0:db2cdeb6928a 27 * from this software without specific prior written permission.
adisuciu 0:db2cdeb6928a 28 * - The use of this software may or may not infringe the patent rights
adisuciu 0:db2cdeb6928a 29 * of one or more patent holders. This license does not release you
adisuciu 0:db2cdeb6928a 30 * from the requirement that you obtain separate licenses from these
adisuciu 0:db2cdeb6928a 31 * patent holders to use this software.
adisuciu 0:db2cdeb6928a 32 * - Use of the software either in source or binary form, must be run
adisuciu 0:db2cdeb6928a 33 * on or directly connected to an Analog Devices Inc. component.
adisuciu 0:db2cdeb6928a 34 *
adisuciu 0:db2cdeb6928a 35 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
adisuciu 0:db2cdeb6928a 36 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
adisuciu 0:db2cdeb6928a 37 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
adisuciu 0:db2cdeb6928a 38 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
adisuciu 0:db2cdeb6928a 39 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
adisuciu 0:db2cdeb6928a 40 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
adisuciu 0:db2cdeb6928a 41 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
adisuciu 0:db2cdeb6928a 42 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
adisuciu 0:db2cdeb6928a 43 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
adisuciu 0:db2cdeb6928a 44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
adisuciu 0:db2cdeb6928a 45 *
adisuciu 0:db2cdeb6928a 46 ********************************************************************************/
adisuciu 0:db2cdeb6928a 47
adisuciu 0:db2cdeb6928a 48 #ifndef CN0357_H
adisuciu 0:db2cdeb6928a 49 #define CN0357_H
adisuciu 0:db2cdeb6928a 50
adisuciu 0:db2cdeb6928a 51 #include "mbed.h"
adisuciu 0:db2cdeb6928a 52 #include "AD7790.h"
adisuciu 0:db2cdeb6928a 53 #include "AD5270.h"
adisuciu 0:db2cdeb6928a 54
adisuciu 0:db2cdeb6928a 55 /**
adisuciu 0:db2cdeb6928a 56 * @brief EVAL-CN0357 toxic gas sensor shield
adisuciu 0:db2cdeb6928a 57 */
adisuciu 0:db2cdeb6928a 58 class CN0357
adisuciu 0:db2cdeb6928a 59 {
adisuciu 0:db2cdeb6928a 60 public:
adisuciu 0:db2cdeb6928a 61
adisuciu 0:db2cdeb6928a 62 private:
adisuciu 0:db2cdeb6928a 63 float _vref;
adisuciu 0:db2cdeb6928a 64 float _sensor_sensitivity;
adisuciu 0:db2cdeb6928a 65 float _sensor_range;
adisuciu 0:db2cdeb6928a 66 float _RDACvalue;
adisuciu 0:db2cdeb6928a 67 public:
adisuciu 0:db2cdeb6928a 68 AD7790 ad7790; ///< AD7790 instance - can be used for manual overriding
adisuciu 0:db2cdeb6928a 69 AD5270 ad5270; ///< AD5270 instance - can be used for manual overriding
adisuciu 0:db2cdeb6928a 70
adisuciu 0:db2cdeb6928a 71 /// CN0357 shield jumper configuration
adisuciu 0:db2cdeb6928a 72 typedef enum {
adisuciu 0:db2cdeb6928a 73 INTERNAL_AD7790 = 0, ///< The shield's AD7790 is used
adisuciu 0:db2cdeb6928a 74 EXTERNAL_ADC ///< Sensor analog output is routed to A1 pin of the shield
adisuciu 0:db2cdeb6928a 75 } JumperConfig_t;
adisuciu 0:db2cdeb6928a 76
adisuciu 0:db2cdeb6928a 77 CN0357(PinName CSAD7790 = D8, PinName CSAD5270 = D6, PinName MOSI = SPI_MOSI, PinName MISO = SPI_MISO, PinName SCK = SPI_SCK);
adisuciu 0:db2cdeb6928a 78 void init(float range, float sensitivity, JumperConfig_t jp = INTERNAL_AD7790, uint8_t mode_val = _DEFAULT_MODE_VAL, uint8_t filter_val = _DEFAULT_FILTER_VAL);
adisuciu 0:db2cdeb6928a 79
adisuciu 0:db2cdeb6928a 80 uint8_t read_adc_status(void);
adisuciu 0:db2cdeb6928a 81 uint16_t read_sensor(void);
adisuciu 0:db2cdeb6928a 82 float read_sensor_voltage(void);
adisuciu 0:db2cdeb6928a 83 float data_to_voltage(uint16_t data);
adisuciu 0:db2cdeb6928a 84 float calc_ppm(float adcVoltage);
adisuciu 0:db2cdeb6928a 85 float read_ppm(void);
adisuciu 0:db2cdeb6928a 86
adisuciu 0:db2cdeb6928a 87 void set_RDAC_value(float resistor_val);
adisuciu 0:db2cdeb6928a 88 float get_RDAC_value(void);
adisuciu 0:db2cdeb6928a 89 float set_sensor_parameters(float range, float sensitivity);
adisuciu 0:db2cdeb6928a 90 float get_sensor_range(void);
adisuciu 0:db2cdeb6928a 91 float get_sensor_sensitivity(void);
adisuciu 0:db2cdeb6928a 92
adisuciu 0:db2cdeb6928a 93 private:
adisuciu 0:db2cdeb6928a 94 const static int _RESET = 0xff;
adisuciu 0:db2cdeb6928a 95 const static int _DEFAULT_MODE_VAL = AD7790::MD1 | AD7790::MD0; // POWERDOWN MODE
adisuciu 0:db2cdeb6928a 96 const static int _DEFAULT_FILTER_VAL = AD7790::FS0 | AD7790::FS1 | AD7790::FS2;
adisuciu 0:db2cdeb6928a 97 void _rdac_init(float resistanceValue);
adisuciu 0:db2cdeb6928a 98 void _AD7790_init(uint8_t mode_val, uint8_t filter_val);
adisuciu 0:db2cdeb6928a 99
adisuciu 0:db2cdeb6928a 100 };
adisuciu 0:db2cdeb6928a 101
adisuciu 0:db2cdeb6928a 102 #endif // CN0357_H