Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 //input control for DDRO 00003 00004 Ticker CLK; 00005 00006 Serial pc(USBTX, USBRX); // tx, rx 00007 00008 DigitalOut ref_clk(p5); 00009 DigitalOut count(p6); 00010 DigitalOut read(p7); 00011 DigitalOut enable(p8); 00012 DigitalOut S0(p9); 00013 DigitalOut S1(p10); 00014 DigitalOut S2(p11); 00015 DigitalOut S3(p12); 00016 DigitalOut S4(p13); 00017 DigitalOut S5(p14); 00018 DigitalOut OS(p15); 00019 DigitalIn FDO(p16); 00020 DigitalIn O0(p21); 00021 DigitalIn O1(p22); 00022 DigitalIn O2(p23); 00023 DigitalIn O3(p24); 00024 DigitalIn O4(p25); 00025 DigitalIn O5(p26); 00026 DigitalIn O6(p27); 00027 DigitalIn O7(p28); 00028 00029 void clk_gen() 00030 { 00031 ref_clk = !ref_clk; 00032 } 00033 00034 void assign_s(int selection) 00035 { 00036 int remainder = selection; 00037 S0 = selection % 2; 00038 selection = selection / 2; 00039 S1 = selection % 2; 00040 selection = selection / 2; 00041 S2 = selection % 2; 00042 selection = selection / 2; 00043 S3 = selection % 2; 00044 selection = selection / 2; 00045 S4 = selection % 2; 00046 selection = selection / 2; 00047 S5 = selection % 2; 00048 } 00049 00050 int read_out() 00051 { 00052 int out; 00053 out = 0; 00054 OS = 1; 00055 out += O7.read(); 00056 out *= 2; 00057 out += O6.read(); 00058 out *= 2; 00059 out += O5.read(); 00060 out *= 2; 00061 out += O4.read(); 00062 out *= 2; 00063 out += O3.read(); 00064 out *= 2; 00065 out += O2.read(); 00066 out *= 2; 00067 out += O1.read(); 00068 out *= 2; 00069 out += O0.read(); 00070 out *= 2; 00071 OS = 0; 00072 wait(0.001); 00073 out += O7.read(); 00074 out *= 2; 00075 out += O6.read(); 00076 out *= 2; 00077 out += O5.read(); 00078 out *= 2; 00079 out += O4.read(); 00080 out *= 2; 00081 out += O3.read(); 00082 out *= 2; 00083 out += O2.read(); 00084 out *= 2; 00085 out += O1.read(); 00086 out *= 2; 00087 out += O0.read(); 00088 return out; 00089 } 00090 00091 int main() { 00092 pc.printf("Testing Starts here\n"); 00093 O0.mode(OpenDrain); 00094 O1.mode(OpenDrain); 00095 O2.mode(OpenDrain); 00096 O3.mode(OpenDrain); 00097 O4.mode(OpenDrain); 00098 O5.mode(OpenDrain); 00099 O6.mode(OpenDrain); 00100 O7.mode(OpenDrain); 00101 count = 0; 00102 read = 0; 00103 enable = 0; 00104 int i; 00105 for (i=0;i<64;i++) 00106 { 00107 //measure using 0.01 00108 int select = i; 00109 pc.printf("%d ", select); 00110 enable = 0; 00111 count = 0; 00112 read = 0; 00113 assign_s(select); 00114 CLK.attach(&clk_gen, 0.01); 00115 wait(0.1); 00116 enable = 1; 00117 count = 0; 00118 wait(0.001); 00119 count = 0; 00120 wait(0.001); 00121 count = 1; 00122 wait(0.001); 00123 count = 0; 00124 wait(0.1); 00125 read = 0; 00126 read = 1; 00127 read = 0; 00128 enable = 0; 00129 int out = read_out(); 00130 pc.printf("%d ", out); 00131 OS = 1; 00132 wait(0.1); 00133 pc.printf("%d%d%d%d%d%d%d%d",O7.read(),O6.read(),O5.read(),O4.read(),O3.read(),O2.read(),O1.read(),O0.read()); 00134 wait(0.1); 00135 OS = 0; 00136 pc.printf("%d%d%d%d%d%d%d%d ",O7.read(),O6.read(),O5.read(),O4.read(),O3.read(),O2.read(),O1.read(),O0.read()); 00137 00138 //measure using 0.1 00139 CLK.detach(); 00140 enable = 0; 00141 count = 0; 00142 read = 0; 00143 CLK.attach(&clk_gen, 0.04); 00144 wait(0.2); 00145 enable = 1; 00146 count = 0; 00147 wait(0.001); 00148 count = 0; 00149 wait(0.001); 00150 count = 1; 00151 wait(0.001); 00152 count = 0; 00153 wait(0.2); 00154 read = 0; 00155 read = 1; 00156 read = 0; 00157 enable = 0; 00158 out = read_out(); 00159 pc.printf("%d ", out); 00160 OS = 1; 00161 wait(0.1); 00162 pc.printf("%d%d%d%d%d%d%d%d",O7.read(),O6.read(),O5.read(),O4.read(),O3.read(),O2.read(),O1.read(),O0.read()); 00163 wait(0.1); 00164 OS = 0; 00165 pc.printf("%d%d%d%d%d%d%d%d\n",O7.read(),O6.read(),O5.read(),O4.read(),O3.read(),O2.read(),O1.read(),O0.read()); 00166 } 00167 }
Generated on Thu Jul 21 2022 15:48:26 by
1.7.2