 // data is clocked on the rising edge of the clock (seems to be SPI_MODE0)
 // max clock speed: 20 mHz
 // Using TDC7200 timing mode 1...
-
-
 void setup() {
+  int i;
   // start the SPI library:
   SPI.begin();
   
   pinMode(intPin, INPUT);
-  
-  pinMode(ChA->ENABLE,OUTPUT);
-  pinMode(ChA->INTB,INPUT);
-  pinMode(ChA->CSB,OUTPUT);
-  pinMode(ChA->STOP,INPUT);
-  pinMode(ChB->ENABLE,OUTPUT);
-  pinMode(ChB->INTB,INPUT);
-  pinMode(ChB->CSB,OUTPUT);
-  pinMode(ChB->STOP,INPUT);
+
+  for(i = 0; i < ARRAY_SIZE(channels); ++i) {
+    pinMode(channels[i].ENABLE,OUTPUT);
+    pinMode(channels[i].INTB,INPUT);
+    pinMode(channels[i].CSB,OUTPUT);
+    pinMode(channels[i].STOP,INPUT);
+    TDC_setup(&channels[i]);
+  }
   
   attachInterrupt(interrupt, coarseTimer, RISING);
+
+  delay(10);
   
-  TDC_setup(ChA);
-  TDC_setup(ChB);
-  delay(10);
-  ready_next(ChA);
-  ready_next(ChB);
+  for(i = 0; i < ARRAY_SIZE(channels); ++i)
+      ready_next(&channels[i]);
   
   Serial.begin(115200);
   Serial.println("Starting...");
 }
 
 void loop() {
- 
-  if (ChA->STOP) 
-    ChA->stopTime = coarseCount; // capture time stamp of gated stop clock
- 
-  if (ChB->STOP) 
-    ChB->stopTime = coarseCount;
+  int i;
 
-  if (ChA->INTB) { // channel measurement complete
-    ChA->result = TDC_calc(ChA); // get registers and calc TOF
-    ready_next(ChA); // enable next measurement
+  for(i = 0; i < ARRAY_SIZE(channels); ++i) {
+    if(channels[i].STOP)
+      channels[i].stopTime = coarseCount;
+
+    if(channels[i].INTB) {
+      channels[i].result = TDC_calc(&channels[i]);
+      ready_next(&channels[i]);
+    }
   }
-  
-  if (ChB->INTB) {
-    ChB->result = TDC_calc(ChB);
-    ready_next(ChB);
+     
+   // if we have both channels, subtract channel 0 from channel 1, print result, and reset vars
+  if (channels[0].result && channels[1].result) { 
+    output_ti();
+    for(i = 0; i < ARRAY_SIZE(channels); ++i) {
+      channels[i].result = 0;
+      channels[i].stopTime = 0;
+    }
   }
-   
-   // if we have both channels, subtract channel 0 from channel 1, print result, and reset vars
-   if (ChanA.result && ChanB.result) { 
-    output_ti();
-    ChA->result = 0;
-    ChB->result = 0;
-    ChA->stopTime = 0;
-    ChB->stopTime = 0;
-   } 
 }  
 
 // ISR for timer. NOTE: uint_64 rollover would take


// Initial config for TDC7200

int TDC_setup(chanTDC7200* channel) {
  digitalWrite(channel->ENABLE, HIGH);
}


// Fetch and calculate results from TDC7200
int TDC_calc(chanTDC7200* channel) {
    TDC_read(channel);
    // calc the values (John...)
}

// Read TDC for channel
void TDC_read(chanTDC7200* channel) {

  byte inByte = 0;
  int timeResult = 0;
  int clockResult = 0;
  int calResult = 0;

  // read the TIMER1 register
    // take the chip select low to select the device:
  digitalWrite(channel->CSB, LOW);

  SPI.transfer(TIME1);

void output_ti() {
}

void writeTDC7200(struct chanTDC7200 *channel, byte address, byte value) {
  // take the chip select low to select the device:
  digitalWrite(channel->CSB, LOW);

