Teensy 3.6 - Multiple SPI DACs

Status
Not open for further replies.

TomV

Member
Hi,

I'm currently trying to run multiple SPI DACs at a high speed (around 30k updates a second) using T3.6. I'm using the AD5328 12Bit 8 Channel DAC, I'm trying to run 10 of these at the same time, using only 5 channels on each. My calculations for the SPI bus are as follows:

1x 16Bit word * 5 Channels = 80 Bits
80 Bits * 10 Dacs = 800 Bits per update
800 Bits * 30,000times per second = 24,000,000 bits = 24MHz Bus.

Ive got the code set up and the SPI bus clocked at 30MHz. A single update of all DACs is taking 45uS according to my scope. Which equates to approx 22k updates a second. Is there a way I can optimise this code? Or am I really pushing the limits of the teensy here? Ideally Id like the rate to be much higher to allow CPU time for manipulation of the data being fed to the DACs, then I can slow the output down to my required rate. Attached is the test code I'm currently using, only one DAC is currently connected to the teensy but code is present for all 10.

Thanks.

Code:
#include <SPI.h>  

const int CS_Pins [10] = {10, 0, 0, 0, 0, 0, 0, 0, 0};
const int noOfDACs = 10;
const int LDAC =32;

SPISettings setAD5328(30000000, MSBFIRST, SPI_MODE1);


void setup() {

for (int i=0; i<noOfDACs; i++) {
   pinMode (CS_Pins[i], OUTPUT);
  digitalWriteFast(CS_Pins[i], HIGH);
}




  pinMode(LDAC, OUTPUT);
  digitalWriteFast(LDAC, HIGH);

  SPI.begin();
}




int x =0;

void loop() {
if (x == 0) x = 4095;
else x=0;

 for (int i=0; i<noOfDACs; i++) {
 write_value(CS_Pins[i], x,x, x, x, x);
}

  digitalWriteFast(LDAC, LOW);

}



void write_value(int module_CS, int xVal, int yVal, int rVal, int gVal, int bVal) {
SPI.beginTransaction(setAD5328);

  int xDAC = xVal | 0b0000000000000000; //channel A output mask
  int yDAC = yVal | 0b0001000000000000; //channel B output mask
  int rDAC = rVal | 0b0010000000000000; //channel C output mask
  int gDAC = gVal | 0b0011000000000000; //channel D output mask
  int bDAC = bVal | 0b0100000000000000; //channel E output mask
  

digitalWriteFast(module_CS, LOW);
  SPI.transfer16(xDAC);
  digitalWriteFast(module_CS, HIGH);

digitalWriteFast(module_CS, LOW);
  SPI.transfer16(yDAC);
  digitalWriteFast(module_CS, HIGH);

digitalWriteFast(module_CS, LOW);
  SPI.transfer16(rDAC);
  digitalWriteFast(module_CS, HIGH);

  digitalWriteFast(module_CS, LOW);
  SPI.transfer16(gDAC);
  digitalWriteFast(module_CS, HIGH);

  digitalWriteFast(module_CS, LOW);
  SPI.transfer16(bDAC);
  digitalWriteFast(module_CS, HIGH);


}
 
I suggest that you be very cautious when you try to run multiple devices at high speeds on the same SCK line. The capacitive loading of many connected devices has caused problems for other users.
 
Status
Not open for further replies.
Back
Top