Hello everyone.I have some question about ADC.from topic what the reason to use ADC Ex. ---> MCP3208,MCP3008 in arduino because in arduino have analog input already.
What is the resolution of the built-in ADC? What is it's speed? What do you do if you need greater resolution or speed?
Internal ADC: 10 bit
Speed: 110uS/sample. Lots of interference between channels with high impedance sources.
MCP3208: 12 bit
Speed: Sample can be read in 3 SPI.transfer()s at SPI CLK = 2 MHz (SPI divisor = 8 ) about 12 uS.
digitalWrite(csPin, LOW);
dummyByte = SPI.transfer(upperCommandByte); // see Figure 6-1, 6-2 for lower 3 bits
upperByte = SPI.transfer(lowerCommandByte); // see Figure 6-1, 6-2 for upper 2 bits
lowerByte = SPI.transfer(0);
digitalWrite(csPin, HIGH);
int 12bitResult =( (upperByte<<8) & 0x0F) | lowerByte; // maybe + lowerByte? try it
Other multichannel ADCs can go even faster, transferring data at SPI clock = 8 MHz (SPI divisor = 2 ) in just 2 SPI.transfers, ~2uS total.
Example:
Of course, this chip also costs twice the price of the Atmega328P - but when you need performance, what's a couple of dollars?
For fastest performance, direct port manipulation for the csPin would be used in place of digitalWrites:
// using D3 for CS for example
PORTD = PORTD 0b11111011; // cs pin low
upperByte = SPI.transfer(CommandByte); // see Figure 45 for upper bits
lowerByte = SPI.transfer(0); //
PORTD = PORTD | 0b00000100; //cs pin high
int 12bitResult =( (upperByte<<8) & 0x0F) | lowerByte; // maybe + lowerByte? try it
Some assembler code could be used in place of the SPI library too, I think this:
(I haven't tried this for reading in, only sending out)
upperByte = spdr(CommandByte);
nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
lowerByte = SPI.transfer(0);
nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
Thank you for your answer.