Equip your Genius
Welcome to the Parallax Discussion Forums, sign-up to participate.
Learn with BlocklyProp
SPIN driver for MCP3208
2020-11-19 - 19:34:28
Wondering if anyone created (and willing to share) a SPIN driver for the MCP320x family of A/Ds (SPI bus) ?
2020-11-19 - 20:24:02
edited 2020-11-19 - 22:20:56
Here is a Spin1 PUB function I have.
Read app notes 6.3 Buffering & filtering carefully
also 6.4 Layout Considerations.
Must use a MCP1541 voltage reference chip (or equal ) along with the required 1uF cap
There is way too much voltage variance and noise in a system voltage supply, and you will never get consistent readings either long or short term.
Using the P2 Smart pin ADC gives much better short and long term readings. My tests is to short a P2 DAC and ADC together. Set the DAC at some nice voltage (1.000 VDC) and read the voltage using a Smart pin ADC. Consistent short and long term (2000 hours plus) readings 1.00x plus/minus 1or 2 counts, as compared with my 4 half digit voltmeter.
2020-11-19 - 20:53:43
edited 2020-11-19 - 22:39:34
This is converted from some P1 code. Since we have inline assembly with the P2, I used that for the SPI transaction so you can control the speed.
Warning: Not tested (yet) by JM -- though I feel like this is an accurate translation of P1 code that I've used in other projects.
Of course, after I posted I looked back and found some little gotchas. While I don't have a loose chip to test with, I do have a logic analyzer. The attached image shows a test of this version of the object attempting to read channel 0 in single-ended mode. The constant for that is %11000, and you can see that corresponds to the first five bits out of the MOSI pin.
1406 x 790
2020-11-19 - 22:08:38
Thank you both of you very much.
This will be a great head-start (or complete finish if they run as-is!!).
Whatever happens, I'll post back a tested working code sample later next week. As soon as I finish a test fixture for a certain large P2 development board