this is BOSCH oil temp. measurement program write for STM32 (Nucleo- F746ZG)

Revision:
0:a1e3728036c5
Child:
1:e79bc88f73d6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Nov 02 12:30:34 2020 +0000
@@ -0,0 +1,221 @@
+#include "mbed.h"
+
+Serial pc(USBTX, USBRX);
+
+AnalogIn   vrefint1(PA_3);
+AnalogIn   vrefint2(PC_0);
+AnalogIn   vrefint3(PC_3);
+AnalogIn   vrefint4(PF_3);
+AnalogIn   vrefint5(PF_5);
+AnalogIn   vrefint6(PF_10);
+AnalogIn   vrefint7(PB_1);
+AnalogIn   vrefint8(PA_6);
+
+DigitalOut Buzzer(PA_5);
+
+DigitalOut led1(PF_15);
+DigitalOut led2(PE_13);
+DigitalOut led3(PF_14);
+DigitalOut led4(PE_11);
+DigitalOut led5(PE_9);
+DigitalOut led6(PF_13);
+DigitalOut led7(PF_12);
+DigitalOut led8(PD_15);
+
+
+
+int main() 
+{
+    Buzzer = 1;
+    led1 = 1;
+    led2 = 1;
+    led3 = 1;
+    led4 = 1;
+    led5 = 1;
+    led6 = 1;
+    led7 = 1;
+    led8 = 1;
+
+    float val1, val2, val3, val4, val5, val6, val7, val8;
+      
+    float Volts1, Volts2, Volts3, Volts4, Volts5, Volts6, Volts7, Volts8;
+    
+    float temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8;
+    
+    float tempC1, tempC2, tempC3, tempC4, tempC5, tempC6, tempC7, tempC8;
+    
+    float avg1[50], avg2[50], avg3[50], avg4[50], avg5[50], avg6[50], avg7[50], avg8[50];
+    
+    float totalavg1, totalavg2, totalavg3, totalavg4, totalavg5, totalavg6, totalavg7, totalavg8 = 0.0;
+    
+    float Rx;
+    //for 3v
+    //float C = -74.26;
+    //for 5v
+    float C = 106.85;
+    //for 3.3v
+    //float slope = 167.03;
+    //for 5v
+    float slope = 48.31;
+    
+    float calibration;
+    
+    float R0 = 100.0;
+    
+    float alpha = 0.00385;
+    
+    float tempTh = 30;
+            
+    while(true) 
+    {
+        
+        for(int i=0; i < 50; i++)
+        {
+            val1 = vrefint1.read_u16();
+                    
+            Volts1 = (val1/65536)*3.3;
+            Rx = Volts1*slope+C;
+            temp1= (Rx/R0-1.0)/alpha;
+            calibration=0.3+(0.005*temp1);
+            tempC1=temp1-calibration;
+            avg1[i]=tempC1;
+            
+            val2 = vrefint2.read_u16();
+                    
+            Volts2 = (val2/65536)*3.3;
+            Rx = Volts2*slope+C;
+            temp2= (Rx/R0-1.0)/alpha;
+            calibration=0.3+(0.005*temp2);
+            tempC2=temp2-calibration;
+            avg2[i]=tempC2;
+            
+            val3 = vrefint3.read_u16();
+                    
+            Volts3 = (val3/65536)*3.3;
+            Rx = Volts3*slope+C;
+            temp3= (Rx/R0-1.0)/alpha;
+            calibration=0.3+(0.005*temp3);
+            tempC3=temp3-calibration;
+            avg3[i]=tempC3;
+            
+            val4 = vrefint4.read_u16();
+                    
+            Volts4 = (val4/65536)*3.3;
+            Rx = Volts4*slope+C;
+            temp4= (Rx/R0-1.0)/alpha;
+            calibration=0.3+(0.005*temp4);
+            tempC4=temp4-calibration;
+            avg4[i]=tempC4;
+            
+            val5 = vrefint5.read_u16();
+                    
+            Volts5 = (val5/65536)*3.3;
+            Rx = Volts5*slope+C;
+            temp5= (Rx/R0-1.0)/alpha;
+            calibration=0.3+(0.005*temp5);
+            tempC5=temp5-calibration;
+            avg5[i]=tempC5;
+            
+            val6 = vrefint6.read_u16();
+                    
+            Volts6 = (val6/65536)*3.3;
+            Rx = Volts6*slope+C;
+            temp6= (Rx/R0-1.0)/alpha;
+            calibration=0.3+(0.005*temp6);
+            tempC6=temp6-calibration;
+            avg6[i]=tempC6;
+            
+            val7 = vrefint7.read_u16();
+                    
+            Volts7 = (val7/65536)*3.3;
+            Rx = Volts7*slope+C;
+            temp7= (Rx/R0-1.0)/alpha;
+            calibration=0.3+(0.005*temp7);
+            tempC7=temp7-calibration;
+            avg7[i]=tempC7;
+            
+            val8 = vrefint8.read_u16();
+                    
+            Volts8 = (val8/65536)*3.3;
+            Rx = Volts8*slope+C;
+            temp8= (Rx/R0-1.0)/alpha;
+            calibration=0.3+(0.005*temp8);
+            tempC8=temp8-calibration;
+            avg8[i]=tempC8;
+        
+            wait(0.01);
+        }
+        
+        for(int j=0; j < 50; j++)
+        {
+          totalavg1 =  totalavg1 + avg1[j];
+          totalavg2 =  totalavg2 + avg2[j];
+          totalavg3 =  totalavg3 + avg3[j];
+          totalavg4 =  totalavg4 + avg4[j];
+          totalavg5 =  totalavg5 + avg5[j];
+          totalavg6 =  totalavg6 + avg6[j];
+          totalavg7 =  totalavg7 + avg7[j];
+          totalavg8 =  totalavg8 + avg8[j];
+          wait(0.01);
+        }
+        
+        pc.printf("%3.2f    %3.2f   %3.2f   %3.2f   %3.2f   %3.2f   %3.2f   %3.2f\n", totalavg1/50, totalavg2/50, totalavg3/50, totalavg4/50, totalavg5/50, totalavg6/50, totalavg7/50, totalavg8/50);
+        
+        if((totalavg1 || totalavg2 || totalavg3 || totalavg4 || totalavg5 || totalavg6 || totalavg7 || totalavg8) > tempTh)
+            Buzzer = 0;
+        else
+            Buzzer = 1;
+        
+        if(totalavg1 > tempTh)
+            led1 = 0;
+        else
+            led1 = 1;
+        totalavg1 = 0;
+            
+        if(totalavg2 > tempTh)
+            led2 = 0;
+        else
+            led2 = 1;
+        totalavg2 = 0;
+            
+        if(totalavg3 > tempTh)
+            led3 = 0;
+        else
+            led3 = 1;
+        totalavg3 = 0;
+            
+        if(totalavg4 > tempTh)
+            led4 = 0;
+        else
+            led4 = 1;
+        totalavg4 = 0;
+            
+        if(totalavg5 > tempTh)
+            led5 = 0;
+        else
+            led5 = 1;
+        totalavg5 = 0;
+        
+        if(totalavg6 > tempTh)
+            led6 = 0;
+        else
+            led6 = 1;
+        totalavg6 = 0;
+            
+        if(totalavg7 > tempTh)
+            led7 = 0;
+        else
+            led7 = 1;
+        totalavg7 = 0;
+            
+        if(totalavg8 > tempTh)
+            led8 = 0;
+        else
+            led8 = 1;
+        totalavg8 = 0;
+        
+               
+        wait(0.5f);
+        //totalavg1, totalavg2, totalavg3, totalavg4, totalavg5, totalavg6, totalavg7, totalavg8  = 0.0;
+    }
+} 
\ No newline at end of file