TRYING TO TEST SPEED OF ARDUINO.

TRYING TO TEST SPEED OF ARDUINO... @ 16Mhz (The Uno is what I have), how fast can it simply print the time since the program/sketch started to a file/serial port...
[I plan to put the actual answers here, but Hutkikz has given a couple I was looking for...]

Using the IDE from Arduino, the Serial monitor, I simply want to write the smallest code possible, and see how fast it can simply send the time since it started, to a list, which I can read after, and see how many times it can execute that simplest possible code in one second.

THEN I can figure out how fast it can control several devices on the 20 or so pins I can use to control/sense other devices.
SO, here is the code I just tried, and either it does not load to the board, or I pull the USB and reconnect and it seems to upload, but then it wont open the COM1 port (Only on avail. in its list in 'Tools')...
Saying 'can't open device' and 'Access is denied', 'Problem uploading to board'...
"avrdude: stk500_recv(): programmer is not responding"

So what am I doing wrong?
I am trying to use the example code for "ReadAnalogVoltage" to start, and turning it into this...

void setup() {Serial.begin(9600);}

void loop() {
float TimeSinceStart = millis();
Serial.println(TimeSinceStart);
delay(500);

}

So is this code good? What is wrong? When the Serial Monitor does open, it shows only blank screen.
It said to set the Monitor and the Serial.begin() to 9600, so they are that way.

So is this code good?

So-so.
"millis()" returns an unsigned long, not a float.

Please get into the habit of using code tags when posting code.

And please don't hijack unrelated threads.

First off - this seems a new subject and I have suggested to the Moderator it be moved to its own Thread.

Second millis() returns an unsigned long rather than a float.

Float arithemetic is very slow so use integer maths everywhere you can.

In your example the delay(500); will govern the speed. However if you make the delay() very short you may find that the Serial output buffer fills up because the data cannot be sent fast enough at 9600 baud.

The Serial functions are themselves slow so they are not suitable for testing speed - unless you want to test the speed of Serial.

If you tell us what you actually want to do and how fast you want it to happen you may get a more useful answer.

One way to measure timing is to write a series of values into an array (perhaps 20 or 50 values) and time how long it takes to fill the array. When the array is full then you can print the results at leisure as the printing will not impact on the timing.

...R

Based on your idea, This is the smallest code using the fastest Serial baud rate available.

It printed an avg. 10 times per millisecond. that's 10,000 times per second avg.
Even at 250,000 baud the buffer would overflow in about a second.
Serial communication just can't keep up.

Of course this test means nothing. Actual code has many variations that effect how fast loop() will run. Properly written most programs should run thru loop() at 1k+ per second or more.

Using delay() is a real speed killer as it stops the arduino dead in it's tracks for the duration. it is best to avoid using it. See Blink Without Delay

void setup() 
{
Serial.begin(250000);
}

void loop() 
{
 Serial.println(millis());
}

HarleyBorgais:
TRYING TO TEST SPEED OF ARDUINO... @ 16Mhz

The speed of my UNO laying on the table and running @16MHZ is 0.000 miles per hour. ;D

jurs wrote:

The speed of my UNO laying on the table and running @16MHZ is 0.000 miles per hour. ;D

I like it, even my DUE running at 84MHz is, well, let's talk metric, 0 km/hr. Gosh, I better check the new i5 Intel next to see if I can catch it :smiley:

It all seems rather pointless to me.


Paul VK7KPA

rockwallaby:
It all seems rather pointless to me.

ACK, totally pointless as a "speed test" I'd say. But nevertheless the sketch code posted by the TO should work for quite a while after starting the sketch and opening the Serial Monitor while printing (roughly) each 500 milliseconds one line to the Serial Monitor.

If he just sees a blank Serial Monitor window he most likely forgot to set the baudrate to 9600 in the Serial Monitor window.

I cant find where my last post went, and the links in the 2 emails say it was split and moved, but dont take me anywhere but here.

I was asking why I cant seem to get my code to work:
Serial.println(millis());

which I am trying to use just to see how fast the processor is. I know its 16Mhz, but I am trying to use the simplest codes on infinite loops, which also report the time (Since the program started with the millis(s) command, or another method perhaps)...

