Skip to content

Commit

Permalink
update 0.01.1zzz
Browse files Browse the repository at this point in the history
fixed atmega32u4 compile
  • Loading branch information
sensorium committed Jun 1, 2013
1 parent 485de65 commit 76e855c
Show file tree
Hide file tree
Showing 307 changed files with 21,199 additions and 16,793 deletions.
6 changes: 5 additions & 1 deletion ADSR.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
#ifndef ADSR_H_
#define ADSR_H_

#include "Arduino.h"
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
//#include <util/atomic.h>
#include "Line.h"
#include "mozzi_fixmath.h"
Expand Down
7 changes: 6 additions & 1 deletion AudioDelayFeedback.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#ifndef AUDIODELAY_FEEDBACK_H_
#define AUDIODELAY_FEEDBACK_H_

#include "Arduino.h"
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "mozzi_utils.h"
#include "meta.h"

Expand Down Expand Up @@ -344,6 +348,7 @@ class AudioDelayFeedback
_coeff = float_to_Q15n16((1.f-alpha_)/(1.f+alpha_));
}



// /** Retrieve the signal in the delay line at the position delaytime_cells.
// It doesn't change the stored internal value of _delaytime_cells or feedback the output to the input.
Expand Down
22 changes: 22 additions & 0 deletions DCfilter.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/*
* DCfilter.h
*
* Copyright 2012 Tim Barrass.
*
* This file is part of Mozzi.
*
* Mozzi is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Mozzi 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Mozzi. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef DCFILTER_H
#define DCFILTER_H

Expand Down
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ PROJECT_NAME = Mozzi
# This could be handy for archiving the generated documentation or
# if some version control system is used.

PROJECT_NUMBER = "alpha 0.01.1zz"
PROJECT_NUMBER = "alpha 0.01.1zzz"

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer
Expand Down
221 changes: 135 additions & 86 deletions FrequencyTimer2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
for compatibility with newer hardware and Arduino 1.0
Modified for Mozzi by Tim Barrass 2013,
commented out ISR so it could be defined in Mozzi code directly.
-commented out ISR so it could be defined in Mozzi code directly.
-added support for ATMEGA32U4 processors (Leonardo,Teensy2.0)
using Timer 4 instead of Timer 2
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -38,6 +40,8 @@ uint8_t FrequencyTimer2::enabled = 0;
ISR(TIMER2_COMPA_vect)
#elif defined(TIMER2_COMP_vect)
ISR(TIMER2_COMP_vect)
#elif defined(TIMER4_COMPA_vect)
ISR(TIMER4_COMPA_vect)
#else
#error "This board does not have a hardware timer which is compatible with FrequencyTimer2"
void dummy_function(void)
Expand All @@ -54,122 +58,167 @@ void dummy_function(void)
*/
void FrequencyTimer2::setOnOverflow( void (*func)() )
{
FrequencyTimer2::onOverflow = func;
FrequencyTimer2::onOverflow = func;
#if defined(TIMSK2)
if ( func) TIMSK2 |= _BV(OCIE2A);
else TIMSK2 &= ~_BV(OCIE2A);
// enable compare match interrupt
if ( func) TIMSK2 |= _BV(OCIE2A);
else TIMSK2 &= ~_BV(OCIE2A);
#elif defined(TIMSK)
if ( func) TIMSK |= _BV(OCIE2);
else TIMSK &= ~_BV(OCIE2);
if ( func) TIMSK |= _BV(OCIE2);
else TIMSK &= ~_BV(OCIE2);
#elif defined(TIMSK4)
// output compare interrupt enable 4A
if ( func) TIMSK4 = _BV(OCIE4A);
else TIMSK4 = 0;
#endif
}


