Development continues. With the analog capture and CAN interfaces done and working, I moved on to getting the SDCard interface configured. While it is great to log over CAN, I also want to be able to log to SD from the ADCs and from the CAN bus. When I made the board I put a set of SPI pins on a header so I could connect a MicroSD socket. (note I didn’t remember to put a pullup on DO which is normally open collector, but it appears the SD card itself has a weak pullup internally).
Interfacing to the SDCard over SPI has been an interesting endeavor. The SD-SPI spec is an odd one, with lots of goofy timing constraints. When you initialize the the card you have to start it up with 100-500khz SPI, then once it is initialized you can switch to a higher clock rate. And of course with SPI you send and receive at the same time, so if you are waiting for something, you are sitting in an transmit loop waiting for something that looks like data to appear.
The PIC I am using (dsPIC33) only supports SPI speeds up to 15MHz SCLK (according to the datasheet), although I was able to get it working at 20Mhz SCLK. With single wire SPI, using single block writes (which have a lot of overhead) I am getting about 640KB/sec, or a bit over 5Mbit/sec. That is more than sufficient for my use case, as even with 24 channels at 1000 hz we are talking about writing 240KB/sec maximum write speed.
For running this on my desk I was using an inexpensive 12V wall wort, and when I looked at the output I was surprised. (see last picture).. 250mv noise that is just terrible. I have similar noise on the +5 and +3.3V rails, which means I don’t have enough filtering on the power regulation side. The 12V source in a car can be much worse, so I need to look at adding some LC filtering. I’ll finish up my SD interface, then get working on overlaying a FAT16/FAT32 filesystem implementation.
Thanks to Matthew R. Wilson for the help debugging the clock signals!