SAMD20 RTC

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello. I have the following code (in my conf_clocks.h)

/* SYSTEM_CLOCK_SOURCE_OSC32K configuration - Internal 32KHz oscillator */
#  define CONF_CLOCK_OSC32K_ENABLE                true
#  define CONF_CLOCK_OSC32K_STARTUP_TIME          SYSTEM_OSC32K_STARTUP_130
#  define CONF_CLOCK_OSC32K_ENABLE_1KHZ_OUTPUT    false
#  define CONF_CLOCK_OSC32K_ENABLE_32KHZ_OUTPUT   false
#  define CONF_CLOCK_OSC32K_ON_DEMAND             true
#  define CONF_CLOCK_OSC32K_RUN_IN_STANDBY        false

/* Configure GCLK generator 2 (RTC) */
#  define CONF_CLOCK_GCLK_2_ENABLE                true
#  define CONF_CLOCK_GCLK_2_RUN_IN_STANDBY        false
#  define CONF_CLOCK_GCLK_2_CLOCK_SOURCE          SYSTEM_CLOCK_SOURCE_OSC32K
#  define CONF_CLOCK_GCLK_2_PRESCALER             32
#  define CONF_CLOCK_GCLK_2_OUTPUT_ENABLE         false

From my understanding, the RTC (GCLK2) is getting clock source from the internal oscillator of 32KHz. As far as I know, along with my external oscillator of 32KHz, these are not 32KHz but 32.768KHz. Right?

Now, having a prescaler of 32 on GCLK2, that means that my clock generator will be ticking 32768/32 = 1024 times per second. Right?

Now, I put the following code in my main.c:

void configure_rtc_count(void)

{

struct rtc_count_config config_rtc_count;

rtc_count_get_config_defaults(&config_rtc_count);

config_rtc_count.prescaler           = RTC_COUNT_PRESCALER_DIV_1;

config_rtc_count.mode                = RTC_COUNT_MODE_16BIT;

config_rtc_count.continuously_update = true;

config_rtc_count.compare_values[0]   = 1000;

rtc_count_init(&rtc_instance, RTC, &config_rtc_count);

rtc_count_enable(&rtc_instance);

}

int main (void) {

system_init();

/* Insert application code here, after the board has been initialized. */

configure_rtc_count();

configure_port_pins();

if (rtc_count_set_period(&rtc_instance, 1000) != STATUS_OK) {}

while (true) {

if (rtc_count_is_compare_match(&rtc_instance, RTC_COUNT_COMPARE_0)) {

/* Do something on RTC count match here */

port_pin_toggle_output_level(LED_0_PIN);

rtc_count_clear_compare_match(&rtc_instance, RTC_COUNT_COMPARE_0);

}

}

}

Having RTC_COUNT_PRESCALER_DIV_1 on my RTC means that still my RTC is clicking at 1024 times per second (1024Hz). But this does not seem to be the case.

I have set both the config_rtc_count.compare_values[0] and the rtc_count_set_period at 1000 and 1024 and I can confirm timing 2 whole minutes (60 led blinks) that the RTC is ticking at 1000Hz since when I set them both at 1024, it takes 2 mins and 4 secs.

Am I missing something here?

 

Thank you very much.

Last Edited: Thu. Feb 22, 2018 - 07:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can someone verify me that the two Internal clocks 32kHz and ULP clock 32kHz operate on 32000 hertz and not on 32768 hertz?