On a project I'm currently doing R&D work on, I'll be incorporating an SD card for reading of external data. What I'd like to do is store instructions, specifically in_idx, angle_pan, speed_pan, angle_tilt, speed_tilt, and a timestamp index. Imagine an Excel file with all the data in it. in_idx is simply the instruction index.
My question is, is it possible to "stream" this data. In other words, rather than having the MCU open the file and read the whole thing in memory to execute, is it possible to read-as-needed? What I'm thinking is, let's say the first few instruction look like this:
in_idx angle_pan speed_pan angle_tilt speed_tilt timestamp
0 90 2 90 2 5
1 45 4 90 0 2
2 135 4 90 0 5
This tells me from the first instruction, that both pan and tilt servos need to go to their 90 degree position at speed = 2. The '5' timestamps at the end means nothing happens for 5 seconds after that, so the MCU knows not to come back for another instruction for 5 seconds. (The board will have an RTC on it for accurate timings and syncing with other units nearby.)
After those 5 seconds have elapsed, it reads the next set which is 45, 4, 90, 2, 2: move the pan servo to 45 degrees at speed = 4, keep the tilt servo at 90, and wait 2 seconds before getting the next instruction.
After 2 seconds, read the next instruction which tells the pan servo to go to 135 degrees at speed = 4, keep the tilt servo at 90, and wait 5 seconds for the next instruction.
I suppose I can open/close the file each time, but I'm more concerned about delays in doing that. Basically I want a system I can time accurately to music. I can tear the audio apart and get exact timings for it. I want to be able to feed the timing data (modified of course) into a table and onto the SD card for the MCU to then read from.
What caveats do I need to look out for? What potential problems and/or headaches will I encounter here? I know I need to figure out how long to wait before expecting the servo to be where I sent it to and feeding it another instruction (otherwise it will never reach its intended target angle.)
Honestly, I don't know if this is the best way of doing this process, so I am open for suggestions here. The reason I want to incorporate an SD card for this is two fold,
a) I suspect the data will be rather large to fit it all in 32K of memory (actually, I know it won't fit.)
b) Using an SD card means I can set all the instructions in Excel, and export it as a comma delimited file and onto the SD card from my computer, then just pop the card onto the board.
Ideas/suggestions?