Teensy 2++ faster than ATMEL 328 ??

Status
Not open for further replies.

2n3055

Well-known member
Hello,

The teensy seems to be faster than the duemilanove (328); why?

Both are 16MHz.

I tried with this program:
Code:
//#define LEDTEENSY      PIN_D6 
#define LEDTEENSY      13  //for duemilanove


void setup()
{
  pinMode(LEDTEENSY, OUTPUT);
}

void loop() 
{   
  byte a,b, i;

  digitalWrite(LEDTEENSY, HIGH);   // set the LED on 
  for (int i=0; i<1000; i++) 
  {      
    delayMicroseconds(1);
  }
  digitalWrite(LEDTEENSY, LOW);   // set the LED off
  for (int i=0; i<1000; i++) 
  {    
    delayMicroseconds(1);
  }

}
f out with teensy 416Hz
f out 328: 377Hz

I tried another xtal but approx the same value!

Does anybody now why?
 
It could be anything really..(maybe the implementaion of the digitalWrite function?) but it is good practice to time your program independedly from the cpu performance.
E.g: If you had used pure delayMicroseconds(1000), without the loops, you'd get the same results with all different boards.
 
Many of the Arduino functions are implemented more efficiently in Teensyduino than Arduino.

Arduino's digitalWrite function is very slow. Teensy has a much faster one.

Arduino's delayMicroseconds function has a bug where it doesn't produce accurate delays under 3 us. Teensy's version is much better.

Many of the improvements I've made for Teensy have found their way into Arduino over the years. But some, like these, have been consistently rejected by the Arduino Team, even though I've tried to contribute and it's obvious many Arduino users want these improvements.

For a sad history of my attempt to contribute fast digitalWrite to Arduino since 2009, read this page:

http://code.google.com/p/arduino/issues/detail?id=140
 
thanks Paul, for correcting us.. and I've read the thread.. you did your best to help Arduino there!
I'm afraid Arduino on itself will get stuck if they cling to hard to old stuff, rejecting your improvements was not particularry intelligent imho.
Highlevel calls should be the standard to build upon, compromising the quality of the calls for backwardcomptability seems insane to me, because the version system of Arduino allows anyone to keep whatever Arduino version he/she needs on his/her computer! Thats the backward compatibility!
 
For digitalWrite, I originally implemented the const case optimization as a giant if-else chain. In fact, Teensyduino still has that version for Teensy 2.0.

On the Arduino Developers Mail List, in early November 2009, David Mellis specifically asked me to re-implement it using trinary operators. The he asked if anyone would do it for Arduino Mega, and as you can see, I did just a week later, on November 17, 2009.

Why he wanted that style is still a mystery to me. For a brief time, this optimization was actually committed to svn (back before they and everyone else switched to git/github). But ultimately he took the change out. The reasoning stated was that it duplicated the pins to registers mapping. Apparently he felt that would be simply too much long-term maintenance for Arduino and 3rd parties using the Arduino core for clones and close derivatives that use Arduino's published code with little or no modification.

Inside Teensyduino's core library, the pin mapping is defined in only 1 place. But instead of numerical constants populating an array, it's #define symbols. That allows the const case and non-const case to both compile from the same pin mapping info. It also provided AVR-based abstractions that allowed code to port easily between AVR-based boards.

This too I tried to contribute on several occasions in the 2009-2010 era. When they came out to Arduino Mega, it seems certain they'd have to go with this approach, or something more flexible. But instead, nearly all development continued on Duemilanove and later Uno, without any extra work on hardware abstractions or expanding the Arduino API beyond such basic functions. As a result, today lots of stuff simply doesn't work on Arduino Mega, and even moreso for Arduino Due, and newer 3rd party boards like Intel Galileo have horrible compatibility.

The only non-Uno Arduino board that actually is highly compatible today is Arduino Leonardo, and irs derivatives Yun & Micro. When Leonardo came out in 2012, I had spent nearly 3 years porting every widely used Arduino library to the 32u4 chip, so the Arduino folks have enjoyed a world where nearly all widely used code already had #ifdef __Atmega32U4__ embedded, even in their official libraries like Servo, SoftwareSerial and Firmata. It was much, much easier to contribute code to ALL the widely used libraries than to get Arduino to accept just 1 contribution to make things cross-board compatible.

About a year ago, David Mellis stepped down as Arduino's software lead, replaced by Cristian Maglie. Cristian seems far more open to ideas and contributions. Had he been the software lead before I was working so heavily on Teensy 3.x, and many others were offering contributions, Arduino as a platform would have probably turned out quite a bit differently.

I've had far less time for Arduino contributions since about April 2012, when nearly all my development time shifted to ARM and Teensy3. I'm far behind where I wanted to be on the audio library, but steady progress is being made. I have some other big plans for the Teensy3 platform later this year, which are going to keep me really busy.

My hope is sometime in 2015 or 2016, Teensy 3.x will be a very mature platform and maybe I'll get a year or two to really work on a lot of Arduino contributions and other stuff that isn't basically starting it all over again on a new platform. The newest, latest and greatest hardware is sexy and it's what sells, but that not-to-glamorous work on software infrastructure and refining usability and thousands of tiny details so everything "just works" is what really makes for a first class experience when people build projects.

If only there were a LOT more hours in every day....
 
When Leonardo came out in 2012, I had spent nearly 3 years porting every widely used Arduino library to the 32u4 chip, so the Arduino folks have enjoyed a world where nearly all widely used code already had #ifdef __Atmega32U4__ embedded, even in their official libraries like Servo, SoftwareSerial and Firmata. It was much, much easier to contribute code to ALL the widely used libraries than to get Arduino to accept just 1 contribution to make things cross-board compatible.

Did I read it right the Leonardo and the Teensy 2 are at the same speed Level?
 
Both Teensy 2.0 and Arduino Leonardo use the Atmel ATMEGA32U4 chip running at 16 MHz. They have identical speed when running identical code.

Teensyduino does not use identical code as Arduino, so when you run Arduino sketches, Teensy 2.0 often runs faster than Arduino Leonardo.
 
I'm totally new to Teensy and relatively new to Arduino, though I've written many sketches for the atmega32u4 chip in the smaller micro and pro micro boards. I'm wondering why the PIN numbers and functions differ in Teensy 2 and where the i2c pins would be. Thanks
 
Status
Not open for further replies.
Back
Top