it-artikel:arduino:my-research-or-reaction-on-julian-investigates-how-slow-is-arduino-video

My Reaction / Research on julian's investigates how slow is arduino youtube video

After i have seen Julian's YouTube Video ( https://youtu.be/U7I0GkwW1yE ) on Arduino Microcontrollers i was courious about if the Arduino is really that slow and so i wanted to test it myself, trying out multiple methods to switch on and of a single pin on the arduino as fast as we can. This Page summarizes my results and shows the oscilloscope (scope) Screenshots and code that i have made and used.

The Task : Switch on and off a single arduino pin as fast as we possibly can using Arduino IDE (C language)

Here is the Code i used to measure the different methods and ways to achieve that. Please note that i dont just run this Code with all the different methods enabled (uncommented), but uncomment one method a time.

/**
 * this is some test code to test arduino speed.
 * just switching on and off one single digital pin as fast
 * as i can, just to see and measure with an osciloscope how 
 * fast switching by C code can be achieved.
 * 
 * Using an Arduino Uno at 16Mhz with Arduino IDE 1.6.7 (Linux) 
 * and a HAMEG (Rhode & Schwarz) HMO2024 Oscilloscope
 * 
 * by Axel Werner [axel.werner.1973@gmail.com]
 */
 
 
#define PIN 12
 
 
void setup() {
  pinMode(PIN, OUTPUT);
  noInterrupts();
}
 
void loop() {
 
 
  /*
   * Using the Arduinos own loop() function AND 
   * these "arduino" methods to set and reset a pin
   * only gives me a maximum switching
   * frequency of 94.6KHz at ca 48% duty cicle. 
   * 
   * See Scope Screenshot:
   * http://www.awerner.myhome-server.de/lib/exe/fetch.php?media=it-artikel:arduino:test-how-fast-is-arduino-using-arduino-loop-digitalwrite.png
   */
//  digitalWrite(PIN,HIGH);
//  digitalWrite(PIN,LOW);
 
 
  /*
   * Using the Arduino loop() function but using bit wise 
   * operation on a data register to loop through 
   * on and off state of a pin gives me a maximum switching
   * frequency of 999KHz at ca 87.5% duty cicle . 
   * 
   * See Scope Screenshot:
   * http://www.awerner.myhome-server.de/lib/exe/fetch.php?media=it-artikel:arduino:test-how-fast-is-arduino-using-arduino-loop-bitwise-setreset.png
   */
//  PORTB &= 0<<4; // PORT B Bit 4 is Arduino Pin 12
//  PORTB |= 1<<4;
 
 
  while(1){ // using my OWN (real) loop now...
    /*
     * with my own while loop and these "arduino" methods 
     * a maximum switching frequency of only ca. 97.5 KHz 
     * at a perfect 50% duty cicle has been achieved
     * while the interupts where disabled. 
     */
//    digitalWrite(PIN,HIGH);
//    digitalWrite(PIN,LOW);
 
    /*
     * Both bit operation methods work effectively the same
     * when it comes to timing. A maximum switching frequency of 2.66MHz at
     * ca 66.8% duty cicle has been achieved. Even while Interrupts enabled.
     * 
     * See Scope Screenshot:
     * http://www.awerner.myhome-server.de/lib/exe/fetch.php?media=it-artikel:arduino:test-how-fast-is-arduino-using-own-while-loop-and-bitwise-setreset.png
     */
    //    PORTB = PORTB & B11101111; // clearing bit 4
    //    PORTB = PORTB | B00010000; // setting bit 4
 
    //    PORTB &= 0<<4; // Just another way to write it.
    //    PORTB |= 1<<4;
 
    PORTB &= 0<<PB4; // Yet another way to write it, using Atmels Port-/Register- and Pin-Names 
    PORTB |= 1<<PB4;
 
  } // end of MY while loop.
} // end of Arduinos loop() function. 

See C Code for Screenshot-URLs. Just klick on them. Or see them here out of context.

  • Using the Arduinos own loop() function AND these “arduino” methods to set and reset a pin only gives me a maximum switching frequency of 94.6KHz at ca 48% duty cicle.
  • Using the Arduino loop() function but using bit wise operation on a data register to loop through on and off state of a pin gives me a maximum switching frequency of 999KHz at ca 87.5% duty cicle .
  • With my own while loop and these “arduino” methods a maximum switching frequency of only ca. 97.5 KHz at a perfect 50% duty cicle has been achieved while the interupts where disabled.

Axel Werner 2016-01-28 16:55

it-artikel/arduino/my-research-or-reaction-on-julian-investigates-how-slow-is-arduino-video.txt · Last modified: 2022-08-31 12:30 by 127.0.0.1