Hi Claes,
I have found why/when the Arduino is slow.
It's because of the Arduino’s digitalWrite() command.
The same problems with a analogWrite() which takes longer than the digitalWrite().
Because of simplicity the pins are labeled, by the makers of the Arduino, as digital 0-13 and analog 0-5. The ATMega chip’s pins are labeled differently.
The trick seems to be to use “true c” style commands, what the AVR compiler uses.
void setup()
{
Serial.begin(9600);
}
void loop()
{
int initial = 0;
int final = 0;
initial = micros();
for(int i = 0; i < 500; i++)
{
digitalWrite(13,HIGH);
digitalWrite(13,LOW);
}
final = micros();
Serial.print(\"Time for digitalWrite(): \");
Serial.print(final-initial);
Serial.println(\"\");
initial = micros();
for(int i = 0; i < 500; i++)
{
PORTB = 0b00100000;
PORTB = 0b00000000;
}
final = micros();
Serial.print(\"Time for true c command: \");
Serial.print(final-initial);
while(1);
}
Off topic:
The cheap balance system with a metal ball is still playing my mind......
If on the axis is a stepper and a potentiometer I can only see an undefined area (when the coils of the stepper are not activated) where the ball it can't win from the \"friction\"....