0

so I need to make a simple but reliable stopwatch with an 1 ms accuracy for an android device (transformer tablet). I have no experience at all with android. After searching I'm not finding any specifics about what's the maximum accuracy I could get in this specific context(described below). Perhaps some one here can give me the info I need. As the stopwatch is going to be used for time reactions and diagnoses 1 ms is the accuracy we need.

what the stopwatch should do is quite simple:

  • Obviously the program start at 00:00.000, from there 7 measures are going to be taken. When the users push a key or the screen, the program should log the elapsed time. at the 7th time the program will save the measures in a txt file.

I don't even need to display the stamp or the elapsed time and refresh the display. except for the OS apps, no other applications are going to be running.

Theoretically System.nanoTime() or timestamp would do it. But I'm not sure if this will give me the 1 ms accuracy that I need. can they give me the accuracy I'm looking for? a brief explanation would be useful. are there another methods? If some one is a android developer the info will be really appreciated .

Thanks,

UPDATE: Altho the user Nanno made a valid point about the limitations in the Android OS, thus making the 1 ms accuracy stopwatch impossible in a "tablet-only" scenario, Julian's further answer described an interesting and relatively cheap solution to accomplish the goal using Android ADK (external hardware).

7
  • 2
    what makes you think hitting a button on the activity will always get you a message to your onClick() method in <1ms? - Getting yourself a fast enough response from the outside world to your app code is your first hurdle. May 11, 2012 at 6:34
  • @mariomario Because System.currentTimeMillis provides ms precision not ms accuracy May 11, 2012 at 6:35
  • @JulianHigginson you are not making any sense. read the question again. thanks May 11, 2012 at 6:38
  • 2
    I've read your question. If the issue I raised doesn't make any sense to you, then you really need to think for a while about what realtime software actually means. May 11, 2012 at 6:42
  • 1
    you are worried about the accuracy of the timer subsystem. I am sugesting that if you don't have better accuracy than that in the touch event handler to get messages to the timer subsystem as they are generated by the user, then accuracy of the timer subsystem is not important. May 11, 2012 at 6:52

5 Answers 5

1

a <1ms accurate android stopwatch solution could be made to work using something like this:

http://developer.android.com/guide/topics/usb/adk.html

hook up buttons to the board, and have your timing code in the remote processor (AVR, programmed using arduino tools. very easy for embedded beginners) Then communicate between the android tablet and the open accessory development kit over USB to display the result on the tablet.

Of course this solution isn't so useful if you want people to be able to just download it to their devices all over the world from google play... but seeing you mentioned a specific device, maybe you just want to make this project for yourself?

In that case it is doable, just in a very roundabout way.

7
  • It seems like that's the way to go!!. Also it won't be expensive and already have standardized components so I don't have to build it ad-hoc. it also supports PIC. (I was thinking in using PIC but from scratch , this save times) thanks for this info julian. pdta: Seems like you are experienced in this area, any chance to have a brief chat? May 11, 2012 at 7:32
  • pdta: yes the project is intended for myself only. May 11, 2012 at 7:40
  • going by your comment, it looks like you awarded the correct answer prize to the wrong answer. May 11, 2012 at 12:30
  • Nanno's answer was closer to the original question (only the tablet + android), providing a brief explanation, Altho your second answer provide a good alternative solution to the problem. Anyway, I changed the correct answer prize to your answer. May 11, 2012 at 19:18
  • fair enough, though his answer was a rewording of what I'd already said in the comments to the original question, too... May 12, 2012 at 8:03
1

With your current setup, I doubt you can get this kind of accuracy, simply because of the inaccuracy of users push a key or the screen.

Before you have successfully pushed the screen, caught the event, and called the function, your accuracy is going to be off. Especially when you think about nanoTime, the interface is adding a random-factor in your measuring that I would not trust it.

Android is not made to run real-time programs, and even if you are not running other programs in the background, the system is ready for it. It can broadcast intents or do other unexpected stuff in the background.. Sure, your interface does have priority, but with the accuracy you're implying? I don't think so.

5
  • Thank you very much for your answer. self explained. Yeah sadly, seems like is not possible at all and there's not work around for it. May 11, 2012 at 7:00
  • going a bit further.. what's the accuracy range that you think is possible to achieve in the scenario described in my question? May 11, 2012 at 16:38
  • The problem is that it is unpredictable. I suspect (but just guestimating here really!) that it would be about the ms you can get right. But to get the accuracy/vs precission confusion out of the way, I thinkt that it's really hard to be talking about ms and reaction time, as a human wouldn't be able to react with ms precision. If we are talking about the touch event vs the clock stopping, sure, you'd get a margin of maybe even less then 1ms, but you'd have lost a multitude of that in reaction time before actually touching?
    – Nanne
    May 13, 2012 at 9:45
  • I'm a bit confused because you said "ms" not sure if u mean "ONE ms". I'll try to clear this. A typicall reaction to a visual stimuli ( Go/No-Go) could be around 180 and 220 ms. A difference about 20 or 30 ms between two individuals represents different brain fuctioning. The goal of having a stopwatch with 1 ms accuracy is to avoid error and noise in the measures that aren't part of the individual's performance but due to the system performance (hardware, software). Sure one could accept a bigger level of error but that means less accuracy in the diagnosis too. May 13, 2012 at 10:32
  • I'd say it would be sufficient in most cases (the system not being busy) to measure with an error-margin of about 2 ms, guessing defensively. But these will all be guesses. "we" have allready established that this set-up is not perfect for real-time applications, but it might as well be good enough for your purposes. I are probably going to have to test this. If you have a set-up that can measure actual time and recorded time with an automated "touch", you could check it out. Or compare several predictable results from a subject (statistically harder, but do-able).
    – Nanne
    May 13, 2012 at 10:41
0

Why not use System.currentTimeMillis, you can find here an example of a stop watch written to have a ms accuracy.

1
  • Because System.currentTimeMillis provides ms precision not ms accuracy May 11, 2012 at 6:20
0

You should try this first:

It would be plausible to get 1 ms accuracy between the keypress and the clock stopping using your android tablet BUT NOT with android OS. You should use UBUNTU for android devices.

get it here: http://www.ubuntu.com/devices/android

About the code , use C++ high precision timers.

Set the app and calls to the higher priority.

As I said try it. you could save time and money!! (Better than starting to buy external hardware)

0

One comment about using System.currentTimeMillis as a stopwatch, I've been attempting to use it in this application, and it fails when the user changes the time between the start and stop events. For example, the current time might be 3:09pm when the stopwatch starts timing a 5 minute event.

Then, at 3:11pm, the user may set the time ahead an hour, to 4:11pm. Then, 5 minutes later, the stopwatch stops, and calls System.currentTimeMilli's, which will return 4:14pm. The program will minus the two times and return a stopwatch elapsed time of 1 hour 5 minutes (instead of the correct 5 minutes)!!!

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.