I'm using an Atmega1284p to record audio at 19,500 bytes per second. When I play the music back, I hear a brief skip-ahead every 50 seconds or so.
I think the cause must be that reading the audio buffer into the SD Card is just a tad slower than the ISR is writing to that buffer, causing the ISR's writing to catch up with and pass the SD Card's reading about once every 50 seconds. This, of course, causes one full buffer of data to never get saved to the SD Card.
However, the ISR frequency settings I'm aware of (shown in the code below) are basically Times Two, or Divide by Two, while I only need a slight slow-down of the ISR frequency.
How can I manage that?
char buffA[2049];
char buffB[2049];
int buffCnt = 0;
void setupISR()
{
// ADC ISR frequencies available
// *** ISR FREQUENCIES ***
// 0-1-2 9,700 // (1 << ADPS0) | (1 << ADPS1) | (1 << ADPS2)
// x-1-2 19,500
// 0-x-2 37,800
// x-x-2 76,900
// 0-1-x 154,000
// 0-x-x 233,000
// x-1-x 233,000
cli();//disable interrupts
ADCSRA = 0; // clear before adding bits
ADCSRB = 0; // clear before adding bits
ADMUX |= (1 << MUX0); //setting input pin A7
ADMUX |= (1 << MUX1); //setting input pin A7
ADMUX |= (1 << MUX2); //set input pin A7
ADMUX |= (1 << REFS0); //set reference voltage 0 0 external, 0 1
//ADMUX |= (1 << REFS1); //
ADMUX |= (1 << ADLAR); //left align the ADC value- so we can read highest 8 bits from ADCH register only
bitSet(ADMUX, 6); // set bits 6, 7 for AREF of 2.56 Volts
bitClear(ADMUX, 7); //
ADCSRA |= (1 << ADPS1) | (1 << ADPS2); //set ADC clock
ADCSRA |= (1 << ADATE); //enabble auto trigger
ADCSRA |= (1 << ADIE); //enable interrupts when measurement complete
ADCSRA |= (1 << ADEN); //enable ADC
ADCSRA |= (1 << ADSC); //start ADC measurements
isrB = true;
sei();//enable interrupts
}
unsigned int bCount = 0;
ISR(ADC_vect)
{
if(aReady)
PORTC = buffA[buffCnt];
else
PORTC = buffB[buffCnt];
if (buffCnt == 2047)
{
buffCnt = 0;
aReady = ! aReady;
myFileDo = true;
}
else
buffCnt++;
}
// ....
void loop()
{
while (!myFileDo) {};
myFileDo = false;
if (aReady)
myFile.read(buffB,2048);
else
myFile.read(buffA,2048);
}