Pages: [1]   Go Down
Author Topic: need an estimate of time required to scan 11x8 matrix  (Read 1123 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to use an adriuno micro to scan a 8 x 11 matrix.  i need to do this in under 2ms, maybe 1ms, possibly including debounce.  I am a noob.  About how much time will it take to do this scan?

Thanks, Mike
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Depends on what you mean by "scan" and "matrix". If you're talking about iterating through a multidimensional array of ints looking for a specific value, then it shouldn't be a problem.The Arduino Micro runs at 16MHz. That's 16,000 instructions per mS. That would give you an average of 181 instruction per item in this "matrix" to do whatever you need to do to "scan" it.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This functions exactly like a standard keyboard matrix,  I the need to detect and identify the switch the closed for the 88 possible switches (only one switch will be actuated at a time) in under 2ms, as their closure time could be as little as that.   So, the polling cycle needs to be less than 2ms.  I would do this with pull ups on the output side.
Logged

Montreal
Offline Offline
Edison Member
*
Karma: 23
Posts: 2487
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 DigitalWrite digitalRead , AFAIK, takes 4 - 5 usec. 88 x 5 = 440 usec. You have half a millisec to do something else. Way to accelerate, direct readings/writing port register, especially if all 8 lines belong to same port you can read in 2 cycles CPU (125 nanosec.)
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 444
Posts: 23861
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Why not try it with the Keypad.h library, see if its fast enough?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am unfamiliar with how i could get the time used by using the library

Mike
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 444
Posts: 23861
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Add some start_time = millis() and end_time = milis() statements in your code, see how long it takes to get thru the code.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Montreal
Offline Offline
Edison Member
*
Karma: 23
Posts: 2487
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Something like this:
Code:
time_start = micros();

    fix_fftr( fx, FFT_SIZE );

time_fft  = micros() - time_start;
You checking time - micros() before and tight after some procedure, than printing out via serial monitor your results.
 Arduino scetch as an example , linked at this page:
http://coolarduino.wordpress.com/2011/09/03/arduino-musical-note-recognition-pushing-the-limits/
Logged

Phillipsburg, NJ
Offline Offline
Full Member
***
Karma: 6
Posts: 174
Author: Matrix Keypad Library
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why not try it with the Keypad.h library, see if its fast enough?
I throttle the keypad library so a slight modification would be required before he could do this.  I tested a sketch with the throttling removed and just as Magician said it requires 448uS per loop.  Of course that includes the entire sketch so his calculated value of 440uS is slightly more accurate.
« Last Edit: January 17, 2013, 06:34:11 pm by mstanley » Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 65
Posts: 6937
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You should read up what debunce means. You can't debunce in a millisecond.
Logged


Offline Offline
Edison Member
*
Karma: 29
Posts: 2048
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How do you know only one button will be pushed at a time ?
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 444
Posts: 23861
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Because that's the stated requirement smiley-wink
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Phillipsburg, NJ
Offline Offline
Full Member
***
Karma: 6
Posts: 174
Author: Matrix Keypad Library
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You should read up what debunce means. You can't debunce in a millisecond.
Actually it might be possible.  I use a state machine to debounce after scanning so if his hardware needs to have the scan completed in 1mS the debouncing could be completed separately.  Some things would need to be stripped out of the code but who knows what might work.

How do you know only one button will be pushed at a time ?
If your requirement is to test for a single button then you simply ignore everything else after detecting the first one.

Another way is to store Highs and Lows into an array for ALL the buttons that are being pushed.  Then you can post-process the array any way you like.  With a 1mS time limit I assume that his hardware is not a keyboard and may return multiple detections per scan.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 65
Posts: 6937
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You should read up what debunce means. You can't debunce in a millisecond.
Actually it might be possible.  I use a state machine to debounce after scanning so if his hardware needs to have the scan completed in 1mS the debouncing could be completed separately.  Some things would need to be stripped out of the code but who knows what might work.

Same with my phi_interfaces library. You just can't debounce in 1ms but you can finish a scan within 1ms and debounce with state machine.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you everyone for your input.

This is an attempt to hack a electronic soft tip dartboard.  Research on the internet indicates that the pulse could be as little as 1ms and as much as 4ms.  Hard thrown darts sometime cause false readings in some false sectors.  It is possible that i will find simply ignoring any other switch closures past the initial detection with a delay will be effective.  I suspect that no the hit sector would always be closed first before any other chatter on other sectors would occur.  I will find out with testing and experimentation.  The reason I ask the original question is that I have not yet purchased the board, and I don't want to go thru to process of doing this and fail due to hardware limitations.  After I determine a dart has registered, I will send the information to a pc by emulating an usb keyboard, where the input will be used by an external program.

So in short, It sounds like this should work.  My plan would be to set all outputs low and use the chip pullups on the inputs.  Continuously scan the inputs, upon detection, start setting the outputs high one at a time and recheck the input for a change in status.  Once found, delay(possibly) set all outputs high except the active pin, and re query inputs to confirm correctness.  So, from the initial detection to the confirmation i need to be under 1ms.  Data intperpretation and transfer can be handled afterwards easily.  After 1 second delay or so, the whole thing resets and stars over.

Any further conformations or opinions about my plan would be appreciated.  If the opinion is that it isnt fast enough, I will look into a faster board, such as an arduino due.

Thanks, Mike
Logged

Pages: [1]   Go Up
Jump to: