Page 1 of 1

BBB Arduino clock: resonator or crystal

Posted: Fri Apr 22, 2011 12:17 pm
by jftheoret

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() {
  while (1) {
    PORTD |= 0x8;
    PORTD &= ~0x8;
I am noticing, however, very different quality results with both devices. Here are the scope traces for both:

Arduino UNO w/ crystal

Arduino BBB with resonator

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)?


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...

Re: BBB Arduino clock: resonator or crystal

Posted: Fri Apr 22, 2011 2:57 pm
by paul

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.


Re: BBB Arduino clock: resonator or crystal

Posted: Fri Apr 22, 2011 3:33 pm
by jftheoret
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

Arduino BBB with resonator OFF BREADBOARD (detail)

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

Thanks a lot for your help.