PHung Tung
/
ADCin_DACout_UART
a
Revision 0:d89d5712d45e, committed 2019-06-04
- Comitter:
- phungductung
- Date:
- Tue Jun 04 09:02:38 2019 +0000
- Commit message:
- hello
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r d89d5712d45e main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jun 04 09:02:38 2019 +0000 @@ -0,0 +1,40 @@ +#include "mbed.h" + +AnalogIn in(A0); + +/*#if !DEVICE_ANALOGOUT +#error You cannot use this example as the AnalogOut is not supported on this device. +#else*/ +AnalogOut out(PA_4); +//#endif + +DigitalOut led(LED1); + +int main() +{ + printf("\nvong lap Analog\n\r"); + printf("*** ket noi chan A0 va PA_4 voi nhau ***\n\r"); + while(1) { + for (float out_value = 0.0f; out_value < 1.1f; out_value += 0.1f) { + // Giá trị đầu ra sử dụng DAC + out.write(out_value); + wait(0.1); + // doc ADC input + float in_value = in.read(); + // DAC - ADC + float diff = fabs(out_value - in_value); + printf("(out:%.4f) - (in:%.4f) = (%.4f) \n\r", out_value, in_value, diff); + if (diff > 0.05f) { + printf("FAIL\n\r"); + } else { + printf("\nOK\n\r"); + printf("\033[1A\n\r"); // di chuyen con tro len dong truoc do + // printf("DAC and ADC:"); + printf("(DAC out:%.4f) - (ADC in:%.4f) = (su khac biet giua hai gia tri: %.4f) \n\n\n\r", out_value, in_value, diff); + + } + led = !led; //nhap nhay led + } + } +} +
diff -r 000000000000 -r d89d5712d45e mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Jun 04 09:02:38 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file