If that statement even makese sense because clock speed is probably not the same as the execution speed of loop()?
I am using an Arduino UNO R3 with an Atmega328P U on top.
As I'm rather new to microcontrollers I would like to understand "how fast" they are. Particularly because when it comes to data transmission I'm aware that there's some limitations to what I'll be able to do.
However, I thought I can go simple about it and just see how many times I can increment a counter for each loop. Since printing something to the console takes time I count up for two seconds (=2,000,000 mircoseconds) and divide by two:
unsigned long startTime = micros();
unsigned long counter = 0;
void loop() {
unsigned long elapsedTime = micros() - startTime;
if (elapsedTime >= 2000000) {
Serial.println(counter >> 1);
startTime = micros();
counter = 0;
}
counter += 1;
}
Unless I have an error, it looks like the loop() runs at around ~177kHz which is not really what I expected:
With 'counter' I suppose you are trying to measure loop() execution time. But I'm not at all clear, why you think this should run at 128kHz or for that matter, and any known rate?
When you compile the code, what you end up with is some arbitrary number of machine cycles measured in this case, in a few hundred. There is also some overhead in the repetitive call to loop() that the core makes.
The IC has clock options, if you read the data sheet you can find out what they are. But the one you are holding, probably has the standard fixed 16MHz external oscillator.
The 128kHz figure is for a clock configuration that you are not using at all.
So that would actually mean that the clock speed must be higher than 128kHz right?
Otherwise I wouldn't be able to count up 177k-times per second. Therefore I can probably assume that the clock speed is 1MHz or 8MHz (rather 1 than 8)?
I was just assuming that the internal clock of the chip is being used. Didn't know that the Arduino provides an external clock to it.
Okay, that's certainly interesting. If somebody asked my "how many times do you think this thing can 'add one' to an integer given the clock speed is 16MHz" I would have said "more than 177k-times".
What did you run the tests on? If you Googled and found the data sheet and spent a little time there, you would know about the multiple clock options I mentioned.
Well yeah, I get it. The chip consumes perhaps a number of cycles in order to perform one instructions. My understanding of hardware got a little rusty over time.
It isn't just that. The software requires a number of instructions to perform each one of certain high level (C/C++) operations as well...
I commend your curiosity but you are looking in the wrong place, you just need to do some reading of original documentation, and tutorials and other reference material.
I'm not telling you to do, anything I didn't have to do.