Go Down

Topic: Can Atmega328 or Attiny handle interrupts at 200Khz (Read 111 times) previous topic - next topic


Feb 23, 2021, 09:41 am Last Edit: Feb 23, 2021, 01:02 pm by wonderfuliot

I have a need to do some logic processing at 200Khz. I would like to accomplish this on Atmega328 (Nano) as a proof of concept and then move to a smaller chip like Attiny1614 or something similar later on.

The main program starts a timer that periodically interrupts the processor at 200Khz approximately. Thereafter, the main program just kills time in an infinite loop.

The timer ISR is triggered once every 200Khz, it reads 3 digital inputs, performs some logic operation and outputs on 2 outputs.  Nothing complicated in the logic operation.

Can the processor handle interrupts at 200Khz?
Can it be accomplished using 16Mhz Atmega328?

Thanks and Regards,


Feb 23, 2021, 01:28 pm Last Edit: Feb 23, 2021, 01:32 pm by wonderfuliot
Timer0 can be used to generate an interrupt @200Khz. Its an 8 bit timer, MCU clock is 16Mhz so each cycle is 1/16Mhz = 0.0625uS.
200khz is 1/200Khz = 5uS.
No of clock cycles to be counted by timer = 5uS/0.0625uS = 80.
Note:- Timer0 is used by millis, which is really not needed here


It's what you do in between the pulses that matters. If the processing required in your program exceeds the number cycles in between pulses, then you end up with bad data since you'll be starting a new calculation before the previous one is finished.

Take note that jumping to ISRs takes clock cycles too so take that into account 


200kHz is about every 130 instructions.   So I'd say "no", you won't be able to do that.


I get 1 per 80 instructions, 100 if running at 20 mhz (and 160 if using at AVR Dx-series clocked at 32, which works fine at room temp as far as I can tell)... Yeah that's a pretty tall order. It is do-able if the math is VERY simple, and you're comfortable in AVR assembly...  but it requires attention to detail... and probably no millis either. And while there are tasks running in the background, they ain't getting much CPU time.

BUT when you say logical operations - is this something that could be done with the CCL on an ATtiny1614 or similar? The 0/1-series only has 2 LUTs, but that might be enough, and AVR128DA is available with 4 or even 6 LUTs... Those can be run *asynchronously* - generally significantly faster than the processor clock speed. (something like 110 MHz divided by the number of async stages, roughly - in my tests at least)
ATTinyCore and megaTinyCore for all ATtiny, DxCore for DA/DB-series! github.com/SpenceKonde
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy


For reading pins, some logic and writing result 80 CK could be enough time. I think it can even be done in C. But you must avoid superslow digitalRead and digitalWrite. Also if it is the only task of the MCU avoid the ISR overheat. Just wait for the timer flag, clear it, do your task and repeat.

Go Up