clock_scaling_example.c File Reference


Detailed Description

Clock scaling example for the AVR32 UC3.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file clock_scaling_example.c.

#include <avr32/io.h>
#include "board.h"
#include "pm.h"
#include "gpio.h"

Include dependency graph for clock_scaling_example.c:

Go to the source code of this file.

Defines

#define CLOCK_DIV_OFF   0
#define CLOCK_DIV_ON   1
#define DIV_FOURTH   1
#define DIV_HALF   0

Functions

int main (void)
 main function : set clock scaling according to pressed button.


Define Documentation

#define CLOCK_DIV_OFF   0

Definition at line 94 of file clock_scaling_example.c.

#define CLOCK_DIV_ON   1

Introduction

This example demonstrates the CPU (and HSB) frequency scaling feature of the AVR32. This can be done on-the-fly. Operating mode: Press button 0 to set CPU (HSB) clock to full speed (Oscillator 0 = 12MHz). Press button 1 to set CPU (HSB) clock to half speed (6MHz). Press button 2 to set CPU (HSB) clock to forth speed (3MHz).

Depending on the current CPU speed a LED is turned on. LED0 = full speed LED1 = half speed LED2 = forth speed

NOTE: If the user of this software intends to change division factors for the clocks or use the PLL take following rules into account:

Flash wait states must be added when high frequencies are used

Main Files

Compilation Information

This software is written for GNU GCC for AVR32 and for IAR Embedded Workbench for Atmel AVR32. Other compilers may or may not work.

Device Information

All AVR32 devices with GPIO controller and power manager.

Configuration Information

This example has been tested with the following configuration:

Contact Information

For further information, visit Atmel AVR32.
Support and FAQ: http://support.atmel.no/

Definition at line 93 of file clock_scaling_example.c.

#define DIV_FOURTH   1

Definition at line 96 of file clock_scaling_example.c.

#define DIV_HALF   0

Definition at line 95 of file clock_scaling_example.c.


Function Documentation

int main ( void   ) 

main function : set clock scaling according to pressed button.

Definition at line 101 of file clock_scaling_example.c.

References CLOCK_DIV_OFF, CLOCK_DIV_ON, DIV_FOURTH, DIV_HALF, FOSC0, gpio_clr_gpio_pin(), gpio_get_pin_value(), GPIO_PUSH_BUTTON_0, GPIO_PUSH_BUTTON_1, GPIO_PUSH_BUTTON_2, gpio_set_gpio_pin(), LED0_GPIO, LED1_GPIO, LED2_GPIO, OSC0_STARTUP, pm_cksel(), and pm_switch_to_osc0().

00101                {
00102         unsigned int pbasel = DIV_FOURTH;
00103         unsigned int pbbsel = DIV_FOURTH;
00104         
00105         // set synchronous clock source to external oscillator 0
00106         pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);
00107         
00108         // set lower frequency on peripheral busses
00109         // the pm_cksel function takes care of safe clock adjustments
00110         pm_cksel(&AVR32_PM, CLOCK_DIV_ON, pbasel, CLOCK_DIV_ON, pbbsel,
00111                         CLOCK_DIV_OFF, 0);
00112         
00113         // indicate full speed with LED
00114         gpio_clr_gpio_pin(LED0_GPIO);
00115         
00116         while(1){
00117                 
00118                 // Set CPU speed according to the pressed button
00119 
00120                         if(gpio_get_pin_value(GPIO_PUSH_BUTTON_0) == 0) {
00121                                 // No clock division for CPU
00122                                 pm_cksel(&AVR32_PM, CLOCK_DIV_ON, pbasel, CLOCK_DIV_ON, pbbsel,
00123                                                 CLOCK_DIV_OFF, 0);
00124                                 gpio_clr_gpio_pin(LED0_GPIO);
00125                                 gpio_set_gpio_pin(LED1_GPIO);
00126                                 gpio_set_gpio_pin(LED2_GPIO);
00127                         }
00128                         if(gpio_get_pin_value(GPIO_PUSH_BUTTON_1) == 0){
00129                                 // CPU speed = 1/2 * oscillator0
00130                                 pm_cksel(&AVR32_PM, CLOCK_DIV_ON, pbasel, CLOCK_DIV_ON, pbbsel,
00131                                                 CLOCK_DIV_ON, DIV_HALF);
00132                                 gpio_clr_gpio_pin(LED1_GPIO);
00133                                 gpio_set_gpio_pin(LED0_GPIO);
00134                                 gpio_set_gpio_pin(LED2_GPIO);
00135                         }
00136                         if(gpio_get_pin_value(GPIO_PUSH_BUTTON_2) == 0){
00137                                 // CPU speed = 1/4 * oscillator0
00138                                 pm_cksel(&AVR32_PM, CLOCK_DIV_ON, pbasel, CLOCK_DIV_ON, pbbsel,
00139                                                 CLOCK_DIV_ON, DIV_FOURTH);
00140                                 gpio_clr_gpio_pin(LED2_GPIO);
00141                                 gpio_set_gpio_pin(LED0_GPIO);
00142                                 gpio_set_gpio_pin(LED1_GPIO);
00143                         }
00144                                 
00145         }
00146         return 0;
00147 }

Here is the call graph for this function:


Generated on Wed May 7 14:40:10 2008 for AVR32114 Using the AVR32 LCD Controller by  doxygen 1.5.3-20071008