0

Getting millisecond resolution measurements
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Getting millisecond resolution measurements

by mrrmay on Tue Mar 30, 2021 4:17 pm

Hi all, second post here.

I've searched the forum for questions related to very short time measurements. There are a couple of posts on measuring extended times (CircuitPython long timer events and Innacurate PyPortal timing). My question is at the other end of the spectrum.

A previous AutoHotKey project I worked on required millisecond resolution measurements. AHK's default time-related code is inaccurate by +/-15ms. The Windows workaround is to use the OS's QueryPerformanceCounter with a DLLcall.

Does CircuitPython have a similar limitation?
Does using an RTC and rtc.RTC produce more precise times than time.monotonic or time.monotonic_ns?

I haven't gotten the parts yet, but I'm going to build a lag meter with these parts:


mrrmay
 
Posts: 7
Joined: Sun Mar 28, 2021 11:51 am

Re: Getting millisecond resolution measurements

by blnkjns on Wed Mar 31, 2021 12:29 am

Doesn't sound too difficult to code in C++: why not do it with interrupts in the Arduino IDE? Maybe on an even simpler platform like a 32U4 based board, so interrupts are very well documented. Or to keep it really simple with your current setup: use the standard call for micros(), it will be more than good enough for you.
The RTC won't help, as it has a 32kHz clock and you will need complex input handling to deal with that clock pulse, whereas the system clock is 48MHz ready to use.

blnkjns
 
Posts: 330
Joined: Fri Oct 02, 2020 3:33 am

Re: Getting millisecond resolution measurements

by mrrmay on Wed Mar 31, 2021 1:33 am

Interesting.

I'm a little intimidated by C++ as I just learned AHK and R since December. Programming is one of those things I've wanted to do since my mom brought home an Apple IIc in 2nd grade. LOL (Who can estimate my age from that statement?)

Anyhow, there's plenty of resources out there to learn Arduino. I should give it s shot. Besides, a lower level language will ultimately be more efficient.

mrrmay
 
Posts: 7
Joined: Sun Mar 28, 2021 11:51 am

Re: Getting millisecond resolution measurements

by blnkjns on Wed Mar 31, 2021 2:53 am

Start with uploading the sample code from the sensor library. Few clicks, and you can start modding from there.
https://learn.adafruit.com/adafruit-tsl ... g-and-test
But to make sure there is no lag in the sensor and its I2C circuit, you might be better off using an LDR on the analog input. No, even better: LDR+threshold potentiometer and fast comparator IC.
If you combine it with the USB-HID library, the board can make both the keypress and start measuring time from your key hit.

blnkjns
 
Posts: 330
Joined: Fri Oct 02, 2020 3:33 am

Re: Getting millisecond resolution measurements

by mrrmay on Thu Apr 01, 2021 3:48 pm

blnkjns wrote:No, even better: LDR+threshold potentiometer and fast comparator IC.
If you combine it with the USB-HID library, the board can make both the keypress and start measuring time from your key hit.


So, at first that went waaaay over my head.

But a little google and little window shopping and I think I get it:

I could try geting as much done with analogue instruments to bypass questions of poll rate and timings. I can use a dial (potentiometer) to regulate current to a light sensor (LDR) which has a gatekeeper (comparator) on the other side that will allow current to pass after it reaches a given threshold. I'm guessing the potentiometer is there to calibrate the system to "normal" light levels, it's much easier than changing the sensor and comparator to match conditions.

This turns the system on its head. Instead of the microprocessor asking the sensor "are we there yet?" (polling) the sensor has an alarm (the comparator) that sends the microprocessor into action.

I'll be trying that out next.

This is a very interesting idea indeed.

mrrmay
 
Posts: 7
Joined: Sun Mar 28, 2021 11:51 am

Please be positive and constructive with your questions and comments.