Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More accurate control of integration time #40

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

campagnola
Copy link

The changes here are all related to my attempts to achieve more reliable readings from the TCS43725, particularly when dealing with changes in integration time. The initial problem I ran into is that getRawData was returning values that were not consistent with the configured integration time (also reported in #15). After digging into that issue, I found that the implementation of setIntegrationTime wasn't consistent with the model described in the datasheet (also reported in #37). These two issues are addressed across several changes:

  • Adds a boolean wait argument to getRawData, allowing to delay until integration has finished. (fixes Issues with accuracy and speed #15).
  • Adds reset() and calls this whenever changing integration time in order to begin the new integration immediately. This ensures that the delay in getRawData is sufficiently long to guarantee integration has completed.
  • Removes delay from enable(); this is no longer necessary due to the above changes.
  • Adds an override for setIntegrationTime that accepts a uint8 argument rather than tcs34725IntegrationTime_t. The datasheet specifies that any value 0-255 is acceptable here, whereas tcs34725IntegrationTime_t only provides access to a few specific values.
  • Adds setIntegrationTimeMsec, which selects the closest ATIME value to the requested duration and returns the actual integration time.
  • Adds getRawDataMax(), which returns the maximum possible raw data value given the current integration time, making it possible to detect saturation.
  • Adds calculateIntegrationTime and calculateIntegrationConstant`, which map back and forth between ATIME and integration time in msec. Note--the values I use here are based on my own measurements from my device, which did not match the values in the datasheet. I don't know whether these values will be universally accurate.

I believe these changes are backward compatible, with the exception of some timing differences and the addition of a reset() when setting integration time. I have tested both examples/tcs34725 and examples/tcs34725autorange; everything seems ok there. The other two examples would have required some hardware modifications, though, so I haven't tried those.

 - Allow setting any ATIME value 0-255
 - Add mathod for setting integration time in msec
 - Add setRawData option to delay by integration time before reading
@ladyada
Copy link
Member

ladyada commented Jan 2, 2021

thanks, it may be a bit till we get back to this library. till then can you check the CI failure report above? there some non-compiling example code - clieck Details on the CI build report :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issues with accuracy and speed
2 participants