WathchDog

Dependencies:   mbed WDT

Committer:
orain3
Date:
Fri Jan 26 12:00:55 2018 +0000
Revision:
0:63c74ee8bffc
Child:
1:c896654c679b
???

Who changed what in which revision?

UserRevisionLine numberNew contents of line
orain3 0:63c74ee8bffc 1 #include "mbed.h"
orain3 0:63c74ee8bffc 2
orain3 0:63c74ee8bffc 3 /*
orain3 0:63c74ee8bffc 4 This basic example just shows how to read the ADC internal channels raw values.
orain3 0:63c74ee8bffc 5 Please look in the corresponding device reference manual for a complete
orain3 0:63c74ee8bffc 6 description of how to make a temperature sensor, VBat or Vref measurement.
orain3 0:63c74ee8bffc 7 */
orain3 0:63c74ee8bffc 8
orain3 0:63c74ee8bffc 9 Serial pc(SERIAL_TX,SERIAL_RX);
orain3 0:63c74ee8bffc 10 Serial rs485(D1,D0);
orain3 0:63c74ee8bffc 11 AnalogIn adc_1(A1);
orain3 0:63c74ee8bffc 12 AnalogIn adc_2(A2);
orain3 0:63c74ee8bffc 13 //AnalogIn adc_3(A3);
orain3 0:63c74ee8bffc 14 //AnalogIn adc_4(A4);
orain3 0:63c74ee8bffc 15 //AnalogIn adc_5(A5);
orain3 0:63c74ee8bffc 16 //AnalogIn adc_6(A6);
orain3 0:63c74ee8bffc 17 //AnalogIn adc_7(A7);
orain3 0:63c74ee8bffc 18
orain3 0:63c74ee8bffc 19 DigitalOut led(LED1);
orain3 0:63c74ee8bffc 20 //DigitalIn in1(PA_1,PullNone);
orain3 0:63c74ee8bffc 21 //DigitalIn in2(PA_3,PullNone);
orain3 0:63c74ee8bffc 22
orain3 0:63c74ee8bffc 23
orain3 0:63c74ee8bffc 24 int main()
orain3 0:63c74ee8bffc 25 {
orain3 0:63c74ee8bffc 26 float sum1,sum2;
orain3 0:63c74ee8bffc 27 float ad1,ad2;
orain3 0:63c74ee8bffc 28 float temp,turb,s;
orain3 0:63c74ee8bffc 29 int i,cnt;
orain3 0:63c74ee8bffc 30
orain3 0:63c74ee8bffc 31 rs485.baud(38400);
orain3 0:63c74ee8bffc 32 rs485.format(8,Serial::None,1);
orain3 0:63c74ee8bffc 33
orain3 0:63c74ee8bffc 34 pc.printf("\nSTM32 ADC internal channels reading example\r\n");
orain3 0:63c74ee8bffc 35 temp = 0;
orain3 0:63c74ee8bffc 36 turb = 0;
orain3 0:63c74ee8bffc 37 s = 0;
orain3 0:63c74ee8bffc 38 while(1) {
orain3 0:63c74ee8bffc 39 sum1 = 0;
orain3 0:63c74ee8bffc 40 sum2 = 0;
orain3 0:63c74ee8bffc 41 cnt = 0;
orain3 0:63c74ee8bffc 42 for (i=0;i<1000;i++) {
orain3 0:63c74ee8bffc 43 sum1 += adc_1.read();
orain3 0:63c74ee8bffc 44 sum2 += adc_2.read();
orain3 0:63c74ee8bffc 45 cnt += 1;
orain3 0:63c74ee8bffc 46 wait(0.001);
orain3 0:63c74ee8bffc 47
orain3 0:63c74ee8bffc 48 if (rs485.readable()) {
orain3 0:63c74ee8bffc 49 pc.printf("%c\r",rs485.getc());
orain3 0:63c74ee8bffc 50 wait(0.01);
orain3 0:63c74ee8bffc 51 rs485.printf("=01,PVAL,%01.04f,%01.03f,%01.03f\r", turb/1000,temp,s);
orain3 0:63c74ee8bffc 52 }
orain3 0:63c74ee8bffc 53 }
orain3 0:63c74ee8bffc 54 if(cnt != 0) {
orain3 0:63c74ee8bffc 55 ad1 = sum1/cnt;
orain3 0:63c74ee8bffc 56 ad2 = sum2/cnt;
orain3 0:63c74ee8bffc 57 } else {
orain3 0:63c74ee8bffc 58 ad1 = adc_1.read();
orain3 0:63c74ee8bffc 59 ad2 = adc_2.read();
orain3 0:63c74ee8bffc 60 }
orain3 0:63c74ee8bffc 61
orain3 0:63c74ee8bffc 62 pc.printf("ADC 1 = %f ad %f mV : %f temp\r\n", ad1,ad1*3300,ad1*66-30+0.3);
orain3 0:63c74ee8bffc 63 pc.printf("ADC 2 = %f ad %f mA : %f turb\r\n", ad2,(ad2*3.3/2.74)*20,(ad2-0.166)/0.6642*1000+25.5);
orain3 0:63c74ee8bffc 64 temp = ad1*66-30+0.3;
orain3 0:63c74ee8bffc 65 turb = 2.1*((ad2-0.166)/0.6642*1000+25.5);
orain3 0:63c74ee8bffc 66 s = 0;
orain3 0:63c74ee8bffc 67
orain3 0:63c74ee8bffc 68 // if (rs485.readable()) {
orain3 0:63c74ee8bffc 69 // pc.printf("%c\r",rs485.getc());
orain3 0:63c74ee8bffc 70 // wait(0.01);
orain3 0:63c74ee8bffc 71 // rs485.printf("=01,PVAL,%01.03f,%01.03f,%01.03f\r", temp,turb,s);
orain3 0:63c74ee8bffc 72 // }
orain3 0:63c74ee8bffc 73 }
orain3 0:63c74ee8bffc 74 }