Analog to Digital Conversion in uSec? Possible

Hi folks,

I know that conversion happens with pulses rated in MilliSeconds intervals but I wanted to have these pulses in MicroSeconds, Is this possible?

With the internal ADC: No. With some external (expensive) hardware: Yes, but you won't get the values fast enough to the Arduino.

NI$HANT: I know that conversion happens with pulses rated in MilliSeconds intervals [...]

Probably I'm missing something with the "pulses" thing, but the ADC clock can be set (using an appropriate value for the prescaler) at a frequency up to 200KHz (the default is 125KHz). Since it takes 13 clock cycles to complete the conversion, the rate could become higher than 10KHz (it is 9.6KHz with the default setting). A resolution lower than 10 bits (values from 0 to 1023) could also increase the conversion rate. Anyway, the frequency is higher than the millisecs interval indicates.

There are many techniques for doing an A/D conversion. The fastest method is called a flash conversion. There are also some chips that use a half flash method and are SPI so you can simply get the data in quickly. Data rates in the MHz range are possible.

Look at a major distribuitors where you are and see what choice of chips they have.

Probably I'm missing something with the "pulses" thing, but the ADC clock can be set (using an appropriate value for the prescaler) at a frequency up to 200KHz (the default is 125KHz). Since it takes 13 clock cycles to complete the conversion, the rate could become higher than 10KHz (it is 9.6KHz with the default setting). A resolution lower than 10 bits (values from 0 to 1023) could also increase the conversion rate. Anyway, the frequency is higher than the millisecs interval indicates.

I'll be writing these analogwrites to pwm pins I hope to get this working with the following:

// defines for setting and clearing register bits

ifndef cbi

define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))

endif

ifndef sbi

define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

endif

// set prescale to 16(these are registers for ATmega328 will need to refer to the ATmega2560 registors) sbi(ADCSRA,ADPS2) ; cbi(ADCSRA,ADPS1) ; cbi(ADCSRA,ADPS0) ;

NI$HANT: Hi folks,

I know that conversion happens with pulses rated in MilliSeconds intervals but I wanted to have these pulses in MicroSeconds, Is this possible?

10-bit analog read takes about 104 microseconds.

You can do 9 10-bit analog reads with small processing each per millisec on the same pin. 8-bit reads go faster.

If you can live with rough, low resolution then using (carefully checked and matched) resistors you could make near-instant conversion to the pins of 1 port rather cheaply. How fast you can read and evaluate the port would be your speed. It won't be terribly accurate but could be calibrated to known values. There are components I think called resistor ladders for such and other purposes.

I'll be writing these analogwrites to pwm pins

I don't know where the PWM pins go into the analog-digital conversion but keep in mind that although it's called analogWrite() you don't get an analog value out of the pin. With some additional electronics you can convert the PWM signal to an analog signal usable in most situations. BTW, the code you posted has nothing to do with the PWM pins.

BTW, the code you posted has nothing to do with the PWM pins.

The code I posted prescales the Analog converter clock so it basically upscales the speed from 125khz to 200khz the speed which ATmel deems is fine and the upper limit to get acceptable values thought accuracy can be minor issue so it has a lot to do with PWM pins if I apply that prescaled pulses to a PWM output to get the digital pin work.

so it has a lot to do with PWM pins if I apply that prescaled pulses to a PWM output to get the digital pin work.

Maybe it’s because I’m not a native English speaker but I don’t understand this sentence. And I still don’t see the relation between PWM output and the ADC frequency.

The relationship is that when you do analog write on a PWM pin then the PWM pin should toggle as per the analog clock set and as in our case the pulses generated must correspond to the clock speed set on analog converter

Never heard of this relationship. Can you point me to the part of the datasheet (or application note) where this is defined?

NI$HANT: The relationship is that when you do analog write on a PWM pin then the PWM pin should toggle as per the analog clock set and as in our case the pulses generated must correspond to the clock speed set on analog converter

No, the ADC and its clock are for analog reading. Analog write uses the Timer counters. The analog converter has absolutely nothing to do with analogWrite(). If you want to change PWM frequency, then you need to be looking at the timers, not the ADC.