What's going on?
what's going on?
i purchased nice new digital scope, , thought i'd @ arduino nano's speed performance.
here's code - toggling pin in various ways.
note 5 versions . vary in use direct port writes vs digitalwrite, , in embedding of while(1) inside normal loop{} test that's performance.
the scope pictures appended.
some things become clear.
digitalwrite incredibly slow. 6-8us write pin . that's around 100 instructions @ 16mhz ( checked - 15.973mhz - pretty good)
why?
the loop{} seems take 6 go round - why? - it's jump label.
the while(1) reasonably ok - test 'one' seems take 1 instruction.
there's continuous processor stop every millisecond or - presumably corect millis() count. takes again 8us - it's simple interrupt incrementing counter - doesn't take 100 instructions!
just curious - , can turn millis() stuff off time critical stuff doesn't need it?
allan
i purchased nice new digital scope, , thought i'd @ arduino nano's speed performance.
here's code - toggling pin in various ways.
code: [select]
//1: newfile1,2,3.png
void loop() {
while (1) {
portd |= 0x20;
//digitalwrite( pulsepin , high);
portd &= 0xcf;
// digitalwrite( pulsepin , low);
}
}
//2:newfile4.png
void loop() {
while (1) {
//digitalwrite( pulsepin , high);
portd &= 0xcf;
// digitalwrite( pulsepin , low);
portd |= 0x20;
}
}
//3:newfile5.png
void loop() {
// while (1) {
//digitalwrite( pulsepin , high);
portd &= 0xcf;
// digitalwrite( pulsepin , low);
portd |= 0x20;
// }
}
//4: newfile6.png
void loop() {
// while (1) {
portd |= 0x20;
//digitalwrite( pulsepin , high);
portd &= 0xcf;
//digitalwrite( pulsepin , low);
// }
}
//5: newfile7.png
void loop() {
// while (1) {
// portd |= 0x20;
digitalwrite( pulsepin , high);
// portd &= 0xcf;
digitalwrite( pulsepin , low);
// }
}
note 5 versions . vary in use direct port writes vs digitalwrite, , in embedding of while(1) inside normal loop{} test that's performance.
the scope pictures appended.
some things become clear.
digitalwrite incredibly slow. 6-8us write pin . that's around 100 instructions @ 16mhz ( checked - 15.973mhz - pretty good)
why?
the loop{} seems take 6 go round - why? - it's jump label.
the while(1) reasonably ok - test 'one' seems take 1 instruction.
there's continuous processor stop every millisecond or - presumably corect millis() count. takes again 8us - it's simple interrupt incrementing counter - doesn't take 100 instructions!
just curious - , can turn millis() stuff off time critical stuff doesn't need it?
allan
we aware digitalwrite() slow - seems reasonable price convenience.
it seems me detailed explanations , other questions lie in study of arduino source code included ide.
a lot of arduino system focused on convenience rather absolute performance.
i presume can modify source code prevent millis() working if necessary.
...r
it seems me detailed explanations , other questions lie in study of arduino source code included ide.
a lot of arduino system focused on convenience rather absolute performance.
i presume can modify source code prevent millis() working if necessary.
...r
Arduino Forum > Using Arduino > Programming Questions > What's going on?
arduino
Comments
Post a Comment