MAX31855 Cold-Junction Compensated Thermocouple-to-Digital Converter

Committer:
mederic
Date:
Tue Sep 09 08:17:42 2014 +0000
Revision:
0:cd9dd4f2c484
Child:
1:aa96d283eead
first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mederic 0:cd9dd4f2c484 1 #ifndef MAX31855_H
mederic 0:cd9dd4f2c484 2 #define MAX31855_H
mederic 0:cd9dd4f2c484 3
mederic 0:cd9dd4f2c484 4 #include "mbed.h"
mederic 0:cd9dd4f2c484 5 /** MAX31855 class.
mederic 0:cd9dd4f2c484 6 * Used for read MAX31855 Cold-Junction Compensated Thermocouple-to-Digital Converter
mederic 0:cd9dd4f2c484 7 *
mederic 0:cd9dd4f2c484 8 * Example:
mederic 0:cd9dd4f2c484 9 * @code
mederic 0:cd9dd4f2c484 10 * DigitalOut led(LED2);
mederic 0:cd9dd4f2c484 11 * Serial pc(USBTX,USBRX);
mederic 0:cd9dd4f2c484 12 * MAX31855 therm(p5,p6,p7,p8);
mederic 0:cd9dd4f2c484 13 *
mederic 0:cd9dd4f2c484 14 * int main()
mederic 0:cd9dd4f2c484 15 * {
mederic 0:cd9dd4f2c484 16 * while(1)
mederic 0:cd9dd4f2c484 17 * {
mederic 0:cd9dd4f2c484 18 * pc.printf("T=%f;Chip=%f\r\n",therm.thermocouple(),therm.chip());
mederic 0:cd9dd4f2c484 19 * led = therm.fault();
mederic 0:cd9dd4f2c484 20 * wait(0.5);
mederic 0:cd9dd4f2c484 21 * }
mederic 0:cd9dd4f2c484 22 * }
mederic 0:cd9dd4f2c484 23 * @endcode
mederic 0:cd9dd4f2c484 24 */
mederic 0:cd9dd4f2c484 25 class MAX31855
mederic 0:cd9dd4f2c484 26 {
mederic 0:cd9dd4f2c484 27 public:
mederic 0:cd9dd4f2c484 28 /** Create MAX31855 instance connected to spi & ncs
mederic 0:cd9dd4f2c484 29 * @param mosi SPI master out slave in pin (MAX31855 is only read device)
mederic 0:cd9dd4f2c484 30 * @param miso SPI master in slave out pin
mederic 0:cd9dd4f2c484 31 * @param sck SPI clock pin
mederic 0:cd9dd4f2c484 32 * @param ncs pin to connect at CS input
mederic 0:cd9dd4f2c484 33 */
mederic 0:cd9dd4f2c484 34 MAX31855(PinName mosi, PinName miso, PinName sck, PinName ncs);
mederic 0:cd9dd4f2c484 35
mederic 0:cd9dd4f2c484 36 /**Get Thermocouple temperature
mederic 0:cd9dd4f2c484 37 * @returns temperature [°C]
mederic 0:cd9dd4f2c484 38 */
mederic 0:cd9dd4f2c484 39 float thermocouple(void);
mederic 0:cd9dd4f2c484 40
mederic 0:cd9dd4f2c484 41 /**Get Chip temperature
mederic 0:cd9dd4f2c484 42 * @returns temperature [°C]
mederic 0:cd9dd4f2c484 43 */
mederic 0:cd9dd4f2c484 44 float chip(void);
mederic 0:cd9dd4f2c484 45
mederic 0:cd9dd4f2c484 46 /**Check if thermocouple disconnected
mederic 0:cd9dd4f2c484 47 */
mederic 0:cd9dd4f2c484 48 bool opened(void);
mederic 0:cd9dd4f2c484 49
mederic 0:cd9dd4f2c484 50 /**Check if an error
mederic 0:cd9dd4f2c484 51 */
mederic 0:cd9dd4f2c484 52 bool fault(void);
mederic 0:cd9dd4f2c484 53
mederic 0:cd9dd4f2c484 54 /**Check if thermocouple short-circuited to Vcc
mederic 0:cd9dd4f2c484 55 */
mederic 0:cd9dd4f2c484 56 bool scToVcc(void);
mederic 0:cd9dd4f2c484 57
mederic 0:cd9dd4f2c484 58 /**Check if thermocouple shorted-circuited to GND
mederic 0:cd9dd4f2c484 59 */
mederic 0:cd9dd4f2c484 60 bool scToGnd(void);
mederic 0:cd9dd4f2c484 61
mederic 0:cd9dd4f2c484 62 #ifdef MBED_OPERATORS
mederic 0:cd9dd4f2c484 63 /** An operator shorthand for thermocouple()
mederic 0:cd9dd4f2c484 64 *
mederic 0:cd9dd4f2c484 65 * The float() operator can be used as a shorthand for thermocouple() to simplify common code sequences
mederic 0:cd9dd4f2c484 66 *
mederic 0:cd9dd4f2c484 67 * Example:
mederic 0:cd9dd4f2c484 68 * @code
mederic 0:cd9dd4f2c484 69 * float x = temp.thermocouple();
mederic 0:cd9dd4f2c484 70 * float x = temp;
mederic 0:cd9dd4f2c484 71 *
mederic 0:cd9dd4f2c484 72 * if(temp.thermocouple() > 20.25) { ... }
mederic 0:cd9dd4f2c484 73 * if(temp > 20.25) { ... }
mederic 0:cd9dd4f2c484 74 * @endcode
mederic 0:cd9dd4f2c484 75 */
mederic 0:cd9dd4f2c484 76 operator float(){return thermocouple();}
mederic 0:cd9dd4f2c484 77 #endif
mederic 0:cd9dd4f2c484 78
mederic 0:cd9dd4f2c484 79 protected:
mederic 0:cd9dd4f2c484 80 void read(void);
mederic 0:cd9dd4f2c484 81
mederic 0:cd9dd4f2c484 82 private:
mederic 0:cd9dd4f2c484 83 SPI _spi;
mederic 0:cd9dd4f2c484 84 DigitalOut _ncs;
mederic 0:cd9dd4f2c484 85 float _t;
mederic 0:cd9dd4f2c484 86 float _chip_t;
mederic 0:cd9dd4f2c484 87 bool _fault;
mederic 0:cd9dd4f2c484 88 bool _scv;
mederic 0:cd9dd4f2c484 89 bool _scg;
mederic 0:cd9dd4f2c484 90 bool _oc;
mederic 0:cd9dd4f2c484 91 };
mederic 0:cd9dd4f2c484 92
mederic 0:cd9dd4f2c484 93 #endif