Hey folks. I have a problem that I just cannot seem to figure out with my code using IntervalTimers
This code gives me a compile time error (with no diagnostic information). Sad Panda. If I comment out the line: Speaker3Timer.begin(Speaker3, 125), the code compiles and runs fine. I tried commenting out other SpeakerTimer (similar) lines to see if this specific to one repeating section of my code and this doesn't seem to fix the issue. Presumably, this is an issue with the Speaker3 section of my code but I just don't see it.
On top of the fact that I don't get an compile time errors, I wonder if this is some odd bug?
Would be grateful for any help. Thanks.
Snippet of my male.h header file as an example:
This code gives me a compile time error (with no diagnostic information). Sad Panda. If I comment out the line: Speaker3Timer.begin(Speaker3, 125), the code compiles and runs fine. I tried commenting out other SpeakerTimer (similar) lines to see if this specific to one repeating section of my code and this doesn't seem to fix the issue. Presumably, this is an issue with the Speaker3 section of my code but I just don't see it.
On top of the fact that I don't get an compile time errors, I wonder if this is some odd bug?
Would be grateful for any help. Thanks.
Code:
// Render small 8bit, 8kHz file from voicesSample Reaper project
// From https://github.com/olleolleolle/wav2c
// run: ./wav2c male.wav male.h <chosen_arrayname> from wav2c folder.
#include <avr/pgmspace.h> // needed to support defining sounddata as FLASH based
#include "male.h" // this is the noise/sound to play
#include "female.h"
//#include "male2.h"
#include "female2.h"
const int speaker1Pin = 9; // Teensy3 has Speaker on pwm digital pin 9
const int speaker2Pin = 10;
const int speaker3Pin = 23;
void Speaker1(void); // we’re going to call this function at 8kHz
void Speaker2(void);
void Speaker3(void);
IntervalTimer Speaker1Timer; // interval timer construct to call Speaker
IntervalTimer Speaker2Timer;
IntervalTimer Speaker3Timer;
volatile uint32_t sample1 = 0; // needed 32 bit unsigned, had issues w larger (8 seconds) samples rolling over the 16 bit counter – duh
volatile uint32_t sample2 = 0;
volatile uint32_t sample3 = 0;
volatile uint16_t PlaybackCount = 0; // keep track of the number of plays per ISR playback loops
byte lastSample1;
byte lastSample2;
byte lastSample3;
void setup(){
analogWriteResolution(8);
//Serial.begin(9600);
//pinMode(LED_BUILTIN, OUTPUT); // duh, LED is an output
pinMode(speaker1Pin, OUTPUT); // the PWM speaker output is an output
analogWriteFrequency(speaker1Pin, 50000); // Teensy 3.0 lets you do 400kHz comfortably, no aliasing or high freq artifacts
analogWrite(speaker1Pin, 0); // pull down the speaker to 0 to reduce current consumption
Speaker1Timer.begin(Speaker1, 125); //sets the ISR rate in microseconds for the TardisSpeaker – 8kHz rate
pinMode(speaker2Pin, OUTPUT);
analogWriteFrequency(speaker2Pin, 50000); // Teensy 3.0 lets you do 400kHz comfortably, no aliasing or high freq artifacts
analogWrite(speaker2Pin, 0); // pull down the speaker to 0 to reduce current consumption
Speaker2Timer.begin(Speaker2, 125); //sets the ISR rate in microseconds for the TardisSpeaker – 8kHz rate
pinMode(speaker3Pin, OUTPUT); // the PWM speaker output is an output
analogWriteFrequency(speaker3Pin, 50000); // Teensy 3.0 lets you do 400kHz comfortably, no aliasing or high freq artifacts
analogWrite(speaker3Pin, 0); // pull down the speaker to 0 to reduce current consumption
Speaker3Timer.begin(Speaker3, 125);
}
void loop(){
// unsigned long playbackCopy; // holds a copy of the blinkCount
// noInterrupts();
// playbackCopy = PlaybackCount;
// interrupts();
// Serial.print("PlaybackCount = ");
// Serial.println(playbackCopy);
// delay(100);
}
void Speaker1(void){
if (sample1 < male_length) {
lastSample1 = pgm_read_byte(&male_data[sample1]); // read the sample index into lastSample from the datastructure hard-coded into sounddata.h
analogWrite(speaker1Pin, lastSample1); //set the PWM to the just-read sample, this will average out because of the speaker’s inertia to a position
sample1 = sample1 +1; // increment sample
} else {
// PlaybackCount++; // guess we’re done playing the sample, inc the count and pause a second
delay(1000);
sample1=1; // reset sample to 1}
}
}
void Speaker2(void){
if (sample2 < female_length) {
lastSample2 = pgm_read_byte(&female_data[sample2]); // read the sample index into lastSample from the datastructure hard-coded into sounddata.h
analogWrite(speaker2Pin, lastSample2); //set the PWM to the just-read sample, this will average out because of the speaker’s inertia to a position
sample2 = sample2 +1; // increment sample
} else {
// PlaybackCount++; // guess we’re done playing the sample, inc the count and pause a second
delay(1000);
sample2=1; // reset sample to 1}
}
}
void Speaker3(void){
if (sample3 < female2_length) {
lastSample3 = pgm_read_byte(&female2_data[sample3]); // read the sample index into lastSample from the datastructure hard-coded into sounddata.h
analogWrite(speaker3Pin, lastSample3); //set the PWM to the just-read sample, this will average out because of the speaker’s inertia to a position
sample3 = sample3 +1; // increment sample
} else {
// PlaybackCount++; // guess we’re done playing the sample, inc the count and pause a second
delay(1000);
sample3=1; // reset sample to 1}
}
}
Snippet of my male.h header file as an example:
Code:
// const int male_sampleRate = 8000;
const int male_length = 120000;
const signed char male_data[] PROGMEM ={128,
128, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
129, 129, 129, 129, 129, 129, 129, 129, 129, 129, 128, 128, 128, 128, 128, 128, 128, 128, 127, 127,
127, 127,...