You need to log in to create posts and topics.

Arduino Nano ATMega 328P interrupt vector

I am using the Arduino Nano/ATMega328P board in SimulIDE.
Can someone confirm I am using the right interrupt vectors here for SimulIDE :

// --- Timer1 Overflow ISR ---

ISR(TIMER1_OVF_vect) {
overflowCount++; // Keep track of overflows
}

Also :

ISR(TIMER1_CAPT_vect) {
...
}

Looking at file megax8_int.xml I see very different names :
T1_OVF or T1CAP
I am looking in the wrong file ?
- Using SimulIDE SimulIDE_1.1.0-R2089_Win64 with Arduino IDE 2.3.7.
Thanks for the help !

Maybe this helps, generated by Copilot:

The datasheet is a bit confusing here, so you’re not imagining things. Let’s untangle it cleanly.


🧩 Why the datasheet says TIM1_OVF but the C vector is TIMER1_OVF_vect

On page 50 of the ATmega328P datasheet, the interrupt table lists the mnemonic names used inside the chip’s internal documentation. These are not the names used by avr‑gcc or avr‑libc.

  • TIM1_OVF is the datasheet’s internal label for “Timer/Counter1 Overflow”.
  • TIMER1_OVF_vect is the compiler’s ISR vector name defined in <avr/interrupt.h>.

These two naming systems are related but not identical:

Datasheet name Meaning C ISR name (avr‑gcc)
TIM1_OVF Timer1 overflow interrupt source TIMER1_OVF_vect

So the datasheet uses a short internal mnemonic, while the compiler uses a standardized naming scheme:

TIMER<n>_<EVENT>_vect

📘 Where to find the correct C vector names

The datasheet does not list the C vector names.
Instead, the official names come from:

✔️ The device header file

<avr/iom328p.h> (included automatically when you #include <avr/io.h>)

Inside that file you’ll find lines like:

#define TIMER1_OVF_vect _VECTOR(13)

✔️ avr-libc documentation

The full list is here:
https://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html (nongnu.org in Bing)


📄 Where in the datasheet to look

Even though the datasheet doesn’t give the C names, it does give the interrupt order and meaning.

Section 11 — “Interrupts” (starts on page 49)

This section contains:

  • The interrupt vector table
  • The internal names (like TIM1_OVF)
  • The priority order
  • A short description of each interrupt source

But again — these are not the C identifiers.


Why the mismatch exists

Historically:

  • Atmel used short mnemonics in the datasheet (TIM1_OVF, TIM0_COMPA, etc.)
  • avr‑gcc/avr‑libc created a consistent naming scheme across all AVR chips
  • So the compiler names are longer and more descriptive

This is why you always trust the header file for the actual ISR names.

************************* end of quote ******************************************

I do not quite understand why you ask if your syntax is correct for Simulide?
"Can someone confirm I am using the right interrupt vectors here for SimulIDE ?"
As far as I know the micros in Simulide only need a hex file generated by some compiler outside of Simulide. So to my understanding Simulide has not much to do with how you write your program.

 

 

Going on, I asked this question:

At Simulide the TS says: Looking at file megax8_int.xml ....
Which file is he talking about?

Answer:

He’s referring to a SimulIDE‑internal device definition file, not anything from Atmel, avr‑gcc, or the Arduino toolchain.

Here’s the key point from the page you’re viewing simulide.com:

The thread mentions:

“Looking at file megax8_int.xml I see very different names: T1_OVF or T1CAP”

That file is part of SimulIDE’s own microcontroller model, located inside the SimulIDE installation folders. It defines:

  • The interrupt names used internally by SimulIDE
  • How those interrupts map to the simulated AVR core
  • The XML structure that describes the ATmega‑x8 family (328P, 168, 88, etc.)

So megax8_int.xml is NOT part of avr‑gcc, Arduino, or the real ATmega328P datasheet.
It is a SimulIDE resource file.


📍 Where the file usually lives

Depending on your SimulIDE version, it is typically found in one of these folders:

Windows (SimulIDE portable ZIP)

SimulIDE/data/mcus/avr/megax8_int.xml

Linux

/usr/share/simulide/data/mcus/avr/megax8_int.xml

Or inside the SimulIDE installation directory:

simulide/data/mcus/avr/

The exact path may vary slightly, but the file is always under:

.../data/mcus/avr/

Why the names differ (T1_OVF vs TIMER1_OVF_vect)

SimulIDE uses its own short internal interrupt labels:

  • T1_OVF
  • T1CAP
  • T0_COMPA
  • etc.

These are not the names you use in C.

Your C code must still use the avr‑gcc names:

  • ISR(TIMER1_OVF_vect)
  • ISR(TIMER1_CAPT_vect)
  • etc.

SimulIDE doesn’t care about the C names — it only reads the compiled .hex file.

The XML file is only for SimulIDE’s internal mapping.


If you want, I can show you how SimulIDE maps each XML interrupt name to the real AVR interrupt vector order, or help you locate the file on your system.
*********************************** end of quote *************************************************

The copilot also generated an example ~1 second Blink:

#include <avr/io.h>
#include <avr/interrupt.h>

void timer1_init(void)
{
    // 1. Set Timer1 prescaler (example: clk/256)
    TCCR1B |= (1 << CS12);     // CS12=1, CS11=0, CS10=0 → prescaler 256

    // 2. Enable Timer1 overflow interrupt
    TIMSK1 |= (1 << TOIE1);

    // 3. Enable global interrupts
    sei();
}

// 4. Interrupt Service Routine
ISR(TIMER1_OVF_vect)
{
    // This code runs every time Timer1 overflows
    // Example: toggle PB5 (Arduino pin 13)
    PORTB ^= (1 << PB5);
}

int main(void)
{
    DDRB |= (1 << PB5);   // Set PB5 as output
    timer1_init();

    while (1)
    {
        // main loop
    }
}

It is verified in Arduino IDE 2.3.4, exported compiled binary and firmware loaded into Simulide