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

Committer:
rahulp5
Date:
Mon Nov 02 12:30:34 2020 +0000
Revision:
0:a1e3728036c5
Child:
1:e79bc88f73d6
this is BOSCH oil temp. measurement program write for STM32 (Nucleo- F746ZG)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rahulp5 0:a1e3728036c5 1 #include "mbed.h"
rahulp5 0:a1e3728036c5 2
rahulp5 0:a1e3728036c5 3 Serial pc(USBTX, USBRX);
rahulp5 0:a1e3728036c5 4
rahulp5 0:a1e3728036c5 5 AnalogIn vrefint1(PA_3);
rahulp5 0:a1e3728036c5 6 AnalogIn vrefint2(PC_0);
rahulp5 0:a1e3728036c5 7 AnalogIn vrefint3(PC_3);
rahulp5 0:a1e3728036c5 8 AnalogIn vrefint4(PF_3);
rahulp5 0:a1e3728036c5 9 AnalogIn vrefint5(PF_5);
rahulp5 0:a1e3728036c5 10 AnalogIn vrefint6(PF_10);
rahulp5 0:a1e3728036c5 11 AnalogIn vrefint7(PB_1);
rahulp5 0:a1e3728036c5 12 AnalogIn vrefint8(PA_6);
rahulp5 0:a1e3728036c5 13
rahulp5 0:a1e3728036c5 14 DigitalOut Buzzer(PA_5);
rahulp5 0:a1e3728036c5 15
rahulp5 0:a1e3728036c5 16 DigitalOut led1(PF_15);
rahulp5 0:a1e3728036c5 17 DigitalOut led2(PE_13);
rahulp5 0:a1e3728036c5 18 DigitalOut led3(PF_14);
rahulp5 0:a1e3728036c5 19 DigitalOut led4(PE_11);
rahulp5 0:a1e3728036c5 20 DigitalOut led5(PE_9);
rahulp5 0:a1e3728036c5 21 DigitalOut led6(PF_13);
rahulp5 0:a1e3728036c5 22 DigitalOut led7(PF_12);
rahulp5 0:a1e3728036c5 23 DigitalOut led8(PD_15);
rahulp5 0:a1e3728036c5 24
rahulp5 0:a1e3728036c5 25
rahulp5 0:a1e3728036c5 26
rahulp5 0:a1e3728036c5 27 int main()
rahulp5 0:a1e3728036c5 28 {
rahulp5 0:a1e3728036c5 29 Buzzer = 1;
rahulp5 0:a1e3728036c5 30 led1 = 1;
rahulp5 0:a1e3728036c5 31 led2 = 1;
rahulp5 0:a1e3728036c5 32 led3 = 1;
rahulp5 0:a1e3728036c5 33 led4 = 1;
rahulp5 0:a1e3728036c5 34 led5 = 1;
rahulp5 0:a1e3728036c5 35 led6 = 1;
rahulp5 0:a1e3728036c5 36 led7 = 1;
rahulp5 0:a1e3728036c5 37 led8 = 1;
rahulp5 0:a1e3728036c5 38
rahulp5 0:a1e3728036c5 39 float val1, val2, val3, val4, val5, val6, val7, val8;
rahulp5 0:a1e3728036c5 40
rahulp5 0:a1e3728036c5 41 float Volts1, Volts2, Volts3, Volts4, Volts5, Volts6, Volts7, Volts8;
rahulp5 0:a1e3728036c5 42
rahulp5 0:a1e3728036c5 43 float temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8;
rahulp5 0:a1e3728036c5 44
rahulp5 0:a1e3728036c5 45 float tempC1, tempC2, tempC3, tempC4, tempC5, tempC6, tempC7, tempC8;
rahulp5 0:a1e3728036c5 46
rahulp5 0:a1e3728036c5 47 float avg1[50], avg2[50], avg3[50], avg4[50], avg5[50], avg6[50], avg7[50], avg8[50];
rahulp5 0:a1e3728036c5 48
rahulp5 0:a1e3728036c5 49 float totalavg1, totalavg2, totalavg3, totalavg4, totalavg5, totalavg6, totalavg7, totalavg8 = 0.0;
rahulp5 0:a1e3728036c5 50
rahulp5 0:a1e3728036c5 51 float Rx;
rahulp5 0:a1e3728036c5 52 //for 3v
rahulp5 0:a1e3728036c5 53 //float C = -74.26;
rahulp5 0:a1e3728036c5 54 //for 5v
rahulp5 0:a1e3728036c5 55 float C = 106.85;
rahulp5 0:a1e3728036c5 56 //for 3.3v
rahulp5 0:a1e3728036c5 57 //float slope = 167.03;
rahulp5 0:a1e3728036c5 58 //for 5v
rahulp5 0:a1e3728036c5 59 float slope = 48.31;
rahulp5 0:a1e3728036c5 60
rahulp5 0:a1e3728036c5 61 float calibration;
rahulp5 0:a1e3728036c5 62
rahulp5 0:a1e3728036c5 63 float R0 = 100.0;
rahulp5 0:a1e3728036c5 64
rahulp5 0:a1e3728036c5 65 float alpha = 0.00385;
rahulp5 0:a1e3728036c5 66
rahulp5 0:a1e3728036c5 67 float tempTh = 30;
rahulp5 0:a1e3728036c5 68
rahulp5 0:a1e3728036c5 69 while(true)
rahulp5 0:a1e3728036c5 70 {
rahulp5 0:a1e3728036c5 71
rahulp5 0:a1e3728036c5 72 for(int i=0; i < 50; i++)
rahulp5 0:a1e3728036c5 73 {
rahulp5 0:a1e3728036c5 74 val1 = vrefint1.read_u16();
rahulp5 0:a1e3728036c5 75
rahulp5 0:a1e3728036c5 76 Volts1 = (val1/65536)*3.3;
rahulp5 0:a1e3728036c5 77 Rx = Volts1*slope+C;
rahulp5 0:a1e3728036c5 78 temp1= (Rx/R0-1.0)/alpha;
rahulp5 0:a1e3728036c5 79 calibration=0.3+(0.005*temp1);
rahulp5 0:a1e3728036c5 80 tempC1=temp1-calibration;
rahulp5 0:a1e3728036c5 81 avg1[i]=tempC1;
rahulp5 0:a1e3728036c5 82
rahulp5 0:a1e3728036c5 83 val2 = vrefint2.read_u16();
rahulp5 0:a1e3728036c5 84
rahulp5 0:a1e3728036c5 85 Volts2 = (val2/65536)*3.3;
rahulp5 0:a1e3728036c5 86 Rx = Volts2*slope+C;
rahulp5 0:a1e3728036c5 87 temp2= (Rx/R0-1.0)/alpha;
rahulp5 0:a1e3728036c5 88 calibration=0.3+(0.005*temp2);
rahulp5 0:a1e3728036c5 89 tempC2=temp2-calibration;
rahulp5 0:a1e3728036c5 90 avg2[i]=tempC2;
rahulp5 0:a1e3728036c5 91
rahulp5 0:a1e3728036c5 92 val3 = vrefint3.read_u16();
rahulp5 0:a1e3728036c5 93
rahulp5 0:a1e3728036c5 94 Volts3 = (val3/65536)*3.3;
rahulp5 0:a1e3728036c5 95 Rx = Volts3*slope+C;
rahulp5 0:a1e3728036c5 96 temp3= (Rx/R0-1.0)/alpha;
rahulp5 0:a1e3728036c5 97 calibration=0.3+(0.005*temp3);
rahulp5 0:a1e3728036c5 98 tempC3=temp3-calibration;
rahulp5 0:a1e3728036c5 99 avg3[i]=tempC3;
rahulp5 0:a1e3728036c5 100
rahulp5 0:a1e3728036c5 101 val4 = vrefint4.read_u16();
rahulp5 0:a1e3728036c5 102
rahulp5 0:a1e3728036c5 103 Volts4 = (val4/65536)*3.3;
rahulp5 0:a1e3728036c5 104 Rx = Volts4*slope+C;
rahulp5 0:a1e3728036c5 105 temp4= (Rx/R0-1.0)/alpha;
rahulp5 0:a1e3728036c5 106 calibration=0.3+(0.005*temp4);
rahulp5 0:a1e3728036c5 107 tempC4=temp4-calibration;
rahulp5 0:a1e3728036c5 108 avg4[i]=tempC4;
rahulp5 0:a1e3728036c5 109
rahulp5 0:a1e3728036c5 110 val5 = vrefint5.read_u16();
rahulp5 0:a1e3728036c5 111
rahulp5 0:a1e3728036c5 112 Volts5 = (val5/65536)*3.3;
rahulp5 0:a1e3728036c5 113 Rx = Volts5*slope+C;
rahulp5 0:a1e3728036c5 114 temp5= (Rx/R0-1.0)/alpha;
rahulp5 0:a1e3728036c5 115 calibration=0.3+(0.005*temp5);
rahulp5 0:a1e3728036c5 116 tempC5=temp5-calibration;
rahulp5 0:a1e3728036c5 117 avg5[i]=tempC5;
rahulp5 0:a1e3728036c5 118
rahulp5 0:a1e3728036c5 119 val6 = vrefint6.read_u16();
rahulp5 0:a1e3728036c5 120
rahulp5 0:a1e3728036c5 121 Volts6 = (val6/65536)*3.3;
rahulp5 0:a1e3728036c5 122 Rx = Volts6*slope+C;
rahulp5 0:a1e3728036c5 123 temp6= (Rx/R0-1.0)/alpha;
rahulp5 0:a1e3728036c5 124 calibration=0.3+(0.005*temp6);
rahulp5 0:a1e3728036c5 125 tempC6=temp6-calibration;
rahulp5 0:a1e3728036c5 126 avg6[i]=tempC6;
rahulp5 0:a1e3728036c5 127
rahulp5 0:a1e3728036c5 128 val7 = vrefint7.read_u16();
rahulp5 0:a1e3728036c5 129
rahulp5 0:a1e3728036c5 130 Volts7 = (val7/65536)*3.3;
rahulp5 0:a1e3728036c5 131 Rx = Volts7*slope+C;
rahulp5 0:a1e3728036c5 132 temp7= (Rx/R0-1.0)/alpha;
rahulp5 0:a1e3728036c5 133 calibration=0.3+(0.005*temp7);
rahulp5 0:a1e3728036c5 134 tempC7=temp7-calibration;
rahulp5 0:a1e3728036c5 135 avg7[i]=tempC7;
rahulp5 0:a1e3728036c5 136
rahulp5 0:a1e3728036c5 137 val8 = vrefint8.read_u16();
rahulp5 0:a1e3728036c5 138
rahulp5 0:a1e3728036c5 139 Volts8 = (val8/65536)*3.3;
rahulp5 0:a1e3728036c5 140 Rx = Volts8*slope+C;
rahulp5 0:a1e3728036c5 141 temp8= (Rx/R0-1.0)/alpha;
rahulp5 0:a1e3728036c5 142 calibration=0.3+(0.005*temp8);
rahulp5 0:a1e3728036c5 143 tempC8=temp8-calibration;
rahulp5 0:a1e3728036c5 144 avg8[i]=tempC8;
rahulp5 0:a1e3728036c5 145
rahulp5 0:a1e3728036c5 146 wait(0.01);
rahulp5 0:a1e3728036c5 147 }
rahulp5 0:a1e3728036c5 148
rahulp5 0:a1e3728036c5 149 for(int j=0; j < 50; j++)
rahulp5 0:a1e3728036c5 150 {
rahulp5 0:a1e3728036c5 151 totalavg1 = totalavg1 + avg1[j];
rahulp5 0:a1e3728036c5 152 totalavg2 = totalavg2 + avg2[j];
rahulp5 0:a1e3728036c5 153 totalavg3 = totalavg3 + avg3[j];
rahulp5 0:a1e3728036c5 154 totalavg4 = totalavg4 + avg4[j];
rahulp5 0:a1e3728036c5 155 totalavg5 = totalavg5 + avg5[j];
rahulp5 0:a1e3728036c5 156 totalavg6 = totalavg6 + avg6[j];
rahulp5 0:a1e3728036c5 157 totalavg7 = totalavg7 + avg7[j];
rahulp5 0:a1e3728036c5 158 totalavg8 = totalavg8 + avg8[j];
rahulp5 0:a1e3728036c5 159 wait(0.01);
rahulp5 0:a1e3728036c5 160 }
rahulp5 0:a1e3728036c5 161
rahulp5 0:a1e3728036c5 162 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);
rahulp5 0:a1e3728036c5 163
rahulp5 0:a1e3728036c5 164 if((totalavg1 || totalavg2 || totalavg3 || totalavg4 || totalavg5 || totalavg6 || totalavg7 || totalavg8) > tempTh)
rahulp5 0:a1e3728036c5 165 Buzzer = 0;
rahulp5 0:a1e3728036c5 166 else
rahulp5 0:a1e3728036c5 167 Buzzer = 1;
rahulp5 0:a1e3728036c5 168
rahulp5 0:a1e3728036c5 169 if(totalavg1 > tempTh)
rahulp5 0:a1e3728036c5 170 led1 = 0;
rahulp5 0:a1e3728036c5 171 else
rahulp5 0:a1e3728036c5 172 led1 = 1;
rahulp5 0:a1e3728036c5 173 totalavg1 = 0;
rahulp5 0:a1e3728036c5 174
rahulp5 0:a1e3728036c5 175 if(totalavg2 > tempTh)
rahulp5 0:a1e3728036c5 176 led2 = 0;
rahulp5 0:a1e3728036c5 177 else
rahulp5 0:a1e3728036c5 178 led2 = 1;
rahulp5 0:a1e3728036c5 179 totalavg2 = 0;
rahulp5 0:a1e3728036c5 180
rahulp5 0:a1e3728036c5 181 if(totalavg3 > tempTh)
rahulp5 0:a1e3728036c5 182 led3 = 0;
rahulp5 0:a1e3728036c5 183 else
rahulp5 0:a1e3728036c5 184 led3 = 1;
rahulp5 0:a1e3728036c5 185 totalavg3 = 0;
rahulp5 0:a1e3728036c5 186
rahulp5 0:a1e3728036c5 187 if(totalavg4 > tempTh)
rahulp5 0:a1e3728036c5 188 led4 = 0;
rahulp5 0:a1e3728036c5 189 else
rahulp5 0:a1e3728036c5 190 led4 = 1;
rahulp5 0:a1e3728036c5 191 totalavg4 = 0;
rahulp5 0:a1e3728036c5 192
rahulp5 0:a1e3728036c5 193 if(totalavg5 > tempTh)
rahulp5 0:a1e3728036c5 194 led5 = 0;
rahulp5 0:a1e3728036c5 195 else
rahulp5 0:a1e3728036c5 196 led5 = 1;
rahulp5 0:a1e3728036c5 197 totalavg5 = 0;
rahulp5 0:a1e3728036c5 198
rahulp5 0:a1e3728036c5 199 if(totalavg6 > tempTh)
rahulp5 0:a1e3728036c5 200 led6 = 0;
rahulp5 0:a1e3728036c5 201 else
rahulp5 0:a1e3728036c5 202 led6 = 1;
rahulp5 0:a1e3728036c5 203 totalavg6 = 0;
rahulp5 0:a1e3728036c5 204
rahulp5 0:a1e3728036c5 205 if(totalavg7 > tempTh)
rahulp5 0:a1e3728036c5 206 led7 = 0;
rahulp5 0:a1e3728036c5 207 else
rahulp5 0:a1e3728036c5 208 led7 = 1;
rahulp5 0:a1e3728036c5 209 totalavg7 = 0;
rahulp5 0:a1e3728036c5 210
rahulp5 0:a1e3728036c5 211 if(totalavg8 > tempTh)
rahulp5 0:a1e3728036c5 212 led8 = 0;
rahulp5 0:a1e3728036c5 213 else
rahulp5 0:a1e3728036c5 214 led8 = 1;
rahulp5 0:a1e3728036c5 215 totalavg8 = 0;
rahulp5 0:a1e3728036c5 216
rahulp5 0:a1e3728036c5 217
rahulp5 0:a1e3728036c5 218 wait(0.5f);
rahulp5 0:a1e3728036c5 219 //totalavg1, totalavg2, totalavg3, totalavg4, totalavg5, totalavg6, totalavg7, totalavg8 = 0.0;
rahulp5 0:a1e3728036c5 220 }
rahulp5 0:a1e3728036c5 221 }