So that I can figure out just how fast it can switch connected LEDs, Speakers, Motors, and other devices, on and off.
Example:
Can this 16Mhz Arduino Uno with I think 20 Pins I can use as outputs, switch all 20 pins on and off at 20,000hz? (Thats the fastest my ears can perceive, and eyes only go to 50 per second)

I know there are tones and PWM codes, but I want to convert to Analog, smooth control for the devices...
And I want to be able to know how fast this can control...however many devices (1 to however many it can, at 20,000 changes per second on each pin, ON or OFF, HIGH or LOW).

Then I can start to plan my projects, knowing what the limits are for this board.
16Mhz can process 100 Bytes in 1/20,000th of a second.
So it can process up to 5 Bytes for each one of 20 pins in one second.
So how much code actually has to be processed to do this...

Check if a pin is ON or OFF...
Check How Long since it was last changed...
Check an equation to calculate how long it should be before the next change, according to algorithms which I can nest or pile one on top of another, to get complex ON/OFF patterns (Faster than 20,000hz, for each pin, but how many can it do?).

THEN, I can plan projects to make LEDs and Speakers and Motors do many things I have been planning.
And then I can get an idea of what I need to purchase to make the items I want to make (the TinyDuino, TinyLily, TinkerKit, or whatever is smallest and most suited for each project).

THE POINT:
I am trying to find out how fast it can turn devices ON and OFF according to simple algorithms/equations, to find how many pins it is capable of controlling, ON and OFF, @ at least 20,000hz....
That way I know its limits and how to design the next projects.

P.S. I cant find my last post, the Email links go here, so please make sure that does not happen again when reviewing this one, or please insure I get direct links to the new posts, as I was told in emails it was moved and split.

http://forum.arduino.cc/index.php?topic=400905.0

Clicking on your name gets you to a profile page.
There you can see your posts (Show Posts).
Leo..

Here

Ok, first thank you, I am new to this, and figuring out how to do all these things for the first time.
Just found this page which helps me find how fast the Serial communication can work with my Arduino Uno from OSEPP...

So now, for my code...
The part with the delay I should not have there, that was just to see if it would make it start showing up in the Serial monitor window. So far I have not even achieved that.
All I have done so far is make the blink program with a bunch of different ON/OFF times and two LEDs on the OSEPP Motor Driver ($10 at Frys, Uno was $30, btw).
Those worked the first time, but now It fails to communicate with the Uno or the Monitor (Says Serial communication busy).

NOW, I am about to read all of what you have here (Now that I finally found it, from a link I just got in a new email a minute ago), and come back to make another UPDATE post, with my new code, and goal, and I'll figure out how to use Code tags (????Where do I look??? I'll figure it out)....

THIS IS BASICALLY MY ANSWER, THANK YOU...
"Actual code has many variations that effect how fast loop() will run. Properly written most programs should run thru loop() at 1k+ per second or more."

I meant to remove the delay, it was only a temporary test to try and get the Serial Monitor to work.
Your code there is exactly what I was going for.
Thank you.

NOW...
What I am trying to do is control LEDs, Motors, and Speakers, and other devices...
As fast as I can (On and Off)..
As many as I can (With my one Uno).

If I can see 50hz max and hear up to 17-20,000hz max, and there are 14 pins to use, then the fastest I would need a loop to run would be 14 x 20,000 = 180,000 x per second.

If its only running 1-10k, that is not enough to turn on and off one speaker faster than I can hear, but is plenty to flash an LED on every pin faster than I can see.

THAT WAS THE GOAL TO FIGURE OUT. THANK YOU.

You said:
"It printed an avg. 10 times per millisecond. that's 10,000 times per second avg.
Even at 250,000 baud the buffer would overflow in about a second. "

NOW...
The link I shared said the Uno can handle actually 2 million baud/pulses per second, so that may allow 8x the numbers you put there if I understand this right.

That would mean I can get 1 device to turn on and off at closer to 8-80,000 times a second.

BUT HERE IS WHERE I THINK I AM STILL CONFUSED...
I am trying to turn things ON and OFF... and it WILL be according to patterns, algorithms stacked on top of/nested inside of other algorithms (To create complex patterns where you cannot see a repeat)...

