/* FreqCounter.h - Using Counter1 for counting Frequency on T1 / PD5 / digitalPin 5 Using Timer2 for Gatetime generation Martin Nawrath KHM LAB3 Kunsthochschule für Medien Köln Academy of Media Arts http://www.khm.de http://interface.khm.de/index.php/labor/experimente/ History: Dec/08 - V1.0 Oct/10 - V1.1 removed occasional glitches through interference with Jan/12 - V1.2 Arduino 1.0 timer0 set intterrupt timebase to 1ms works with atmega328 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include unsigned long FreqCounter::f_freq; volatile unsigned char FreqCounter::f_ready; volatile unsigned char FreqCounter::f_mlt; volatile unsigned int FreqCounter::f_tics; volatile unsigned int FreqCounter::f_period; volatile unsigned int FreqCounter::f_comp; void FreqCounter::start(int ms) { #if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1280__) TIMSK0 &=~(1<= FreqCounter::f_period) { // end of gate time, measurement ready // GateCalibration Value, set to zero error with reference frequency counter // delayMicroseconds(FreqCounter::f_comp); // 0.01=1/ 0.1=12 / 1=120 sec delayMicroseconds(FreqCounter::f_comp); TCCR1B = TCCR1B & ~7; // Gate Off / Counter T1 stopped TIMSK2 &= ~(1<