mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 #include "test_env.h"
elessair 0:f269e3021894 2
elessair 0:f269e3021894 3 #if !DEVICE_ANALOGIN
elessair 0:f269e3021894 4 #error [NOT_SUPPORTED] AnalogIn not supported
elessair 0:f269e3021894 5 #endif
elessair 0:f269e3021894 6
elessair 0:f269e3021894 7 #if !DEVICE_ANALOGOUT
elessair 0:f269e3021894 8 #error [NOT_SUPPORTED] AnalogOut not supported
elessair 0:f269e3021894 9 #endif
elessair 0:f269e3021894 10
elessair 0:f269e3021894 11 #if defined(TARGET_K64F) || defined(TARGET_K66F) || defined (TARGET_K22F)
elessair 0:f269e3021894 12 AnalogIn in(A0);
elessair 0:f269e3021894 13 AnalogOut out(DAC0_OUT);
elessair 0:f269e3021894 14
elessair 0:f269e3021894 15 #elif defined(TARGET_KL25Z)
elessair 0:f269e3021894 16 AnalogIn in(PTC2);
elessair 0:f269e3021894 17 AnalogOut out(PTE30);
elessair 0:f269e3021894 18
elessair 0:f269e3021894 19 #elif defined(TARGET_KL05Z)
elessair 0:f269e3021894 20 AnalogIn in(PTB11); // D9
elessair 0:f269e3021894 21 AnalogOut out(PTB1); // D1
elessair 0:f269e3021894 22
elessair 0:f269e3021894 23 #elif defined(TARGET_KL46Z) || defined(TARGET_KL43Z)
elessair 0:f269e3021894 24 AnalogIn in(PTB0);
elessair 0:f269e3021894 25 AnalogOut out(PTE30);
elessair 0:f269e3021894 26
elessair 0:f269e3021894 27 #elif defined(TARGET_KL82Z)
elessair 0:f269e3021894 28 AnalogIn in(A2);
elessair 0:f269e3021894 29 AnalogOut out(DAC0_OUT);
elessair 0:f269e3021894 30
elessair 0:f269e3021894 31 #elif defined(TARGET_LPC1549)
elessair 0:f269e3021894 32 AnalogIn in(A0);
elessair 0:f269e3021894 33 AnalogOut out(D12); //D12 is P0_12, the DAC output pin
elessair 0:f269e3021894 34
elessair 0:f269e3021894 35 // No DAC on these targets:
elessair 0:f269e3021894 36 //TARGET_NUCLEO_F030R8
elessair 0:f269e3021894 37 //TARGET_NUCLEO_F070RB
elessair 0:f269e3021894 38 //TARGET_NUCLEO_F103RB
elessair 0:f269e3021894 39 //TARGET_NUCLEO_F401RE
elessair 0:f269e3021894 40 //TARGET_NUCLEO_F411RE
elessair 0:f269e3021894 41 #elif defined(TARGET_NUCLEO_F072RB) || \
elessair 0:f269e3021894 42 defined(TARGET_NUCLEO_F091RC) || \
elessair 0:f269e3021894 43 defined(TARGET_NUCLEO_F302R8) || \
elessair 0:f269e3021894 44 defined(TARGET_NUCLEO_F303RE) || \
elessair 0:f269e3021894 45 defined(TARGET_NUCLEO_F334R8) || \
elessair 0:f269e3021894 46 defined(TARGET_NUCLEO_F446RE) || \
elessair 0:f269e3021894 47 defined(TARGET_NUCLEO_F446ZE) || \
elessair 0:f269e3021894 48 defined(TARGET_NUCLEO_L053R8) || \
elessair 0:f269e3021894 49 defined(TARGET_NUCLEO_L073RZ) || \
elessair 0:f269e3021894 50 defined(TARGET_NUCLEO_L152RE)
elessair 0:f269e3021894 51 AnalogIn in(A0);
elessair 0:f269e3021894 52 AnalogOut out(A2);
elessair 0:f269e3021894 53
elessair 0:f269e3021894 54 #elif defined(TARGET_NUCLEO_F746ZG)
elessair 0:f269e3021894 55 AnalogIn in(A0);
elessair 0:f269e3021894 56 AnalogOut out(PA_4);
elessair 0:f269e3021894 57
elessair 0:f269e3021894 58 #elif defined(TARGET_NUCLEO_F207ZG)
elessair 0:f269e3021894 59 AnalogIn in(A0);
elessair 0:f269e3021894 60 AnalogOut out(D13);
elessair 0:f269e3021894 61
elessair 0:f269e3021894 62 #elif defined(TARGET_ARCH_MAX)
elessair 0:f269e3021894 63 AnalogIn in(PA_0);
elessair 0:f269e3021894 64 AnalogOut out(PA_4);
elessair 0:f269e3021894 65
elessair 0:f269e3021894 66 #elif defined(TARGET_DISCO_F407VG) || \
elessair 0:f269e3021894 67 defined(TARGET_DISCO_F469NI)
elessair 0:f269e3021894 68 AnalogIn in(PC_5);
elessair 0:f269e3021894 69 AnalogOut out(PA_4);
elessair 0:f269e3021894 70
elessair 0:f269e3021894 71 #elif defined(TARGET_NUCLEO_F303ZE)
elessair 0:f269e3021894 72 AnalogIn in(PC_5);
elessair 0:f269e3021894 73 AnalogOut out(PA_5);
elessair 0:f269e3021894 74
elessair 0:f269e3021894 75 #elif defined(TARGET_DISCO_F429ZI)
elessair 0:f269e3021894 76 AnalogIn in(PC_3);
elessair 0:f269e3021894 77 AnalogOut out(PA_5);
elessair 0:f269e3021894 78
elessair 0:f269e3021894 79 #elif defined(TARGET_MAX32600MBED)
elessair 0:f269e3021894 80 AnalogIn in(AIN_7P);
elessair 0:f269e3021894 81 AnalogOut out(AOUT_DO);
elessair 0:f269e3021894 82
elessair 0:f269e3021894 83 #elif defined(TARGET_SAMD21J18A) || defined(TARGET_SAML21J18A)
elessair 0:f269e3021894 84 AnalogIn in(PA04);
elessair 0:f269e3021894 85 AnalogOut out(PA02);
elessair 0:f269e3021894 86
elessair 0:f269e3021894 87 #elif defined(TARGET_SAMD21G18A)
elessair 0:f269e3021894 88 AnalogIn in(PB02);
elessair 0:f269e3021894 89 AnalogOut out(PA02);
elessair 0:f269e3021894 90
elessair 0:f269e3021894 91 #else
elessair 0:f269e3021894 92 AnalogIn in(p17);
elessair 0:f269e3021894 93 AnalogOut out(p18);
elessair 0:f269e3021894 94
elessair 0:f269e3021894 95 #endif
elessair 0:f269e3021894 96
elessair 0:f269e3021894 97 #define ERROR_TOLLERANCE 0.05
elessair 0:f269e3021894 98
elessair 0:f269e3021894 99 int main() {
elessair 0:f269e3021894 100 bool check = true;
elessair 0:f269e3021894 101
elessair 0:f269e3021894 102 for (float out_value=0.0; out_value<1.1; out_value+=0.1) {
elessair 0:f269e3021894 103 out.write(out_value);
elessair 0:f269e3021894 104 wait(0.1);
elessair 0:f269e3021894 105
elessair 0:f269e3021894 106 float in_value = in.read();
elessair 0:f269e3021894 107 float diff = fabs(out_value - in_value);
elessair 0:f269e3021894 108 if (diff > ERROR_TOLLERANCE) {
elessair 0:f269e3021894 109 check = false;
elessair 0:f269e3021894 110 printf("ERROR (out:%.4f) - (in:%.4f) = (%.4f)"NL, out_value, in_value, diff);
elessair 0:f269e3021894 111 } else {
elessair 0:f269e3021894 112 printf("OK (out:%.4f) - (in:%.4f) = (%.4f)"NL, out_value, in_value, diff);
elessair 0:f269e3021894 113 }
elessair 0:f269e3021894 114 }
elessair 0:f269e3021894 115
elessair 0:f269e3021894 116 notify_completion(check);
elessair 0:f269e3021894 117 }