"Difference" between interruptions

Hi:

I've been wondering, what is the difference between the interruptions made with the pins 2 and 3 (arduino uno). These interruptions are called with the instruction "attachInterrupt". The other type of interrupt is set up with the timers, for example:

cli();
TCCR1A=0;
TCCR1B=0;
OCR1A=1561;
TCCR1B |= (1<<WGM12);
TCCR1B |= (1<<CS10);
TCCR1B |= (0<<CS11);
TCCR1B |= (1<<CS12);
TIMSK1=(1<<OCIE1A);
sei();

By the way, how do you define the sampling time for the "attachInterrupt" kind of interrupt.

Thanks in advance!

These interruptions are called with the instruction "attachInterrupt"

There are interrupts triggered by internal events(timers, adc, whatchdog, lots of then) and external events(when a pin change state)
For more details read this

These interruptions are called with the instruction "attachInterrupt".

No, they aren't. The attachInterrupt() function registers a handler to be called when an external event happens. You change the frequency with which the handler gets called by changing how often the external event happens.

The other code is you show is setting up a timer-based event. You diddle with the values being assigned to the registers to change how often the timer-based events happen.

No, they aren't. The attachInterrupt() function registers a handler to be called when an external event happens. You change the frequency with which the handler gets called by changing how often the external event happens.

Well, regardless of the function registering external events, it should have a sampling time, isnt it? I mean it cannot register ultra fast events. For example the max frecuency on the arduino uno is 16MHz so it cannot register events faster than 0.0000000625 seconds. Right?

You need to read the ATmega328 datasheet section on pin change interrupts, section 12.1
shows the input circuit used to trigger interrupts, and yes it is latched with the system
clock (there is also some cycles latency).

When a transition on an interrupt occurs the ISR will be called the next clock cycle. If external interrupts happen faster than one clock cycle they might be missed.

That last post had little to do with the quote you put with it.

It's slower than that, interrupts take more than 1 cycle to process. SREG has to be saved, interrupts turned off, the IRQ run and SREG restored along the way.

You can read micros() in the IRQ and take the difference between 2 of those. Be aware that micros() is only good to 4 usecs due to the code it needs to run, micros is a 32 bit value and the AVR is 8 bit.

You could run a tight loop that does a pin check and counter increment and get down to about 1 usec timing.

If one wants to read to pulses from an encoder (attached to a DC motor) what interruption would be better?. The encoder has 334 CPR and a maximum speed of 4000rpm.

Could you put a CTC between the encoder and the MCU? Have it count 334?

GoForSmoke:
Could you put a CTC between the encoder and the MCU? Have it count 334?

Can you elaborate? (what's a CTC/MCU?)

A counter-timer chip. But you don't need one. 4000 rpm is 15 msec per rev. 334 pulses per rev is 44.9 usec per pulse. Even at top speed there is plenty of time to read that directly with an UNO or even a Tiny.

Phew! That's a relief!

Did you look at Nick Gammon's page on interrupts?