OK, have been reading all about interrupts. Thanks to forum for lots of info on them.
I have now got to this point and can generate a sample data stream, all in a small portion of the time available; about 10uSec out of 250uSec available so it seems worth continuing this route. Here is code if any one is interested.
Have found a possible BUG (maybe) with IDE. error message occurs ONLY if I try to make #defines the first lines of code.
Am I missing something?
// V0.1B Data streaming
// Platform; Arduino Mini 16Mhz
// IDE Arduino 0017
// V0.1A 27 Jan 2010 Set up 2usec interrupt and toogle pin 13
// V0.1B 28 Jan 2010 Biphase data streaming on pin 12; sync pulses on pin 13
//------------------------------------------------------------------------------
// #define dataPin 12 // VERY STRANGE! WILL GENERATE ERROR IF ACTIVE HERE
#define led 13
volatile byte temp1;
volatile byte toggle;
volatile byte data[9];
//#define led 13
#define dataPin 12 // BUT IS OK HERE!!
volatile byte i=0;
volatile byte j=0;
volatile byte buffer;
volatile byte mask;
volatile boolean dataBit=0;
//-------------------------------- set up ---------------------------------------
void setup(){
//set up timer 2 cotrol registers here
TCCR2A = B00000000; //select Normal Mode,freerunning counter, no connection to hardware pins
TCCR2B = B00000011; //normale, prescaler equals clock/32. With 16Mhz clock this give 2uSec clock to the TCNT2
OCR2A = 125; //initialise compare register for first interrupt
TIMSK2 = B00000010; //generate interrupt on output compare match A
pinMode(led,OUTPUT); // set DDR
pinMode(dataPin,OUTPUT);data[1]=B00000000; // dummy data
data[0]=B00011001; // dummy data
buffer=data[0];
mask=B00000001;}
//-------------------------------- interrupt service routine ---------------------
ISR (TIMER2_COMPA_vect){
OCR2A += 125; //add 250uSec increment to timer2
toggle = !toggle;
//digitalWrite(led,toggle); // nice stable 2Khz square wave here
digitalWrite(led,1); // start pulse for synching 'scopedigitalWrite(dataPin,dataBit); //write to output
if (i!=1) { // shift data only every second interrupt
i=1;
dataBit=!dataBit; // data bit must be toggledat every data read
temp1 =buffer & mask; //put zero or non zero depending on the state of the bit under the maskmask=mask<<1; // shift the mask left 1 bit
if (mask==0) {
mask=B00000001; // reset the mask bit
j=j+1; // increment data pointer
if (j>1) {
j=0;
}
buffer=data[j]; // get the next data byte
}
}
else{
i=0;
if (temp1!=0) { // if bit to be sent is a 1 then toggle dataBit again on the next interrupt
dataBit=!dataBit;
}
}
digitalWrite(led,0); //end syn pulse. THe pulse length indicates the fraction used of the time available
// So far this code uses about 10uSec out of the 250uSec period. There is still
// space for a fair bit of code.}
//--------------------------------------- main loop ------------------------------void loop(){
}