So then the speed at which it can process the bit of code to check a pin, check the time since last change, check the equation to find how long before it should change, and how, and then make the change...

Will be closer to the 1000 or 8000 times per second (If the baud max is a real reflection on how fast the Processor is actually processing the commands, which is what I am trying to test).

I CAN/COULD/Probably will test this by...
Setting as many pins to OUTPUT as I can (All 14 I think it is)...
Give each its own equation/pattern to its ON/OFF timing...
Set a loop which goes through each one in order, checking how long its been since the last change on that pin (Using the millis() command to see time since program started, or the MicroSecond one probably)...

and changing/flipping its setting (HIGH to LOW, or ON to OFF), then moving to the next pin...

And have it write to a file each time it checks one, and/or each time the loop runs...

AND THEN I will know the limits of what I can do with my future projects.
(Now I have to read the rest of your answers here. Thank you guys).

jurs:
If he just sees a blank Serial Monitor window he most likely forgot to set the baudrate to 9600 in the Serial Monitor window.

That I DID remember, as it was already there, but I clicked it to be sure it was set there.

I was thinking maybe the anti-virus is the problem, like the post I was originally posting this on...
But the blink programs were working just fine, so I think that means this is not the issue.

Oddly, I had to unplug and plug back in the USB Mini cable to the Arduino after trying to upload code a few times (I tried maybe 5 versions of the blink program, until it was flashing two LEDs with different complex patterns, about 70 lines of Code or so, VERY redundant...hence why I am planning to make functions and equations/algorithms next, for ON timeVsOFF time (One variable, the Duty cycle), peak voltage/brightness/volume, and wavelength/cycle time.

With those three variables, I can make Sine wave outputs, using a Tiny capacitor and MOSFET set up...
"A low pass filer as shown below..."... https://arduino-info.wikispaces.com/Analog-Output

...and then I have several inventions I plan to work on, which will operate motors and leds and speakers and other devices, using these, for multiple purposes.
The whole point being just to make patterns which are not annoyingly repeating, but are clearly patterns, such as the natural noises of Frogs, Crickets, and Birds, etc..
I have posted on my Facebook (HarleyBorgais) my progress, and the Waveforms of these species, so I plan to figure out the algorithms, and make functions which produce these sounds, and can be modified in all three variables, according to more patterns/algorithms/equations, to produce constantly changing patterns inside patterns inside patterns...etc.

SUMMARY OF THIS THREAD...
Hutkikz gave me exactly the code I was TRYING to make (See that post above)...

Except the thread I found says the serial port can go faster (2 Million per sec, instead of only 250,000 in that example above).

NOW, that is exactly the same as 16Mhz, if each pulse there in the serial port is taking 8bits/1byte of processing in the CPU. That might be the reason for that limit???
[Link to that chart: arduino uno smd - How high of a baud rate can I go (without errors)? - Arduino Stack Exchange ]

But he said that he got that simple loop (which only returns the time since the program started) to run 10,000 times a second.
THAT was the answer I was basically looking for.

Thats 1/25th then, of the Baud rate of the Serial com (250K), that it ran through that loop.

Then I guess the baud rate was NOT what limited that, but rather, it was the processor speed, processing the tiny bit of code?
If thats correct, then its processing 16Mhz/10Khz=1600bits per run of the loop, to process that simple loop in that example (which only returns time since program started, repeatedly).

That would be 200 bytes of data processed in the processor for just that one command.
Which is actually more than the total number of characters in the written Code I think.

So I doubt these numbers are correct.
I think it can go faster.

THE GOAL IS...
I'M TRYING to figure out how many devices it can simply turn on and off, according to different timing patterns for each pin, and how fast... with the goal of being faster than I can see or hear (As those are the max #s I will need), and to figure out how many devices I can operate that fast (one on each pin).
[Max 50hz for eyesight, 17-20,000hz for hearing, max speeds we can perceive. ]

THE PROBLEM, is that its apparently only able to operate multiple pins/devices, by checking one, maybe changing a setting, then checking another setting on another pin, maybe changing it, and going through one pin at a time (Of the ones activated/used in the Loop).

So I cant just have multiple programs running different timing patterns on multiple pins, but I have to have one program go from one pin to the next, as fast as possible, checking and changing settings according to equations/algorithms I set...
By creating Functions, blocks of code, which I can change the values in, and put on top of/inside of one-another, to create more and more complex patterns inside patterns...until you cant see any repeat, and they are pleasant to hear/see/feel (Depending on what sorts of devices I am building, and I have many planned).

NOW I NEED TO use the example code given here, test the same myself as they did, then start adding to the code and figure out just what I can make it do.
THEN I plan to come back here and share my results.
THANKS GUYS!

Hutkikz:
See Blink Without Delay

void setup() 

{
Serial.begin(250000);
}
void loop()
{
Serial.println(millis());
}

Now I see how to do the code tags (Lets test it)...
And that Blink Without Delay program is what showed me HOW I can make it control different things with different ON/OFF timings on different pins...
AND THATS WHAT LED ME TO THIS, to try and figure out just how fast it CAN do that.

AND I DID TRY THIS EXACT CODE TOO, but it failed, and I dont know why yet.
Now I have to get it all set up and try it again, and see what went wrong.
I was assuming it either was too fast for the Serial monitor (hence why I put in the delay command), OR..
It does not allow you to nest the
millis() command/function inside of the Serial.println() command/function (Which apparently is not the case, from the example given by Hutkikz).

I have not yet got the serial monitor to work, but I have got the flash LED programs to work (1st times too, but I had to upload, and it failed, then unplug and plug back in the USB cable, THEN upload again, and THEN it started flashing like I programed it to).

DOES THIS TELL YOU WHY MY SERIAL MONITOR HAS NOT WORKED?
(The errors were saying serial communications busy).
Well when I get back to it, I will come back here and tell you what happened.
Thanks again!

Hi,

SO, here is the code I just tried, and either it does not load to the board, or I pull the USB and reconnect and it seems to upload, but then it wont open the COM1 port

What version IDE are you using?
What model arduino are you using?
What PC are you using, sounds like a MAC :cry:

Thanks .. Tom.. :slight_smile:

@HarleyBorgais, I am finding this all very confusing. Please post the latest version of the program you are trying.

I have the impression you want to be able to do something which is well within the capacity of an Arduino but you are going about testing that in completely the wrong way.

Did you read Reply #2?

The demo Several Things at a Time is an extended example of BWoD and the same technique is used in Planning and Implementing a Program

...R

(The errors were saying serial communications busy).

I most often get this error when I try to open the serial monitor before the program has finished uploading.

The Arduino can only run one program at a time. indeed only one thread at a time. which is why we need to use timing code like blink without delay to perform multitasking.

That's not to say the Arduino can't be fast. it executes an instruction every 62.5 ns which is pretty quick. But many of the statements(commands) that make Arduino easy to use for beginners are also fairly slow. digitalWrite for example takes around 60-70 cycles to complete.

There are ways to increase that speed dramatically but often with the cost of added complexity. e.g."direct port manipulation"(search term) can control up to 8 pins at a time in a single instruction cycle.

Here are a few links that can get you up to speed.(bad pun intended)
Maximum pin toggle speed
Ready, Set, Oscillate! The Fastest Way to Change Arduino Pins
digitalWriteFast, digitalReadFast, pinModeFast etc -speed and easy to use

It seems my problem is not the code now, its something in the hardware or Drivers I think.

The help page says this (Below), but I do NOT find any of this in device driver.
It seems like the laptop is not responding to the Arduino when I plug it in.
But the Arduino definitely gets powered up and flashes and all that.
I have that Motor Driver from OSEPP to plug into it, which worked before.

I just tried to manually install the arduino.inf driver into the only COM port I have, COM1.
So now I am trying to figure out what is wrong here.

"Look under Ports (COM & LPT). You should see an open port named "Arduino UNO (COMxx)". If there is no COM & LPT section, look under "Other Devices" for "Unknown Device".
Right click on the "Arduino UNO (COmxx)" port and choose the "Update Driver Software" option. "

THE ERROR IT GIVES ME IS:

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xc3

Now what do I do?

HarleyBorgais:
Now what do I do?

Read carefully through all the replies you have received so far (2 or 3 times) to make sure you have not missed anything ?

Feedback from you about your understanding of the various replies helps us enormously.

...R