timer_example2.c File Reference

#include "timer.h"

Include dependency graph for timer_example2.c:

Go to the source code of this file.

Defines

#define CLEAR   2
#define EACH_EDGE   3
#define FALLING_EDGE   2
#define FALSE   0
#define NONE   0
#define NOOP   0
#define RISING_EDGE   1
#define SET   1
#define TOGGLE   3
#define TRUE   1

Functions

void init_timer_input (unsigned int instance, unsigned int channel)
void init_timer_output (unsigned int instance, unsigned int channel)
int main (int argc, char *argv[])


Define Documentation

#define CLEAR   2

Definition at line 21 of file timer_example2.c.

#define EACH_EDGE   3

Definition at line 27 of file timer_example2.c.

#define FALLING_EDGE   2

Definition at line 26 of file timer_example2.c.

Referenced by init_timer_input().

#define FALSE   0

Definition at line 32 of file timer_example2.c.

#define NONE   0

Definition at line 24 of file timer_example2.c.

Referenced by init_timer_input().

#define NOOP   0

Definition at line 19 of file timer_example2.c.

#define RISING_EDGE   1

Definition at line 25 of file timer_example2.c.

#define SET   1

Definition at line 20 of file timer_example2.c.

#define TOGGLE   3

Definition at line 22 of file timer_example2.c.

#define TRUE   1

Definition at line 31 of file timer_example2.c.


Function Documentation

void init_timer_input ( unsigned int  instance,
unsigned int  channel 
)

Definition at line 82 of file timer_example2.c.

References timer_capture_opt_t::abetrg, timer_capture_opt_t::burst, timer_capture_opt_t::channel, timer_capture_opt_t::clki, timer_capture_opt_t::cpctrg, timer_capture_opt_t::etrgedg, FALLING_EDGE, FALSE, timer_capture_opt_t::ldbdis, timer_capture_opt_t::ldbstop, timer_capture_opt_t::ldra, timer_capture_opt_t::ldrb, NONE, timer_capture_opt_t::tcclks, TIMER_CLOCK_SOURCE_TC5, timer_init_capture(), and TRUE.

Referenced by main().

00083 {
00084         struct timer_capture_opt_t capture_opt;
00085 
00086         /* Options for Capture mode */
00087         capture_opt.channel = channel;
00088         capture_opt.tcclks = TIMER_CLOCK_SOURCE_TC5;
00089         capture_opt.clki = FALSE;
00090         capture_opt.burst = FALSE;
00091         capture_opt.ldbstop = FALSE;
00092         capture_opt.ldbdis = FALSE;
00093         capture_opt.etrgedg = FALLING_EDGE;
00094         capture_opt.abetrg = FALSE; /* Select TIOB */
00095         capture_opt.cpctrg = TRUE;
00096         capture_opt.ldra = FALLING_EDGE;
00097         capture_opt.ldrb = NONE;
00098 
00099         /*Initialize the timer*/
00100         timer_init_capture(instance, &capture_opt);
00101 }

Here is the call graph for this function:

void init_timer_output ( unsigned int  instance,
unsigned int  channel 
)

Definition at line 104 of file timer_example2.c.

References timer_waveform_opt_t::acpa, timer_waveform_opt_t::acpc, timer_waveform_opt_t::aeevt, timer_waveform_opt_t::aswtrg, timer_waveform_opt_t::bcpb, timer_waveform_opt_t::bcpc, timer_waveform_opt_t::beevt, timer_waveform_opt_t::bswtrg, timer_waveform_opt_t::burst, timer_waveform_opt_t::channel, CLEAR, timer_waveform_opt_t::clki, timer_waveform_opt_t::cpcdis, timer_waveform_opt_t::cpcstop, timer_waveform_opt_t::eevt, timer_waveform_opt_t::eevtedg, timer_waveform_opt_t::enetrg, FALSE, NOOP, SET, timer_waveform_opt_t::tcclks, TIMER_CLOCK_SOURCE_TC4, timer_init_waveform(), TIMER_WAVEFORM_SEL_UP_MODE, and timer_waveform_opt_t::wavsel.

Referenced by main().

00105 {
00106         struct timer_waveform_opt_t waveform_opt;
00107 
00108         /* Options for Waveform genration */
00109         waveform_opt.channel = channel;
00110         waveform_opt.tcclks = TIMER_CLOCK_SOURCE_TC4;
00111         waveform_opt.clki = FALSE;
00112         waveform_opt.burst = FALSE;
00113         waveform_opt.cpcstop = FALSE;
00114         waveform_opt.cpcdis = FALSE;
00115         waveform_opt.eevtedg = FALSE;
00116         waveform_opt.eevt = 0;
00117         waveform_opt.enetrg = FALSE;
00118         waveform_opt.wavsel = TIMER_WAVEFORM_SEL_UP_MODE;
00119 
00120         waveform_opt.acpa = CLEAR;
00121         waveform_opt.acpc = SET;
00122         waveform_opt.aeevt = NOOP;
00123         waveform_opt.aswtrg = NOOP;
00124 
00125         waveform_opt.bcpb = NOOP;
00126         waveform_opt.bcpc = NOOP;
00127         waveform_opt.beevt = NOOP;
00128         waveform_opt.bswtrg = NOOP;
00129 
00130         /* Initialize the timer */
00131         timer_init_waveform(instance, &waveform_opt);
00132 }

Here is the call graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 39 of file timer_example2.c.

References init_timer_input(), init_timer_output(), timer_read_ra(), timer_start(), and timer_write_ra().

00040 {
00041 
00042         avr32_pio_t *piob = (void *) AVR32_PIOB_ADDRESS;
00043 
00044 
00045         /* The channel number and instance is used in several functions */
00046         /* It's defined as local variable for ease-of-use and readability */
00047         int output_instance = 1;
00048         int output_channel = 1;
00049 
00050         int input_instance = 2;
00051         int input_channel = 0;
00052 
00053         /* Used for reading the RA value for the input Timer/Counter instance */
00054         int ra=0;
00055 
00056         /* Enable Timer module on PIOB */
00057         piob->pdr = 0x0000ffff;
00058         piob->asr = 0x0000ffff;
00059 
00060         /* Init the Timer */
00061         init_timer_input(input_instance, input_channel);
00062         init_timer_output(output_instance, output_channel);
00063 
00064         /* Set the compare triggers*/
00065         timer_write_ra(output_instance, output_channel, 0x2000 );
00066 
00067         /* Start the timers */
00068         timer_start(output_instance, output_channel);
00069         timer_start(input_instance, input_channel);
00070 
00071         while(1){
00072                 ra = timer_read_ra(input_instance, input_channel);
00073                 if(ra>0){
00074                         timer_write_ra(output_instance, output_channel, ra);
00075                         ra=0;
00076                 }
00077         }
00078         return 0;
00079 }

Here is the call graph for this function:


Generated on Fri Oct 13 09:41:18 2006 for AVR32110 Using the AVR32 Timer/Counter by  doxygen 1.4.7