Execution time on AtMega32

I made my own arduino board using atmega32 following this schematic:

I'm wondering, how much time does it take for atmega32 to complete one operation(eg. add up two numbers in a for loop)

I tried testing myself. I modified timer one library so it uses pin b1 on atmega32 and wrote this code:

#include <TimerOneMighty.h>

int cnt = 0;
int i = 1;

void setup() {


void loop() {
  while(i == 1){
  if(i == 0){
    i = 1;
    cnt = 0;


void print(){
  i = 0;

After that, all I did was change timer interrupt values from 10us to 1 000 000us and got values like this:

10us; cnt == 2
100us; cnt == 10-67
1 000us; cnt == 126-735
10 000us; cnt == 7 435-7 436
100 000us; cnt == 10 432-10 433
1 000 000us; cnt == 24 760-24 761

I can't answer as asked. You need to specify the clock speed, this determines the cycle time of the microprocessor. Then you run it in a loop, that is software, what is the code look like. Do you have background interrupts going, that can cause time variations. There is a lot more information needed. Depending on the numbers, you can do a register to register add, that only takes one CPU cycle. You need to define one complete operation, everything in the loop takes time.

I have a 16MHz oscillator. I would need to add up two numbers from 300 to 2000 inside of a around 10ms for 10ish seconds. Will the atmega32 or 64 be fast enough?

Adding two 16 bit integers takes less than one microsecond on an ATmega32 with 16 MHz clock.

Thanks for the information, it helps a lot. Do you maybe know how long does it take to do a digital/analog write and/or read?

Using Arduino default timing, analogRead() takes about 110 microseconds on most AVR-based processors.

You should be looking at the ATmega32 data sheet for the basic timing information.

1 Like

Thanks for the answer, I’ll take a look at a datasheet.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.