Mozzi  alpha 0.01.1s
sound synthesis library for Arduino
 All Classes Functions
MozziTimer2.h
00001 /*
00002   MozziTimer2.cpp - Using timer 2 (or 4 on ATmega32U4) with a configurable interrupt rate.
00003 
00004   Copyright 2012 Tim Barrass
00005 
00006   This file is part of Mozzi.
00007 
00008   Combines the hardware compatibility of Flexitimer2/MsTimer2 with the
00009   precision and efficiency of TimerTwo library, with other tweaks.
00010   (unknown, from https://bitbucket.org/johnmccombs, 4/2/2012).
00011 
00012   FlexiTimer2
00013   Wim Leers <work@wimleers.com>
00014 
00015   Based on MsTimer2
00016   Javier Valencia <javiervalencia80@gmail.com>
00017 
00018   History:
00019     25/Aug/2012 (TB) - Replaced scheme for setting up timers with
00020                 one based on TImerTwo library.
00021                 Kept precompiler directives selecting processor models.
00022     16/Dec/2011 - Added Teensy/Teensy++ support (bperrybap)
00023                                 note: teensy uses timer4 instead of timer2
00024     25/April/10 - Based on MsTimer2 V0.5 (from 29/May/09)
00025 
00026   This library is free software; you can redistribute it and/or
00027   modify it under the terms of the GNU Lesser General Public
00028   License as published by the Free Software Foundation; either
00029   version 2.1 of the License, or (at your option) any later version.
00030 
00031   This library is distributed in the hope that it will be useful,
00032   but WITHOUT ANY WARRANTY; without even the implied warranty of
00033   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00034   Lesser General Public License for more details.
00035 
00036   You should have received a copy of the GNU Lesser General Public
00037   License along with this library; if not, write to the Free Software
00038   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00039 */
00040 
00041 #ifndef MOZZITIMER2_H_
00042 #define MOZZITIMER2_H_
00043 
00044 #ifdef __AVR__
00045 #include <avr/interrupt.h>
00046 #include <avr/pgmspace.h>
00047 #else
00048 #error MozziTimer2 library only works on AVR architecture
00049 #endif
00050 
00051 
00052 namespace MozziTimer2
00053 {
00054 
00055 // call f every usec microseconds if start == false
00056 // call f after delay of usec microseconds from call return if start == true
00057 // max delay is 256*1024 clock cycles or 16,384 microseconds for a 16 MHz CPU
00058 unsigned char set(unsigned int usec, void (*f)(), bool start = false);
00059 void start();
00060 void stop();
00061 
00062 extern unsigned period_;
00063 // timer start flag
00064 extern bool start_;
00065 // user function
00066 extern void (*f_)();
00067 
00068 // period in usec
00069 inline unsigned period()
00070 {
00071                 return period_;
00072 }
00073 
00074 }
00075 
00076 #endif /* MOZZITIMER2_H_ */