it-artikel:arduino:my-research-or-reaction-on-julian-investigates-how-slow-is-arduino-video
Differences
This shows you the differences between two versions of the page.
— | it-artikel:arduino:my-research-or-reaction-on-julian-investigates-how-slow-is-arduino-video [2022-08-31 12:30] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== My Reaction / Research on julian' | ||
+ | |||
+ | After i have seen Julian' | ||
+ | |||
+ | ===== 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), | ||
+ | |||
+ | <code c> | ||
+ | /** | ||
+ | * 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, | ||
+ | noInterrupts(); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | |||
+ | |||
+ | /* | ||
+ | * Using the Arduinos own loop() function AND | ||
+ | * these " | ||
+ | * only gives me a maximum switching | ||
+ | * frequency of 94.6KHz at ca 48% duty cicle. | ||
+ | | ||
+ | * See Scope Screenshot: | ||
+ | * http:// | ||
+ | */ | ||
+ | // digitalWrite(PIN, | ||
+ | // digitalWrite(PIN, | ||
+ | | ||
+ | |||
+ | /* | ||
+ | * 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:// | ||
+ | */ | ||
+ | // 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 " | ||
+ | * 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, | ||
+ | // digitalWrite(PIN, | ||
+ | |||
+ | /* | ||
+ | * 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:// | ||
+ | */ | ||
+ | // 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<< | ||
+ | PORTB |= 1<< | ||
+ | |||
+ | } // 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 " | ||
+ | * 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 " | ||
+ | |||
+ | --- // | ||
+ | |||
+ | {{tag> | ||
+ | |||