i have been searching all over the internet to find a simple and understandable example of an analogRead in the faster AVR type of approach, by adressing the ADC directly instead of through the arduino firmware.
i need to read 5 flex sensors as fast as possible. they are connected to the analog pins 0-3 and 6.analog pin 7 is used too so practically i need to read every analogpin except 4 and 5 because they are used for i2C
What i don't understand is all that mux and adscr setup stuff.
Your best bet is to use the ADC conversion complete interrupt to change the multiplexer, read the ADC value, save the result in a variable, and start another conversion. The default ADC clock is 125kHz, resulting in a conversion time of about 110us. You can double the ADC clock to 250kHz with almost no loss of precision. Beyond that, you can double it again to 500kHz and get ~9 bits precision, or quadruple it again to 1MHz and get ~8 bits precision.
As an example of what you can do, I'm currently clocking the ADC at 1MHz in an induction balance metal detector project, in order to sample a 7.8kHz signal 8 times per cycle to do phase sensitive detection.
dc42:
Your best bet is to use the ADC conversion complete interrupt to change the multiplexer, read the ADC value, save the result in a variable, and start another conversion. The default ADC clock is 125kHz, resulting in a conversion time of about 110us. You can double the ADC clock to 250kHz with almost no loss of precision. Beyond that, you can double it again to 500kHz and get ~9 bits precision, or quadruple it again to 1MHz and get ~8 bits precision.
As an example of what you can do, I'm currently clocking the ADC at 1MHz in an induction balance metal detector project, in order to sample a 7.8kHz signal 8 times per cycle to do phase sensitive detection.
That is really cool! you could do obstacle avoidance like that!
though... i have troubles finding a clear example. do you have one or can post one?
i need an example that contains everything to read one analog pin and instructions on what to change to select/read another pin.
iSpider:
i need an example that contains everything to read one analog pin and instructions on what to change to select/read another pin.
I could post the code for my metal detector, but it would need a lot of adaptation to meet your needs. Why not start by looking at file wiring_analog.c in your Arduino installation, and relating it to the datasheet for the microcontroller?