120,000 hz arduino only oscilloscope?

Not looking for arduino language support for this, but if you know an answer give a shout out:

  1. does the hardware behind analogRead need to be blocking?
  2. Does the performance of an analog read improve with a faster clock rate?
  3. and if(!1) can you gang the analog read pins together and not have the reads interfere with each other if triggered at different (overlapping) times?

I'm just wondering because it seems that if you put the fastest crystal the atmega can stand (say 32mhz) and determine the max time for an analog read (say .05 microseconds @ 32mhz), then you could set up a timer to trigger a read every 1/6th of .05 microseconds, or 120,000 hz. Or 60khz at standard arduino timings. You would evenly space the reads between the analog pins as fast as possible.

Also, how does one autorange? With an op amp and a pwm pin or something?

Anyway, I like to do mockups on my cheesey standard device, so this is how it might look on an inexpensive character display :slight_smile: (32x20 resolution)

  1. does the hardware behind analogRead need to be blocking?

I don't understand what you're asking. The mega168 only has one ADC, which means you can only be performing a conversion on one channel at a time. While the conversion is going on, the ADC hardware is by definition busy, but this does not occupy the processor in any way.

  1. Does the performance of an analog read improve with a faster clock rate?

The ADC has its own clock (a prescaled version of the system clock). To get maximum resolution (i.e. 10 bits), the ADC clock must be between 50 and 200 kHz. If you don't need maximum resolution, you can run the ADC faster than 200 kHz, but the faster it is, the lower the resolution. Note that the analog-to-digital conversion takes 13 ADC clock cycles while the ADC is running normally and 25 clock cycles to initialize the ADC and perform the first conversion. This means that if you want maximum resolution, you will have a sample rate of around 15 kHz.

  1. and if(!1) can you gang the analog read pins together and not have the reads interfere with each other if triggered at different (overlapping) times?

No. The ADC spends nearly its entire conversion time measuring the voltage on the channel for which it is set.

I'm just wondering because it seems that if you put the fastest crystal the atmega can stand (say 32mhz)

The fastest the mega168 can run (according to its spec) is 20 MHz. If you run it faster than this it might work (or seem to work, but it is out of spec and could lead to all sorts of obscure problems.

  • Ben

Thanks Bens! Thats exactly what I needed to know, though not what I hoped to hear :wink:

Anyone explain what blocking means?

When you call a function (i.e. analogRead), it does not return until the read is complete. This is a very simple way to keep the order of operations in order. Most everything in arduino is blocking, much easier to keep things straight especially for folks just learning. So later in your program you don't need an "are you done with that analog read yet?" bit of code.

The reasons why you might not want to block are usually performance oriented and a slightly more advanced topic. But if a function took a long time to execute, you might want to do something else and check back later to see if the operation is done or not. Or give it the name of a function to execute when it is completed. That would be a non-blocking call.