Trying to get the fastest possible throughput using an ADS8331 ADC with Teensy.
The main loop looks like this right now:
I'm clocking the Teensy at 96MHz and it's not fast enough.
From the falling edge of CONVSTB to the rising edge of CS_adc takes just a tad over 1.5us, I need to get that down to about 1.4us.
Here's the time breakdown, measured on the scope:
- width of the negative-going CONVSTB pulse: 80ns
- rising edge of CONVSTB to falling edge of CS_adc: 250ns
- falling edge of CS_adc to first SPI clock edge: 200ns
- 16 SPI clocks: 640ns (using 24MHz SPI clock speed, defining a higher clock speed produces the same result)
- last SPI clock edge to CS_adc rising edge: 350ns
Where's the low-hanging fruit where I can shave off a couple of hundred nanoseconds?
- Replace the digitalWriteFast commands with something faster? Inline assembly maybe? (never tried that but up for it)
- Try to rewrite the SPI.transfer16 function to make it faster? (my C/C++ is extremely rusty but maybe this is my opportunity to scrape off the rust)
- Something else?
I'm relatively new to Teensy and Arduino, any pointers much appreciated.
The main loop looks like this right now:
Code:
digitalWriteFast(ADS8331_CONVSTB_pin, LOW); // "conversion start" pulse tells ADC to do its thing, needs to be at least 40ns wide
digitalWriteFast(ADS8331_CONVSTB_pin, HIGH);
digitalWriteFast(CS_adc, LOW);
// read a 16-bit data word from the ADC
// Note, this actually reads data from the previous iteration of the loop.
// The A-to-D conversion initiated in the current iteration of this loop is happening while we read out the last result
ch0_raw = SPI.transfer16(0x0000);
digitalWriteFast(CS_adc, HIGH);
I'm clocking the Teensy at 96MHz and it's not fast enough.
From the falling edge of CONVSTB to the rising edge of CS_adc takes just a tad over 1.5us, I need to get that down to about 1.4us.
Here's the time breakdown, measured on the scope:
- width of the negative-going CONVSTB pulse: 80ns
- rising edge of CONVSTB to falling edge of CS_adc: 250ns
- falling edge of CS_adc to first SPI clock edge: 200ns
- 16 SPI clocks: 640ns (using 24MHz SPI clock speed, defining a higher clock speed produces the same result)
- last SPI clock edge to CS_adc rising edge: 350ns
Where's the low-hanging fruit where I can shave off a couple of hundred nanoseconds?
- Replace the digitalWriteFast commands with something faster? Inline assembly maybe? (never tried that but up for it)
- Try to rewrite the SPI.transfer16 function to make it faster? (my C/C++ is extremely rusty but maybe this is my opportunity to scrape off the rust)
- Something else?
I'm relatively new to Teensy and Arduino, any pointers much appreciated.