Code to operate ADC(MCP3008)/programming micro chip

HI GUYS

any have a code similar that i can use to operate ADC conveter from the arduino reading signal from MCP3008 or a place i could go to on how to go about it.

Adafruit make shield with one and would doubtless supply a driver...

but it's only 10-bit - no better than the arduino adc - why not just use that?

regards

Allan

Because MCP3008 has 8 channels, is something like 10-12 times faster, and doesn't need the Arduino's read-twice when switching channels.

See Figure 6.1.
You're going to do 3 SPI.transfers. The first one sends data to chip, the second sends data and receives data, the third receives data:

digitalWrite (ssPin, LOW);
SPI.transfer(0x01); // start bit
incomingBits98 = SPI.transfer(commandBits);
incomingBits7to0 = SPI.transfer(0);
digitalWrite (ssPin, HIGH);
dataInt = ((incomingBits98 & 0x03) << 8) | incomingBits7to0;

where commandBits = 0b10000000, 0b10010000, 0b10100000, 0b10110000, 0b11000000, 0b11010000, 0b11100000, 0b11110000
or 0x80, 0x90, 0xao, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0 per table 5-2.
So you could write for loop to have the commandBits pulled from an array to be sent out:

for ( x=0; x<8; x=x+1){
digitalWrite (ssPin, LOW);
SPI.transfer(0x01); // start bit
incomingBits98 = SPI.transfer(commandArray[x]);
incomingBits7to0 = SPI.transfer(0);
digitalWrite (ssPin, HIGH);
dataArray[x] = ((incomingBits98 & 0x03) << 8) | incomingBits7to0;
}

with
byte commandArray[] = {0x80, 0x90, 0xao, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0,};

You have to slow the SPI clock to 2 MHz after SPI.begin() is called in setup(), see page 4 of the datasheet, results in about 12uS for the 3 SPI transfers,
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV8); // divides 16 MHz clock by 8, down to 2 MHz

SPI - Arduino Reference see setClockDivider
plus the digitalWrites and the math time. Replacing the digitalWrites with direct port manipulation can speed that up:

PORTB = PORTB & 0b11111011; // clear D10 (SS for SPI.transfers typically.
// code from above
PORTB = PORTB | 0b00000100; // set D10

If you want the 8 results even faster, then don't use a for loop, just hardcode the 8 transfers. The for loop adds time.