Atmel AT32UC3
Home - Developer - Contact us

 

Up

Introduction

Literature

Chapter 1: Start

Chapter 2: Clocks

Chapter 3: Port

Chapter 4: Interrupt

Chapter 5: Timer

Chapter 6: Real Time

Chapter 7: Serial Link

 

Lecture Material

Application_6
Application_6a

Chapter 6

In this chapter we will introduce the Real Time Counter (RTC) that typically is used to operate a clock or signal the execution of taks at a certain time. It typically operates from a 32kHz quartz oscillator, but Atmel made also the option available to operate it from the 115kHz RC-oscillator. The latter is for sure not an option if one wants to achieve a high precision timer. Here we will use the 32kHz oscillator on-board the STK600 as input to the RTC and then divide the clock so that we get an interrupt every second. Since other output devices than the LEDs are not available yet (they will become available in later chapters), we will use the LEDs to display a counter from 0 to 59, advancing every second.

32kHz oscillator setup

The setup of the 32kHz oscillator is added to the routine clock.c in the 'support' directory. The current values are read from the RTC-registers with the structure avr32_pm_gcctrl_t and then modified to:

Finally the values are written back to the registers.

Real Time Counter

The Real Time Counter consists of a prescaler with selectable dividion ratio and input source and a read- and writable counter that can generate an interrupt when it equals the setting of a read- and writable TOP-register. The programming proceeds as follows:

Writing the initialization is straight forward. To make the 32kHz clock of the STK600 available to the processor, shorten the pins '32kHz' and 'TOSC1' on the 'AUX port' connector.

Programs

Application_6 directly programs the registers of the 'Real Time Counter' and thus is much more transparent than programming using the ASF infrastructure. The LED initializarion used in the prior programs has been moved into the user_initialization.c and the RTC initialization is done in support/rtc.c. This makes the structure much cleaner.
Attention: the RTC interrupt routine has to be registered before the RTC is being initialized!

The initialization of the oscillators - including the 32kHz oscillator - is done in the routine clock.c in directory 'support'. This routine will be used in this or in slightly changed form in all routines.

After loading the program the RTC counter will generate interrupts every second and count up an 8bit-variable that is mapped to the LEDs. The count is cyclic from 0 to 59, just 1min per cycle.

Application_6a uses the ASF infrastructure for programming the 'Real Time Counter'. After creating the project (call it 'Application_6a'), copy the 'Application_6a' zip-file into your directories as explained in prior projects. Then open 'Project' and 'ASF Wizzard' in the 'Atmel Studio Menu'. Add the 'Real Time Counter (driver)' to your project. This will result not only in adding an 'rtc'-directory in 'src/ASF/avr32/drivers', but also 'flashc' (Flash Memory Driver) and 'pm' (Power Management). We will only use routines from the 'rtc' directory, but the others don't hurt (apart from size).

info@tsseshop.com