?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik //*****************************************************************************
2 // File Name : timertest.c
3 //
4 // Title : example usage of timer library functions
5 // Revision : 1.0
6 // Notes :
7 // Target MCU : Atmel AVR series
8 // Editor Tabs : 4
9 //
10 // Revision History:
11 // When Who Description of change
12 // ----------- ----------- -----------------------
13 // 30-Apr-2003 pstang Created the program
14 //*****************************************************************************
15  
16  
17 //----- Include Files ---------------------------------------------------------
18 #include <avr/io.h> // include I/O definitions (port names, pin names, etc)
19 #include <avr/interrupt.h> // include interrupt support
20  
21 #include "global.h" // include our global settings
22 #include "uart.h" // include uart function library
23 #include "rprintf.h" // include printf function library
24 #include "timer.h" // include timer function library (timing, PWM, etc)
25  
26 void timerTest(void);
27  
28 //----- Begin Code ------------------------------------------------------------
29 int main(void)
30 {
31 // initialize our libraries
32 // initialize the UART (serial port)
33 uartInit();
34 // set the baud rate of the UART for our debug/reporting output
35 uartSetBaudRate(9600);
36 // initialize rprintf system
37 rprintfInit(uartSendByte);
38  
39 // run the test
40 timerTest();
41  
42 return 0;
43 }
44  
45 void timerTest(void)
46 {
47 // print a little intro message so we know things are working
48 rprintf("\r\n\n\nWelcome to the timer library test program!\r\n");
49  
50 // initialize the timer system
51 timerInit();
52  
53 // to use the internal timers to produce a calibrated delay,
54 // use the timerPause() function. timerPause takes a 16-bit
55 // integer argument in milliseconds
56  
57 // example: wait for 1/2 of a second, or 500ms
58 rprintf("\r\nTest of timerPause() function\r\n");
59 rprintf("Here comes a 1/2-second delay...\r\n");
60 timerPause(500);
61 rprintf("Done!\r\n");
62  
63  
64 // here's an example of using the timer library to do
65 // pulse-width modulation or PWM. PWM signals can be created on
66 // any output compare (OCx) pin. See your processor's data sheet
67 // for more information on which I/O pins have output compare
68 // capability.
69 rprintf("\r\nTest of timer1 PWM output\r\n");
70  
71 // set the OC1x port pins to output
72 // We need to do this so we can see and use the PWM signal
73 // ** these settings are correct for most processors, but not for all
74 sbi(DDRD, PD4);
75 sbi(DDRD, PD5);
76  
77 // initialize timer1 for PWM output
78 // - you may use 8,9, or 10 bit PWM resolution
79 rprintf("Initializing timer1 for PWM\r\n");
80 timer1PWMInit(8);
81  
82 // turn on the channel A PWM output of timer1
83 // - this signal will come out on the OC1A I/O pin
84 rprintf("Turning on timer1 channel A PWM output\r\n");
85 timer1PWMAOn();
86  
87 // set the duty cycle of the channel A output
88 // - let's try 25% duty, or 256*25% = 64
89 rprintf("Setting duty cycle to 25%%\r\n");
90 timer1PWMASet(64);
91  
92 // turn on channel B and set it to 75% duty cycle
93 rprintf("Turning on channel B too, with 75%% duty\r\n");
94 timer1PWMBOn();
95 timer1PWMBSet(192);
96  
97 // wait for 5 seconds
98 rprintf("Pause for 5 seconds...\r\n");
99 timerPause(5000);
100  
101 // now turn off all PWM on timer1
102 rprintf("Turning off all PWM on timer1\r\n");
103 timer1PWMOff();
104 }
105  
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3