A collection of Analog Devices drivers for the mbed platform
Embed:
(wiki syntax)
Show/hide line numbers
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 class CN0396 00012 { 00013 public: 00014 00015 #define V_REF 1.200 // [V] 00016 #define _2_16 65535.0 // 2^16 00017 #define _2_15 32767.0 // 2^16 00018 #define COMPENSATION_TABLE_SIZE 9 00019 00020 typedef enum { 00021 CO_SENSOR, 00022 H2S_SENSOR 00023 } sensor_type_t; 00024 00025 typedef struct { 00026 int8_t temp; 00027 float CO_percent; 00028 float H2S_percent; 00029 } ppm_compensation_t; 00030 00031 /** 00032 * @brief compensation look-up table 00033 */ 00034 const ppm_compensation_t ppm_compensation[COMPENSATION_TABLE_SIZE] = { 00035 { -30 , 29.9 , 82.3 }, 00036 { -20 , 38.8 , 84.6 }, 00037 { -10 , 53.7 , 88.6 }, 00038 {0 , 69.6 , 92.2 }, 00039 {10 , 84.9 , 96.2 }, 00040 {20 , 100.0 , 100.0}, 00041 {30 , 112.7 , 103.1}, 00042 {40 , 123.7 , 105.6}, 00043 {50 , 133.1 , 107.4} 00044 }; 00045 00046 00047 /** 00048 * @brief CN0396 class constructor 00049 * @param csad - chipselect pin of the ADC 00050 * @param csrdac - chipselect pin of the RDAC 00051 * @param cstemp - chipselect pin of the temperature sensor 00052 */ 00053 CN0396(PinName csad, PinName csrdac, PinName cstemp); 00054 /** 00055 * @brief Initializes the board 00056 */ 00057 void init(); 00058 00059 /** 00060 * @brief - Reads the sensor and computes the PPM values 00061 */ 00062 void read(); 00063 00064 /** 00065 * @brief computes the feedback resistor value for the sensor 00066 * @param sensitivity - sensor sensitivity 00067 * @param range - sensor range 00068 * @return resistor value 00069 */ 00070 float get_feedback_resistor_value(float sensitivity, float range); 00071 00072 /** 00073 * @brief configures the RDACs with the resistance values 00074 * @param resistance1 - resistance of RDAC1 00075 * @param resistance2 - resistance of RDAC2 00076 * @return 00077 */ 00078 void configure_feedback_resistors(float resistance1, float resistance2); 00079 00080 /** 00081 * @brief computes ADC counts-to-voltage in unipolar configuration 00082 * @param adcValue - value in counts 00083 * @param voltage - voltage value returned by the method 00084 * @param gain_adc - the gain of the adc 00085 */ 00086 void data_to_voltage(uint16_t adcValue, float *voltage, int gain_adc = 1); 00087 00088 /** 00089 * @brief computes ADC counts-to-voltage in bipolar configuration 00090 * @param adcValue - value in counts 00091 * @param voltage - voltage value returned by the method 00092 * @param gain_adc - the gain of the adc 00093 */ 00094 void data_to_voltage_bipolar(uint16_t adcValue, float *voltage, int gain_adc = 1); 00095 00096 /** 00097 * @brief compensates ppm value based on temperature reading 00098 * @param result - ppm value before compensation 00099 * @param temp - temperature used in compensation 00100 * @param sensor - sensor id 00101 * @return compensated value 00102 */ 00103 float compensate_ppm(float result, float temp, sensor_type_t sensor); 00104 DigitalOut csad, csrdac, cstemp; 00105 AD7798 ad; 00106 AD5270 rdac; 00107 ADT7310 temp; 00108 float resistance0, resistance1; 00109 private: 00110 00111 00112 }; 00113 #endif
Generated on Tue Jul 12 2022 17:59:52 by 1.7.2