Maxim MAX6675 Cold-Junction-Compensated K-Thermocoupleto-Digital Converter (0°C to +1024°C) os2 and os5

Dependents:   proyectoprueba3 proyectoRTOS proyectoRTOS2 proyectoRTOS ... more

Files at this revision

API Documentation at this revision

Comitter:
star297
Date:
Thu May 09 22:17:49 2019 +0000
Child:
1:5ab1e58f1574
Child:
2:74731b8476a0
Commit message:
Initial revision

Changed in this revision

max6675.cpp Show annotated file Show diff for this revision Revisions of this file
max6675.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/max6675.cpp	Thu May 09 22:17:49 2019 +0000
@@ -0,0 +1,30 @@
+
+#include "max6675.h"
+
+max6675::max6675(PinName miso, PinName sclk, PinName cs) :
+    max(NC, miso, sclk), _cs(cs)
+{
+    max.format(16,1);   // set 16 bit SPI format
+    max.frequency(4000000);
+}
+float max6675::gettemp(int cf)
+{
+    float temp  = 0;
+    int tempByte= 0;
+    
+    _cs = 0;
+    wait_us(1);     // wait to stablize
+    tempByte  =  max.write(0);
+    wait_us(1);     // wait to finish
+    _cs = 1;
+
+    if (tempByte & (1<<2)) { // faulty or no sensor connected
+        return -99;
+    } else {
+        temp = (tempByte)/32.0f;
+    }
+    if(cf) {
+        temp = (temp*9.0f/5.0f) + 32.0f; // Convert value to ˚F
+    }
+    return temp;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/max6675.h	Thu May 09 22:17:49 2019 +0000
@@ -0,0 +1,48 @@
+#ifndef max6675_h
+#define max6675_h
+
+#include "mbed.h"
+
+/*
+#include "mbed.h"
+#include "max6675.h"
+
+max6675 sensor(D5,D3,D6);  //miso, sclk, cs
+Serial pc(USBTX,USBRX);
+
+int main()
+{
+    pc.baud(921600);
+    pc.printf("\033[0m\033[2J\033[HMAX6675 Thermocouple!\r\n\n\n");
+
+    int cf = 0; // 0 Centigrade, 1 Fahrenheit
+
+    while (1) {
+
+        float temp = sensor.gettemp(cf);
+        if (cf) {
+            printf(" Temp: %4.2f%cF \n\033[2K\033[1A",temp,176);
+        } else {
+            printf(" Temp: %4.2f%cC \n\033[2K\033[1A",temp,176);
+        }
+        wait_ms(250);   // requires 250mS for temperature conversion process
+    }
+}
+*/
+
+
+class max6675
+{    
+  public:
+  
+    max6675(PinName miso, PinName sclk, PinName cs);
+    
+    // read temperature 0 Centigrade, 1 Fahrenheit       
+    float gettemp(int cf);    
+    
+  private:  
+    SPI max;
+    DigitalOut _cs;    
+};
+
+#endif