Atmel Atsamd21G18 Clock generation

Hi!

I want to use the Atmel Studio for programming the zero, so far so good but I struggle to generate the proper clock. If I only use the internal Clock the Core will run on 8Mhz.

If I use the "Fractional Digital Phase Locked Loop" to drive the Generic Clock Generator 0 (which drives the Core) I can achieve 48Mhz. But which reference Clock source do I use for the Fractional Digital Phase Locked Loop? The 32khz external crystal?

Or Do I just have to crank up the internal Crystal to 48Mhz by reducing the Oscillator Division Selector from 0xb to 0?

Is this correct (using the Locked Loop) ? https://www.dropbox.com/s/xr7tep3i6zginyl/image_clock.png

If you will look around on the forum you will find a post telling you where in the Arduino IDE you can find the start-up code used. You can copy the code from there. Are you successful getting Atmel Studio to program the Zero? I could not get Studio to accept the serial number of the EBDG.

If you cannot find the code I refer to, post again and from home I will find it. It was very helpful to me to learn how to manupulate registers. Also another post where there is a code link to print out register contents. With that and the SAMD datasheet I was successful getting the watchdog timer to work.

I started writing a library to dump out the SAMD21 registers: http://forum.arduino.cc/index.php?topic=362291.0

It's meant to be run from an Arduino sketch. This part looks relevant:

GCLK DFLL48M: GEN=0x1
GEN 0x0:  DFLL48M/1 IDC
GEN 0x1:  XOSC32K/1
GEN 0x2:  XOSC32K/16 DIVSEL
GEN 0x3:  OSC8M/1

There's a bug in my library: GEN2 is really divided by 32. (The code on github has already been corrected.)

The "GEN" are the generic clocks. On the Zero (and clones) XOSC32K is a 32.768kHz oscillator.

Hmm... I think the RTCZero library (which I used before capturing the above configuration) is what setup GEN2.

Unfortunately my library doesn't yet capture how DFLL48M is configured.

The Zero core file "startup.c" contains the code that sets up the generic clocks (GCLKs).

On my Windows machine it's currently located at C:\Users\Computer\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.2\cores\arduino\startup.c

Generic clocks 0-3 are used by the Zero's core, while 4-7 are free and available for user configuration.