| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 6 | kaklik | /*! \file pulse.h \brief Pulse/frequency generation function library. */ |
| 2 | //***************************************************************************** |
||
| 3 | // |
||
| 4 | // File Name : 'pulse.h' |
||
| 5 | // Title : Pulse/frequency generation function library |
||
| 6 | // Author : Pascal Stang - Copyright (C) 2000-2002 |
||
| 7 | // Created : 2002-08-19 |
||
| 8 | // Revised : 2003-05-29 |
||
| 9 | // Version : 0.7 |
||
| 10 | // Target MCU : Atmel AVR Series |
||
| 11 | // Editor Tabs : 4 |
||
| 12 | // |
||
| 13 | /// \ingroup driver_avr |
||
| 14 | /// \defgroup pulse Pulse/Frequency Generation Function Library (pulse.c) |
||
| 15 | /// \code |
||
| 16 | /// #include "timer.h" |
||
| 17 | /// #include "pulse.h" |
||
| 18 | /// \endcode |
||
| 19 | /// \par Overview |
||
| 20 | /// This library is designed to facilitate the output of square wave pulses |
||
| 21 | /// at a frequency determined by the user. The user may specify a continuous |
||
| 22 | /// stream of pulses, or a certain fixed number. Common uses include stepper |
||
| 23 | /// motor speed control, tone generation, communications, etc. The library |
||
| 24 | /// uses the AVR processor built-in timers and pulse output is on the timer |
||
| 25 | /// Output Compare (OC) pins. This library requires the timer function |
||
| 26 | /// library to work. |
||
| 27 | /// |
||
| 28 | /// The allowable range of frequencies which can be generated is governed |
||
| 29 | /// by the tic rate of the timer (therefore the CPU clock rate and the |
||
| 30 | /// timer prescaler), and the computing speed of the processor itself. See |
||
| 31 | /// the SetFreq commands for more details. |
||
| 32 | /// |
||
| 33 | /// \Note In order for the pulse library to work, pulseInit() will attach |
||
| 34 | /// the pulse service routines to the timer interrupts using the |
||
| 35 | /// timerAttach function. You must not detach the service routines during |
||
| 36 | /// pulse library operation. |
||
| 37 | // |
||
| 38 | // This code is distributed under the GNU Public License |
||
| 39 | // which can be found at http://www.gnu.org/licenses/gpl.txt |
||
| 40 | // |
||
| 41 | //***************************************************************************** |
||
| 42 | |||
| 43 | #ifndef PULSE_H |
||
| 44 | #define PULSE_H |
||
| 45 | |||
| 46 | #include "global.h" |
||
| 47 | |||
| 48 | // constants/macros/typdefs |
||
| 49 | |||
| 50 | // functions |
||
| 51 | |||
| 52 | // Master Pulse Commands |
||
| 53 | // pulseInit() |
||
| 54 | // Initializes the pulse system/library. |
||
| 55 | void pulseInit(void); |
||
| 56 | |||
| 57 | // Pulse commands for timer1 |
||
| 58 | // pulseT1Init() |
||
| 59 | // configures the timer1 hardware to produce pulses on pins OC1A and OC1B. |
||
| 60 | // A "pulse" is considered to be one high and low period of a square wave. |
||
| 61 | void pulseT1Init(void); |
||
| 62 | |||
| 63 | // pulseT1Off() |
||
| 64 | // Turns pulse output off immediately (cancels running pulse operations). |
||
| 65 | // Unconfigures hardware and interrupts. |
||
| 66 | void pulseT1Off(void); |
||
| 67 | |||
| 68 | // pulseT1ASetFreq() and pulseT1BSetFreq() |
||
| 69 | // sets the frequency in hertz for each channel of square-wave pulse output |
||
| 70 | // Note1: the freqency <freqHz> must always be greater than zero |
||
| 71 | // Note2: both channels share the same frequency range which is governed |
||
| 72 | // by the timer1 prescaler setting. A prescaler setting of DIV/8 allows |
||
| 73 | // frequencies of a few hertz through a few kilohertz. |
||
| 74 | // |
||
| 75 | // Lower frequency bound = overflow rate of timer1 at current prescaling |
||
| 76 | // Upper frequency bound = the tics rate of timer1 at current prescaling, |
||
| 77 | // or approx. the (clock rate of the processor)/50, |
||
| 78 | // whichever is smaller |
||
| 79 | void pulseT1ASetFreq(u16 freqHz); |
||
| 80 | void pulseT1BSetFreq(u16 freqHz); |
||
| 81 | |||
| 82 | // pulseT1ARun() and pulseT1BRun(); |
||
| 83 | // Sets the number of square-wave pulses to be output on the given channel. |
||
| 84 | // For continuous (unlimited) pulse output, use nPulses = 0. Pulses begin |
||
| 85 | // coming out immediately. |
||
| 86 | // Note: <nPulses> must be between 0 and 32767 |
||
| 87 | void pulseT1ARun(u16 nPulses); |
||
| 88 | void pulseT1BRun(u16 nPulses); |
||
| 89 | |||
| 90 | // pulseT1AStop() and pulseT1BStop(); |
||
| 91 | // Stop pulse output at the next cycle (regardless of the number of |
||
| 92 | // remaining pulses). |
||
| 93 | void pulseT1AStop(void); |
||
| 94 | void pulseT1BStop(void); |
||
| 95 | |||
| 96 | // pulseT1ARemaining() and pulseT1BRemaining() |
||
| 97 | // Returns the number of pulses remaining to be output for each channel. |
||
| 98 | // This function is useful for figuring out if the pulses are done. |
||
| 99 | u16 pulseT1ARemaining(void); |
||
| 100 | u16 pulseT1BRemaining(void); |
||
| 101 | |||
| 102 | // pulseT1AService() and pulseT1BService() |
||
| 103 | // Interrupt service routines for pulse output (do not call these functions directly) |
||
| 104 | void pulseT1AService(void); |
||
| 105 | void pulseT1BService(void); |
||
| 106 | |||
| 107 | |||
| 108 | #endif |
Powered by WebSVN v2.8.3