WathchDog

Dependencies:   mbed WDT

main.cpp

Committer:
orain3
Date:
2018-01-26
Revision:
0:63c74ee8bffc
Child:
1:c896654c679b

File content as of revision 0:63c74ee8bffc:

#include "mbed.h"

/*
   This basic example just shows how to read the ADC internal channels raw values.
   Please look in the corresponding device reference manual for a complete
   description of how to make a temperature sensor, VBat or Vref measurement.
*/

Serial pc(SERIAL_TX,SERIAL_RX);
Serial rs485(D1,D0);
AnalogIn adc_1(A1);
AnalogIn adc_2(A2);
//AnalogIn adc_3(A3);
//AnalogIn adc_4(A4);
//AnalogIn adc_5(A5);
//AnalogIn adc_6(A6);
//AnalogIn adc_7(A7);

DigitalOut led(LED1);
//DigitalIn in1(PA_1,PullNone);
//DigitalIn in2(PA_3,PullNone);


int main()
{
    float sum1,sum2;
    float ad1,ad2;
    float temp,turb,s;
    int i,cnt;

    rs485.baud(38400);
    rs485.format(8,Serial::None,1);    

    pc.printf("\nSTM32 ADC internal channels reading example\r\n");
    temp = 0;
    turb = 0;
    s = 0;
    while(1) {
        sum1 = 0;
        sum2 = 0;
        cnt = 0;
        for (i=0;i<1000;i++) {
            sum1 += adc_1.read();
            sum2 += adc_2.read();
            cnt += 1;
            wait(0.001);

            if (rs485.readable()) {
                pc.printf("%c\r",rs485.getc());
                wait(0.01);
                rs485.printf("=01,PVAL,%01.04f,%01.03f,%01.03f\r", turb/1000,temp,s);
            }
        }
        if(cnt != 0) {
            ad1 = sum1/cnt;
            ad2 = sum2/cnt;
        } else {
            ad1 = adc_1.read();
            ad2 = adc_2.read();
        }
        
        pc.printf("ADC 1 = %f ad %f mV : %f temp\r\n", ad1,ad1*3300,ad1*66-30+0.3);
        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);
        temp = ad1*66-30+0.3;
        turb = 2.1*((ad2-0.166)/0.6642*1000+25.5);
        s = 0;
        
//        if (rs485.readable()) {
//            pc.printf("%c\r",rs485.getc());
//            wait(0.01);
//            rs485.printf("=01,PVAL,%01.03f,%01.03f,%01.03f\r", temp,turb,s);
//        }
    }
}