void FrequencyTimer2::setPeriod(unsigned long period)
{
uint8_t pre, top;

if ( period == 0) period = 1;
period *= clockCyclesPerMicrosecond();

period /= 2; // we work with half-cycles before the toggle
if ( period <= 256) {
pre = 1;
top = period-1;
} else if ( period <= 256L*8) {
pre = 2;
top = period/8-1;
} else if ( period <= 256L*32) {
pre = 3;
top = period/32-1;
} else if ( period <= 256L*64) {
pre = 4;
top = period/64-1;
} else if ( period <= 256L*128) {
pre = 5;
top = period/128-1;
} else if ( period <= 256L*256) {
pre = 6;
top = period/256-1;
} else if ( period <= 256L*1024) {
pre = 7;
top = period/1024-1;
} else {
pre = 7;
top = 255;
}
uint8_t pre, top;

if ( period == 0) period = 1;
period *= clockCyclesPerMicrosecond();
period /= 2; // we work with half-cycles before the toggle

#if defined(TCCR2A) || defined(TCCR2)
if ( period <= 256) {
pre = 1;
top = period-1;
} else if ( period <= 256L*8) { // this for AUDIO_RATE 16384, pre=2 is a bitfield 010 which means prescaler = 8
pre = 2;
top = period/8-1;
} else if ( period <= 256L*32) {
pre = 3;
top = period/32-1;
} else if ( period <= 256L*64) {
pre = 4;
top = period/64-1;
} else if ( period <= 256L*128) {
pre = 5;
top = period/128-1;
} else if ( period <= 256L*256) {
pre = 6;
top = period/256-1;
} else if ( period <= 256L*1024) {
pre = 7;
top = period/1024-1;
} else {
pre = 7;
top = 255;
}
#elif defined(TCCR4A)
unsigned long prescaler = 1;
for(int i=1; i<=16; i++){
if ( period <= 256*prescaler){
pre = i;
top = period/prescaler -1;
break;
}
prescaler *= 2;
}

//pre = 4; // this for AUDIO_RATE 16384, pre=4 is a bitfield 100 which means prescaler = 8
//top = period/8-1;
#endif

#if defined(TCCR2A)
TCCR2B = 0;
TCCR2A = 0;
TCNT2 = 0;
TCCR2B = 0;
TCCR2A = 0;
TCNT2 = 0;
#if defined(ASSR) && defined(AS2)
ASSR &= ~_BV(AS2); // use clock, not T2 pin
ASSR &= ~_BV(AS2); // use clock, not T2 pin
#endif
OCR2A = top;
TCCR2A = (_BV(WGM21) | ( FrequencyTimer2::enabled ? _BV(COM2A0) : 0));
TCCR2B = pre;
OCR2A = top;
//Clear Timer on Compare Match (CTC) mode
TCCR2A = (_BV(WGM21) | ( FrequencyTimer2::enabled ? _BV(COM2A0) : 0));
TCCR2B = pre;
#elif defined(TCCR2)
TCCR2 = 0;
TCNT2 = 0;
ASSR &= ~_BV(AS2); // use clock, not T2 pin
OCR2 = top;
TCCR2 = (_BV(WGM21) | ( FrequencyTimer2::enabled ? _BV(COM20) : 0) | pre);
TCCR2 = 0;
TCNT2 = 0;
ASSR &= ~_BV(AS2); // use clock, not T2 pin
OCR2 = top;
TCCR2 = (_BV(WGM21) | ( FrequencyTimer2::enabled ? _BV(COM20) : 0) | pre);
#elif defined(TCCR4A) // TB2013 for 32u4 (leonardo,teensy)
TCCR4A = 0;
TCCR4B = 0;
TCCR4C = 0;
TCCR4D = 0;
TCCR4E = 0;
TCNT4 = 0;
OCR4C= top; // Table 15-19
//TCCR4A = _BV(COM4A1);
TCCR4B = pre ;
TIMSK4 = FrequencyTimer2::enabled ? _BV(OCIE4A) : 0;
#endif
}


unsigned long FrequencyTimer2::getPeriod()
{
#if defined(TCCR2B)
uint8_t p = (TCCR2B & 7);
unsigned long v = OCR2A;
#elif defined(TCCR2)
uint8_t p = (TCCR2 & 7);
unsigned long v = OCR2;
uint8_t p = (TCCR2B & 7);
unsigned long v = OCR2A;
#elif defined(TCCR)
uint8_t p = (TCCR2 & 7);
unsigned long v = OCR2;
#elif defined(TCCR4B)
uint8_t p = (TCCR4B & 7);
unsigned long v = OCR4C;
#endif
uint8_t shift;
switch(p) {
case 0 ... 1:
shift = 0;
break;
case 2:
shift = 3;
break;
case 3:
shift = 5;
break;
case 4:
shift = 6;
break;
case 5:
shift = 7;
break;
case 6:
shift = 8;
break;
case 7:
shift = 10;
break;
}
return (((v+1) << (shift+1)) + 1) / clockCyclesPerMicrosecond(); // shift+1 converts from half-period to period
uint8_t shift;

switch(p) {
case 0 ... 1:
shift = 0;
break;
case 2:
shift = 3;
break;
case 3:
shift = 5;
break;
case 4:
shift = 6;
break;
case 5:
shift = 7;
break;
case 6:
shift = 8;
break;
case 7:
shift = 10;
break;
}
return (((v+1) << (shift+1)) + 1) / clockCyclesPerMicrosecond(); // shift+1 converts from half-period to period
}


void FrequencyTimer2::enable()
{
FrequencyTimer2::enabled = 1;
FrequencyTimer2::enabled = 1;
#if defined(TCCR2A)
TCCR2A |= _BV(COM2A0);
//Toggle OC2A on Compare Match
TCCR2A |= _BV(COM2A0);
#elif defined(TCCR2)
TCCR2 |= _BV(COM20);
TCCR2 |= _BV(COM20);
#elif defined(TCCR4A)
//TCCR4A |= _BV(COM4A0);
TIMSK4 = _BV(OCIE4A);
#endif
}

void FrequencyTimer2::disable()
{
FrequencyTimer2::enabled = 0;
FrequencyTimer2::enabled = 0;
#if defined(TCCR2A)
TCCR2A &= ~_BV(COM2A0);
TCCR2A &= ~_BV(COM2A0);
#elif defined(TCCR2)
TCCR2 &= ~_BV(COM20);
TCCR2 &= ~_BV(COM20);
#elif defined(TCCR4A)
//TCCR4A &= ~_BV(COM4A0);
TIMSK4 = 0;
#endif
}
3 changes: 2 additions & 1 deletion FrequencyTimer2.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "WProgram.h"
#endif

/*
// Arduino Mega
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define FREQUENCYTIMER2_PIN 10
Expand All @@ -45,7 +46,7 @@
#else
#define FREQUENCYTIMER2_PIN 11
#endif

*/


class FrequencyTimer2
Expand Down
6 changes: 5 additions & 1 deletion Line.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
#ifndef LINE_H_
#define LINE_H_

#include "Arduino.h"
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <util/atomic.h>

/** For linear changes with a minimum of calculation at each step. For instance,
Expand Down
Loading

0 comments on commit 76e855c

Please sign in to comment.