Periodic click when saving ADC input to SD card

With the main.cpp code RMS noise is ~15 counts at 12 bits and no averaging, 1.17Msamp/s.
Here is one second of photodiode data
Figure_1.png
no data jumps/missing even at high slew rates:
Figure_1b.png
 
I can't get my head around what write() is actually doing, and how to enforce 512 & is_busy() as used by the ISR function in main.cpp:
rb.write() is writing data INTO the RingBuf, while rb.writeOut() extracts data FROM RingBuf and writes TO the file on SD.
main.cpp is running error-free for now, but I could redesign to not write in the ISR as per the TeensySdioLogger I suppose if needed.
I usually choose to keep my ISRs as short as possible and write to SD from loop(), with this approach:
[ISR] ----> RingBuf ----> [loop] ---> SD
 
rb.write() is writing data INTO the RingBuf, while rb.writeOut() extracts data FROM RingBuf and writes TO the file on SD.

I usually choose to keep my ISRs as short as possible and write to SD from loop(), with this approach:
Ah I think I see
And Bill Greiman did not use file.is_busy() in his example TeensyDmaAdcLogger.ino
Code:
if (n >= 512) { // could be if ((n > 512) && !file.isBusy()) {
      if (rb.writeOut(512) != 512) {
        Serial.println("writeOut() failed");
        file.close();
        return;
      }
    }
And this thread explains it best it seems.

What had got me was RingBuf.h:
Code:
* This function must only be used in non-interrupt code.
...
   */
  size_t writeOut(size_t count) {
The call to writeOut() in the examples IS in non-ISR code: runTest() is simply called from loop()
 
Back
Top