SD read -> I2C-DAC; latency and interrupt issues

I posted this in the "Project Guidance" subforum as well, but I figured since it relates a lot to Storage, and the fact that "fat16lib" might have a suggestion, I'd post it here as well.

The goal:
Read bytes from an SD card -> send bytes via I2C to a DAC - MCP4725 (this DAC needs to be performing conversions at a constant rate of around 5-6kHz) -> repeat 1000s of times.

The problem:
For whatever reason (SD card storage architecture, the way my particular SD card is formatted, etc.) the file on my SD card with the data I wish to read is structured in 512-byte "blocks". The first "read" that takes place in a block (I'm using fat16lib's SDFat library. The file was written using fat16lib's AnalogISRLogger sketch), takes ~1.4 ms. Subsequent reads in that block take considerably less time (<50 us). I need to figure out a way to normalize this read time so that I can send data to the DAC at a constant rate.

Solution I was working towards:
Using a buffer to store data before sending it to the DAC. That way, lets say my buffer holds 200 pieces of data, the average read time would be normalized to something like
(1400 + 199 * 50)/200 = 56 microseconds (assuming one of the pieces of data was a "first read").
To ensure that I'm writing to the DAC at a fixed rate while still filling up this buffer, I would let the "read data from the sd card and write to buffer" process occur in the loop() function, and then have the "send the next sample from the buffer to the DAC" occur in an interrupt routine, triggered by the Atmel 328p's Timer/Counter 1

The problem with the "solution":
I'm pretty sure the I2C/Two-Wire Interface runs off the "TWI" interrupt vector, which is a lower priority than the "Timer" vectors (and almost all the other interrupt vectors). As a result, attempting Two-Wire communication inside of a higher-priority ISR has no effect. (This only occurred to me because I spent a couple of hours trying to use the TWI inside my timer interrupt with no success...)

So I'm stuck. I don't know how to get the DAC to convert at a fixed rate (regardless of the current state of the program), without using an interrupt, and the nature of the DAC means that I cannot trigger it off of an interrupt.

Any suggestions? (sorry for the wall of text, I just wanted to coherently present my plight)

Thanks.

There will always be reads that take over 1 ms so you need a solution for read that buffers ahead.

There are I2C libraries that don't use interrupts. I wrote such a library that supports both hardware and software I2C but it is not well documented. It is included in this file, AdafruitLogger20120609.zip here http://code.google.com/p/beta-lib/downloads/list. The library is I2cMaster.

You could look at my libraries for the Adafruit Wave Shield for examples that send data to an DAC at up to 44.1 ksps.

This is a player only library Google Code Archive - Long-term storage for Google Code Project Hosting.. It uses a SPI DAC but could use a I2C DAC at slower speeds.

Here is a player/recorded library Google Code Archive - Long-term storage for Google Code Project Hosting..

These libraries solve the read ahead problem with a timer triggered thread.

I posted this in the "Project Guidance" subforum as well, but I figured since it relates a lot to Storage, and the fact that "fat16lib" might have a suggestion, I'd post it here as well.

Your cross-posting was reported so I figured I'd save people wasting their time responding to a duplicate post, so I deleted it.

DO NOT CROSS-POST.

Thanks fat16lib, I'll take a look at those libraries and see if I can get them working.

Sorry AWOL, wont happen again.

Sorry AWOL, wont happen again.

If you do decide, after posting, that you posted in the wrong place, a PM to a moderator will get your post moved with no scolding. I'm the one that asked that the duplicate in the Project Guidance one be deleted. The process for doing that doesn't leave room for much input. Sometimes it would be nice to be able to let a moderator know that the poster knows he/she posted in the wrong place and wants the post moved/merged.

The moderators have a lot of work to do, and sometimes come down a little strongly. I think this is one case where that happened, and on behalf of the moderators, I'd like to apologize.

There's really no reason to apologise on my behalf.

Once a post is made, the author of that post can not use the Report to moderator function. So it is difficult for a person to get their own posts moved. It is easy for others to report a duplicate post.

Not every duplicate posting needs to be treated the same. When the second post says "I posted this in the wrong place initially", wouldn't go on the "DO NOT CROSS-POST" rampage. Where the same post is made in three or more forums, the rampage is appropriate.

In the interest of full disclosure, the cross-post was intentional to get my question more exposure. I figured there may have been people in one forum that did not read the other, and selfishly wanted my question answered quickly, because it is a time-sensitive project. At any rate, I learned my lesson about forum guidelines, so it's all good.