How to read analog values with a rate of > 1 MHz?

I do not need to store the data, the only info i need is the time it takes from the signal to switch between the rising state and the steady state.

This is very unclear. Do you mean the rise time of the signal? That is often defined as the time the signal takes to go from 10% of steady state amplitude to 90% of steady state.

I'm not sure where i picked up the 64 MHz, can't seem to reproduce it at this time.

The signal I want to measure is the (characteristic) flyback signal of a coil. The signal first rises to a peak level (start timer),and then decays until it becomes steady again (end timer). Or if the signal drops below a certain threshold.

Use two comparators and a flip flop to get digital signals. Then use a high speed oscillator to count the clock pulses between those two events.
No arduino needed.

I strongly agree with @Grumpy_Mike...

KingBee:
I need to know the time between a rising signal and a steady signal, resolution < 1 microsecond.

On a standard 16 MHz Arduino, that gives you 16 processor cycles to complete your task. Just this one line of code...

  analogRead(RxPin);

...is...

  da:	80 91 30 01 	lds	r24, 0x0130
  de:	0e 94 67 01 	call	0x2ce	; 0x2ce <analogRead>
...
 310:	08 95       	ret

2 + 4 + 4 = 10 clock cycles. That's right. Just the function call itself is more than half of your cycle budget.

You may be able to get what you want but it will require carefully crafted assembly to ensure the time constraint is met.

The ATtiny85 has a PLL that runs at 64MHz. The CPU can use that as a clock source after being prescaled/4 (so, 16MHz). Timer1 can also be clocked from the PLL with a variety of prescalers, including /1 (so, 64MHz).

You don't need the PLL to speed up the ADC clock, though. The ADC (on other ATtinies as well as ATmega) has it's own clock which can be prescaled to various values separate from the CPU clock.

Could you elaborate a bit, i'm not sure i can follow you.

Perhaps you could use an interrupt pin.
The datasheet will specify the VIH and VIL levels.
VIH would be the peak level that triggers the interrupt and starts a timer (RISING interrupt).
VIL would signify that the signal is steady and stops the timer (FALLING interrupt).
The time would measure a significant portion of the signal, could scale this result to approximate other trigger levels.

Check the cycles to call the interrupt.

Less than 4 usec timing on Arduino takes loop counting or inline instruction sequences.
You can get sub-usec IIRC down to 4 cycles or so.

The ATtiny85 has a PLL that runs at 64MHz.

So it has, didn't know that.
However, it is only a Peripheral Clock Generation, the CPU will not run at that speed.

This thread could be of interest for information on high speed interrupts and timing.

Attached is an example of the signal I want to measure

You should be able to get accurate timing measurements with a logic analyzer that has adjustable trigger levels. The signal could be connected to 2 inputs, one input triggering on "rising edge" and the other at the required voltage level.

Also, this would be an easy task for a CPLD. You might be interested in this thread:
http://forum.arduino.cc/index.php/topic,120220.0.html

KingBee:
Attached is an example of the signal I want to measure

And do what with the measurements?

The measured time is passed to the controller and compared to a reference time.
Any change in time will mean a change in the inductance of the coil, which means a conductive material is present. The goal is to build a PI metal detector.

Would a comparator, as suggested by Grumpy_Mike, work on a digital input pin? If i set it to a reference voltage of for instance 0.1 V, I would get a 15 ms high signal (see example signal).
In speed of digitalWrite and digitalRead on Arduino Due. - Arduino Due - Arduino Forum the digital read speed is 0.78 ms, which would be sufficient. Can I time the duration a digital pin is high with this resolution?

Thanks
(I'm catching up on comments, quite new to this in depth microprocessor details)

The comparator should work on a digital input pin. If using the Due, ensure the comparator is 3.3V rail-rail type.

These are some functions for reading and writing individual pins on the Due that I believe will work at better than 5 million reads or writes per second.

// example: digitalWriteDirect(13, HIGH)
inline void digitalWriteDirect(int pin, boolean val){
 if(val) g_APinDescription[pin].pPort -> PIO_SODR = g_APinDescription[pin].ulPin;
 else    g_APinDescription[pin].pPort -> PIO_CODR = g_APinDescription[pin].ulPin;
}

// example: digitalReadDirect(12)
inline int digitalReadDirect(int pin){
 return !!(g_APinDescription[pin].pPort -> PIO_PDSR & g_APinDescription[pin].ulPin);
}

Direct register read / writes would be even faster and could acheive 21MHz speed.

EDIT: For timing, the Due has a register "REG_TC1_CV1" that can be set up with a 42MHz clock (MCK/2) for 23.8 ns timing resolution (0.0238µs).

This sounds like a job for the Input Capture Unit. Gammon Forum : Electronics : Microprocessors : Timers and counters

Hi guys,

Still working on this problem.
I've been looking at the Nick gammons files Gammon Forum : Electronics : Microprocessors : Using the Arduino Analog Comparator

I want to toggle the trigger to "change", i therefore left out :"| _BV (ACIS1)" assuming i would turn off this fuse and set ACISx to 00. is that correct?

The code produces a time interval of 700 us, which close to the interval of the repeating signal. It changes accordingly when i change the interval (although a little off compared to the scope).

I am however interested in a second, shorter interval of about 20~40 us.
Would this code allow to detect this interval, or are they happening to fast?

Playing around a bit with a potmeter and this code i could produce measured intervals of 20 us..

Attached is a picture from the oscilloscope with the signals
(vertical resolution of the scope is 0.5V/Div)

Thanks,

detector1.ino (835 Bytes)

Did some measurements with the minimal time interval that could be measured with the code.
minimum appears to be about 28 us, but a with a significant amount of noise up to 44 us (70%).
Noise levels are to high for what i want to measure, see attached

Somewhere on the forum (my links were lost in the forum upgrade) I used a GP22 chip and a dual comparator to build a TDR to measure time difference between sending a pulse and receiving it's reflection so as to determine the length of a cable/find how far along the cable the break/short was.
The waveform of your coil is similar to the cable short waveform I check for (if you squint a bit) so maybe it could do what your looking for?

photo 4.JPG