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.
adc_test.cpp
00001 #include "mbed.h" 00002 00003 extern Serial pc; 00004 extern int frequ; //unit kHz 00005 extern char dev_addr; //fixed 00006 00007 char get_half_byte(int *); //defined in I2C_read.cpp 00008 char get_byte(int *); //defined in EasyFuse_Prog.cpp 00009 void i2c_write_fn(I2C *, char , char );//defined in Easy Fuse Prog 00010 char i2c_read_fn(I2C *, char ); //defined in Easy Fuse Prog 00011 void read_bit(int ); // defined in I2C_hot_read 00012 00013 void i2c_hotread_fn(I2C *i2c_obj, char ptr, int bit_position) { 00014 int flag1; 00015 char temp; 00016 wait_us(10); 00017 (*i2c_obj).start(); 00018 flag1 = (*i2c_obj).write(dev_addr); 00019 if (flag1 != 1) pc.printf("\n\n\n\r\tNo Ack for dev addr :("); 00020 flag1 = (*i2c_obj).write(ptr); 00021 if (flag1 != 1) pc.printf("\n\n\r\tNo Ack reg pointer :("); 00022 (*i2c_obj).stop(); 00023 wait_us(300); 00024 pc.printf("\n\n\n\r\tPress 's' to start hot read : "); 00025 while(temp!='s') { 00026 temp = pc.getc(); 00027 } 00028 //(*i2c_obj).start(); 00029 //flag1 = (*i2c_obj).write(dev_addr | 0x01); //lsb 1 for read 00030 //if (flag1 != 1) pc.printf("\n\n\r\tNo Ack for dev addr :("); 00031 read_bit(bit_position); // hot-read function 00032 (*i2c_obj).stop(); 00033 } 00034 00035 void draw_sig_line() { 00036 pc.printf("\033[%dm ", 33);//change text color to yellow 00037 pc.printf("\n\n\n\n\r \304"); 00038 for ( int i = 0; i<80; i++) pc.printf("\304"); 00039 pc.printf("\033[%dm ", 32);//change text color to green 00040 pc.printf("\n\n\r"); 00041 } 00042 00043 void get_new_val (char *reg_val06) { 00044 int flag1 = 0; 00045 pc.printf("\n\n\n\r\t\033[%dmChoose a Range trim from the above table (\033[%dmRecommended values are highlighted in red\033[%dm)",36,31,36); 00046 while (!flag1) { 00047 pc.printf("\n\n\r\tEnter new Range trim in hex (00 to ff): 0x"); 00048 *reg_val06 = get_byte(&flag1); 00049 if ( *reg_val06 > 0x1F ) flag1 = 0; //Range trim is only 5 bits 00050 if (flag1 == 0) pc.printf(" \033[%dm Invalid Chracter!! No worries, let us try again \033[%dm",41,40); 00051 } 00052 pc.printf("\033[%dm",32); 00053 } 00054 00055 void adc_meas (I2C *i2c_obj, char count, char lsb) { 00056 char adc_op; 00057 int voc; 00058 char temp; 00059 00060 voc = lsb * count; 00061 00062 temp = 0; 00063 pc.printf("\n\n\n\r\t\033[%dmSet Voc = %d mV (%d mV x %d). Press 'c' to continue: \033[%dm", 36, voc, lsb, count, 32); 00064 while ( temp!='c') { 00065 temp = pc.getc(); 00066 } 00067 i2c_write_fn(i2c_obj,0x14,count - 2); //Writing starting value in ADC 00068 wait_ms(5); 00069 i2c_write_fn(i2c_obj,0x0D,0x03); //tm_adc_en = tm_adc_go = 1; start conversion 00070 wait_ms(20); //to make sure conversion is complete 00071 adc_op = i2c_read_fn(i2c_obj,0x14); 00072 pc.printf("\n\n\n\r\t\033[%dmadc_op%d_%dmv = 0x%2.2X\033[%dm", 45, count, lsb, adc_op, 40);//displaying in Magenta background 00073 return; 00074 } 00075 00076 00077 void adc_test() { 00078 00079 I2C i2c(p9,p10); 00080 char temp; 00081 char reg_val06; 00082 char reg_val06_max = 0x1F; //for debug, change to 0x1F 00083 char reg_val05; 00084 char reg_val05_strt; 00085 char reg_val04; 00086 char reg_val07; 00087 char adc_op31[32]; 00088 char adc_op223[32]; 00089 char d_adc_op192[32] = {0x00}; 00090 char adc_op8 = 0x07; 00091 char adc_op8_old; 00092 char adc_op8_disp[32]; 00093 char d_adc_op = 0x00; 00094 char d_adc_op_old = 0x00; 00095 int i = 0; 00096 int x = 0; 00097 00098 i2c.frequency((frequ/2)*1000); 00099 LPC_PINCON->PINMODE_OD0 = (LPC_PINCON->PINMODE_OD0 | 0x0003); // To make p9 & P10 open_drain 00100 i2c.stop(); //add a stop after hot-read 00101 00102 pc.printf("\033[%dm ", 31);//change text color to red 00103 pc.printf("\n\n\n\r\tStarting adc test \n\r\t"); 00104 for ( i = 0; i<18; i++) pc.printf("\334"); 00105 pc.printf("\n\n\r\033[%dm", 32);//change text color to blue 00106 00107 i2c_write_fn(&i2c,0x17,0x03); //dmux op = adc_conversion. DATA2_CLK will be high when adc conversion is ongoing 00108 00109 pc.printf("\033[%dm", 34);//change text color to blue 00110 pc.printf("\n\n\n\r\tConditions: \n\r\t"); 00111 for ( i = 0; i<13; i++) pc.printf("\304"); 00112 pc.printf("\n\n\r\t 1. ASIC in test-mode "); 00113 pc.printf("\n\n\r\t 2. Short input Rin (5ohms) resistor "); 00114 pc.printf("\n\n\r\t 3. Please Monitor DATA2_CLK on oscilloscope. DATA2_CLK = 'adc_conversion'"); 00115 pc.printf("\n\n\r\t 4. Positive input polarity"); 00116 pc.printf("\033[%dm ", 32);//change text color to green 00117 temp = 0; 00118 pc.printf("\n\n\n\r\t\033[%dmPress 'c' to continue: \033[%dm",36,32); 00119 while ( temp!='c') { 00120 temp = pc.getc(); 00121 } 00122 i2c_write_fn(&i2c,0x0F,0x00); //Disabling Flyback 00123 00124 //reg_val06 = i2c_read_fn(&i2c,0x06); //reading the initial range trim 00125 i2c_write_fn(&i2c,0x0D,0x01); //tm_adc_en = 1 00126 00127 draw_sig_line(); 00128 00129 //***************************************************************** 00130 //****** ADC Range trim test 00131 //***************************************************************** 00132 00133 pc.printf("\033[%dm ", 31);//change text color to red 00134 pc.printf("\n\n\n\r\tStarting Range trim \n\r\t"); 00135 for ( i = 0; i<19; i++) pc.printf("\315"); 00136 pc.printf("\033[%dm ", 32);//change text color to green 00137 00138 temp = 0; 00139 pc.printf("\n\n\n\r\t\033[%dmSet Voc = 63mV (2mV x 31.5). Press 'c' to continue: \033[%dm",36,32); 00140 while ( temp!='c') { 00141 temp = pc.getc(); 00142 } 00143 //Making sure input polarity detector outputs are correct. 00144 i2c_write_fn(&i2c,0x10,0x10); //tm_PolComp_en = 1 00145 wait_ms(1); 00146 i2c_write_fn(&i2c,0x10,0x00); //tm_PolComp_en = 0 00147 pc.printf("\n\n\r\tFinding ADC outputs for all adc range with input = 63mV"); 00148 //Finding ADC outputs for all adc range with input = 63mV 00149 00150 for ( reg_val06 = 0x00; reg_val06 <= reg_val06_max; reg_val06 = (reg_val06 + 1)) { 00151 00152 i2c_write_fn(&i2c,0x06,reg_val06); 00153 00154 //Write initial value into ADC register 00155 if ( reg_val06 == 0x00 ) i2c_write_fn(&i2c,0x14,0x64); //starting value = 100. ADC reading will reduce as range trim increases 00156 else i2c_write_fn(&i2c,0x14,adc_op31[(reg_val06 - 1)]); //starting with previous measurement value 00157 00158 wait_ms(5); 00159 i2c_write_fn(&i2c,0x0D,0x03); //tm_adc_en = tm_adc_go = 1; start conversion 00160 wait_ms(20); //to make sure conversion is complete 00161 adc_op31[reg_val06] = i2c_read_fn(&i2c,0x14); 00162 pc.printf("."); 00163 } 00164 00165 temp = 0; 00166 pc.printf("\n\n\n\r\t\033[%dmSet Voc = 447mV (2mV x 223.5). Press 'c' to continue: \033[%dm",36,32); 00167 while ( temp!='c') { 00168 temp = pc.getc(); 00169 } 00170 pc.printf("\n\n\r\tFinding ADC outputs for all adc range with input = 447mV"); 00171 for ( reg_val06 = 0x00; reg_val06 <= reg_val06_max; reg_val06 = (reg_val06 + 1)) { 00172 00173 i2c_write_fn(&i2c,0x06,reg_val06); 00174 00175 //Write initial value into ADC register 00176 if ( reg_val06 == 0x00 ) i2c_write_fn(&i2c,0x14,0x64); //starting value = 100. ADC reading will reduce as range trim increases 00177 else i2c_write_fn(&i2c,0x14,adc_op223[(reg_val06 - 1)]); //starting with previous measurement value 00178 00179 wait_ms(5); 00180 i2c_write_fn(&i2c,0x0D,0x03); //tm_adc_en = tm_adc_go = 1; start conversion 00181 wait_ms(20); //to make sure conversion is complete 00182 adc_op223[reg_val06] = i2c_read_fn(&i2c,0x14); 00183 d_adc_op192[reg_val06] = adc_op223[reg_val06] - adc_op31[reg_val06]; 00184 pc.printf("."); 00185 } 00186 //Printing results 00187 pc.printf("\n\n\n\r\t\332"); 00188 for ( i = 0; i < 4; i++ ) { 00189 for ( x = 0; x < 23; x++ ) pc.printf("\304"); 00190 pc.printf("\302"); 00191 } 00192 00193 pc.printf("\n\r\t\263\t\033[%dmRange Trim\033[%dm\t\263\t\033[%dmadc_op31\033[%dm\t\263\t\033[%dmadc_op223\033[%dm\t\263\t\033[%dmdelta_adc_op\033[%dm\t\263",34,32,34,32,34,32,34,32); 00194 00195 //d_adc_op192[3] = 0xC0; //added for debug. Remove! 00196 00197 for ( reg_val06 = 0x00; reg_val06 <= reg_val06_max; reg_val06 = (reg_val06 + 1)) { 00198 00199 pc.printf("\n\r\t\303"); 00200 for ( i = 0; i < 4; i++ ) { 00201 for ( x = 0; x < 23; x++ ) pc.printf("\304"); 00202 if ( i < 3) pc.printf("\305"); 00203 else pc.printf("\264"); 00204 } 00205 if ( (d_adc_op192[reg_val06] > 0xBE) && (d_adc_op192[reg_val06] < 0xC2)) 00206 pc.printf("\n\r\t\263\t\033[%dm 0x%2.2X\t\t\263\t 0x%2.2X\t\t\263\t 0x%2.2X\t\t\263\t 0x%2.2X\033[%dm\t\263", 31, reg_val06, adc_op31[reg_val06], adc_op223[reg_val06], d_adc_op192[reg_val06], 32); 00207 else 00208 pc.printf("\n\r\t\263\t 0x%2.2X\t\t\263\t 0x%2.2X\t\t\263\t 0x%2.2X\t\t\263\t 0x%2.2X\t\263", reg_val06, adc_op31[reg_val06], adc_op223[reg_val06], d_adc_op192[reg_val06]); 00209 } 00210 00211 pc.printf("\n\r\t\300"); 00212 for ( i = 0; i < 4; i++ ) { 00213 for ( x = 0; x < 23; x++ ) pc.printf("\304"); 00214 if ( i < 3) pc.printf("\301"); 00215 else pc.printf("\331"); 00216 } 00217 00218 get_new_val(®_val06); 00219 i2c_write_fn(&i2c,0x06,reg_val06); 00220 00221 00222 pc.printf("\n\n\n\r\t\033[%dmFinal Range trim = 0x%2.2X\033[%dm ", 45, reg_val06, 40); 00223 00224 pc.printf("\n\n\n\r\t\033[%dmDo you want to continue with offset trim. Press ",36); 00225 pc.printf("\n\n\r\t 'c' - Continue "); 00226 pc.printf("\n\n\r\t 'e' - Exit "); 00227 pc.printf("\n\n\n\r\tYour Selection : \033[%dm",32); 00228 temp = 0; 00229 while ( temp!='c' && temp!='e') { 00230 temp = pc.getc(); 00231 } 00232 if (temp == 'e') return; 00233 00234 //***************************************************************** 00235 //****** ADC Offset trim test 00236 //***************************************************************** 00237 00238 00239 draw_sig_line(); 00240 00241 pc.printf("\033[%dm ", 31);//change text color to red 00242 pc.printf("\n\n\n\n\r\tStarting Offset trim \n\r\t"); 00243 for ( i = 0; i<19; i++) pc.printf("\315"); 00244 pc.printf("\033[%dm ", 32);//change text color to green 00245 00246 temp = 0; 00247 pc.printf("\n\n\n\r\t\033[%dmSet Voc = 16mV (2mV x 8). Press 'c' to continue: \033[%dm",36,32); 00248 while ( temp!='c') { 00249 temp = pc.getc(); 00250 } 00251 // determine trim direction 00252 00253 i2c_write_fn(&i2c,0x14,adc_op8); //Writing starting value in ADC 00254 pc.printf("\n\n\r\tAbout to start ADC conversion. 0 -> 1 -> 0 transition should be seen on DATA2_CLK"); 00255 wait_ms(5); 00256 i2c_write_fn(&i2c,0x0D,0x03); //tm_adc_en = tm_adc_go = 1; start conversion 00257 wait_ms(20); //to make sure conversion is complete 00258 adc_op8 = i2c_read_fn(&i2c,0x14); 00259 pc.printf("\n\n\r\tadc_op8 = 0x%2.2X ",adc_op8); 00260 00261 temp = 0; 00262 if (adc_op8 == 0x08) { 00263 temp = 1; // no trimming procedure 00264 pc.printf("\n\n\r\tNo Trimming Required. Woohoo"); 00265 reg_val05 = i2c_read_fn(&i2c,0x05); 00266 adc_op8_disp[reg_val05] = adc_op8; // for displaying 00267 } 00268 00269 00270 adc_op8_old = adc_op8; //storing previous value in case the trim loop is not entered 00271 00272 00273 if (adc_op8_old < 0x08) { 00274 pc.printf("\n\n\r\tadc_op08 < 0x08; need to perform positive trim"); 00275 reg_val05 = 0x10; 00276 adc_op8 = 0x10;//decimal 16. Set for proper function of the trim procedure 00277 } 00278 00279 if (adc_op8_old > 0x08) { 00280 pc.printf("\n\n\r\tadc_op08 > 0x08; need to perform negative trim"); 00281 reg_val05 = 0x00; 00282 //adc_op8 = 0x00; 00283 } 00284 00285 reg_val05_strt = reg_val05; //storing the starting value 00286 00287 //Start trim 00288 00289 while (temp != 1) { 00290 i2c_write_fn(&i2c,0x05,reg_val05); //programming offset trim 00291 adc_op8_old = adc_op8; //storing previous value 00292 i2c_write_fn(&i2c,0x14,adc_op8); //Writing starting value in ADC 00293 wait_ms(5); 00294 i2c_write_fn(&i2c,0x0D,0x03); //tm_adc_en = tm_adc_go = 1; start conversion 00295 wait_ms(20); //to make sure conversion is complete 00296 adc_op8 = i2c_read_fn(&i2c,0x14); 00297 adc_op8_disp[reg_val05] = adc_op8; // for displaying 00298 00299 if ((adc_op8 == 0x08) || ((adc_op8 > 0x08) && (adc_op8_old < 0x08)) || ((adc_op8 < 0x08) && (adc_op8_old > 0x08))) { 00300 // pc.printf("\n\n\r\tI'm exiting."); 00301 // pc.printf("\n\r\t\t\263\t adc_op8 = 0x%2.2X\t\t\263\t adc_op8_old = 0x%2.2X\t\t\263 ", adc_op8, adc_op8_old); 00302 break; // exit loop 00303 } 00304 if ((reg_val05 == 0x0F) || (reg_val05 == 0x1F)) { 00305 pc.printf("\n\n\r\tTest Failed."); 00306 break; // exit loop 00307 } 00308 reg_val05 = reg_val05 + 0x01; 00309 // pc.printf("\n\r\t\t\263\t reg_val05 = 0x%2.2X\t\t\263\t adc_op8 = 0x%2.2X\t\t\263 ", reg_val05, adc_op8); 00310 00311 } 00312 //Printing Result table 00313 00314 pc.printf("\n\n\n\r\t\t\332"); 00315 for ( i = 0; i < 2; i++ ) { 00316 for ( x = 0; x < 23; x++ ) pc.printf("\304"); 00317 pc.printf("\302"); 00318 } 00319 pc.printf("\n\r\t\t\263\t\033[%dmOffset Trim\033[%dm\t\263\t\033[%dmadc_op8\033[%dm\t\t\263", 34, 32, 34, 32); 00320 for ( temp = reg_val05_strt; temp <= reg_val05; temp = (temp + 1) ) { 00321 00322 pc.printf("\n\r\t\t\303"); 00323 for ( i = 0; i < 2; i++ ) { 00324 for ( x = 0; x < 23; x++ ) pc.printf("\304"); 00325 if ( i < 1) pc.printf("\305"); 00326 else pc.printf("\264"); 00327 } 00328 pc.printf("\n\r\t\t\263\t 0x%2.2X\t\t\263\t 0x%2.2X\t\t\263 ", temp, adc_op8_disp[temp]); 00329 } 00330 00331 pc.printf("\n\r\t\t\300"); 00332 for ( i = 0; i < 2; i++ ) { 00333 for ( x = 0; x < 23; x++ ) pc.printf("\304"); 00334 if ( i < 1) pc.printf("\301"); 00335 else pc.printf("\331"); 00336 } 00337 00338 if (adc_op8 > 0x08) d_adc_op = adc_op8 - 0x08; 00339 else d_adc_op = 0x08 - adc_op8; 00340 00341 if (adc_op8_old > 0x08) d_adc_op_old = adc_op8_old - 0x08; 00342 else d_adc_op_old = 0x08 - adc_op8_old; 00343 00344 if (d_adc_op > d_adc_op_old) { 00345 reg_val05 = reg_val05 - 0x01; 00346 i2c_write_fn(&i2c,0x05,reg_val05); //programming offset trim 00347 } 00348 pc.printf("\n\n\n\r\t\033[%dmFinal Offset trim = 0x%2.2X\033[%dm", 45, reg_val05, 40);//displaying in Magenta background 00349 00350 pc.printf("\n\n\n\r\t\033[%dmDo you want to continue with rest of the adc test. Press ",36); 00351 pc.printf("\n\n\r\t 'c' - Continue "); 00352 pc.printf("\n\n\r\t 'e' - Exit "); 00353 pc.printf("\n\n\n\r\tYour Selection : \033[%dm",32); 00354 temp = 0; 00355 while ( temp!='c' && temp!='e') { 00356 temp = pc.getc(); 00357 } 00358 if (temp == 'e') return; 00359 draw_sig_line(); 00360 00361 //***************************************************************** 00362 //****** measuring adc outputs different inputs 00363 //***************************************************************** 00364 00365 pc.printf("\033[%dm ", 31);//change text color to red 00366 pc.printf("\n\n\n\n\r\tMeasure ADC output for different inputs \n\r\t"); 00367 for ( i = 0; i<39; i++) pc.printf("\315"); 00368 pc.printf("\033[%dm ", 32);//change text color to green 00369 00370 adc_meas(&i2c,16,2); //adc measurement for 16 x 2mV 00371 adc_meas(&i2c,24,2); 00372 adc_meas(&i2c,32,2); 00373 adc_meas(&i2c,64,2); 00374 adc_meas(&i2c,97,2); 00375 adc_meas(&i2c,128,2); 00376 adc_meas(&i2c,196,2); 00377 adc_meas(&i2c,250,2); 00378 00379 pc.printf("\n\n\n\r\t\033[%dmDo you want to continue with rest of the adc test. Press ",36); 00380 pc.printf("\n\n\r\t 'c' - Continue "); 00381 pc.printf("\n\n\r\t 'e' - Exit "); 00382 pc.printf("\n\n\n\r\tYour Selection : \033[%dm",32); 00383 temp = 0; 00384 while ( temp!='c' && temp!='e') { 00385 temp = pc.getc(); 00386 } 00387 if (temp == 'e') return; 00388 draw_sig_line(); 00389 00390 //***************************************************************** 00391 //****** measuring adc outputs different Range Settings 00392 //***************************************************************** 00393 00394 pc.printf("\033[%dm ", 31);//change text color to red 00395 pc.printf("\n\n\n\n\r\tMeasure ADC output for different range settings \n\r\t"); 00396 for ( i = 0; i<47; i++) pc.printf("\315"); 00397 pc.printf("\033[%dm ", 32);//change text color to green 00398 00399 reg_val04 = i2c_read_fn(&i2c,0x04); //Bits [3:2] of 0x04 contains range settings 00400 00401 i2c_write_fn(&i2c,0x04,(reg_val04 & 0xF3)); //Range = 00 => 1mV 00402 adc_meas(&i2c,128,1); //adc measurement for 16 x 2mV 00403 00404 i2c_write_fn(&i2c,0x04,(reg_val04 | 0x0C)); //Range = 11 => 4mV 00405 adc_meas(&i2c,32,4); //adc measurement for 32 x 4mV 00406 00407 i2c_write_fn(&i2c,0x04,reg_val04); //Setting back the original value 00408 00409 pc.printf("\n\n\n\r\t\033[%dmDo you want to continue with rest of the adc test. Press ",36); 00410 pc.printf("\n\n\r\t 'c' - Continue "); 00411 pc.printf("\n\n\r\t 'e' - Exit "); 00412 pc.printf("\n\n\n\r\tYour Selection : \033[%dm",32); 00413 temp = 0; 00414 while ( temp!='c' && temp!='e') { 00415 temp = pc.getc(); 00416 } 00417 if (temp == 'e') return; 00418 draw_sig_line(); 00419 00420 //***************************************************************** 00421 //****** measuring adc outputs for negative inputs 00422 //***************************************************************** 00423 00424 pc.printf("\033[%dm ", 31);//change text color to red 00425 pc.printf("\n\n\n\n\r\tMeasure ADC output for negative inputs \n\r\t"); 00426 for ( i = 0; i<39; i++) pc.printf("\315"); 00427 pc.printf("\033[%dm ", 32);//change text color to green 00428 00429 pc.printf("\033[%dm", 34);//change text color to blue 00430 pc.printf("\n\n\n\r\tInstructions: \n\r\t"); 00431 for ( i = 0; i<13; i++) pc.printf("\304"); 00432 pc.printf("\n\n\r\t 1. Set Voc = 0. Wait for a second "); 00433 pc.printf("\n\n\r\t 2. Change the input connnection such that the input is negative "); 00434 pc.printf("\n\n\r\t 3. Increase Voc to 450mV"); 00435 pc.printf("\033[%dm ", 32);//change text color to green 00436 temp = 0; 00437 pc.printf("\n\n\n\r\t\033[%dmPress 'c' to continue: \033[%dm",36,32); 00438 while ( temp!='c') { 00439 temp = pc.getc(); 00440 } 00441 //Making sure input polarity detector outputs are correct. 00442 i2c_write_fn(&i2c,0x10,0x10); //tm_PolComp_en = 1 00443 pc.printf("\n\n\n\r\tPolarity comparitor was enabled to have correct outputs (vinB_high = 1)"); 00444 wait_ms(1); 00445 i2c_write_fn(&i2c,0x10,0x00); //tm_PolComp_en = 0 00446 pc.printf("\n\n\r\tPolarity comparitor disabled"); 00447 adc_meas(&i2c,16,2); //adc measurement for 16 x 2mV 00448 adc_meas(&i2c,128,2); 00449 adc_meas(&i2c,250,2); 00450 00451 pc.printf("\n\n\n\r\t\033[%dmDo you want to continue to ADC ACP mode test. Press ",36); 00452 pc.printf("\n\n\r\t 'c' - Continue "); 00453 pc.printf("\n\n\r\t 'e' - Exit "); 00454 pc.printf("\n\n\n\r\tYour Selection : \033[%dm",32); 00455 temp = 0; 00456 while ( temp!='c' && temp!='e') { 00457 temp = pc.getc(); 00458 } 00459 if (temp == 'e') return; 00460 draw_sig_line(); 00461 00462 //***************************************************************** 00463 //****** Verify ADC operation for ACP mode 00464 //***************************************************************** 00465 00466 pc.printf("\033[%dm ", 31);//change text color to red 00467 pc.printf("\n\n\n\n\r\tVerify ADC operation in ACP mode \n\r\t"); 00468 for ( i = 0; i<32; i++) pc.printf("\315"); 00469 pc.printf("\033[%dm ", 32);//change text color to green 00470 reg_val07 = i2c_read_fn(&i2c,0x07); //reading the initial pmos off setting 00471 i2c_write_fn(&i2c,0x07,(reg_val07 | 0x0F)); //PMOS_off = 4’hF → ACP mode. In this mode ADC operates as a comparator checking input against 250*lsb 00472 pc.printf("\n\n\r\tCSI066a switched to ACP mode by setting PMOS_off = 4'hF"); 00473 00474 pc.printf("\033[%dm", 34);//change text color to blue 00475 pc.printf("\n\n\n\r\tInstructions: \n\r\t"); 00476 for ( i = 0; i<13; i++) pc.printf("\304"); 00477 pc.printf("\n\n\r\t 1. Set Voc to 480mV (240 x 2mV)"); 00478 pc.printf("\033[%dm ", 32);//change text color to green 00479 temp = 0; 00480 pc.printf("\n\n\n\r\t\033[%dmPress 'c' to continue: \033[%dm",36,32); 00481 while ( temp!='c') { 00482 temp = pc.getc(); 00483 } 00484 pc.printf("\n\n\n\r\tPerforming hot-read on adc_comp_out (0x13[3])"); 00485 pc.printf("\033[%dm", 34);//change text color to blue 00486 pc.printf("\n\n\n\r\tInstructions: \n\r\t"); 00487 for ( i = 0; i<13; i++) pc.printf("\304"); 00488 pc.printf("\n\n\r\t 1. Monitor DATA1_clk on oscilloscope. DATA1_clk should be low in the beginning "); 00489 pc.printf("\n\n\r\t 2. Ramp Voc from 480mV --> 520mV (240lsb --> 260lsb). Stop when DATA1_CLK transitions from 0 --> 1 "); 00490 pc.printf("\n\n\r\t 3. Record Voc / 2mV. Record it as\033[%dm ACP_neg_fb_dis \033[%dm", 47, 40); //background white 00491 pc.printf("\033[%dm ", 32);//change text color to green 00492 00493 i2c_hotread_fn(&i2c,0x13,3); //Performing hot-read on [3] of 0x13 00494 00495 pc.printf("\033[%dm", 34);//change text color to blue 00496 pc.printf("\n\n\n\r\tInstructions: \n\r\t"); 00497 for ( i = 0; i<13; i++) pc.printf("\304"); 00498 pc.printf("\n\n\r\t 1. Reduce Voc to 0V. "); 00499 pc.printf("\n\n\r\t 2. Switch input connections such that input is positive"); 00500 pc.printf("\n\n\r\t 3. Set Voc to 480mV (240 x 2mV)"); 00501 pc.printf("\033[%dm ", 32);//change text color to green 00502 temp = 0; 00503 pc.printf("\n\n\n\r\t\033[%dmPress 'c' to continue: \033[%dm",36,32); 00504 while ( temp!='c') { 00505 temp = pc.getc(); 00506 } 00507 i2c.~I2C(); 00508 I2C i2c2(p9,p10); //Creating new object after hot-read 00509 i2c2.frequency((frequ/2)*1000); 00510 LPC_PINCON->PINMODE_OD0 = (LPC_PINCON->PINMODE_OD0 | 0x0003); // To make p9 & P10 open_drain 00511 i2c2.stop(); //add a stop after hot-read 00512 //Making sure input polarity detector outputs are correct. 00513 i2c_write_fn(&i2c2,0x10,0x10); //tm_PolComp_en = 1 00514 pc.printf("\n\n\n\r\tPolarity comparitor was enabled to have correct outputs (vinB_high = 1)"); 00515 wait_ms(1); 00516 i2c_write_fn(&i2c2,0x10,0x00); //tm_PolComp_en = 0 00517 pc.printf("\n\n\r\tPolarity comparitor disabled"); 00518 00519 pc.printf("\n\n\n\r\tPerforming hot-read on adc_comp_out (0x13[3])"); 00520 00521 pc.printf("\033[%dm", 34);//change text color to blue 00522 pc.printf("\n\n\n\r\tInstructions: \n\r\t"); 00523 for ( i = 0; i<13; i++) pc.printf("\304"); 00524 pc.printf("\n\n\r\t 1. Monitor DATA1_CLk on the oscillscope "); 00525 pc.printf("\n\n\r\t 2. DATA1_CLk should be low initially"); 00526 pc.printf("\n\n\r\t 3. Ramp Voc from 480mV --> 520mV (240lsb --> 260lsb). Stop when DATA1_CLK transitions from 0 --> 1 "); 00527 pc.printf("\n\n\r\t 4. Record Voc / 2mV. Record it as\033[%dm ACP_pos_fb_dis \033[%dm", 47, 40); //yellow background 00528 pc.printf("\033[%dm ", 32);//change text color to green 00529 00530 i2c_hotread_fn(&i2c2,0x13,3); //Performing hot-read on [3] of 0x13 00531 00532 i2c2.~I2C(); 00533 I2C i2c3(p9,p10); //Creating new object after hot-read 00534 i2c3.frequency((frequ/2)*1000); 00535 LPC_PINCON->PINMODE_OD0 = (LPC_PINCON->PINMODE_OD0 | 0x0003); // To make p9 & P10 open_drain 00536 i2c3.stop(); //add a stop after hot-read 00537 i2c_write_fn(&i2c3,0x07,reg_val07); //Restoring Reg 0x07 value 00538 pc.printf("\n\n\n\r\t\033[%dmADC Test finally done!.. Phew\033[%dm", 45, 40);//displaying in Magenta background 00539 00540 } 00541
Generated on Wed Jul 13 2022 07:54:48 by
