CN0396 (4-Wire Electrochemical Dual Toxic Gas Sensing System)
Dependencies: AD5270 AD7798 ADT7310
CN0396.h
00001 #ifndef _CN0396_H_ 00002 #define _CN0396_H_ 00003 #include <mbed.h> 00004 #include "AD7798.h" 00005 #include "AD5270.h" 00006 #include "ADT7310.h" 00007 00008 /** 00009 * @brief The CN0396 class 00010 */ 00011 00012 class CN0396 00013 { 00014 public: 00015 00016 #define V_REF 1.200 // [V] 00017 #define _2_16 65535.0 // 2^16 00018 #define _2_15 32767.0 // 2^16 00019 #define COMPENSATION_TABLE_SIZE 9 00020 00021 typedef enum { 00022 CO_SENSOR, 00023 H2S_SENSOR 00024 } sensor_type_t; 00025 00026 typedef struct { 00027 int8_t temp; 00028 float CO_percent; 00029 float H2S_percent; 00030 } ppm_compensation_t; 00031 00032 /** 00033 * @brief compensation look-up table 00034 */ 00035 ppm_compensation_t ppm_compensation[COMPENSATION_TABLE_SIZE]; 00036 00037 /** 00038 * @brief CN0396 class constructor 00039 * @param csad - chipselect pin of the ADC 00040 * @param csrdac - chipselect pin of the RDAC 00041 * @param cstemp - chipselect pin of the temperature sensor 00042 */ 00043 CN0396(PinName csad, PinName csrdac, PinName cstemp); 00044 /** 00045 * @brief Initializes the board 00046 */ 00047 void init(); 00048 00049 /** 00050 * @brief - Reads the sensor and computes the PPM values 00051 */ 00052 void read(); 00053 00054 /** 00055 * @brief computes the feedback resistor value for the sensor 00056 * @param sensitivity - sensor sensitivity 00057 * @param range - sensor range 00058 * @return resistor value 00059 */ 00060 float get_feedback_resistor_value(float sensitivity, float range); 00061 00062 /** 00063 * @brief configures the RDACs with the resistance values 00064 * @param resistance1 - resistance of RDAC1 00065 * @param resistance2 - resistance of RDAC2 00066 * @return 00067 */ 00068 void configure_feedback_resistors(float resistance1, float resistance2); 00069 00070 /** 00071 * @brief computes ADC counts-to-voltage in unipolar configuration 00072 * @param adcValue - value in counts 00073 * @param voltage - voltage value returned by the method 00074 * @param gain_adc - the gain of the adc 00075 */ 00076 void data_to_voltage(uint16_t adcValue, float *voltage, int gain_adc = 1); 00077 00078 /** 00079 * @brief computes ADC counts-to-voltage in bipolar configuration 00080 * @param adcValue - value in counts 00081 * @param voltage - voltage value returned by the method 00082 * @param gain_adc - the gain of the adc 00083 */ 00084 void data_to_voltage_bipolar(uint16_t adcValue, float *voltage, int gain_adc = 1); 00085 00086 /** 00087 * @brief compensates ppm value based on temperature reading 00088 * @param result - ppm value before compensation 00089 * @param temp - temperature used in compensation 00090 * @param sensor - sensor id 00091 * @return compensated value 00092 */ 00093 float compensate_ppm(float result, float temp, sensor_type_t sensor); 00094 DigitalOut csad, csrdac, cstemp; 00095 AD7798 ad; 00096 AD5270 rdac; 00097 ADT7310 temp; 00098 float resistance0, resistance1; 00099 private: 00100 00101 00102 }; 00103 #endif
Generated on Fri Jul 15 2022 03:23:55 by 1.7.2