TCS34725 error when changing gain

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
wbp
 
Posts: 260
Joined: Mon Mar 07, 2011 1:18 pm

TCS34725 error when changing gain

Post by wbp »

There is a bit of a bug when changing the gain on the TCS34725. If the device is already active, the change does not appear to be recognized until after the current sample is completed. The problem can be demonstrated by setting the integration time to 700 ms, and then repeating this sequence:

Code: Select all

void loop(void) {  
  tcs.setGain(TCS34725_GAIN_1X); // no gain
  tcs.getRawData(&r, &g, &b, &c);
  lux = (float)tcs.calculateLux(r, g, b)/gain;
  Serial.print("Lux: "); Serial.println(lux);
  delay(1000);

  tcs.setGain(TCS34725_GAIN_60X); // 60x gain
  tcs.getRawData(&r, &g, &b, &c);
  lux = (float)tcs.calculateLux(r, g, b)/gain;
  Serial.print("Lux: "); Serial.println(lux);
  delay(1000);
}
After 1 iteration, he values display will be obviously wrong - the first value will be 60 times the second one, the opposite of what one might expect.

If I insert the following 2 lines after each "tcs.setGain" then the readings are what one would expect:

Code: Select all

void loop(void) {  
  tcs.setGain(TCS34725_GAIN_1X); // no gain
  tcs.getRawData(&r, &g, &b, &c);
  delay(700); 
  tcs.getRawData(&r, &g, &b, &c);
  lux = (float)tcs.calculateLux(r, g, b)/gain;
  Serial.print("Lux: "); Serial.println(lux);
  delay(1000);

  tcs.setGain(TCS34725_GAIN_60X); // 60x gain
  tcs.getRawData(&r, &g, &b, &c);
  delay(700); 
  tcs.getRawData(&r, &g, &b, &c);
  lux = (float)tcs.calculateLux(r, g, b)/gain;
  Serial.print("Lux: "); Serial.println(lux);
  delay(1000);
}
In reading the specs for this device one learns that it is double buffered. So it's going to have to go thru 2 reading cycles before the data reflects the new Gain value.

In looking at the TCS34725 library, I noticed that "getRawData" reads the RGBC values first, then does a delay for the Integration time. This seems backward to me - if it's going to wait, shouldn't it wait first, then fetch the data?

William

lady_ada
 
Posts: 3
Joined: Wed Oct 08, 2008 7:53 pm

Re: TCS34725 error when changing gain

Post by lady_ada »

There's some things with the TCS34725 we're not exactly sure about, including this odd delay in 'setting' - if you have a more durable fix suggestion we'll take it! :)

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”