SAMR21: How to select the 1024Hz output from the OSCULP32K

Discussions around product based on ARM Cortex M0+ core.
This forum will be discontinued soon.

Moderator: nferre

gussabina
Posts: 12
Joined: Sat Mar 28, 2015 6:49 am

SAMR21: How to select the 1024Hz output from the OSCULP32K

Wed Dec 09, 2015 5:18 am

Hello All:

I'm working with SAMR21/D21 and I want to have the RTC running while the device is in Standby mode. According to Datasheet, it mentions the following;

The OSCULP32K is enabled by default after a power-on reset (POR) and will always run except during POR. The
OSCULP32K has a 32.768kHz output and a 1.024kHz output that are always running.

I can't figure out how to select between the 32.768Hz and the 1.024Hz outputs....

I would appreciate any help on this.

Regards;
Gus
elektrobjorn
Posts: 7
Joined: Thu Sep 10, 2015 11:10 am

Re: SAMR21: How to select the 1024Hz output from the OSCULP3

Thu Dec 10, 2015 8:23 pm

It appears that the 1 kHz output is only used internally, to clock the brown-out detector. It is not available as a clock source for the application.
Refer to the SAMD21 data sheet, paragraphs 16.6.9.3 and 16.8.14.
sarlacii
Posts: 68
Joined: Mon Jan 26, 2015 2:33 pm

Re: SAMR21: How to select the 1024Hz output from the OSCULP3

Tue Dec 15, 2015 12:07 pm

elektrobjorn wrote:It appears that the 1 kHz output is only used internally, to clock the brown-out detector. It is not available as a clock source for the application.
Refer to the SAMD21 data sheet, paragraphs 16.6.9.3 and 16.8.14.
Correct, the two appear to be mutually exclusive, according to past threads on this forum. You need to enable the internal 32k source, and then declare a suitable "Generator" source to give you the 1024Hz you require. You then configure the RTC to use the newly created generator. Using the ASF, you can do as follows:

In conf_clocks.h:

Code: Select all

/* SYSTEM_CLOCK_SOURCE_OSC32K configuration - Internal 32KHz oscillator - 32768Hz (/32 = 1024Hz) */
// Use for WDT in place of th ULP source? Yes! Use for RTC too.
#  define CONF_CLOCK_OSC32K_ENABLE                true
#  define CONF_CLOCK_OSC32K_STARTUP_TIME          SYSTEM_OSC32K_STARTUP_130
#  define CONF_CLOCK_OSC32K_ENABLE_1KHZ_OUTPUT    false	// See AT91 forum. It appears that 1k and 32k settings are mutually exclusive (XOR). Also, 1k setting seems to kill the clock output. So disable 1k.
#  define CONF_CLOCK_OSC32K_ENABLE_32KHZ_OUTPUT   true
#  define CONF_CLOCK_OSC32K_ON_DEMAND             false // Always run - we will also use this clock for our WDT... should use ULP clock, but for some reason that is not set by ASF, so till I get time to do it... use this one.
#  define CONF_CLOCK_OSC32K_RUN_IN_STANDBY        true
and also, in this case we have declared generator 2 for use with the RTC:

Code: Select all

/* Configure GCLK generator 2 (RTC) */
// Running our RTC in Calendar with Callback mode. From std 1kHz clock as per this generator.
#  define CONF_CLOCK_GCLK_2_ENABLE                true
#  define CONF_CLOCK_GCLK_2_RUN_IN_STANDBY        true
#  define CONF_CLOCK_GCLK_2_CLOCK_SOURCE          GCLK_SOURCE_OSC32K						//SYSTEM_CLOCK_SOURCE_OSC32K from enum dec in clock.h... which generates a warning, so use define value instead
#  define CONF_CLOCK_GCLK_2_PRESCALER             32 // Output is 1024Hz - valid prescaler values: 1x to 128x division
#  define CONF_CLOCK_GCLK_2_OUTPUT_ENABLE         false
The RTC is then configured to use this generator in rtc_calendar_init (rtc_calendar.c):

Code: Select all

gclk_chan_conf.source_generator = GCLK_GENERATOR_2;
Go well.

Return to “SAM D20 Cortex-M0+ MCU”

Who is online

Users browsing this forum: No registered users and 1 guest