Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | //***************************************************************************** |
2 | // File Name : pulsetest.c |
||
3 | // |
||
4 | // Title : example usage of pulse 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 | // 29-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 | #include "pulse.h" // include pulse output support |
||
26 | |||
27 | void pulseTest(void); |
||
28 | |||
29 | //----- Begin Code ------------------------------------------------------------ |
||
30 | int main(void) |
||
31 | { |
||
32 | // initialize our libraries |
||
33 | // initialize the UART (serial port) |
||
34 | uartInit(); |
||
35 | // set the baud rate of the UART for our debug/reporting output |
||
36 | uartSetBaudRate(9600); |
||
37 | // initialize the timer system |
||
38 | timerInit(); |
||
39 | // initialize rprintf system |
||
40 | rprintfInit(uartSendByte); |
||
41 | |||
42 | // run the test |
||
43 | pulseTest(); |
||
44 | |||
45 | return 0; |
||
46 | } |
||
47 | |||
48 | void pulseTest(void) |
||
49 | { |
||
50 | u16 i; |
||
51 | |||
52 | // print a little intro message so we know things are working |
||
53 | rprintf("\r\nWelcome to the pulse library test program!\r\n"); |
||
54 | |||
55 | // set pulse pins as output |
||
56 | // ** these are the correct pins for most processors, but not all ** |
||
57 | sbi(DDRD, 4); |
||
58 | sbi(DDRD, 5); |
||
59 | |||
60 | // initialize pulse library |
||
61 | pulseInit(); |
||
62 | |||
63 | |||
64 | // do logarithmic frequency sweep |
||
65 | rprintf("Running logarithmic frequency sweep...\r\n"); |
||
66 | for(i=1; i<4000; i+=((i/5)+1)) |
||
67 | { |
||
68 | // set the output frequency |
||
69 | pulseT1ASetFreq(i); |
||
70 | // - set the number of pulses to output |
||
71 | // - number of pulses will be set to make each |
||
72 | // frequency last 1/5 of a second in time |
||
73 | // ** make sure we don't request zero pulses |
||
74 | // ** because this means run indefinitely |
||
75 | pulseT1ARun( (i/5)+1 ); |
||
76 | // print a debug message |
||
77 | rprintf("Output Freq = %dHz\r\n", i); |
||
78 | // wait for pulses to finish being output |
||
79 | while(pulseT1ARemaining()); |
||
80 | } |
||
81 | |||
82 | |||
83 | // do simultaneous pulse output on OC1A and OC1B pins with different frequencies |
||
84 | rprintfCRLF(); |
||
85 | rprintf("Running simultaneous output on OC1A and OC1B with different frequencies\r\n"); |
||
86 | rprintf("OC1A will be at 50Hz for 2 seconds (100 pulses)\r\n"); |
||
87 | rprintf("OC1B will be at 175Hz for 4 seconds (700 pulses)\r\n"); |
||
88 | // start OC1A output |
||
89 | pulseT1ASetFreq(50); |
||
90 | pulseT1ARun(100); |
||
91 | // start OC1B output |
||
92 | pulseT1BSetFreq(175); |
||
93 | pulseT1BRun(700); |
||
94 | // enter a debug loop as long as there are pulses remaining |
||
95 | while(pulseT1ARemaining() | pulseT1BRemaining()) |
||
96 | { |
||
97 | rprintf("OC1A has %d pulses remaining, OC1B has %d pulses remaining\r\n", pulseT1ARemaining(), pulseT1BRemaining()); |
||
98 | timerPause(100); |
||
99 | } |
||
100 | rprintf("done!\r\n"); |
||
101 | |||
102 | } |
||
103 |
Powered by WebSVN v2.8.3