Problems using RTC

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

I have an xmega192A3 with a 32.768kHz crystal on the TOSC pins. All i'm trying to do is get a 1Hz overflow interrupt.

My code:

	// real time clock configuration
	sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_RTC);
	//Wait until RTC is stable
	CLK.RTCCTRL = CLK_RTCSRC_TOSC_gc | CLK_RTCEN_bm;
	//CLK.RTCCTRL = CLK_RTCSRC_RCOSC_gc | CLK_RTCEN_bm; // this works
	while (RTC.STATUS & RTC_SYNCBUSY_bm);
	RTC.PER = 1023;
	RTC.CNT = 0;
	RTC.COMP = 0;
	
	/* Since overflow interrupt is needed all the time we limit sleep to
	 * power-save.
	 */
	sleepmgr_lock_mode(SLEEPMGR_PSAVE);
	RTC.INTCTRL = RTC_OVFINTLVL_LO_gc;
	RTC.CTRL = RTC_PRESCALER_DIV1_gc;	


// RTC timer overflow
ISR(RTC_OVF_vect)
{
	LED_PORT.OUTTGL = LED1;
}

This works fine for the internal oscillator, but the external crystal fails.

Any ideas?

Last Edited: Tue. Aug 16, 2011 - 09:25 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you have a scope to verify that it's oscillating ? You have to enable XOSCEN and XOSCSEL[3:0], may be others. Either the XTAL's not working at the pin, you're missing some config. bits or both .

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

Last Edited: Fri. Aug 12, 2011 - 02:58 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Solder the crystal directly onto the TOSC pins.

Why is the RTC.COMP = 0? Shouldn't it be 1 count higher than the counter?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There's no sign of life on the TOSC pins at all.

If i truly have to use XOSCEN and XOSCSEL, then that's really bad, because that would mean that you can't use an RTC crystal and a regular crystal at the same time. Why would you have separate pins for XOSC and TOSC if they are mutually exclusive?

Quote:
Why is the RTC.COMP = 0? Shouldn't it be 1 count higher than the counter?

That value is pretty irrelevant since i'm only enabling the overflow interrupt.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
If i truly have to use XOSCEN and XOSCSEL, then that's really bad, because that would mean that you can't use an RTC crystal and a regular crystal at the same time.
You're right, I took a closer look at those and they do set system ext. clk source. Since it's not oscillating, it looks like an issue with PCB in that area or the XTAL / caps. Can you show your PCB layout for this osc. and the 3 part specs ?

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

Last Edited: Sat. Aug 13, 2011 - 01:16 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

crystal is:

crystal @ farnell

C41 and C44 are 22pF 0603 caps

the pcb is 4 layers, with the layer just below being GND plane.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ext. oscillator circuits can be touchey by component value, PCB cleaness/ layout. What are you using for system clk ? Check out AVR042 section 5 here :
http://www.atmel.com/dyn/product...

Xtal d.sht. states 12.5 pF, that may mean you have to use caps in that range and NOT 22pF. For TOSC circuits, the caps are usually lower value than for ext. system clk. circuits ( where 22pF are doable ) . That might be the issue. Try that suggestion about using a short 2-lead watch XTAL and solder firectly to the pins ( remove the smd XTAl...if you can :cry: ) though and smaller caps .

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AVR4100: Selecting and testing 32kHz crystal oscillators for Atmel AVR microcontrollers
http://atmel.com/dyn/resources/prod_documents/doc8333.pdf
Go to pages 18 and 19.

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I switched the caps to 12pF, still didn't work.

Then i switched the crystal to a CITIZEN AMERICA
CM130 32.768KDZF-UT, and now it works.

Thanks for the help

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Works with the 12 pF caps ? What 's the name of the non-working XTAL so we can avoid it !!

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It may or may not need the capacitors: AVR1012: XMEGA A Schematic Checklist
Pages 8 and 9.

"Dare to be naïve." - Buckminster Fuller