Claudia Haarman / Mbed 2 deprecated Opstellingbachelor_opdracht

Dependencies:   MODSERIAL SDFileSystemSeth mbed

Fork of Opstellingbachelor_opdracht by Seth Ruiter

Revision:
5:f92906aaf1c2
Parent:
4:afab0fda2cf4
Child:
6:5951403edfd2
--- a/main.cpp	Thu Oct 06 19:12:11 2016 +0000
+++ b/main.cpp	Fri Oct 07 15:02:56 2016 +0000
@@ -14,7 +14,7 @@
 DigitalIn pins[12]={D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13};        //thermocouples 1 - 12 select corresponding pin numbers mbed
 
 double d;
-int b[12] = { };
+unsigned int b[12] = { };
 
 // Torque sensor
 AnalogIn fcs(PTB2);     // force sensor output connected to analog 0
@@ -34,7 +34,7 @@
 Ticker tick;
 
 const int baudrate = 115200;      // baud rate
-const float Ts = 0.005;           // sample time (sec)
+const float Ts = 0.01;            // sample time (sec)
 
 const int led_on = 0;
 const int led_off = 1;
@@ -75,26 +75,31 @@
 
 void readTC()
 {
-    CS_1 = 0;
-    wait_ms(70);
+    //uses MAX31855 chip
+    //see https://datasheets.maximintegrated.com/en/ds/MAX31855.pdf for documentation
+    
+    CS_1 = 0;       //Active-Low Chip Select. Set CS low to enable the serial interface.
+    wait_ms(70);    //wait 70 ms for chip to be ready
 
     for (int i = 15; i >= 0; i--) {
-        SCK_1 = 0;
-        SCK_1 = 1;
-        for (int j = 0; j <= 11; j++) {
+        SCK_1 = 0;                      //set clock value to 0
+        wait_ms(0.1);                   //wait for 100ns
+        SCK_1 = 1;                      //then set clock high again
+        wait_ms(0.1);                   //wait for 100ns
+        for (int j = 0; j <= 11; j++) { //read out bits for each thermocouple (0 to 11)
             if (pins[j]) {
-                b[j] |= (1 << i);
+                b[j] |= (1 << i);       //bitshift
             }
         }
     }
     
     CS_1 = 1;
     
-    for (int j = 0; j <= 11; j++) {
-        if (b[j] & 0x1) {
+    for (int j = 0; j <= 11; j++) {     //for every thermocouple (starting from 0 to 11, so 12 in total)
+        if (b[j] & 0x1) {               //b[j] contains the bits that are received from every chip. if least significant bit is 1, then open circuit.
             b[j] = 20000;
         } else {
-            b[j] &= 0xfffc;
+            b[j] &= 0xfffc;             //if no fault then select 14 bit thermocouple data from bitstring
             d = b[j] / 16.0 * 100.0;
             b[j] = d;
         }