I'm making a superfast(2 m/s ) PID linefollower for school. Now, it's just a simple black line so I don't need 10 bits of accuracy. My teacher says I could change the accuracy of the ADC to 8 bit, but I don't know how to do that. He told me to look in the datasheet of the µC to see which internal register I need to change. But even IF I'd find that register, I still don't know the syntax to do it.

Does anyone know how I change the 10 bit to 8 bit? Please don't tell me to get an external ADC which is faster, that's the NEXT step. I want to measure the time it takes to sample my sensor array with 8 bits of accuracy.

Why do you feel you need to speed up the ADC?Isn't getting on for 10000 conversions a second fast enough? (That's one conversion every 2/10th of a mm)

Quote

Now, it's just a simple black line so I don't need 10 bits of accuracy.

If it is a simple black line, why do you need any more than one bit?

I want to speed up the ADC, because it takes me about a milisecond to sample my entire sensor array. And I'm aiming for a cylce time of 4 ms (probably less) and I need every µs of that for the PID algorithm. That 4 ms cycle time results in sampling every cm(we have to be able to take turns with a 10 cm radius). I'll probably have to pick a faster µc than the 328, but I want to try if I can stretch it...

And I do need more than a single bit, because I want to be able to read a certain degree of grey, to interpolate the position of the line between 2 sensors.

// set the analog reference (high two bits of ADMUX) and select the// channel (low 4 bits). this also sets ADLAR (left-adjust result)// to 0 (the default).

/*mask ADMUX see http://www.atmel.com/Images/doc8161.pdf point 23.9!!! set refs1 and refs0 by shifting 3(high high) six bits to the left to use the internal voltage reference shift high to ADLAR to place the most significant bits in ADCH and then mask the last nibble with the channel of the pin */ ADMUX = (0x3 << 6) | (1 << ADLAR) | pin;

// start the conversion sbi(ADCSRA, ADSC);

// ADSC is cleared when the conversion finisheswhile (bit_is_set(ADCSRA, ADSC));

// we have to read ADCL first; doing so locks both ADCL// and ADCH until ADCH is read. reading ADCL second would// cause the results of each conversion to be discarded,// as ADCL and ADCH would be locked when it completed. low = ADCL;//high = ADCH;

// read the high bytereturn ADCH;}

Then in setup, you can also set the division factor to speed things up.

Do you really need to sample that fast. Controlling stuff is about controlling or changing the state they are in. Speed is a state. What is important is how fast does your robot CHANGE speed / steer. I take it it is not going to make a U-turn with a radius of 1 cm if it's doing 2 m/s. There is no point in having a very fast controller if the robot cannot comply with the commands its been given. It will cause the controller to oversteer, and can cause stability issues (oscillations)

Fast sampling creates noisy readings. You will have to filter the readings.

Fast sampling creates lots of data. Arduinos do not have lots of memory to store that information, nor do they have a lot of CPU power to process it in real time.