Ashwath M Pavithran
/
csi066_rev0p3_harald_prog
Publishing for sharing with Harald
adc_test.cpp@4:1c48c9fa44fc, 2020-05-22 (annotated)
- Committer:
- CactusSemi
- Date:
- Fri May 22 19:19:45 2020 +0000
- Revision:
- 4:1c48c9fa44fc
Publishing for sharing with Harald
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CactusSemi | 4:1c48c9fa44fc | 1 | #include "mbed.h" |
CactusSemi | 4:1c48c9fa44fc | 2 | |
CactusSemi | 4:1c48c9fa44fc | 3 | extern Serial pc; |
CactusSemi | 4:1c48c9fa44fc | 4 | extern int frequ; //unit kHz |
CactusSemi | 4:1c48c9fa44fc | 5 | extern char dev_addr; //fixed |
CactusSemi | 4:1c48c9fa44fc | 6 | |
CactusSemi | 4:1c48c9fa44fc | 7 | char get_half_byte(int *); //defined in I2C_read.cpp |
CactusSemi | 4:1c48c9fa44fc | 8 | char get_byte(int *); //defined in EasyFuse_Prog.cpp |
CactusSemi | 4:1c48c9fa44fc | 9 | void i2c_write_fn(I2C *, char , char );//defined in Easy Fuse Prog |
CactusSemi | 4:1c48c9fa44fc | 10 | char i2c_read_fn(I2C *, char ); //defined in Easy Fuse Prog |
CactusSemi | 4:1c48c9fa44fc | 11 | void read_bit(int ); // defined in I2C_hot_read |
CactusSemi | 4:1c48c9fa44fc | 12 | |
CactusSemi | 4:1c48c9fa44fc | 13 | void i2c_hotread_fn(I2C *i2c_obj, char ptr, int bit_position) { |
CactusSemi | 4:1c48c9fa44fc | 14 | int flag1; |
CactusSemi | 4:1c48c9fa44fc | 15 | char temp; |
CactusSemi | 4:1c48c9fa44fc | 16 | wait_us(10); |
CactusSemi | 4:1c48c9fa44fc | 17 | (*i2c_obj).start(); |
CactusSemi | 4:1c48c9fa44fc | 18 | flag1 = (*i2c_obj).write(dev_addr); |
CactusSemi | 4:1c48c9fa44fc | 19 | if (flag1 != 1) pc.printf("\n\n\n\r\tNo Ack for dev addr :("); |
CactusSemi | 4:1c48c9fa44fc | 20 | flag1 = (*i2c_obj).write(ptr); |
CactusSemi | 4:1c48c9fa44fc | 21 | if (flag1 != 1) pc.printf("\n\n\r\tNo Ack reg pointer :("); |
CactusSemi | 4:1c48c9fa44fc | 22 | (*i2c_obj).stop(); |
CactusSemi | 4:1c48c9fa44fc | 23 | wait_us(300); |
CactusSemi | 4:1c48c9fa44fc | 24 | pc.printf("\n\n\n\r\tPress 's' to start hot read : "); |
CactusSemi | 4:1c48c9fa44fc | 25 | while(temp!='s') { |
CactusSemi | 4:1c48c9fa44fc | 26 | temp = pc.getc(); |
CactusSemi | 4:1c48c9fa44fc | 27 | } |
CactusSemi | 4:1c48c9fa44fc | 28 | //(*i2c_obj).start(); |
CactusSemi | 4:1c48c9fa44fc | 29 | //flag1 = (*i2c_obj).write(dev_addr | 0x01); //lsb 1 for read |
CactusSemi | 4:1c48c9fa44fc | 30 | //if (flag1 != 1) pc.printf("\n\n\r\tNo Ack for dev addr :("); |
CactusSemi | 4:1c48c9fa44fc | 31 | read_bit(bit_position); // hot-read function |
CactusSemi | 4:1c48c9fa44fc | 32 | (*i2c_obj).stop(); |
CactusSemi | 4:1c48c9fa44fc | 33 | } |
CactusSemi | 4:1c48c9fa44fc | 34 | |
CactusSemi | 4:1c48c9fa44fc | 35 | void draw_sig_line() { |
CactusSemi | 4:1c48c9fa44fc | 36 | pc.printf("\033[%dm ", 33);//change text color to yellow |
CactusSemi | 4:1c48c9fa44fc | 37 | pc.printf("\n\n\n\n\r \304"); |
CactusSemi | 4:1c48c9fa44fc | 38 | for ( int i = 0; i<80; i++) pc.printf("\304"); |
CactusSemi | 4:1c48c9fa44fc | 39 | pc.printf("\033[%dm ", 32);//change text color to green |
CactusSemi | 4:1c48c9fa44fc | 40 | pc.printf("\n\n\r"); |
CactusSemi | 4:1c48c9fa44fc | 41 | } |
CactusSemi | 4:1c48c9fa44fc | 42 | |
CactusSemi | 4:1c48c9fa44fc | 43 | void get_new_val (char *reg_val06) { |
CactusSemi | 4:1c48c9fa44fc | 44 | int flag1 = 0; |
CactusSemi | 4:1c48c9fa44fc | 45 | 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); |
CactusSemi | 4:1c48c9fa44fc | 46 | while (!flag1) { |
CactusSemi | 4:1c48c9fa44fc | 47 | pc.printf("\n\n\r\tEnter new Range trim in hex (00 to ff): 0x"); |
CactusSemi | 4:1c48c9fa44fc | 48 | *reg_val06 = get_byte(&flag1); |
CactusSemi | 4:1c48c9fa44fc | 49 | if ( *reg_val06 > 0x1F ) flag1 = 0; //Range trim is only 5 bits |
CactusSemi | 4:1c48c9fa44fc | 50 | if (flag1 == 0) pc.printf(" \033[%dm Invalid Chracter!! No worries, let us try again \033[%dm",41,40); |
CactusSemi | 4:1c48c9fa44fc | 51 | } |
CactusSemi | 4:1c48c9fa44fc | 52 | pc.printf("\033[%dm",32); |
CactusSemi | 4:1c48c9fa44fc | 53 | } |
CactusSemi | 4:1c48c9fa44fc | 54 | |
CactusSemi | 4:1c48c9fa44fc | 55 | void adc_meas (I2C *i2c_obj, char count, char lsb) { |
CactusSemi | 4:1c48c9fa44fc | 56 | char adc_op; |
CactusSemi | 4:1c48c9fa44fc | 57 | int voc; |
CactusSemi | 4:1c48c9fa44fc | 58 | char temp; |
CactusSemi | 4:1c48c9fa44fc | 59 | |
CactusSemi | 4:1c48c9fa44fc | 60 | voc = lsb * count; |
CactusSemi | 4:1c48c9fa44fc | 61 | |
CactusSemi | 4:1c48c9fa44fc | 62 | temp = 0; |
CactusSemi | 4:1c48c9fa44fc | 63 | 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); |
CactusSemi | 4:1c48c9fa44fc | 64 | while ( temp!='c') { |
CactusSemi | 4:1c48c9fa44fc | 65 | temp = pc.getc(); |
CactusSemi | 4:1c48c9fa44fc | 66 | } |
CactusSemi | 4:1c48c9fa44fc | 67 | i2c_write_fn(i2c_obj,0x14,count - 2); //Writing starting value in ADC |
CactusSemi | 4:1c48c9fa44fc | 68 | wait_ms(5); |
CactusSemi | 4:1c48c9fa44fc | 69 | i2c_write_fn(i2c_obj,0x0D,0x03); //tm_adc_en = tm_adc_go = 1; start conversion |
CactusSemi | 4:1c48c9fa44fc | 70 | wait_ms(20); //to make sure conversion is complete |
CactusSemi | 4:1c48c9fa44fc | 71 | adc_op = i2c_read_fn(i2c_obj,0x14); |
CactusSemi | 4:1c48c9fa44fc | 72 | 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 |
CactusSemi | 4:1c48c9fa44fc | 73 | return; |
CactusSemi | 4:1c48c9fa44fc | 74 | } |
CactusSemi | 4:1c48c9fa44fc | 75 | |
CactusSemi | 4:1c48c9fa44fc | 76 | |
CactusSemi | 4:1c48c9fa44fc | 77 | void adc_test() { |
CactusSemi | 4:1c48c9fa44fc | 78 | |
CactusSemi | 4:1c48c9fa44fc | 79 | I2C i2c(p9,p10); |
CactusSemi | 4:1c48c9fa44fc | 80 | char temp; |
CactusSemi | 4:1c48c9fa44fc | 81 | char reg_val06; |
CactusSemi | 4:1c48c9fa44fc | 82 | char reg_val06_max = 0x1F; //for debug, change to 0x1F |
CactusSemi | 4:1c48c9fa44fc | 83 | char reg_val05; |
CactusSemi | 4:1c48c9fa44fc | 84 | char reg_val05_strt; |
CactusSemi | 4:1c48c9fa44fc | 85 | char reg_val04; |
CactusSemi | 4:1c48c9fa44fc | 86 | char reg_val07; |
CactusSemi | 4:1c48c9fa44fc | 87 | char adc_op31[32]; |
CactusSemi | 4:1c48c9fa44fc | 88 | char adc_op223[32]; |
CactusSemi | 4:1c48c9fa44fc | 89 | char d_adc_op192[32] = {0x00}; |
CactusSemi | 4:1c48c9fa44fc | 90 | char adc_op8 = 0x07; |
CactusSemi | 4:1c48c9fa44fc | 91 | char adc_op8_old; |
CactusSemi | 4:1c48c9fa44fc | 92 | char adc_op8_disp[32]; |
CactusSemi | 4:1c48c9fa44fc | 93 | char d_adc_op = 0x00; |
CactusSemi | 4:1c48c9fa44fc | 94 | char d_adc_op_old = 0x00; |
CactusSemi | 4:1c48c9fa44fc | 95 | int i = 0; |
CactusSemi | 4:1c48c9fa44fc | 96 | int x = 0; |
CactusSemi | 4:1c48c9fa44fc | 97 | |
CactusSemi | 4:1c48c9fa44fc | 98 | i2c.frequency((frequ/2)*1000); |
CactusSemi | 4:1c48c9fa44fc | 99 | LPC_PINCON->PINMODE_OD0 = (LPC_PINCON->PINMODE_OD0 | 0x0003); // To make p9 & P10 open_drain |
CactusSemi | 4:1c48c9fa44fc | 100 | i2c.stop(); //add a stop after hot-read |
CactusSemi | 4:1c48c9fa44fc | 101 | |
CactusSemi | 4:1c48c9fa44fc | 102 | pc.printf("\033[%dm ", 31);//change text color to red |
CactusSemi | 4:1c48c9fa44fc | 103 | pc.printf("\n\n\n\r\tStarting adc test \n\r\t"); |
CactusSemi | 4:1c48c9fa44fc | 104 | for ( i = 0; i<18; i++) pc.printf("\334"); |
CactusSemi | 4:1c48c9fa44fc | 105 | pc.printf("\n\n\r\033[%dm", 32);//change text color to blue |
CactusSemi | 4:1c48c9fa44fc | 106 | |
CactusSemi | 4:1c48c9fa44fc | 107 | i2c_write_fn(&i2c,0x17,0x03); //dmux op = adc_conversion. DATA2_CLK will be high when adc conversion is ongoing |
CactusSemi | 4:1c48c9fa44fc | 108 | |
CactusSemi | 4:1c48c9fa44fc | 109 | pc.printf("\033[%dm", 34);//change text color to blue |
CactusSemi | 4:1c48c9fa44fc | 110 | pc.printf("\n\n\n\r\tConditions: \n\r\t"); |
CactusSemi | 4:1c48c9fa44fc | 111 | for ( i = 0; i<13; i++) pc.printf("\304"); |
CactusSemi | 4:1c48c9fa44fc | 112 | pc.printf("\n\n\r\t 1. ASIC in test-mode "); |
CactusSemi | 4:1c48c9fa44fc | 113 | pc.printf("\n\n\r\t 2. Short input Rin (5ohms) resistor "); |
CactusSemi | 4:1c48c9fa44fc | 114 | pc.printf("\n\n\r\t 3. Please Monitor DATA2_CLK on oscilloscope. DATA2_CLK = 'adc_conversion'"); |
CactusSemi | 4:1c48c9fa44fc | 115 | pc.printf("\n\n\r\t 4. Positive input polarity"); |
CactusSemi | 4:1c48c9fa44fc | 116 | pc.printf("\033[%dm ", 32);//change text color to green |
CactusSemi | 4:1c48c9fa44fc | 117 | temp = 0; |
CactusSemi | 4:1c48c9fa44fc | 118 | pc.printf("\n\n\n\r\t\033[%dmPress 'c' to continue: \033[%dm",36,32); |
CactusSemi | 4:1c48c9fa44fc | 119 | while ( temp!='c') { |
CactusSemi | 4:1c48c9fa44fc | 120 | temp = pc.getc(); |
CactusSemi | 4:1c48c9fa44fc | 121 | } |
CactusSemi | 4:1c48c9fa44fc | 122 | i2c_write_fn(&i2c,0x0F,0x00); //Disabling Flyback |
CactusSemi | 4:1c48c9fa44fc | 123 | |
CactusSemi | 4:1c48c9fa44fc | 124 | //reg_val06 = i2c_read_fn(&i2c,0x06); //reading the initial range trim |
CactusSemi | 4:1c48c9fa44fc | 125 | i2c_write_fn(&i2c,0x0D,0x01); //tm_adc_en = 1 |
CactusSemi | 4:1c48c9fa44fc | 126 | |
CactusSemi | 4:1c48c9fa44fc | 127 | draw_sig_line(); |
CactusSemi | 4:1c48c9fa44fc | 128 | |
CactusSemi | 4:1c48c9fa44fc | 129 | //***************************************************************** |
CactusSemi | 4:1c48c9fa44fc | 130 | //****** ADC Range trim test |
CactusSemi | 4:1c48c9fa44fc | 131 | //***************************************************************** |
CactusSemi | 4:1c48c9fa44fc | 132 | |
CactusSemi | 4:1c48c9fa44fc | 133 | pc.printf("\033[%dm ", 31);//change text color to red |
CactusSemi | 4:1c48c9fa44fc | 134 | pc.printf("\n\n\n\r\tStarting Range trim \n\r\t"); |
CactusSemi | 4:1c48c9fa44fc | 135 | for ( i = 0; i<19; i++) pc.printf("\315"); |
CactusSemi | 4:1c48c9fa44fc | 136 | pc.printf("\033[%dm ", 32);//change text color to green |
CactusSemi | 4:1c48c9fa44fc | 137 | |
CactusSemi | 4:1c48c9fa44fc | 138 | temp = 0; |
CactusSemi | 4:1c48c9fa44fc | 139 | pc.printf("\n\n\n\r\t\033[%dmSet Voc = 63mV (2mV x 31.5). Press 'c' to continue: \033[%dm",36,32); |
CactusSemi | 4:1c48c9fa44fc | 140 | while ( temp!='c') { |
CactusSemi | 4:1c48c9fa44fc | 141 | temp = pc.getc(); |
CactusSemi | 4:1c48c9fa44fc | 142 | } |
CactusSemi | 4:1c48c9fa44fc | 143 | //Making sure input polarity detector outputs are correct. |
CactusSemi | 4:1c48c9fa44fc | 144 | i2c_write_fn(&i2c,0x10,0x10); //tm_PolComp_en = 1 |
CactusSemi | 4:1c48c9fa44fc | 145 | wait_ms(1); |
CactusSemi | 4:1c48c9fa44fc | 146 | i2c_write_fn(&i2c,0x10,0x00); //tm_PolComp_en = 0 |
CactusSemi | 4:1c48c9fa44fc | 147 | pc.printf("\n\n\r\tFinding ADC outputs for all adc range with input = 63mV"); |
CactusSemi | 4:1c48c9fa44fc | 148 | //Finding ADC outputs for all adc range with input = 63mV |
CactusSemi | 4:1c48c9fa44fc | 149 | |
CactusSemi | 4:1c48c9fa44fc | 150 | for ( reg_val06 = 0x00; reg_val06 <= reg_val06_max; reg_val06 = (reg_val06 + 1)) { |
CactusSemi | 4:1c48c9fa44fc | 151 | |
CactusSemi | 4:1c48c9fa44fc | 152 | i2c_write_fn(&i2c,0x06,reg_val06); |
CactusSemi | 4:1c48c9fa44fc | 153 | |
CactusSemi | 4:1c48c9fa44fc | 154 | //Write initial value into ADC register |
CactusSemi | 4:1c48c9fa44fc | 155 | if ( reg_val06 == 0x00 ) i2c_write_fn(&i2c,0x14,0x64); //starting value = 100. ADC reading will reduce as range trim increases |
CactusSemi | 4:1c48c9fa44fc | 156 | else i2c_write_fn(&i2c,0x14,adc_op31[(reg_val06 - 1)]); //starting with previous measurement value |
CactusSemi | 4:1c48c9fa44fc | 157 | |
CactusSemi | 4:1c48c9fa44fc | 158 | wait_ms(5); |
CactusSemi | 4:1c48c9fa44fc | 159 | i2c_write_fn(&i2c,0x0D,0x03); //tm_adc_en = tm_adc_go = 1; start conversion |
CactusSemi | 4:1c48c9fa44fc | 160 | wait_ms(20); //to make sure conversion is complete |
CactusSemi | 4:1c48c9fa44fc | 161 | adc_op31[reg_val06] = i2c_read_fn(&i2c,0x14); |
CactusSemi | 4:1c48c9fa44fc | 162 | pc.printf("."); |
CactusSemi | 4:1c48c9fa44fc | 163 | } |
CactusSemi | 4:1c48c9fa44fc | 164 | |
CactusSemi | 4:1c48c9fa44fc | 165 | temp = 0; |
CactusSemi | 4:1c48c9fa44fc | 166 | pc.printf("\n\n\n\r\t\033[%dmSet Voc = 447mV (2mV x 223.5). Press 'c' to continue: \033[%dm",36,32); |
CactusSemi | 4:1c48c9fa44fc | 167 | while ( temp!='c') { |
CactusSemi | 4:1c48c9fa44fc | 168 | temp = pc.getc(); |
CactusSemi | 4:1c48c9fa44fc | 169 | } |
CactusSemi | 4:1c48c9fa44fc | 170 | pc.printf("\n\n\r\tFinding ADC outputs for all adc range with input = 447mV"); |
CactusSemi | 4:1c48c9fa44fc | 171 | for ( reg_val06 = 0x00; reg_val06 <= reg_val06_max; reg_val06 = (reg_val06 + 1)) { |
CactusSemi | 4:1c48c9fa44fc | 172 | |
CactusSemi | 4:1c48c9fa44fc | 173 | i2c_write_fn(&i2c,0x06,reg_val06); |
CactusSemi | 4:1c48c9fa44fc | 174 | |
CactusSemi | 4:1c48c9fa44fc | 175 | //Write initial value into ADC register |
CactusSemi | 4:1c48c9fa44fc | 176 | if ( reg_val06 == 0x00 ) i2c_write_fn(&i2c,0x14,0x64); //starting value = 100. ADC reading will reduce as range trim increases |
CactusSemi | 4:1c48c9fa44fc | 177 | else i2c_write_fn(&i2c,0x14,adc_op223[(reg_val06 - 1)]); //starting with previous measurement value |
CactusSemi | 4:1c48c9fa44fc | 178 | |
CactusSemi | 4:1c48c9fa44fc | 179 | wait_ms(5); |
CactusSemi | 4:1c48c9fa44fc | 180 | i2c_write_fn(&i2c,0x0D,0x03); //tm_adc_en = tm_adc_go = 1; start conversion |
CactusSemi | 4:1c48c9fa44fc | 181 | wait_ms(20); //to make sure conversion is complete |
CactusSemi | 4:1c48c9fa44fc | 182 | adc_op223[reg_val06] = i2c_read_fn(&i2c,0x14); |
CactusSemi | 4:1c48c9fa44fc | 183 | d_adc_op192[reg_val06] = adc_op223[reg_val06] - adc_op31[reg_val06]; |
CactusSemi | 4:1c48c9fa44fc | 184 | pc.printf("."); |
CactusSemi | 4:1c48c9fa44fc | 185 | } |
CactusSemi | 4:1c48c9fa44fc | 186 | //Printing results |
CactusSemi | 4:1c48c9fa44fc | 187 | pc.printf("\n\n\n\r\t\332"); |
CactusSemi | 4:1c48c9fa44fc | 188 | for ( i = 0; i < 4; i++ ) { |
CactusSemi | 4:1c48c9fa44fc | 189 | for ( x = 0; x < 23; x++ ) pc.printf("\304"); |
CactusSemi | 4:1c48c9fa44fc | 190 | pc.printf("\302"); |
CactusSemi | 4:1c48c9fa44fc | 191 | } |
CactusSemi | 4:1c48c9fa44fc | 192 | |
CactusSemi | 4:1c48c9fa44fc | 193 | 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); |
CactusSemi | 4:1c48c9fa44fc | 194 | |
CactusSemi | 4:1c48c9fa44fc | 195 | //d_adc_op192[3] = 0xC0; //added for debug. Remove! |
CactusSemi | 4:1c48c9fa44fc | 196 | |
CactusSemi | 4:1c48c9fa44fc | 197 | for ( reg_val06 = 0x00; reg_val06 <= reg_val06_max; reg_val06 = (reg_val06 + 1)) { |
CactusSemi | 4:1c48c9fa44fc | 198 | |
CactusSemi | 4:1c48c9fa44fc | 199 | pc.printf("\n\r\t\303"); |
CactusSemi | 4:1c48c9fa44fc | 200 | for ( i = 0; i < 4; i++ ) { |
CactusSemi | 4:1c48c9fa44fc | 201 | for ( x = 0; x < 23; x++ ) pc.printf("\304"); |
CactusSemi | 4:1c48c9fa44fc | 202 | if ( i < 3) pc.printf("\305"); |
CactusSemi | 4:1c48c9fa44fc | 203 | else pc.printf("\264"); |
CactusSemi | 4:1c48c9fa44fc | 204 | } |
CactusSemi | 4:1c48c9fa44fc | 205 | if ( (d_adc_op192[reg_val06] > 0xBE) && (d_adc_op192[reg_val06] < 0xC2)) |
CactusSemi | 4:1c48c9fa44fc | 206 | 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); |
CactusSemi | 4:1c48c9fa44fc | 207 | else |
CactusSemi | 4:1c48c9fa44fc | 208 | 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]); |
CactusSemi | 4:1c48c9fa44fc | 209 | } |
CactusSemi | 4:1c48c9fa44fc | 210 | |
CactusSemi | 4:1c48c9fa44fc | 211 | pc.printf("\n\r\t\300"); |
CactusSemi | 4:1c48c9fa44fc | 212 | for ( i = 0; i < 4; i++ ) { |
CactusSemi | 4:1c48c9fa44fc | 213 | for ( x = 0; x < 23; x++ ) pc.printf("\304"); |
CactusSemi | 4:1c48c9fa44fc | 214 | if ( i < 3) pc.printf("\301"); |
CactusSemi | 4:1c48c9fa44fc | 215 | else pc.printf("\331"); |
CactusSemi | 4:1c48c9fa44fc | 216 | } |
CactusSemi | 4:1c48c9fa44fc | 217 | |
CactusSemi | 4:1c48c9fa44fc | 218 | get_new_val(®_val06); |
CactusSemi | 4:1c48c9fa44fc | 219 | i2c_write_fn(&i2c,0x06,reg_val06); |
CactusSemi | 4:1c48c9fa44fc | 220 | |
CactusSemi | 4:1c48c9fa44fc | 221 | |
CactusSemi | 4:1c48c9fa44fc | 222 | pc.printf("\n\n\n\r\t\033[%dmFinal Range trim = 0x%2.2X\033[%dm ", 45, reg_val06, 40); |
CactusSemi | 4:1c48c9fa44fc | 223 | |
CactusSemi | 4:1c48c9fa44fc | 224 | pc.printf("\n\n\n\r\t\033[%dmDo you want to continue with offset trim. Press ",36); |
CactusSemi | 4:1c48c9fa44fc | 225 | pc.printf("\n\n\r\t 'c' - Continue "); |
CactusSemi | 4:1c48c9fa44fc | 226 | pc.printf("\n\n\r\t 'e' - Exit "); |
CactusSemi | 4:1c48c9fa44fc | 227 | pc.printf("\n\n\n\r\tYour Selection : \033[%dm",32); |
CactusSemi | 4:1c48c9fa44fc | 228 | temp = 0; |
CactusSemi | 4:1c48c9fa44fc | 229 | while ( temp!='c' && temp!='e') { |
CactusSemi | 4:1c48c9fa44fc | 230 | temp = pc.getc(); |
CactusSemi | 4:1c48c9fa44fc | 231 | } |
CactusSemi | 4:1c48c9fa44fc | 232 | if (temp == 'e') return; |
CactusSemi | 4:1c48c9fa44fc | 233 | |
CactusSemi | 4:1c48c9fa44fc | 234 | //***************************************************************** |
CactusSemi | 4:1c48c9fa44fc | 235 | //****** ADC Offset trim test |
CactusSemi | 4:1c48c9fa44fc | 236 | //***************************************************************** |
CactusSemi | 4:1c48c9fa44fc | 237 | |
CactusSemi | 4:1c48c9fa44fc | 238 | |
CactusSemi | 4:1c48c9fa44fc | 239 | draw_sig_line(); |
CactusSemi | 4:1c48c9fa44fc | 240 | |
CactusSemi | 4:1c48c9fa44fc | 241 | pc.printf("\033[%dm ", 31);//change text color to red |
CactusSemi | 4:1c48c9fa44fc | 242 | pc.printf("\n\n\n\n\r\tStarting Offset trim \n\r\t"); |
CactusSemi | 4:1c48c9fa44fc | 243 | for ( i = 0; i<19; i++) pc.printf("\315"); |
CactusSemi | 4:1c48c9fa44fc | 244 | pc.printf("\033[%dm ", 32);//change text color to green |
CactusSemi | 4:1c48c9fa44fc | 245 | |
CactusSemi | 4:1c48c9fa44fc | 246 | temp = 0; |
CactusSemi | 4:1c48c9fa44fc | 247 | pc.printf("\n\n\n\r\t\033[%dmSet Voc = 16mV (2mV x 8). Press 'c' to continue: \033[%dm",36,32); |
CactusSemi | 4:1c48c9fa44fc | 248 | while ( temp!='c') { |
CactusSemi | 4:1c48c9fa44fc | 249 | temp = pc.getc(); |
CactusSemi | 4:1c48c9fa44fc | 250 | } |
CactusSemi | 4:1c48c9fa44fc | 251 | // determine trim direction |
CactusSemi | 4:1c48c9fa44fc | 252 | |
CactusSemi | 4:1c48c9fa44fc | 253 | i2c_write_fn(&i2c,0x14,adc_op8); //Writing starting value in ADC |
CactusSemi | 4:1c48c9fa44fc | 254 | pc.printf("\n\n\r\tAbout to start ADC conversion. 0 -> 1 -> 0 transition should be seen on DATA2_CLK"); |
CactusSemi | 4:1c48c9fa44fc | 255 | wait_ms(5); |
CactusSemi | 4:1c48c9fa44fc | 256 | i2c_write_fn(&i2c,0x0D,0x03); //tm_adc_en = tm_adc_go = 1; start conversion |
CactusSemi | 4:1c48c9fa44fc | 257 | wait_ms(20); //to make sure conversion is complete |
CactusSemi | 4:1c48c9fa44fc | 258 | adc_op8 = i2c_read_fn(&i2c,0x14); |
CactusSemi | 4:1c48c9fa44fc | 259 | pc.printf("\n\n\r\tadc_op8 = 0x%2.2X ",adc_op8); |
CactusSemi | 4:1c48c9fa44fc | 260 | |
CactusSemi | 4:1c48c9fa44fc | 261 | temp = 0; |
CactusSemi | 4:1c48c9fa44fc | 262 | if (adc_op8 == 0x08) { |
CactusSemi | 4:1c48c9fa44fc | 263 | temp = 1; // no trimming procedure |
CactusSemi | 4:1c48c9fa44fc | 264 | pc.printf("\n\n\r\tNo Trimming Required. Woohoo"); |
CactusSemi | 4:1c48c9fa44fc | 265 | reg_val05 = i2c_read_fn(&i2c,0x05); |
CactusSemi | 4:1c48c9fa44fc | 266 | adc_op8_disp[reg_val05] = adc_op8; // for displaying |
CactusSemi | 4:1c48c9fa44fc | 267 | } |
CactusSemi | 4:1c48c9fa44fc | 268 | |
CactusSemi | 4:1c48c9fa44fc | 269 | |
CactusSemi | 4:1c48c9fa44fc | 270 | adc_op8_old = adc_op8; //storing previous value in case the trim loop is not entered |
CactusSemi | 4:1c48c9fa44fc | 271 | |
CactusSemi | 4:1c48c9fa44fc | 272 | |
CactusSemi | 4:1c48c9fa44fc | 273 | if (adc_op8_old < 0x08) { |
CactusSemi | 4:1c48c9fa44fc | 274 | pc.printf("\n\n\r\tadc_op08 < 0x08; need to perform positive trim"); |
CactusSemi | 4:1c48c9fa44fc | 275 | reg_val05 = 0x10; |
CactusSemi | 4:1c48c9fa44fc | 276 | adc_op8 = 0x10;//decimal 16. Set for proper function of the trim procedure |
CactusSemi | 4:1c48c9fa44fc | 277 | } |
CactusSemi | 4:1c48c9fa44fc | 278 | |
CactusSemi | 4:1c48c9fa44fc | 279 | if (adc_op8_old > 0x08) { |
CactusSemi | 4:1c48c9fa44fc | 280 | pc.printf("\n\n\r\tadc_op08 > 0x08; need to perform negative trim"); |
CactusSemi | 4:1c48c9fa44fc | 281 | reg_val05 = 0x00; |
CactusSemi | 4:1c48c9fa44fc | 282 | //adc_op8 = 0x00; |
CactusSemi | 4:1c48c9fa44fc | 283 | } |
CactusSemi | 4:1c48c9fa44fc | 284 | |
CactusSemi | 4:1c48c9fa44fc | 285 | reg_val05_strt = reg_val05; //storing the starting value |
CactusSemi | 4:1c48c9fa44fc | 286 | |
CactusSemi | 4:1c48c9fa44fc | 287 | //Start trim |
CactusSemi | 4:1c48c9fa44fc | 288 | |
CactusSemi | 4:1c48c9fa44fc | 289 | while (temp != 1) { |
CactusSemi | 4:1c48c9fa44fc | 290 | i2c_write_fn(&i2c,0x05,reg_val05); //programming offset trim |
CactusSemi | 4:1c48c9fa44fc | 291 | adc_op8_old = adc_op8; //storing previous value |
CactusSemi | 4:1c48c9fa44fc | 292 | i2c_write_fn(&i2c,0x14,adc_op8); //Writing starting value in ADC |
CactusSemi | 4:1c48c9fa44fc | 293 | wait_ms(5); |
CactusSemi | 4:1c48c9fa44fc | 294 | i2c_write_fn(&i2c,0x0D,0x03); //tm_adc_en = tm_adc_go = 1; start conversion |
CactusSemi | 4:1c48c9fa44fc | 295 | wait_ms(20); //to make sure conversion is complete |
CactusSemi | 4:1c48c9fa44fc | 296 | adc_op8 = i2c_read_fn(&i2c,0x14); |
CactusSemi | 4:1c48c9fa44fc | 297 | adc_op8_disp[reg_val05] = adc_op8; // for displaying |
CactusSemi | 4:1c48c9fa44fc | 298 | |
CactusSemi | 4:1c48c9fa44fc | 299 | if ((adc_op8 == 0x08) || ((adc_op8 > 0x08) && (adc_op8_old < 0x08)) || ((adc_op8 < 0x08) && (adc_op8_old > 0x08))) { |
CactusSemi | 4:1c48c9fa44fc | 300 | // pc.printf("\n\n\r\tI'm exiting."); |
CactusSemi | 4:1c48c9fa44fc | 301 | // 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); |
CactusSemi | 4:1c48c9fa44fc | 302 | break; // exit loop |
CactusSemi | 4:1c48c9fa44fc | 303 | } |
CactusSemi | 4:1c48c9fa44fc | 304 | if ((reg_val05 == 0x0F) || (reg_val05 == 0x1F)) { |
CactusSemi | 4:1c48c9fa44fc | 305 | pc.printf("\n\n\r\tTest Failed."); |
CactusSemi | 4:1c48c9fa44fc | 306 | break; // exit loop |
CactusSemi | 4:1c48c9fa44fc | 307 | } |
CactusSemi | 4:1c48c9fa44fc | 308 | reg_val05 = reg_val05 + 0x01; |
CactusSemi | 4:1c48c9fa44fc | 309 | // 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); |
CactusSemi | 4:1c48c9fa44fc | 310 | |
CactusSemi | 4:1c48c9fa44fc | 311 | } |
CactusSemi | 4:1c48c9fa44fc | 312 | //Printing Result table |
CactusSemi | 4:1c48c9fa44fc | 313 | |
CactusSemi | 4:1c48c9fa44fc | 314 | pc.printf("\n\n\n\r\t\t\332"); |
CactusSemi | 4:1c48c9fa44fc | 315 | for ( i = 0; i < 2; i++ ) { |
CactusSemi | 4:1c48c9fa44fc | 316 | for ( x = 0; x < 23; x++ ) pc.printf("\304"); |
CactusSemi | 4:1c48c9fa44fc | 317 | pc.printf("\302"); |
CactusSemi | 4:1c48c9fa44fc | 318 | } |
CactusSemi | 4:1c48c9fa44fc | 319 | 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); |
CactusSemi | 4:1c48c9fa44fc | 320 | for ( temp = reg_val05_strt; temp <= reg_val05; temp = (temp + 1) ) { |
CactusSemi | 4:1c48c9fa44fc | 321 | |
CactusSemi | 4:1c48c9fa44fc | 322 | pc.printf("\n\r\t\t\303"); |
CactusSemi | 4:1c48c9fa44fc | 323 | for ( i = 0; i < 2; i++ ) { |
CactusSemi | 4:1c48c9fa44fc | 324 | for ( x = 0; x < 23; x++ ) pc.printf("\304"); |
CactusSemi | 4:1c48c9fa44fc | 325 | if ( i < 1) pc.printf("\305"); |
CactusSemi | 4:1c48c9fa44fc | 326 | else pc.printf("\264"); |
CactusSemi | 4:1c48c9fa44fc | 327 | } |
CactusSemi | 4:1c48c9fa44fc | 328 | 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]); |
CactusSemi | 4:1c48c9fa44fc | 329 | } |
CactusSemi | 4:1c48c9fa44fc | 330 | |
CactusSemi | 4:1c48c9fa44fc | 331 | pc.printf("\n\r\t\t\300"); |
CactusSemi | 4:1c48c9fa44fc | 332 | for ( i = 0; i < 2; i++ ) { |
CactusSemi | 4:1c48c9fa44fc | 333 | for ( x = 0; x < 23; x++ ) pc.printf("\304"); |
CactusSemi | 4:1c48c9fa44fc | 334 | if ( i < 1) pc.printf("\301"); |
CactusSemi | 4:1c48c9fa44fc | 335 | else pc.printf("\331"); |
CactusSemi | 4:1c48c9fa44fc | 336 | } |
CactusSemi | 4:1c48c9fa44fc | 337 | |
CactusSemi | 4:1c48c9fa44fc | 338 | if (adc_op8 > 0x08) d_adc_op = adc_op8 - 0x08; |
CactusSemi | 4:1c48c9fa44fc | 339 | else d_adc_op = 0x08 - adc_op8; |
CactusSemi | 4:1c48c9fa44fc | 340 | |
CactusSemi | 4:1c48c9fa44fc | 341 | if (adc_op8_old > 0x08) d_adc_op_old = adc_op8_old - 0x08; |
CactusSemi | 4:1c48c9fa44fc | 342 | else d_adc_op_old = 0x08 - adc_op8_old; |
CactusSemi | 4:1c48c9fa44fc | 343 | |
CactusSemi | 4:1c48c9fa44fc | 344 | if (d_adc_op > d_adc_op_old) { |
CactusSemi | 4:1c48c9fa44fc | 345 | reg_val05 = reg_val05 - 0x01; |
CactusSemi | 4:1c48c9fa44fc | 346 | i2c_write_fn(&i2c,0x05,reg_val05); //programming offset trim |
CactusSemi | 4:1c48c9fa44fc | 347 | } |
CactusSemi | 4:1c48c9fa44fc | 348 | pc.printf("\n\n\n\r\t\033[%dmFinal Offset trim = 0x%2.2X\033[%dm", 45, reg_val05, 40);//displaying in Magenta background |
CactusSemi | 4:1c48c9fa44fc | 349 | |
CactusSemi | 4:1c48c9fa44fc | 350 | pc.printf("\n\n\n\r\t\033[%dmDo you want to continue with rest of the adc test. Press ",36); |
CactusSemi | 4:1c48c9fa44fc | 351 | pc.printf("\n\n\r\t 'c' - Continue "); |
CactusSemi | 4:1c48c9fa44fc | 352 | pc.printf("\n\n\r\t 'e' - Exit "); |
CactusSemi | 4:1c48c9fa44fc | 353 | pc.printf("\n\n\n\r\tYour Selection : \033[%dm",32); |
CactusSemi | 4:1c48c9fa44fc | 354 | temp = 0; |
CactusSemi | 4:1c48c9fa44fc | 355 | while ( temp!='c' && temp!='e') { |
CactusSemi | 4:1c48c9fa44fc | 356 | temp = pc.getc(); |
CactusSemi | 4:1c48c9fa44fc | 357 | } |
CactusSemi | 4:1c48c9fa44fc | 358 | if (temp == 'e') return; |
CactusSemi | 4:1c48c9fa44fc | 359 | draw_sig_line(); |
CactusSemi | 4:1c48c9fa44fc | 360 | |
CactusSemi | 4:1c48c9fa44fc | 361 | //***************************************************************** |
CactusSemi | 4:1c48c9fa44fc | 362 | //****** measuring adc outputs different inputs |
CactusSemi | 4:1c48c9fa44fc | 363 | //***************************************************************** |
CactusSemi | 4:1c48c9fa44fc | 364 | |
CactusSemi | 4:1c48c9fa44fc | 365 | pc.printf("\033[%dm ", 31);//change text color to red |
CactusSemi | 4:1c48c9fa44fc | 366 | pc.printf("\n\n\n\n\r\tMeasure ADC output for different inputs \n\r\t"); |
CactusSemi | 4:1c48c9fa44fc | 367 | for ( i = 0; i<39; i++) pc.printf("\315"); |
CactusSemi | 4:1c48c9fa44fc | 368 | pc.printf("\033[%dm ", 32);//change text color to green |
CactusSemi | 4:1c48c9fa44fc | 369 | |
CactusSemi | 4:1c48c9fa44fc | 370 | adc_meas(&i2c,16,2); //adc measurement for 16 x 2mV |
CactusSemi | 4:1c48c9fa44fc | 371 | adc_meas(&i2c,24,2); |
CactusSemi | 4:1c48c9fa44fc | 372 | adc_meas(&i2c,32,2); |
CactusSemi | 4:1c48c9fa44fc | 373 | adc_meas(&i2c,64,2); |
CactusSemi | 4:1c48c9fa44fc | 374 | adc_meas(&i2c,97,2); |
CactusSemi | 4:1c48c9fa44fc | 375 | adc_meas(&i2c,128,2); |
CactusSemi | 4:1c48c9fa44fc | 376 | adc_meas(&i2c,196,2); |
CactusSemi | 4:1c48c9fa44fc | 377 | adc_meas(&i2c,250,2); |
CactusSemi | 4:1c48c9fa44fc | 378 | |
CactusSemi | 4:1c48c9fa44fc | 379 | pc.printf("\n\n\n\r\t\033[%dmDo you want to continue with rest of the adc test. Press ",36); |
CactusSemi | 4:1c48c9fa44fc | 380 | pc.printf("\n\n\r\t 'c' - Continue "); |
CactusSemi | 4:1c48c9fa44fc | 381 | pc.printf("\n\n\r\t 'e' - Exit "); |
CactusSemi | 4:1c48c9fa44fc | 382 | pc.printf("\n\n\n\r\tYour Selection : \033[%dm",32); |
CactusSemi | 4:1c48c9fa44fc | 383 | temp = 0; |
CactusSemi | 4:1c48c9fa44fc | 384 | while ( temp!='c' && temp!='e') { |
CactusSemi | 4:1c48c9fa44fc | 385 | temp = pc.getc(); |
CactusSemi | 4:1c48c9fa44fc | 386 | } |
CactusSemi | 4:1c48c9fa44fc | 387 | if (temp == 'e') return; |
CactusSemi | 4:1c48c9fa44fc | 388 | draw_sig_line(); |
CactusSemi | 4:1c48c9fa44fc | 389 | |
CactusSemi | 4:1c48c9fa44fc | 390 | //***************************************************************** |
CactusSemi | 4:1c48c9fa44fc | 391 | //****** measuring adc outputs different Range Settings |
CactusSemi | 4:1c48c9fa44fc | 392 | //***************************************************************** |
CactusSemi | 4:1c48c9fa44fc | 393 | |
CactusSemi | 4:1c48c9fa44fc | 394 | pc.printf("\033[%dm ", 31);//change text color to red |
CactusSemi | 4:1c48c9fa44fc | 395 | pc.printf("\n\n\n\n\r\tMeasure ADC output for different range settings \n\r\t"); |
CactusSemi | 4:1c48c9fa44fc | 396 | for ( i = 0; i<47; i++) pc.printf("\315"); |
CactusSemi | 4:1c48c9fa44fc | 397 | pc.printf("\033[%dm ", 32);//change text color to green |
CactusSemi | 4:1c48c9fa44fc | 398 | |
CactusSemi | 4:1c48c9fa44fc | 399 | reg_val04 = i2c_read_fn(&i2c,0x04); //Bits [3:2] of 0x04 contains range settings |
CactusSemi | 4:1c48c9fa44fc | 400 | |
CactusSemi | 4:1c48c9fa44fc | 401 | i2c_write_fn(&i2c,0x04,(reg_val04 & 0xF3)); //Range = 00 => 1mV |
CactusSemi | 4:1c48c9fa44fc | 402 | adc_meas(&i2c,128,1); //adc measurement for 16 x 2mV |
CactusSemi | 4:1c48c9fa44fc | 403 | |
CactusSemi | 4:1c48c9fa44fc | 404 | i2c_write_fn(&i2c,0x04,(reg_val04 | 0x0C)); //Range = 11 => 4mV |
CactusSemi | 4:1c48c9fa44fc | 405 | adc_meas(&i2c,32,4); //adc measurement for 32 x 4mV |
CactusSemi | 4:1c48c9fa44fc | 406 | |
CactusSemi | 4:1c48c9fa44fc | 407 | i2c_write_fn(&i2c,0x04,reg_val04); //Setting back the original value |
CactusSemi | 4:1c48c9fa44fc | 408 | |
CactusSemi | 4:1c48c9fa44fc | 409 | pc.printf("\n\n\n\r\t\033[%dmDo you want to continue with rest of the adc test. Press ",36); |
CactusSemi | 4:1c48c9fa44fc | 410 | pc.printf("\n\n\r\t 'c' - Continue "); |
CactusSemi | 4:1c48c9fa44fc | 411 | pc.printf("\n\n\r\t 'e' - Exit "); |
CactusSemi | 4:1c48c9fa44fc | 412 | pc.printf("\n\n\n\r\tYour Selection : \033[%dm",32); |
CactusSemi | 4:1c48c9fa44fc | 413 | temp = 0; |
CactusSemi | 4:1c48c9fa44fc | 414 | while ( temp!='c' && temp!='e') { |
CactusSemi | 4:1c48c9fa44fc | 415 | temp = pc.getc(); |
CactusSemi | 4:1c48c9fa44fc | 416 | } |
CactusSemi | 4:1c48c9fa44fc | 417 | if (temp == 'e') return; |
CactusSemi | 4:1c48c9fa44fc | 418 | draw_sig_line(); |
CactusSemi | 4:1c48c9fa44fc | 419 | |
CactusSemi | 4:1c48c9fa44fc | 420 | //***************************************************************** |
CactusSemi | 4:1c48c9fa44fc | 421 | //****** measuring adc outputs for negative inputs |
CactusSemi | 4:1c48c9fa44fc | 422 | //***************************************************************** |
CactusSemi | 4:1c48c9fa44fc | 423 | |
CactusSemi | 4:1c48c9fa44fc | 424 | pc.printf("\033[%dm ", 31);//change text color to red |
CactusSemi | 4:1c48c9fa44fc | 425 | pc.printf("\n\n\n\n\r\tMeasure ADC output for negative inputs \n\r\t"); |
CactusSemi | 4:1c48c9fa44fc | 426 | for ( i = 0; i<39; i++) pc.printf("\315"); |
CactusSemi | 4:1c48c9fa44fc | 427 | pc.printf("\033[%dm ", 32);//change text color to green |
CactusSemi | 4:1c48c9fa44fc | 428 | |
CactusSemi | 4:1c48c9fa44fc | 429 | pc.printf("\033[%dm", 34);//change text color to blue |
CactusSemi | 4:1c48c9fa44fc | 430 | pc.printf("\n\n\n\r\tInstructions: \n\r\t"); |
CactusSemi | 4:1c48c9fa44fc | 431 | for ( i = 0; i<13; i++) pc.printf("\304"); |
CactusSemi | 4:1c48c9fa44fc | 432 | pc.printf("\n\n\r\t 1. Set Voc = 0. Wait for a second "); |
CactusSemi | 4:1c48c9fa44fc | 433 | pc.printf("\n\n\r\t 2. Change the input connnection such that the input is negative "); |
CactusSemi | 4:1c48c9fa44fc | 434 | pc.printf("\n\n\r\t 3. Increase Voc to 450mV"); |
CactusSemi | 4:1c48c9fa44fc | 435 | pc.printf("\033[%dm ", 32);//change text color to green |
CactusSemi | 4:1c48c9fa44fc | 436 | temp = 0; |
CactusSemi | 4:1c48c9fa44fc | 437 | pc.printf("\n\n\n\r\t\033[%dmPress 'c' to continue: \033[%dm",36,32); |
CactusSemi | 4:1c48c9fa44fc | 438 | while ( temp!='c') { |
CactusSemi | 4:1c48c9fa44fc | 439 | temp = pc.getc(); |
CactusSemi | 4:1c48c9fa44fc | 440 | } |
CactusSemi | 4:1c48c9fa44fc | 441 | //Making sure input polarity detector outputs are correct. |
CactusSemi | 4:1c48c9fa44fc | 442 | i2c_write_fn(&i2c,0x10,0x10); //tm_PolComp_en = 1 |
CactusSemi | 4:1c48c9fa44fc | 443 | pc.printf("\n\n\n\r\tPolarity comparitor was enabled to have correct outputs (vinB_high = 1)"); |
CactusSemi | 4:1c48c9fa44fc | 444 | wait_ms(1); |
CactusSemi | 4:1c48c9fa44fc | 445 | i2c_write_fn(&i2c,0x10,0x00); //tm_PolComp_en = 0 |
CactusSemi | 4:1c48c9fa44fc | 446 | pc.printf("\n\n\r\tPolarity comparitor disabled"); |
CactusSemi | 4:1c48c9fa44fc | 447 | adc_meas(&i2c,16,2); //adc measurement for 16 x 2mV |
CactusSemi | 4:1c48c9fa44fc | 448 | adc_meas(&i2c,128,2); |
CactusSemi | 4:1c48c9fa44fc | 449 | adc_meas(&i2c,250,2); |
CactusSemi | 4:1c48c9fa44fc | 450 | |
CactusSemi | 4:1c48c9fa44fc | 451 | pc.printf("\n\n\n\r\t\033[%dmDo you want to continue to ADC ACP mode test. Press ",36); |
CactusSemi | 4:1c48c9fa44fc | 452 | pc.printf("\n\n\r\t 'c' - Continue "); |
CactusSemi | 4:1c48c9fa44fc | 453 | pc.printf("\n\n\r\t 'e' - Exit "); |
CactusSemi | 4:1c48c9fa44fc | 454 | pc.printf("\n\n\n\r\tYour Selection : \033[%dm",32); |
CactusSemi | 4:1c48c9fa44fc | 455 | temp = 0; |
CactusSemi | 4:1c48c9fa44fc | 456 | while ( temp!='c' && temp!='e') { |
CactusSemi | 4:1c48c9fa44fc | 457 | temp = pc.getc(); |
CactusSemi | 4:1c48c9fa44fc | 458 | } |
CactusSemi | 4:1c48c9fa44fc | 459 | if (temp == 'e') return; |
CactusSemi | 4:1c48c9fa44fc | 460 | draw_sig_line(); |
CactusSemi | 4:1c48c9fa44fc | 461 | |
CactusSemi | 4:1c48c9fa44fc | 462 | //***************************************************************** |
CactusSemi | 4:1c48c9fa44fc | 463 | //****** Verify ADC operation for ACP mode |
CactusSemi | 4:1c48c9fa44fc | 464 | //***************************************************************** |
CactusSemi | 4:1c48c9fa44fc | 465 | |
CactusSemi | 4:1c48c9fa44fc | 466 | pc.printf("\033[%dm ", 31);//change text color to red |
CactusSemi | 4:1c48c9fa44fc | 467 | pc.printf("\n\n\n\n\r\tVerify ADC operation in ACP mode \n\r\t"); |
CactusSemi | 4:1c48c9fa44fc | 468 | for ( i = 0; i<32; i++) pc.printf("\315"); |
CactusSemi | 4:1c48c9fa44fc | 469 | pc.printf("\033[%dm ", 32);//change text color to green |
CactusSemi | 4:1c48c9fa44fc | 470 | reg_val07 = i2c_read_fn(&i2c,0x07); //reading the initial pmos off setting |
CactusSemi | 4:1c48c9fa44fc | 471 | 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 |
CactusSemi | 4:1c48c9fa44fc | 472 | pc.printf("\n\n\r\tCSI066a switched to ACP mode by setting PMOS_off = 4'hF"); |
CactusSemi | 4:1c48c9fa44fc | 473 | |
CactusSemi | 4:1c48c9fa44fc | 474 | pc.printf("\033[%dm", 34);//change text color to blue |
CactusSemi | 4:1c48c9fa44fc | 475 | pc.printf("\n\n\n\r\tInstructions: \n\r\t"); |
CactusSemi | 4:1c48c9fa44fc | 476 | for ( i = 0; i<13; i++) pc.printf("\304"); |
CactusSemi | 4:1c48c9fa44fc | 477 | pc.printf("\n\n\r\t 1. Set Voc to 480mV (240 x 2mV)"); |
CactusSemi | 4:1c48c9fa44fc | 478 | pc.printf("\033[%dm ", 32);//change text color to green |
CactusSemi | 4:1c48c9fa44fc | 479 | temp = 0; |
CactusSemi | 4:1c48c9fa44fc | 480 | pc.printf("\n\n\n\r\t\033[%dmPress 'c' to continue: \033[%dm",36,32); |
CactusSemi | 4:1c48c9fa44fc | 481 | while ( temp!='c') { |
CactusSemi | 4:1c48c9fa44fc | 482 | temp = pc.getc(); |
CactusSemi | 4:1c48c9fa44fc | 483 | } |
CactusSemi | 4:1c48c9fa44fc | 484 | pc.printf("\n\n\n\r\tPerforming hot-read on adc_comp_out (0x13[3])"); |
CactusSemi | 4:1c48c9fa44fc | 485 | pc.printf("\033[%dm", 34);//change text color to blue |
CactusSemi | 4:1c48c9fa44fc | 486 | pc.printf("\n\n\n\r\tInstructions: \n\r\t"); |
CactusSemi | 4:1c48c9fa44fc | 487 | for ( i = 0; i<13; i++) pc.printf("\304"); |
CactusSemi | 4:1c48c9fa44fc | 488 | pc.printf("\n\n\r\t 1. Monitor DATA1_clk on oscilloscope. DATA1_clk should be low in the beginning "); |
CactusSemi | 4:1c48c9fa44fc | 489 | pc.printf("\n\n\r\t 2. Ramp Voc from 480mV --> 520mV (240lsb --> 260lsb). Stop when DATA1_CLK transitions from 0 --> 1 "); |
CactusSemi | 4:1c48c9fa44fc | 490 | 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 |
CactusSemi | 4:1c48c9fa44fc | 491 | pc.printf("\033[%dm ", 32);//change text color to green |
CactusSemi | 4:1c48c9fa44fc | 492 | |
CactusSemi | 4:1c48c9fa44fc | 493 | i2c_hotread_fn(&i2c,0x13,3); //Performing hot-read on [3] of 0x13 |
CactusSemi | 4:1c48c9fa44fc | 494 | |
CactusSemi | 4:1c48c9fa44fc | 495 | pc.printf("\033[%dm", 34);//change text color to blue |
CactusSemi | 4:1c48c9fa44fc | 496 | pc.printf("\n\n\n\r\tInstructions: \n\r\t"); |
CactusSemi | 4:1c48c9fa44fc | 497 | for ( i = 0; i<13; i++) pc.printf("\304"); |
CactusSemi | 4:1c48c9fa44fc | 498 | pc.printf("\n\n\r\t 1. Reduce Voc to 0V. "); |
CactusSemi | 4:1c48c9fa44fc | 499 | pc.printf("\n\n\r\t 2. Switch input connections such that input is positive"); |
CactusSemi | 4:1c48c9fa44fc | 500 | pc.printf("\n\n\r\t 3. Set Voc to 480mV (240 x 2mV)"); |
CactusSemi | 4:1c48c9fa44fc | 501 | pc.printf("\033[%dm ", 32);//change text color to green |
CactusSemi | 4:1c48c9fa44fc | 502 | temp = 0; |
CactusSemi | 4:1c48c9fa44fc | 503 | pc.printf("\n\n\n\r\t\033[%dmPress 'c' to continue: \033[%dm",36,32); |
CactusSemi | 4:1c48c9fa44fc | 504 | while ( temp!='c') { |
CactusSemi | 4:1c48c9fa44fc | 505 | temp = pc.getc(); |
CactusSemi | 4:1c48c9fa44fc | 506 | } |
CactusSemi | 4:1c48c9fa44fc | 507 | i2c.~I2C(); |
CactusSemi | 4:1c48c9fa44fc | 508 | I2C i2c2(p9,p10); //Creating new object after hot-read |
CactusSemi | 4:1c48c9fa44fc | 509 | i2c2.frequency((frequ/2)*1000); |
CactusSemi | 4:1c48c9fa44fc | 510 | LPC_PINCON->PINMODE_OD0 = (LPC_PINCON->PINMODE_OD0 | 0x0003); // To make p9 & P10 open_drain |
CactusSemi | 4:1c48c9fa44fc | 511 | i2c2.stop(); //add a stop after hot-read |
CactusSemi | 4:1c48c9fa44fc | 512 | //Making sure input polarity detector outputs are correct. |
CactusSemi | 4:1c48c9fa44fc | 513 | i2c_write_fn(&i2c2,0x10,0x10); //tm_PolComp_en = 1 |
CactusSemi | 4:1c48c9fa44fc | 514 | pc.printf("\n\n\n\r\tPolarity comparitor was enabled to have correct outputs (vinB_high = 1)"); |
CactusSemi | 4:1c48c9fa44fc | 515 | wait_ms(1); |
CactusSemi | 4:1c48c9fa44fc | 516 | i2c_write_fn(&i2c2,0x10,0x00); //tm_PolComp_en = 0 |
CactusSemi | 4:1c48c9fa44fc | 517 | pc.printf("\n\n\r\tPolarity comparitor disabled"); |
CactusSemi | 4:1c48c9fa44fc | 518 | |
CactusSemi | 4:1c48c9fa44fc | 519 | pc.printf("\n\n\n\r\tPerforming hot-read on adc_comp_out (0x13[3])"); |
CactusSemi | 4:1c48c9fa44fc | 520 | |
CactusSemi | 4:1c48c9fa44fc | 521 | pc.printf("\033[%dm", 34);//change text color to blue |
CactusSemi | 4:1c48c9fa44fc | 522 | pc.printf("\n\n\n\r\tInstructions: \n\r\t"); |
CactusSemi | 4:1c48c9fa44fc | 523 | for ( i = 0; i<13; i++) pc.printf("\304"); |
CactusSemi | 4:1c48c9fa44fc | 524 | pc.printf("\n\n\r\t 1. Monitor DATA1_CLk on the oscillscope "); |
CactusSemi | 4:1c48c9fa44fc | 525 | pc.printf("\n\n\r\t 2. DATA1_CLk should be low initially"); |
CactusSemi | 4:1c48c9fa44fc | 526 | pc.printf("\n\n\r\t 3. Ramp Voc from 480mV --> 520mV (240lsb --> 260lsb). Stop when DATA1_CLK transitions from 0 --> 1 "); |
CactusSemi | 4:1c48c9fa44fc | 527 | 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 |
CactusSemi | 4:1c48c9fa44fc | 528 | pc.printf("\033[%dm ", 32);//change text color to green |
CactusSemi | 4:1c48c9fa44fc | 529 | |
CactusSemi | 4:1c48c9fa44fc | 530 | i2c_hotread_fn(&i2c2,0x13,3); //Performing hot-read on [3] of 0x13 |
CactusSemi | 4:1c48c9fa44fc | 531 | |
CactusSemi | 4:1c48c9fa44fc | 532 | i2c2.~I2C(); |
CactusSemi | 4:1c48c9fa44fc | 533 | I2C i2c3(p9,p10); //Creating new object after hot-read |
CactusSemi | 4:1c48c9fa44fc | 534 | i2c3.frequency((frequ/2)*1000); |
CactusSemi | 4:1c48c9fa44fc | 535 | LPC_PINCON->PINMODE_OD0 = (LPC_PINCON->PINMODE_OD0 | 0x0003); // To make p9 & P10 open_drain |
CactusSemi | 4:1c48c9fa44fc | 536 | i2c3.stop(); //add a stop after hot-read |
CactusSemi | 4:1c48c9fa44fc | 537 | i2c_write_fn(&i2c3,0x07,reg_val07); //Restoring Reg 0x07 value |
CactusSemi | 4:1c48c9fa44fc | 538 | pc.printf("\n\n\n\r\t\033[%dmADC Test finally done!.. Phew\033[%dm", 45, 40);//displaying in Magenta background |
CactusSemi | 4:1c48c9fa44fc | 539 | |
CactusSemi | 4:1c48c9fa44fc | 540 | } |
CactusSemi | 4:1c48c9fa44fc | 541 |