-
Notifications
You must be signed in to change notification settings - Fork 58
Wait for conversions in continuous example #62
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
Wait for conversions in continuous example #62
Conversation
Previously polling rate (apparent sample rate) was limited purely by I2C speed, script will now wait a full conversion cycle until it next reads the conversion result. NOTE: Not implementing a time.sleep() in _read(self, pin) as this would be blocking and would inhibit easy implementation of interrupt driven sampling by the ALERT/RDY pin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(44e135d) This commit affected local file EOLs only
- Remove accumulating error introduced by basing next sample time on time.monotonic call - Skip samples if scheduled time has passed to prevent over polling one conversion result in order to catch up - Pre-calculate time_next_sample in while loop comparison and sample_interval
This pull request resolves #27, #35, #43. New
Plot of time.monotonic() error in comparison to time_next_sample at ADC read (3,300 sps jitter target is 303 μs) Bugs: Will often skip first 1 or 2 samples, I suspect this is due to the following line however I don't think it's worth the trouble to change it.
|
- Do first slow channel read(&configure/wait) and discard result before entering timed loop - Align start time with acquisition timing - Bug not entirely fixed, will still sometimes skip 1 reading when taking >1,000 samples, probably won't fix this
New
|
Sorry. Just now seeing this. So this essentially looks like you've implemented something like suggested here? |
Yes pretty much although this implementation is a bit more advanced to make sure the sample rate doesn't drift or over-sample to catch up. It also uses a blocking |
Yep. Thanks. Looks like you also tested it, so I'm fine with merging. If this was useful for you, hopefully will be for others trying to use fast read. |
Updating https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15 to 2.2.5 from 2.2.4: > Merge pull request adafruit/Adafruit_CircuitPython_ADS1x15#62 from WizardTim/WizardTim-continuous-fix-1 Updating https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel to 6.0.1 from 6.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_NeoPixel#100 from funkfinger/master Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE_BroadcastNet to 0.10.2 from 0.10.1: > Merge pull request adafruit/Adafruit_CircuitPython_BLE_BroadcastNet#16 from alexwhittemore/master Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Added the following libraries: Adafruit_CircuitPython_OAuth2
Previously polling rate (apparent sample rate) was limited purely by I2C speed, script will now wait a full conversion cycle until it next reads the conversion result.
Requires #61 to be merged first.
With
RATE=250
andi2c_baudrate=1000000
(1 MHz)Old
New
Also constrains polling rate at any other valid sample rate, eg.
RATE=3300
andi2c_baudrate=1000000
(1 MHz)New