
Originally Posted by
Adlibber
Just completed a main.S for the blink programme. Blown away by the performance of this little machine (Teensy 4.1). The Assembler version is four times faster than the C code: the uncalibrated delay loop requires 100,000,000 cycles to achieve a delay of approximately half a second. Thats about three clocks a loop!
But how any beginner could have got to this stage without all the demo code available is beyond me. Understanding the i.MX RT1060 manual is not a logical statement.
Indeed the T_4.1 is fast - and PJRC support code makes avoiding the RefManual generally easy
- and the resulting code is tested for correctness and presented for use.
Would be cool to see that on a thread. ASM.s code used versus c code for blink - not sure what it entailed?
This C sketch toggles LED pin 100M times in one third of a second just over 2.0 cycles per loop and second loop watches for half second of cycles to pass and only completes 60M cycles - so 10 cycles per loop with ref of the CYCCNT taking 3 cycles IIRC:
Code:
void setup() {
while (!Serial && millis() < 4000 );
Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
pinMode( 13, OUTPUT );
uint32_t tClk = ARM_DWT_CYCCNT;
int ii;
for ( ii = 0; ii < 100*1000*1000; ii++ ) digitalToggleFast(13);
tClk = ARM_DWT_CYCCNT - tClk;
Serial.printf("[100M] %lu loops LED toggle in cycles %lu\n", ii, tClk);
Serial.printf("[100M] %lu loops LED toggle in Sec %f\n", ii, 1.0*tClk/F_CPU_ACTUAL);
tClk = ARM_DWT_CYCCNT;
for ( ii = 0; ii < 100*1000*1000; ii++ ) if ( ARM_DWT_CYCCNT-tClk > F_CPU_ACTUAL/2) break;
tClk = ARM_DWT_CYCCNT - tClk;
Serial.printf("%lu loops test to half Sec in cycles %lu\n", ii, tClk);
Serial.printf("%lu loops test to half Sec %f\n", ii, 1.0*tClk/F_CPU_ACTUAL);
}
void loop() {}
Output:
Code:
T:\tCode\FORUM\MinWait\MinWait.ino Mar 8 2021 17:15:59
T:\tCode\FORUM\MinWait\MinWait.ino Mar 8 2021 17:27:39
[100M] 100000000 loops LED toggle in cycles 200010460
[100M] 100000000 loops LED toggle in Sec 0.333351
59996864 loops test to half Sec in cycles 300000012
59996864 loops test to half Sec 0.500000