Atmega328 clock swaying

I'm a relative newbie to this so it seems like an odd question but probably one with an easy answer.

I created a sketch on my Uno and everything works right. Lots of LEDs blinking at certain intervals with some sound. When I uploaded it to my ATMmega328 the sketch works, But every once in a while the timing goes off.

To test, I simply hooked up to LEDs. One goes on for a second and off for half a second, the other goes on for 700 milliseconds and all for 500 milliseconds. They work for a while, then every once in a while one will lag in either the on or off position or both will, then they go back into sync.

I have an oscillator on pins 9 and 10 along with a 22pF capacitor on each leg.

Any thoughts would be helpful. Thanks!

And . . ?

I'm not sure what you mean by and? I'm trying to figure out how to get the timing right now with the crystal.

It means "and what else do you want to tell us?"

I'm trying to figure out why the external clock is not keeping time. Did I miss a step? Did I hook up something wrong? I'm not sure what else you might need to know

Would you be kind enough to upload your sketch for people to check over? Autoformat it first using Tools | Autoformat. Then Edit | Copy for forum and paste into the forum text box.

You missed the step where you post your schematic and your code

Maybe you should've led with that :slight_smile:

#include <jled.h>
 
const int pinStrobeLights = 12;
const int pinNavLights = 4;

auto strobeLights = JLed(pinStrobeLights).Off();
auto navLights = JLed(pinNavLights).Off();

void setup() {
  strobeLights = JLed(pinStrobeLights).Blink(75, 925).Forever();
  navLights = JLed(pinNavLights).Blink(1000,500).Forever().DelayAfter(700);
}

void loop() {
  navLights.Update();
  strobeLights.Update ();
}  

I should also mention it's a 16 mHz crystal

You should mention it is a 16MHz crystal.
Or so I would hope.

What happens with a simple blink sketch?
Not everyone has that library.