Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# pulse.h

Go to the documentation of this file.

    00001 /*! \file pulse.h \brief Pulse/frequency generation function library. */
    00002 //*****************************************************************************
    00003 //
    00004 // File Name    : 'pulse.h'
    00005 // Title        : Pulse/frequency generation function library
    00006 // Author       : Pascal Stang - Copyright (C) 2000-2002
    00007 // Created      : 2002-08-19
    00008 // Revised      : 2003-05-29
    00009 // Version      : 0.7
    00010 // Target MCU   : Atmel AVR Series
    00011 // Editor Tabs  : 4
    00012 //
    00013 /// \ingroup driver_avr
    00014 /// \defgroup pulse Pulse/Frequency Generation Function Library (pulse.c)
    00015 /// \code
    00016 ///     #include "timer.h"
    00017 ///     #include "pulse.h"
    00018 /// \endcode
    00019 /// \par Overview
    00020 ///     This library is designed to facilitate the output of square wave pulses
    00021 /// at a frequency determined by the user.  The user may specify a continuous
    00022 /// stream of pulses, or a certain fixed number. Common uses include stepper
    00023 /// motor speed control, tone generation, communications, etc.  The library
    00024 /// uses the AVR processor built-in timers and pulse output is on the timer
    00025 /// Output Compare (OC) pins.  This library requires the timer function
    00026 /// library to work.
    00027 ///
    00028 /// The allowable range of frequencies which can be generated is governed
    00029 /// by the tic rate of the timer (therefore the CPU clock rate and the
    00030 /// timer prescaler), and the computing speed of the processor itself. See
    00031 /// the SetFreq commands for more details.
    00032 ///
    00033 /// \Note In order for the pulse library to work, pulseInit() will attach
    00034 /// the pulse service routines to the timer interrupts using the
    00035 /// timerAttach function. You must not detach the service routines during
    00036 /// pulse library operation.
    00037 //
    00038 // This code is distributed under the GNU Public License
    00039 //      which can be found at http://www.gnu.org/licenses/gpl.txt
    00040 //
    00041 //*****************************************************************************
    00042
    00043 #ifndef PULSE_H
    00044 #define PULSE_H
    00045
    00046 #include "global.h"
    00047
    00048 // constants/macros/typdefs
    00049
    00050 // functions
    00051
    00052 // Master Pulse Commands
    00053 // pulseInit()
    00054 //      Initializes the pulse system/library.
    00055 void pulseInit(void);
    00056
    00057 // Pulse commands for timer1
    00058 // pulseT1Init()
    00059 //      configures the timer1 hardware to produce pulses on pins OC1A and OC1B.
    00060 //      A "pulse" is considered to be one high and low period of a square wave.
    00061 void pulseT1Init(void);
    00062
    00063 // pulseT1Off()
    00064 //      Turns pulse output off immediately (cancels running pulse operations).
    00065 //      Unconfigures hardware and interrupts.
    00066 void pulseT1Off(void);
    00067
    00068 //  pulseT1ASetFreq() and pulseT1BSetFreq()
    00069 //      sets the frequency in hertz for each channel of square-wave pulse output
    00070 //      Note1: the freqency <freqHz> must always be greater than zero
    00071 //      Note2: both channels share the same frequency range which is governed
    00072 //      by the timer1 prescaler setting.  A prescaler setting of DIV/8 allows
    00073 //      frequencies of a few hertz through a few kilohertz.
    00074 //
    00075 //      Lower frequency bound = overflow rate of timer1 at current prescaling
    00076 //      Upper frequency bound = the tics rate of timer1 at current prescaling,
    00077 //                              or approx. the (clock rate of the processor)/50,
    00078 //                              whichever is smaller
    00079 void pulseT1ASetFreq(u16 freqHz);
    00080 void pulseT1BSetFreq(u16 freqHz);
    00081
    00082 // pulseT1ARun() and pulseT1BRun();
    00083 //      Sets the number of square-wave pulses to be output on the given channel.
    00084 //      For continuous (unlimited) pulse output, use nPulses = 0.  Pulses begin
    00085 //      coming out immediately.
    00086 //      Note: <nPulses> must be between 0 and 32767
    00087 void pulseT1ARun(u16 nPulses);
    00088 void pulseT1BRun(u16 nPulses);
    00089
    00090 // pulseT1AStop() and pulseT1BStop();
    00091 //      Stop pulse output at the next cycle (regardless of the number of
    00092 //      remaining pulses).
    00093 void pulseT1AStop(void);
    00094 void pulseT1BStop(void);
    00095
    00096 // pulseT1ARemaining() and pulseT1BRemaining()
    00097 //      Returns the number of pulses remaining to be output for each channel.
    00098 //      This function is useful for figuring out if the pulses are done.
    00099 u16  pulseT1ARemaining(void);
    00100 u16  pulseT1BRemaining(void);
    00101
    00102 // pulseT1AService() and pulseT1BService()
    00103 //      Interrupt service routines for pulse output (do not call these functions directly)
    00104 void pulseT1AService(void);
    00105 void pulseT1BService(void);
    00106
    00107
    00108 #endif