pwm_example.c File Reference


Detailed Description

PWM example driver for AVR32 UC3.

This file provides an example for the PWM on AVR32 UC3 devices.

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

Definition in file pwm_example.c.

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

Go to the source code of this file.

Defines

PWM Configuration
#define EXAMPLE_PWM_CHANNEL_ID   0
#define EXAMPLE_PWM_FUNCTION   AVR32_PWM_0_0_FUNCTION
#define EXAMPLE_PWM_PIN   AVR32_PWM_0_0_PIN

Functions

int main ()
 Main function. Execution starts here.


Define Documentation

#define EXAMPLE_PWM_CHANNEL_ID   0

Definition at line 98 of file pwm_example.c.

Referenced by main().

#define EXAMPLE_PWM_FUNCTION   AVR32_PWM_0_0_FUNCTION

Definition at line 97 of file pwm_example.c.

Referenced by main().

#define EXAMPLE_PWM_PIN   AVR32_PWM_0_0_PIN

Definition at line 96 of file pwm_example.c.

Referenced by main().


Function Documentation

int main (  ) 

Main function. Execution starts here.

Returns:
0 on success

Definition at line 117 of file pwm_example.c.

References pwm_opt_t::diva, pwm_opt_t::divb, EXAMPLE_PWM_CHANNEL_ID, EXAMPLE_PWM_FUNCTION, EXAMPLE_PWM_PIN, pwm_opt_t::prea, pwm_opt_t::preb, pwm_channel_init(), pwm_init(), PWM_MODE_LEFT_ALIGNED, PWM_POLARITY_LOW, pwm_start_channels(), and PWM_UPDATE_DUTY.

00118 {
00119   pwm_opt_t pwm_opt;                                // PWM option config.
00120   avr32_pwm_channel_t pwm_channel = { .ccnt = 0 };  // One channel config.
00121   // The channel number and instance is used in several functions.
00122   // It's defined as local variable for ease-of-use.
00123   unsigned int channel_id;
00124 
00125   channel_id = EXAMPLE_PWM_CHANNEL_ID;
00126   gpio_enable_module_pin(EXAMPLE_PWM_PIN, EXAMPLE_PWM_FUNCTION);
00127 
00128   // PWM controller configuration.
00129   pwm_opt.diva = AVR32_PWM_DIVA_CLK_OFF;
00130   pwm_opt.divb = AVR32_PWM_DIVB_CLK_OFF;
00131   pwm_opt.prea = AVR32_PWM_PREA_MCK;
00132   pwm_opt.preb = AVR32_PWM_PREB_MCK;
00133 
00134   pwm_init(&pwm_opt);
00135 
00136   pwm_channel.CMR.calg = PWM_MODE_LEFT_ALIGNED;       // Channel mode.
00137   pwm_channel.CMR.cpol = PWM_POLARITY_LOW;            // Channel polarity.
00138   pwm_channel.CMR.cpd = PWM_UPDATE_DUTY;              // Not used the first time.
00139   pwm_channel.CMR.cpre = AVR32_PWM_CPRE_MCK_DIV_256;  // Channel prescaler.
00140   pwm_channel.cdty = 5;   // Channel duty cycle, should be < CPRD.
00141   pwm_channel.cprd = 20;  // Channel period.
00142   pwm_channel.cupd = 0;   // Channel update is not used here.
00143   // With these settings, the output waveform period will be :
00144   // (115200/256)/20 == 22.5Hz == (MCK/prescaler)/period, with MCK == 115200Hz,
00145   // prescaler == 256, period == 20.
00146 
00147   pwm_channel_init(channel_id, &pwm_channel); // Set channel configuration to channel 0.
00148 
00149   pwm_start_channels(1 << channel_id);  // Start channel 0.
00150 
00151   while(1);
00152 }


Generated on Thu Dec 17 19:59:13 2009 for AVR32 - PWM Driver by  doxygen 1.5.5