WathchDog

Dependencies:   mbed WDT

Committer:
orain3
Date:
Sat Feb 23 09:11:23 2019 +0000
Revision:
2:d69d10b670c5
Parent:
1:c896654c679b
Child:
3:b082ed02d08c
ver0

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 Serial pc(SERIAL_TX,SERIAL_RX);
orain3 1:c896654c679b 4 Serial modem(D1,D0);
orain3 1:c896654c679b 5 AnalogIn adc_1(A0);
orain3 1:c896654c679b 6 AnalogIn adc_2(A1);
orain3 1:c896654c679b 7 AnalogIn adc_3(A2);
orain3 1:c896654c679b 8 AnalogIn adc_4(A3);
orain3 0:63c74ee8bffc 9
orain3 0:63c74ee8bffc 10 DigitalOut led(LED1);
orain3 1:c896654c679b 11 DigitalOut sokutei(D3);
orain3 1:c896654c679b 12 DigitalOut commndout(D4);
orain3 1:c896654c679b 13 DigitalIn in1(D9,PullNone);
orain3 1:c896654c679b 14 DigitalIn in2(D10,PullNone);
orain3 1:c896654c679b 15 DigitalIn kansyutu(D6,PullNone);
orain3 1:c896654c679b 16 DigitalIn commandin(D7,PullNone);
orain3 1:c896654c679b 17 DigitalIn jmp(D2,PullUp);
orain3 0:63c74ee8bffc 18
orain3 0:63c74ee8bffc 19
orain3 0:63c74ee8bffc 20 int main()
orain3 0:63c74ee8bffc 21 {
orain3 1:c896654c679b 22 float sum1,sum2,sum3,sum4;
orain3 1:c896654c679b 23 float ad1,ad2,ad3,ad4;
orain3 0:63c74ee8bffc 24 float temp,turb,s;
orain3 0:63c74ee8bffc 25 int i,cnt;
orain3 0:63c74ee8bffc 26
orain3 1:c896654c679b 27 modem.baud(38400);
orain3 1:c896654c679b 28 modem.format(8,Serial::None,1);
orain3 0:63c74ee8bffc 29
orain3 0:63c74ee8bffc 30 pc.printf("\nSTM32 ADC internal channels reading example\r\n");
orain3 0:63c74ee8bffc 31 temp = 0;
orain3 0:63c74ee8bffc 32 turb = 0;
orain3 0:63c74ee8bffc 33 s = 0;
orain3 1:c896654c679b 34
orain3 1:c896654c679b 35 sokutei = 1;
orain3 1:c896654c679b 36
orain3 0:63c74ee8bffc 37 while(1) {
orain3 1:c896654c679b 38
orain3 1:c896654c679b 39 if (jmp) sokutei = 1;
orain3 1:c896654c679b 40 else sokutei = 0;
orain3 1:c896654c679b 41
orain3 0:63c74ee8bffc 42 sum1 = 0;
orain3 0:63c74ee8bffc 43 sum2 = 0;
orain3 1:c896654c679b 44 sum3 = 0;
orain3 1:c896654c679b 45 sum4 = 0;
orain3 0:63c74ee8bffc 46 cnt = 0;
orain3 1:c896654c679b 47 for (i=0;i<10;i++) {
orain3 0:63c74ee8bffc 48 sum1 += adc_1.read();
orain3 0:63c74ee8bffc 49 sum2 += adc_2.read();
orain3 1:c896654c679b 50 sum3 += adc_3.read();
orain3 1:c896654c679b 51 sum4 += adc_4.read();
orain3 0:63c74ee8bffc 52 cnt += 1;
orain3 0:63c74ee8bffc 53 wait(0.001);
orain3 0:63c74ee8bffc 54
orain3 2:d69d10b670c5 55 // if (modem.readable()) {
orain3 2:d69d10b670c5 56 // pc.printf("%c\r",modem.getc());
orain3 2:d69d10b670c5 57 // wait(0.01);
orain3 2:d69d10b670c5 58 // modem.printf("=04,PVAL,%01.04f,0,\r",temp);
orain3 2:d69d10b670c5 59 // }
orain3 0:63c74ee8bffc 60 }
orain3 0:63c74ee8bffc 61 if(cnt != 0) {
orain3 0:63c74ee8bffc 62 ad1 = sum1/cnt;
orain3 0:63c74ee8bffc 63 ad2 = sum2/cnt;
orain3 1:c896654c679b 64 ad3 = sum3/cnt;
orain3 1:c896654c679b 65 ad4 = sum4/cnt;
orain3 0:63c74ee8bffc 66 } else {
orain3 0:63c74ee8bffc 67 ad1 = adc_1.read();
orain3 0:63c74ee8bffc 68 ad2 = adc_2.read();
orain3 1:c896654c679b 69 ad3 = adc_3.read();
orain3 1:c896654c679b 70 ad4 = adc_4.read();
orain3 0:63c74ee8bffc 71 }
orain3 0:63c74ee8bffc 72
orain3 1:c896654c679b 73 pc.printf("ADC = %f %f %f %f \r\n", ad1,ad2,ad3,ad4);
orain3 0:63c74ee8bffc 74 temp = ad1*66-30+0.3;
orain3 0:63c74ee8bffc 75 turb = 2.1*((ad2-0.166)/0.6642*1000+25.5);
orain3 0:63c74ee8bffc 76 s = 0;
orain3 0:63c74ee8bffc 77
orain3 0:63c74ee8bffc 78 }
orain3 0:63c74ee8bffc 79 }