ADC Current Measurement via serial port
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 00003 //------------------------------------ 00004 // Hyperterminal configuration 00005 // 9600 bauds, 8-bit data, no parity 00006 //------------------------------------ 00007 AnalogIn analog_value(A0); 00008 AnalogIn analog_value2(A1); 00009 00010 DigitalOut led(LED1); 00011 Serial pc(SERIAL_TX, SERIAL_RX); 00012 00013 DigitalOut myled(LED1); 00014 00015 int main() 00016 { 00017 int i = 1; 00018 int tim = 0; 00019 float vbat; 00020 float meas; 00021 float average; 00022 float sum; 00023 float current; 00024 //pc.printf("Hello World !\n"); 00025 pc.printf("Time\t Vbat \t Current \n ", tim); 00026 while(1) { 00027 00028 for (int i=0; i<1000; i++) { 00029 00030 meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) 00031 meas = meas * 3300; // Change the value to be in the 0 to 3300 range 00032 //printf("measure = %.0f mV\n", meas); 00033 sum=sum+meas; 00034 00035 if (meas > 2000) { // If the value is greater than 2V then switch the LED on 00036 led = 1; 00037 } else { 00038 led = 0; 00039 } 00040 wait_ms(1);// 200 ms 00041 } 00042 vbat = analog_value2.read(); // Converts and read the analog input value (value from 0.0 to 1.0) 00043 vbat = vbat * 3.300*2; // Change the value to be in the 0 to 3300 range by 2 because of voltage divider 00044 average=sum/1000; 00045 sum=0; 00046 current=(average /10);//-0.96; 00047 tim+=1; 00048 pc.printf(" %d \t", tim); 00049 pc.printf(" %.2f \t", vbat); 00050 pc.printf(" %.2f; \n", current); 00051 00052 myled = !myled; 00053 } 00054 }
Generated on Sat Jul 16 2022 01:42:15 by 1.7.2