Maxim Integrated / Mbed 2 deprecated MAX31856_example_program

Dependencies:   MAX31856 mbed

Fork of MAX31856_example_program by Central Applications - Mbed Code repo

Revision:
7:2e45068189b1
Parent:
6:e1200ae7d6a3
Child:
8:8723d0006097
--- a/MAX31856.h	Mon Jul 31 18:10:24 2017 +0000
+++ b/MAX31856.h	Mon Jul 31 18:46:49 2017 +0000
@@ -202,12 +202,6 @@
 
 class MAX31856
 {
-//    public:
-//        struct time_adjusting_factors {
-//            int samples;  // 1, 2, 4, 8, or 16 samples are the possible values
-//            bool filter;  // 0=60Hz,   1=50Hz
-//            
-//        } conversion_time;
 
 public:
 
@@ -222,29 +216,29 @@
     */
     MAX31856(SPI& _spi, PinName _ncs, uint8_t _type=CR1_TC_TYPE_K, uint8_t _fltr=CR0_FILTER_OUT_60Hz, uint8_t _samples=CR1_AVG_TC_SAMPLES_1, uint8_t _conversion_mode=CR0_CONV_MODE_NORMALLY_OFF); 
     
-//    /** @brief Destructor */
-//    ~MAX31856(void);
+    /** @brief Destructor */
+    ~MAX31856(void);
     
-    /** @brief  Writes the chip seleect pin low to begin SPI communications */
-    void spiEnable();
-    /** @brief  Writes the chip seleect pin high to end SPI communications */
-    void spiDisable();
+//*****************************************************************************    
+//Temperature Functions
+//***************************************************************************** 
     /** 
     * @brief  Requests read of the thermocouple temperature
     * @return float of the converted thermocouple reading based on current configurations
     */
     float readTC();
+    
+    
     /** 
     * @brief  Requests read of the cold junction temperature
     * @return float of the converted artificial cold junction reading based on current configurations
     */
     float readCJ();
-    
-    
+
     
-    
-    
-    //Functions for register CR0
+//*****************************************************************************    
+//Functions for register CR0
+//*****************************************************************************
     /** 
     * @brief  Sets bits in the configuration register zero for setting the rate of conversions
     * @param val -  CR0_CONV_MODE_NORMALLY_OFF
@@ -252,31 +246,43 @@
     * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
     */
     bool setConversionMode(uint8_t val);
+    
+    
     /** 
     * @brief  Sets bits in the configuration register zero for enabling one conversion to take place
     * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
     */
     bool setOneShotMode(uint8_t val);
+    
+    
     /** 
     * @brief  Sets bits in the configuration register zero for configuring open circuit fault detection
     * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
     */
     bool setOpenCircuitFaultDetection(uint8_t val);
+    
+    
     /** 
     * @brief  Sets bits in the configuration register zero for disabling or enabling the Cold Junction
     * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
     */
     bool setColdJunctionDisable(uint8_t val);
+    
+    
     /** 
     * @brief  Sets bits in the configuration register zero for setting fault mode status
     * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
     */
     bool setFaultMode(uint8_t val);
+    
+    
     /** 
     * @brief  Sets bits in the configuration register zero for clearing fault status
     * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
     */
     bool setFaultStatusClear(uint8_t val);
+    
+    
     /** 
     * @brief  Sets bits in the configuration register zero for setting which of the two filter modes either 50Hz or 60Hz cancelation
     * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
@@ -284,37 +290,43 @@
     bool setEmiFilterFreq(uint8_t val);
     
     
-    
-    
-    //Functions for register CR1
+//*****************************************************************************    
+//Functions for register CR1
+//*****************************************************************************
     /** 
     * @brief  Sets bits in the configuration register one for setting how many readings are taken 
     * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
     */
     bool setNumSamplesAvg(uint8_t val);
+    
+    
     /** 
-    * @brief  Sets bits in the configuration register one for setting which thermocouple type is going to beprogrammed into the MAX31856 for linearization of thermovoltage produced and temperature
+    * @brief  Sets bits in the configuration register one for setting which thermocouple type is going to be programmed into the MAX31856 for linearization of thermovoltage produced and temperature
     * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
     */
     bool setThermocoupleType(uint8_t val);
     
-    
-    
-    
-    //Functions for register MASK
+
+//*****************************************************************************    
+//Functions for register MASK
+//*****************************************************************************    
     /** 
-    * @brief  Sets bits in the configuration register one for setting which thermocouple type is going to beprogrammed into the MAX31856 for linearization of thermovoltage produced and temperature
+    * @brief  Sets bits in the configuration register one for setting fault masks
     * @return 1 on success, and zero on failure or if there is an incorrect parameter is selected
     */
     bool setFaultMasks(uint8_t val, bool enable);
+    
+    
+    /** 
+    * @brief  Sets bits in the configuration register one for setting thresholds that corespond to the fault mask settings
+    * @return return value that was programmed into the the threshold register t
+    */
     float setFaultThresholds(uint8_t val, bool enable_mask, float temperature);
     
     
-    
-    
-    
-    //General Functions
-    
+//*****************************************************************************    
+//General Functions
+//*****************************************************************************    
     /**
     * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n
     * Read the value of a register from contents of register matching the parameter "read_address", clear the bits needed to be changed by bitwise ANDing the read value with the 8-bit parameter "clear_bits", set the bits of interest in the 8 bit value by bitwise ORing the value from step two with parameter "val", then rewrite to the register with the new 8bit value to the register with the address with parameter "write_address"
@@ -325,6 +337,8 @@
     * @return 1 on success, and zero on failure
     */
     bool registerReadWriteByte(uint8_t read_address, uint8_t write_address, uint8_t clear_bits, uint8_t val);
+    
+    
     /**
     * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n
     * Read the value of a register from contents of register matching the parameter "read_address", clear the bits needed to be changed by bitwise ANDing the read value with the 8-bit parameter "clear_bits", set the bits of interest in the 8 bit value by bitwise ORing the value from step two with parameter "val", then rewrite to the register with the new 8bit value to the register with the address with parameter "write_address"
@@ -333,6 +347,8 @@
     * @return 1 on success, and zero on failure
     */
     bool registerWriteByte(uint8_t write_address, uint8_t val);
+    
+    
     /**
     * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n
     * Read the value of a register from contents of register matching the parameter "read_address", clear the bits needed to be changed by bitwise ANDing the read value with the 8-bit parameter "clear_bits", set the bits of interest in the 8 bit value by bitwise ORing the value from step two with parameter "val", then rewrite to the register with the new 8bit value to the register with the address with parameter "write_address"
@@ -340,6 +356,8 @@
     * @return 1 on success, and zero on failure
     */
     int8_t twosComplimentToSigned8(int8_t temp);
+
+
     /**
     * @brief This function is to read current contents of register, manipulate the contents, then rewrite the specific register\n
     * Read the value of a register from contents of register matching the parameter "read_address", clear the bits needed to be changed by bitwise ANDing the read value with the 8-bit parameter "clear_bits", set the bits of interest in the 8 bit value by bitwise ORing the value from step two with parameter "val", then rewrite to the register with the new 8bit value to the register with the address with parameter "write_address"
@@ -349,25 +367,50 @@
     int16_t twosComplimentToSigned16(int16_t temp);
 //        void printSetting(string register_bits, string register_info);
     
+
+
+private:
+
+//*****************************************************************************    
+//Private Functions
+//*****************************************************************************    
+    
+    /** @brief  Writes the chip seleect pin low to begin SPI communications */
+    void spiEnable();
+    
+    
+    /** @brief  Writes the chip seleect pin high to end SPI communications */
+    void spiDisable();
+    
+    
+//*****************************************************************************    
+//Private Members
+//*****************************************************************************        
+    /// SPI object
+    SPI& spi;
+    
+    /// Chip select
+    DigitalOut ncs;
+    
+    /// Number of samples the thermocouple is configured to average
+    uint8_t samples;
+    
+    /// 0=thermocouple is set to one of 8 thermocouple types   and   1=Thermocouple is configured to report in voltage mode
+    bool voltage_mode;
+    
+    /// 0=60Hz   and   1=50Hz
+    bool filter_mode;
+    
+    /// 0=Always On and converting   and   1=MAX31856 is off, so no conversion is taking place currently
+    bool conversion_mode;
+    
+    /// 0=cold junction is disabled   and   1=cold junction is enabled
+    bool cold_junction_enabled;
+    
     ///Define a return val for all boolean functions
     bool return_val;
     
-private:
-    /// SPI object
-    SPI& spi;
-    /// SPI object
-    DigitalOut ncs;
-    /// Number of samples the thermocouple is configured to average
-    uint8_t samples;
-    /// value is a 1 if the thermocouple is configured to report in voltage mode, value is a zero if thermocouple is set to one of 8 thermocouple types
-    bool voltage_mode;                  // used to determine what kind of read of the thermalcouple temperature will take place
-    bool filter_mode;                   // 0=60Hz  and  1=50Hz
-    bool conversion_mode;
-    bool cold_junction_enabled;
-    
-    
-    float thermocoupleT;
-    float internalT;
+    ///Used to figure out when a new conversion is ready to go
     uint32_t lastReadTime;
 };