void proses_data_adc(void) { unsigned char temp; if (cek_adc_rdy() == 1) { st_adc.count++; st_adc.data[ st_adc.cur_kanal ] = baca_data(); st_adc.cur_kanal++; if (st_adc.cur_kanal == 10) { /* satu round 10 kanal sudah selesai */ st_adc.cur_kanal = 0; } if (st_adc.cur_kanal == 8) temp = (unsigned char) ((14 << 4) + range_420); else if (st_adc.cur_kanal == 9) temp = (unsigned char) ((15 << 4) + range_420); else temp = (unsigned char) ((st_adc.cur_kanal << 4) + range_420); set_adccon(temp); } }
void start_adc_1(int fdx) { int i; unsigned char temp_char; unsigned char kanal_aktif; st_adc.cur_kanal = 0; printf("Starting ADC collecting data !\r\n"); /* range adc thermocouple adalah fix di range_adc lihat di ad7708.h header sedangkan range_adc untuk thermocouple adalah tergantung masing2 kanal kanal 1 - 5 adalah RTD kanal 6 - 10 adalah 4-20 mA output dari opamp RTD, jika 100 C adalah 0.3 Volt sehingga kanal 1 - 5 harus dipakai range 320 mV */ #ifdef BOARD_KOMON_B_THERMO temp_char = (unsigned char) ((st_adc.cur_kanal << 4) + range_adc); #endif #ifdef BOARD_KOMON_A_RTD temp_char = (unsigned char) ((st_adc.cur_kanal << 4) + range_RTD); #endif #ifdef BOARD_KOMON_420_SAJA temp_char = (unsigned char) ((st_adc.cur_kanal << 4) + range_420); #endif #ifdef BOARD_KOMON_420_SABANG_2_3 temp_char = (unsigned char) ((st_adc.cur_kanal << 4) + range_420); #endif set_adccon(temp_char); set_mode((unsigned char) (3 + 16)); //continuous sampling + CHCON // 0x03 | 0x10 //cek filter printf(" FILTER ADC = %d ;", (unsigned char) cek_filter()); printf(" ADCCON = %d ;", (unsigned char) cek_adccon()); printf(" MODE = %d\r\n",(unsigned char) cek_mode()); }
char kalibrasi_adc1(int fdy) { unsigned char er; char ada_adc_1; int t; int loop_ulang; int loop; int loop_full_calib; //unsigned char kanal_aktif; unsigned char temp_char; unsigned char cek; unsigned int mask; printf("Start calibrating ADC"); stop_adc(); set_calibrated(0); vTaskDelay(100); reset_adc(); vTaskDelay(100); //cek ID cek = cek_adc_id(); printf(" id = 0x%X \n", cek); vTaskDelay(10); set_iocon(0x00); er = 0; ada_adc_1 = false; for (t=0; t<10; t++) { temp_char = (unsigned char) ((er << 4) + 15); // 0x0F if (er == 8) temp_char = (unsigned char) ((14 << 4) + 15); if (er == 9) temp_char = (unsigned char) ((15 << 4) + 15); loop_ulang = 0; kalib_ulang: loop_ulang++; set_adccon(temp_char); /* kalibrasi zero scale + CHCON */ set_mode(4 + 16); cek = cek_adccon(); //if (cek != temp_char) printf(" !%d ", cek); //serial_puts("tidak cocok"); vTaskDelay(1); loop = 0; printf(" : Kanal %3d : ", (1+t)); while ((cek_mode() & 0x3) != 0x1) { vTaskDelay(10); loop++; if (loop > 50) { if (loop_ulang < 6) { printf(" recalib "); goto kalib_ulang; } printf("\n gagal !\r\n"); ada_adc_1 = false; break; } } if (loop < 50) { printf(" try = %d (OK)\n", loop); ada_adc_1 = true; } /* if (ada_adc_1 == false) { printf("tidak terdapat ADC"); return 1; //break; } */ er++; } if (ada_adc_1 == true) { set_filter((unsigned char) rate_7708); printf(" ADC iocon %d", cek_iocon()); printf("; adccon %d", cek_adccon()); printf("; mode %d\r\n", cek_mode()); set_iocon(0x00); set_calibrated(1); return 1; } else { set_calibrated(0); return 0; } }