CN0391 (Multi-channel Thermocouple)

Dependencies:   CN0391 mbed

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:
Mon Nov 07 16:05:43 2016 +0000
Revision:
0:74cd912392c3
Initial revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
adisuciu 0:74cd912392c3 1 /**
adisuciu 0:74cd912392c3 2 * @file main.cpp
adisuciu 0:74cd912392c3 3 * @brief Main file for the CN0357-example project
adisuciu 0:74cd912392c3 4 * @author Analog Devices Inc.
adisuciu 0:74cd912392c3 5 *
adisuciu 0:74cd912392c3 6 * For support please go to:
adisuciu 0:74cd912392c3 7 * Github: https://github.com/analogdevicesinc/mbed-adi
adisuciu 0:74cd912392c3 8 * Support: https://ez.analog.com/community/linux-device-drivers/microcontroller-no-os-drivers
adisuciu 0:74cd912392c3 9 * Product: www.analog.com/EVAL-CN0357-ARDZ
adisuciu 0:74cd912392c3 10 * More: https://wiki.analog.com/resources/tools-software/mbed-drivers-all
adisuciu 0:74cd912392c3 11
adisuciu 0:74cd912392c3 12 ********************************************************************************
adisuciu 0:74cd912392c3 13 * Copyright 2016(c) Analog Devices, Inc.
adisuciu 0:74cd912392c3 14 *
adisuciu 0:74cd912392c3 15 * All rights reserved.
adisuciu 0:74cd912392c3 16 *
adisuciu 0:74cd912392c3 17 * Redistribution and use in source and binary forms, with or without
adisuciu 0:74cd912392c3 18 * modification, are permitted provided that the following conditions are met:
adisuciu 0:74cd912392c3 19 * - Redistributions of source code must retain the above copyright
adisuciu 0:74cd912392c3 20 * notice, this list of conditions and the following disclaimer.
adisuciu 0:74cd912392c3 21 * - Redistributions in binary form must reproduce the above copyright
adisuciu 0:74cd912392c3 22 * notice, this list of conditions and the following disclaimer in
adisuciu 0:74cd912392c3 23 * the documentation and/or other materials provided with the
adisuciu 0:74cd912392c3 24 * distribution.
adisuciu 0:74cd912392c3 25 * - Neither the name of Analog Devices, Inc. nor the names of its
adisuciu 0:74cd912392c3 26 * contributors may be used to endorse or promote products derived
adisuciu 0:74cd912392c3 27 * from this software without specific prior written permission.
adisuciu 0:74cd912392c3 28 * - The use of this software may or may not infringe the patent rights
adisuciu 0:74cd912392c3 29 * of one or more patent holders. This license does not release you
adisuciu 0:74cd912392c3 30 * from the requirement that you obtain separate licenses from these
adisuciu 0:74cd912392c3 31 * patent holders to use this software.
adisuciu 0:74cd912392c3 32 * - Use of the software either in source or binary form, must be run
adisuciu 0:74cd912392c3 33 * on or directly connected to an Analog Devices Inc. component.
adisuciu 0:74cd912392c3 34 *
adisuciu 0:74cd912392c3 35 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
adisuciu 0:74cd912392c3 36 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
adisuciu 0:74cd912392c3 37 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
adisuciu 0:74cd912392c3 38 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
adisuciu 0:74cd912392c3 39 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
adisuciu 0:74cd912392c3 40 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
adisuciu 0:74cd912392c3 41 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
adisuciu 0:74cd912392c3 42 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
adisuciu 0:74cd912392c3 43 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
adisuciu 0:74cd912392c3 44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
adisuciu 0:74cd912392c3 45 *
adisuciu 0:74cd912392c3 46 ********************************************************************************/
adisuciu 0:74cd912392c3 47 #include "mbed.h"
adisuciu 0:74cd912392c3 48 #include "Thermocouple.h"
adisuciu 0:74cd912392c3 49 #include "CN0391.h"
adisuciu 0:74cd912392c3 50
adisuciu 0:74cd912392c3 51 Serial pc(SERIAL_TX, SERIAL_RX);
adisuciu 0:74cd912392c3 52
adisuciu 0:74cd912392c3 53 int main()
adisuciu 0:74cd912392c3 54 {
adisuciu 0:74cd912392c3 55 pc.baud(115200);
adisuciu 0:74cd912392c3 56 //Thermocouple *tcarray[4] = {new Thermocouple_Type_E, new Thermocouple_Type_E,new Thermocouple_Type_B,new Thermocouple_Type_B}
adisuciu 0:74cd912392c3 57 CN0391 cn0391(D10);
adisuciu 0:74cd912392c3 58 pc.printf("Reset the AD7124\r\n");
adisuciu 0:74cd912392c3 59 cn0391.reset();
adisuciu 0:74cd912392c3 60 wait_ms(500);
adisuciu 0:74cd912392c3 61 pc.printf("Init the AD7124\r\n");
adisuciu 0:74cd912392c3 62 cn0391.init();
adisuciu 0:74cd912392c3 63 wait_ms(500);
adisuciu 0:74cd912392c3 64 pc.printf("Done\r\n");
adisuciu 0:74cd912392c3 65
adisuciu 0:74cd912392c3 66 cn0391.set_thermocouple_type(CN0391::CHANNEL_P1, new Thermocouple_Type_E);
adisuciu 0:74cd912392c3 67 cn0391.set_thermocouple_type(CN0391::CHANNEL_P2, new Thermocouple_Type_B);
adisuciu 0:74cd912392c3 68 cn0391.set_thermocouple_type(CN0391::CHANNEL_P3, new Thermocouple_Type_J);
adisuciu 0:74cd912392c3 69 cn0391.set_thermocouple_type(CN0391::CHANNEL_P4, new Thermocouple_Type_S);
adisuciu 0:74cd912392c3 70
adisuciu 0:74cd912392c3 71
adisuciu 0:74cd912392c3 72
adisuciu 0:74cd912392c3 73 pc.printf("Calibration current for channel 1: %f\r\n", cn0391.calibrate(CN0391::CHANNEL_P1));
adisuciu 0:74cd912392c3 74 pc.printf("Calibration current for channel 2: %f\r\n", cn0391.calibrate(CN0391::CHANNEL_P2));
adisuciu 0:74cd912392c3 75 pc.printf("Calibration current for channel 3: %f\r\n", cn0391.calibrate(CN0391::CHANNEL_P3));
adisuciu 0:74cd912392c3 76 pc.printf("Calibration current for channel 4: %f\r\n", cn0391.calibrate(CN0391::CHANNEL_P4));
adisuciu 0:74cd912392c3 77 while(1) {
adisuciu 0:74cd912392c3 78 pc.printf("Thermocouple temperature channel 1: %f\r\n", cn0391.read_channel(CN0391::CHANNEL_P1));
adisuciu 0:74cd912392c3 79 pc.printf("Thermocouple temperature channel 2: %f\r\n", cn0391.read_channel(CN0391::CHANNEL_P2));
adisuciu 0:74cd912392c3 80 pc.printf("Thermocouple temperature channel 3: %f\r\n", cn0391.read_channel(CN0391::CHANNEL_P3));
adisuciu 0:74cd912392c3 81 pc.printf("Thermocouple temperature channel 4: %f\r\n", cn0391.read_channel(CN0391::CHANNEL_P4));
adisuciu 0:74cd912392c3 82
adisuciu 0:74cd912392c3 83 pc.printf("\r\n");
adisuciu 0:74cd912392c3 84
adisuciu 0:74cd912392c3 85 wait_ms(1000);
adisuciu 0:74cd912392c3 86 }
adisuciu 0:74cd912392c3 87 return 0;
adisuciu 0:74cd912392c3 88 }