61
					Electronics / Re: AD7705 16-Bit Analog to Digital (ADC) Converter Hanging After Seconds-To-Minutes
« Last post by Cube on October 11, 2015, 12:17:45 AM »Here is the code: 
				Code: [Select]
void setup() {
	Serial.begin(9600);
	// -- LEDs and IRBS Initialization -- //
	pinMode(BigGreenLED, OUTPUT);
	pinMode(YellowLED, OUTPUT);
	pinMode(IRBS_LED, OUTPUT);
	pinMode(A0, INPUT);
	pinMode(AD_Ready, INPUT);
	// -- DIP Switch Shift Register Initialization -- //
	pinMode(ploadPin, OUTPUT);
	pinMode(clockEnablePin, OUTPUT);
	pinMode(clockPin, OUTPUT);
	pinMode(dataPin, INPUT);
	digitalWrite(clockPin, LOW);
	digitalWrite(ploadPin, HIGH);
	DIPs = read_dip_switches();
	display_dip_switches();
	DIPSwitchValues = DIPs;
	// -- AD7705 Initialization -- //
	ad7706.reset();
	ad7706.init(AD770X::CHN_AIN1, AD770X::CLK_DIV_1, AD770X::BIPOLAR,
			AD770X::GAIN_1, AD770X::UPDATE_RATE_500);
        // Not using the second channel:
	//ad7706.init(AD770X::CHN_AIN2, AD770X::CLK_DIV_1, AD770X::BIPOLAR,
	//		AD770X::GAIN_1, AD770X::UPDATE_RATE_500);
	lcd.init();
	lcd.backlight();
	lcd.print("bbs.venturii.net");
}
void loop() {
	static uint8_t x = 0;
	static unsigned long as = 0, bs = 0, il_sum = 0;
	unsigned int t = 0;
	// Set Green LED to the value of the Data Ready pin from the AD7705:
	digitalWrite(BigGreenLED, digitalRead(AD_Ready));
	as += ad7706.readRawResult(AD770X::CHN_AIN1);
	// IRBS - Take sample with LED On:
	digitalWrite(IRBS_LED, HIGH);
	digitalWrite(YellowLED, HIGH);
	il_sum += 1023 - analogRead(A0);
	// IRBS - Take sample with LED Off:
	digitalWrite(IRBS_LED, LOW);
	digitalWrite(YellowLED, LOW);
	bs += 1023 - analogRead(A0);
	x++;
	// Oversample:
	if (x > 14) {
		// Display rad value from AD7705:
		t = as / x;
		lcd.setCursor(0, 1);
		lcd.print(t);
		lcd.print("     ");
		// Display differential value from IRBS:
		t = bs / x;
		t = il_sum / x;
		lcd.setCursor(7, 1);
		if (il_sum > bs) {
			lcd.print("[");
			lcd.print((il_sum - bs) / x);
			lcd.print("]   ");
		} else {
			lcd.print((bs - il_sum) / x);
			lcd.print("   ");
		}
		// Clear buffers and counter:
		as = bs = x = il_sum = 0;
	}
	// Lather, rinse, repeat. Always repeat.
}

			
Recent Posts
 Scratch that off the list. 
 
