BBB Arduino clock: resonator or crystal

Questions and Discussion concerning the Bare Bones Board
Post Reply
jftheoret
Posts: 2
Joined: Fri Apr 22, 2011 12:12 pm

BBB Arduino clock: resonator or crystal

Post by jftheoret » Fri Apr 22, 2011 12:17 pm

Hello,

I am trying to build a signal generator from an Arduino with a R2R ladder. I have two devices:

1. Arduino UNO with proper crystal;
2. Arduino Bare Bones Board with 16MHz Resonator.

For now, I'm just trying to determine the limits of the system, so I am basically just switching a pin ON and OFF (pin 3 in this case) as fast as I can with the following code:

Code: Select all

void loop() {
  cli();
  while (1) {
    PORTD |= 0x8;
    NOP;
    NOP;
    PORTD &= ~0x8;
  } 
}
I am noticing, however, very different quality results with both devices. Here are the scope traces for both:

Arduino UNO w/ crystal
Image

Arduino BBB with resonator
Image

I would rather use the BBB version, but clearly the signal quality sucks. I am wondering if this is only due to the crystal. Does anyone have a clue? If I build a BBB with a proper crystal instead of a resonator, will the signals be similar?

For what it's worth, here were the test differences:
1. Both were powered through USB, so I don't think voltage regulation could be the cause here.
2. The Uno was on its board, while the BBB was plugged in to a breadboard.
3. The BBB as the Optiboot bootloader while the Uno is factory default.

Anybody have a clue where I could investigate next (other than buying a new BBB and fitting it with a crystal)?

Thanks.

P.S. I've tried this with basic digitalWrite calls, and I I get a 20x speed drop :shock: Guess there's a lot of overhead on those calls...

paul
Site Admin
Posts: 730
Joined: Mon May 12, 2008 4:19 pm

Re: BBB Arduino clock: resonator or crystal

Post by paul » Fri Apr 22, 2011 2:57 pm

jftheoret,

Wow nice scope.

I'll be glad to send you a crystal to put on the BBB for testing. For that matter I'll be glad to send you another BBB - just for the testing and the great pictures. Just send me an email with your address.

Re: Signal quality: So this is a 2 Mhz signal and I believe one thing you may be seeing is the effect of the breadboard, which has a nice capacitor called "two breadboard clips" on it. Try pulling the BBB off the breadboard and putting the scope probes directly on the pins to see if there is any difference.

With all that said if the signal still looks gnarly you can solder up a crystal and see if it makes any difference. Or just lower the clock speed to around 32khz and I predict the signal will look peachy :)

As to the digitalWrite speed - a lot of ink has been spilled on that in the Arduino developer list. I thought David Mellis was going to write something into the next version of Arduino has a fast digitalWrite function. If you look at the source code of the digitalWrite function, it first has to map the pin to a port, check if PWM is on and finally set the pin. It is a lot of overhead.

Paul

jftheoret
Posts: 2
Joined: Fri Apr 22, 2011 12:12 pm

Re: BBB Arduino clock: resonator or crystal

Post by jftheoret » Fri Apr 22, 2011 3:33 pm

Yeah, I know about the scope :D I'm quite lucky! Nice first scope, isn't it? It's a 70 MHz 2000 Series (upgradeable to 100MHz or 200MHz when I need it/have the cash). I got a sweet deal on it.

I just did what you suggested - take it off the breadboard, and VOILÀ!

It was acting as a giant capacitor I guess.

Here are the results. It actually seems even better than the UNO! (I'll re-do some tests a little later and have more comparison points):

Arduino BBB with resonator OFF BREADBOARD
Image


Arduino BBB with resonator OFF BREADBOARD (detail)
Image

Now it's off to implementing the R2R DAC for signal generation :)

Thanks a lot for your help.

Post Reply