A collection of Analog Devices drivers for the mbed platform

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

Committer:
Suciu
Date:
Wed Mar 30 17:35:04 2016 +0300
Revision:
1:c1f0670bb370
Child:
3:1a8c14043a4e
Added CN0357-example project and related drivers

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Suciu 1:c1f0670bb370 1 /**
Suciu 1:c1f0670bb370 2 * @file main.cpp
Suciu 1:c1f0670bb370 3 * @brief Toxic gas sensor shield application
Suciu 1:c1f0670bb370 4 * @version V0.1
Suciu 1:c1f0670bb370 5 * @author ADI
Suciu 1:c1f0670bb370 6 * @date March 2015
Suciu 1:c1f0670bb370 7 **/
Suciu 1:c1f0670bb370 8
Suciu 1:c1f0670bb370 9 #include "mbed.h"
Suciu 1:c1f0670bb370 10 #include "cn0357.h"
Suciu 1:c1f0670bb370 11
Suciu 1:c1f0670bb370 12 /** @mainpage
Suciu 1:c1f0670bb370 13 * CN0357 single-supply, low noise, portable gas detector circuit using an
Suciu 1:c1f0670bb370 14 * electrochemical sensor. The Alphasense CO-AX carbon monoxide sensor is used
Suciu 1:c1f0670bb370 15 * in this example. Electrochemical sensors offer several advantages for
Suciu 1:c1f0670bb370 16 * instruments that detect or measure the concentration of many toxic gases.
Suciu 1:c1f0670bb370 17 * Most sensors are gas specific and have usable resolutions under one part per
Suciu 1:c1f0670bb370 18 * million (ppm) of gas concentration.
Suciu 1:c1f0670bb370 19 *
Suciu 1:c1f0670bb370 20 * EVAL-CN0357 example program for MBED platforms. To achieve connection between
Suciu 1:c1f0670bb370 21 * the shield and the ST Nucleo, the following connections need to be made:
Suciu 1:c1f0670bb370 22 *
Suciu 1:c1f0670bb370 23 * - ICSP pin 1 -> pin 12 of the Arduino header
Suciu 1:c1f0670bb370 24 * - ICSP pin 3 -> pin 13 of the Arduino header
Suciu 1:c1f0670bb370 25 * - ICSP pin 4 -> pin 11 of the Arduino header
Suciu 1:c1f0670bb370 26 * - if VIN is not supplied, 5V to VIN
Suciu 1:c1f0670bb370 27 *
Suciu 1:c1f0670bb370 28 * @page CN0357 CN0357 Analog Devices wiki page
Suciu 1:c1f0670bb370 29 * @brief link->
Suciu 1:c1f0670bb370 30 * https://wiki.analog.com/resources/eval/user-guides/eval-adicup360/hardware/cn0357
Suciu 1:c1f0670bb370 31 * @page AD7790 AD7790 datasheet
Suciu 1:c1f0670bb370 32 * @brief link ->
Suciu 1:c1f0670bb370 33 * http://www.analog.com/media/en/technical-documentation/data-sheets/AD7790.pdf
Suciu 1:c1f0670bb370 34 * @page AD5270 AD5270 datasheet
Suciu 1:c1f0670bb370 35 * @brief link ->
Suciu 1:c1f0670bb370 36 * http://www.analog.com/media/en/technical-documentation/data-sheets/AD5270_5271.pdf
Suciu 1:c1f0670bb370 37 *
Suciu 1:c1f0670bb370 38 */
Suciu 1:c1f0670bb370 39 const float SENSOR_RANGE = 2000; ///< gas sensor range in PPM
Suciu 1:c1f0670bb370 40 const float SENSOR_SENSITIVITY = (65 * pow(10, -9)); ///< gas sensor sensitivity in A/ppm - 65 nA/ppm
Suciu 1:c1f0670bb370 41
Suciu 1:c1f0670bb370 42 Serial pc(USBTX, USBRX); ///< Serial interface to the pc
Suciu 1:c1f0670bb370 43
Suciu 1:c1f0670bb370 44 /**
Suciu 1:c1f0670bb370 45 @brief Displays CN0357 circuit readings and data to the UART
Suciu 1:c1f0670bb370 46
Suciu 1:c1f0670bb370 47 @param ui16Data - ADC data register value to be displayed
Suciu 1:c1f0670bb370 48 @param fData1 - ADC input voltage reading to be displayed
Suciu 1:c1f0670bb370 49 @param fdata2 - Gas Concentration reading to be displayed
Suciu 1:c1f0670bb370 50
Suciu 1:c1f0670bb370 51 **/
Suciu 1:c1f0670bb370 52 void display_data(uint16_t ui16Data, float fData1, float fdata2)
Suciu 1:c1f0670bb370 53 {
Suciu 1:c1f0670bb370 54
Suciu 1:c1f0670bb370 55 pc.printf("\r\nADC Data Register Value = %#08x", ui16Data); /** Send valid ADC data register value*/
Suciu 1:c1f0670bb370 56 pc.printf("\r\nADC Input Voltage input = %f V", fData1); /** Send valid voltage input value */
Suciu 1:c1f0670bb370 57 pc.printf("\r\nGas Concentration = %f PPM", fdata2); /** Send valid gas concentration value */
Suciu 1:c1f0670bb370 58
Suciu 1:c1f0670bb370 59 pc.printf("\r\n");
Suciu 1:c1f0670bb370 60 }
Suciu 1:c1f0670bb370 61
Suciu 1:c1f0670bb370 62
Suciu 1:c1f0670bb370 63 /**
Suciu 1:c1f0670bb370 64 * Project entry-point - initializes the CN0357 shield, reads the data when the ADC is ready and outputs the sensor
Suciu 1:c1f0670bb370 65 * value in PPM
Suciu 1:c1f0670bb370 66 */
Suciu 1:c1f0670bb370 67 int main()
Suciu 1:c1f0670bb370 68 {
Suciu 1:c1f0670bb370 69 /* Main variables */
Suciu 1:c1f0670bb370 70
Suciu 1:c1f0670bb370 71
Suciu 1:c1f0670bb370 72 CN0357 cn0357;
Suciu 1:c1f0670bb370 73 cn0357.init(SENSOR_RANGE, SENSOR_SENSITIVITY);
Suciu 1:c1f0670bb370 74
Suciu 1:c1f0670bb370 75 /* Infinite loop */
Suciu 1:c1f0670bb370 76 while (1) {
Suciu 1:c1f0670bb370 77
Suciu 1:c1f0670bb370 78 uint8_t ui8Status_Reg = cn0357.read_adc_status(); // Read ADC Status Register
Suciu 1:c1f0670bb370 79
Suciu 1:c1f0670bb370 80 if (ui8Status_Reg == 0x08) { // Checks if ADC data is available
Suciu 1:c1f0670bb370 81 uint16_t ui16Adcdata = cn0357.read_sensor();
Suciu 1:c1f0670bb370 82 float fAdcVoltage = cn0357.data_to_voltage(ui16Adcdata); // Convert ADC data to voltage
Suciu 1:c1f0670bb370 83 float fConcentration = cn0357.calc_ppm(fAdcVoltage); // Convert voltage to Gas concentration
Suciu 1:c1f0670bb370 84 display_data(ui16Adcdata, fAdcVoltage, fConcentration); // Display data thru UART
Suciu 1:c1f0670bb370 85
Suciu 1:c1f0670bb370 86 // printf("OneshotRead: %f PPM \r\n", cn0357.readPPM());
Suciu 1:c1f0670bb370 87 }
Suciu 1:c1f0670bb370 88
Suciu 1:c1f0670bb370 89 wait_ms(1000);
Suciu 1:c1f0670bb370 90 }
Suciu 1:c1f0670bb370 91
Suciu 1:c1f0670bb370 92 /* Infinite loop, never returns. */
Suciu 1:c1f0670bb370 93 }
Suciu 1:c1f0670bb370 94