Interrupt does not fire on correct address

Go To Last Post
33 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey!

I've been trying to debug my code all day and can't seem to figure out what the problem could be. I've used interrupts successfully before so I'm not in unfamiliar waters here, but I can't seem to get this simple INT6 interrupt working. All it does when interrupt conditions are met is jump to address 0000 and starts the whole program all over again (like reset, but without actually resetting).

I have tried ISR(BADISR_vect){} too, but nothing. The code never makes it to the ISR routine (not INT, nor BAD).

I'll shoot the relevant code here too. Some functions are defined in the libraries, but they have nothing to do with interrupts.

I hope someone else can see, what I can not.
PS Using ATMega2561 if it matters.

/*
 * PneumoMot2.c
 *
 * Created: 3.10.2012 12:50:05
 *  Author: Rain
 */ 
#define F_CPU 14745600

#include "main.h"

pin led_red    = PIN(C, 5);
pin led_yellow = PIN(C, 4);
pin led_green  = PIN(C, 3);
pin relay14	   = PIN(E, 2);
pin relay23	   = PIN(E, 3);

pin IN1 = PIN(E,6);
pin IN2 = PIN(E,5);
pin S1  = PIN(C, 0);
pin S2  = PIN(C, 1);
pin S3  = PIN(C, 2);

ISR(INT6_vect)
{
	pin_clear(led_green);
}

int main(void)
{
    Init();
	
	while(1)
    {
        //TODO:: Please write your application code 
    }
}

static inline void Init()
{
	// Seab LEDid töökorda
	pin_setup_output(led_red);
	pin_setup_output(led_yellow);
	pin_setup_output(led_green);
	
	// Lülitab LEDid välja
	pin_set(led_green);
	pin_set(led_yellow);
	pin_set(led_red);
	
	// Seab nupud töökorda
	pin_setup_input_with_pullup(S1);
	pin_setup_input_with_pullup(S2);
	pin_setup_input_with_pullup(S3);
	
	pin_setup_input_with_pullup(IN1);
	pin_setup_input_with_pullup(IN2);

	pin_setup_output(relay14);
	pin_setup_output(relay23);
	
	EICRB = (1<<ISC61);//|(1<<ISC51);
	EIMSK = (1<<INT6);// |(1<<INT5);
	sei();
	
	// Set-up of the LCD.
	// Cleaning the screen.
	// Switching on the background light.
	// Displaying the name of the program
	lcd_gfx_init();
	lcd_gfx_clear();
	lcd_gfx_backlight(true);
	lcd_gfx_goto_char_xy(1, 1);
	lcd_gfx_write_string("Enk_07.02");
}

static inline void Valve(uint8_t dir)
{
	if(dir == RIGHT)
	{
		pin_clear(relay14);
		pin_set(relay23);
	}
	else if (dir == LEFT)
	{
		pin_clear(relay23);
		pin_set(relay14);
	}
}

void SetRegulator(uint16_t regulator)
{
	// Set something to value defined in regulator variable
	pin_clear(led_yellow);
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A jump to 0 suggests the catch all mechanism which comes into play when an enabled interrupt source without an ISR occurs.

Try implementing BADISR_vect or, better yet, handlers for all the vectors.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

(Disclaimer: I just woke up.)

According to the datasheet, "Pin change interrupts PCI0 will trigger if any enabled PCINT7:0 pin toggles". Does that imply the need of a handler for PCI0 ?

Also, "Note that recognition of falling or rising
edge interrupts on INT7:4 requires the presence of an I/O clock"
, whatever that may mean.

And, about PCICR/PCIE0 - "When the PCIE0 bit is set (one) and the I-bit in the Status Register (SREG) is set (one), pin change interrupt 0 is enabled. Any change on any enabled PCINT7:0 pin will cause an interrupt. The corresponding interrupt of Pin Change Interrupt Request is executed from the PCI0 Interrupt
Vector. PCINT7:0 pins are enabled individually by the PCMSK0 Register."

Sid

Life... is a state of mind

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
According to the datasheet, "Pin change interrupts PCI0 will trigger if any enabled PCINT7:0 pin toggles". Does that imply the need of a handler for PCI0 ?

...
And, about PCICR/PCIE0 - "When the PCIE0 bit is set (one) and the I-bit in the Status Register (SREG) is set (one), pin change interrupt 0 is enabled. Any change on any enabled PCINT7:0 pin will cause an interrupt. The corresponding interrupt of Pin Change Interrupt Request is executed from the PCI0 Interrupt
Vector. PCINT7:0 pins are enabled individually by the PCMSK0 Register."

The OP is using INT6, not a PCxx interrupt, so these two points are irrelevant.

Quote:
Also, "Note that recognition of falling or rising
edge interrupts on INT7:4 requires the presence of an I/O clock", whatever that may mean.
It means that the interrupt will not work in some sleep modes.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Of course. I kinda knew I was wrong, so I shouldn't have posted that. I guess the interrupt is not the only thing that doesn't work in sleep mode.

Sid

Life... is a state of mind

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the input.

But as I stated in the fist post, I have already tried BADISR and the results are exactly the same as with the code posted above.

Any other ideas?

Rain

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just a guess, but are you sure the signal change is happening to the right pin?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well no matter where the change happens, whether it's the correct one or not, it should not make the program jump to 0 and "reset" everything.
And I am sure about the correct pin.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
better yet, handlers for all the vectors

These are the handlers for all vectors (I used the numbers because it was faster), can you add them and see if that changes anything?
Note that INT6_vect is _VECTOR(7) so you can remove it and use your own in you want

ISR(_VECTOR(1)) {}
ISR(_VECTOR(2)) {}
ISR(_VECTOR(3)) {}
ISR(_VECTOR(4)) {}
ISR(_VECTOR(5)) {}
ISR(_VECTOR(6)) {}
ISR(_VECTOR(7)) {}
ISR(_VECTOR(8)) {}
ISR(_VECTOR(9)) {}
ISR(_VECTOR(10)) {}
ISR(_VECTOR(12)) {}
ISR(_VECTOR(13)) {}
ISR(_VECTOR(14)) {}
ISR(_VECTOR(15)) {}
ISR(_VECTOR(16)) {}
ISR(_VECTOR(17)) {}
ISR(_VECTOR(18)) {}
ISR(_VECTOR(19)) {}
ISR(_VECTOR(20)) {}
ISR(_VECTOR(21)) {}
ISR(_VECTOR(22)) {}
ISR(_VECTOR(23)) {}
ISR(_VECTOR(24)) {}
ISR(_VECTOR(25)) {}
ISR(_VECTOR(26)) {}
ISR(_VECTOR(27)) {}
ISR(_VECTOR(28)) {}
ISR(_VECTOR(29)) {}
ISR(_VECTOR(30)) {}
ISR(_VECTOR(31)) {}
ISR(_VECTOR(32)) {}
ISR(_VECTOR(33)) {}
ISR(_VECTOR(34)) {}
ISR(_VECTOR(35)) {}
ISR(_VECTOR(36)) {}
ISR(_VECTOR(37)) {}
ISR(_VECTOR(38)) {}
ISR(_VECTOR(39)) {}
ISR(_VECTOR(40)) {}
ISR(_VECTOR(42)) {}
ISR(_VECTOR(43)) {}
ISR(_VECTOR(44)) {}
ISR(_VECTOR(45)) {}
ISR(_VECTOR(47)) {}
ISR(_VECTOR(48)) {}
ISR(_VECTOR(49)) {}
ISR(_VECTOR(50)) {}

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Still the same.

Could it be, that something has gone wrong in the GCC files?

I have tried multiple boards, so it can't be AVR's issue. Starting to go a bit insane here...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you get the same problem with a minimal code, just the port and interrupt initialization and the interrupt handler?

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Post your circuit.

Sid

Life... is a state of mind

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you >>sure<< that you are building for the correct AVR model?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Post your circuit.

There's nothing to post, the input is connected via external resistor to Vcc and then to a pinheader. on that I have 2 wires that I connect together to simulate input->gnd connection.

Quote:
Are you >>sure<< that you are building for the correct AVR model?

Well tried to simplify my code, and it doesn't get any simpler than this. Still same error. I even installed Studio 6 again and everything.

And I am >>sure<< that I'm building for ATMega2561, everything else I've written to this board has worked (actually even interrupts have).

/*
 * PneumoMot2.c
 *
 * Created: 3.10.2012 12:50:05
 *  Author: Rain
 */ 
#define F_CPU 14745600

#include 
#include 
#include 

ISR(BADISR_vect) 
{
	PORTC &= ~(1<<PC4);
} 

int main(void)
{
    PORTE |= (1<<PE6);
    
    DDRC |= (1<<PC3)|(1<<PC4);
    PORTC |= (1<<PC3)|(1<<PC4);
    
    _delay_ms(500);

    EICRB = (1<<ISC61);//|(1<<ISC51);
    EIMSK = (1<<INT6);// |(1<<INT5);
    sei();
    
    PORTC &= ~(1<<PC3);
	
	while(1)
    {
        //TODO:: Please write your application code 
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Capture the MCUSR register and look at the flags to see the exact reason you are back at 0x0000.

Also are you seeing this in real silicon or simulator. There's a possibility it's a simulation bug.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bloody-orc wrote:
Quote:
Post your circuit.

There's nothing to post, the input is connected via external resistor to Vcc and then to a pinheader. on that I have 2 wires that I connect together to simulate input->gnd connection.

Yeah ? Perhaps you should add a few decoupling caps and a pullup for the reset pin, then - just for starters.

Or maybe you should end this guessing game by posting your darn circuit. You are the one who have a problem.

Sid

Life... is a state of mind

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
ISR(BADISR_vect) 
{ 
_delay_ms(1000);   
PORTC ^= (1<<PC4); 
}

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm seeing this in real silicon.

Quote:
Yeah ? Perhaps you should add a few decoupling caps and a pullup for the reset pin, then - just for starters.

Or maybe you should end this guessing game by posting your darn circuit. You are the one who have a problem.

Didn't try to be rude or anything, I had just eliminated hardware issues already. This is an old and tested board that I have used for years for different applications. (have used over 20 of them)

Schematic:
http://jumpshare.com/v/6IGO0i
[/code]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you examined the MCUCR value? (Be sure to clear after reading/saving to make sure you get the "right" value. When I'm in a situation like yours, I count resets in an EEPROM byte and save each reset cause in an EEPROM buffer.)

If the reset cause is clear, then somehow the processor arrived back at 0.

If e.g. power-on or brownout, then perhaps tripping the external interrupt pin is causing a short somewhere. With a weak power supply it could even be that the pin was made an output. If you have a current-limiting bench power supply, you could turn the current limit way down and see if it clicks into current-limiting mode.

As there are a number of external interrupt sources on that centipede, do you get the same results with INT4 or INT5 or ... ?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I did the MCUCR trick and got back 0 after "reset". That's how I know it just jumps to 0 and does not just get a watchdog or brownout reset.

I have tested the same code on INT4-7, because I have the easiest access to those atm.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Post the build output, so we can see the actual command lines used for compiling and linking.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Build output:

------ Build started: Project: PneumoMot2, Configuration: Debug AVR ------
Build started.
Project "PneumoMot2.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Electronics\Atmel\AVR Studio 6.0\Vs\Compiler.targets" from project "C:\Users\Rain\Dropbox\ITT Grupp\PneumoMootor\PneumoMot2\PneumoMot2.cproj" (target "Build" depends on it):
	Using "RunCompilerTask" task from assembly "C:\Electronics\Atmel\AVR Studio 6.0\Vs\Compiler.Task.dll".
	Task "RunCompilerTask"
		C:\Electronics\Atmel\AVR Studio 6.0\make\make.exe all 
		make: Nothing to be done for `all'.
	Done executing task "RunCompilerTask".
	Using "RunOutputFileVerifyTask" task from assembly "C:\Electronics\Atmel\AVR Studio 6.0\Vs\Compiler.Task.dll".
	Task "RunOutputFileVerifyTask"
				Program Memory Usage 	:	1278 bytes   0,5 % Full
				Data Memory Usage 		:	0 bytes   0,0 % Full
	Done executing task "RunOutputFileVerifyTask".
Done building target "CoreBuild" in project "PneumoMot2.cproj".
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
Target "Build" in file "C:\Electronics\Atmel\AVR Studio 6.0\Vs\Avr.common.targets" from project "C:\Users\Rain\Dropbox\ITT Grupp\PneumoMootor\PneumoMot2\PneumoMot2.cproj" (entry point):
Done building target "Build" in project "PneumoMot2.cproj".
Done building project "PneumoMot2.cproj".

Build succeeded.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

Dissasembly view:

--- C:\home\tools\hudson\workspace\avr8-gnu-toolchain\src\gcc\gcc\config\avr\libgcc.S 

00000080  ST X+,R1		Store indirect and postincrement 

00000081  CPI R26,0x00		Compare with immediate 

00000082  CPC R27,R17		Compare with carry 

00000083  BRNE PC-0x03		Branch if not equal 
--- No source file -------------------------------------------------------------
00000084  CALL 0x000000B5		Call subroutine 
00000086  JMP 0x0000027D		Jump 
00000088  JMP 0x0000008A		Jump 
--- C:\Users\Rain\Dropbox\ITT Grupp\PneumoMootor\PneumoMot2\Debug/.././main.c --
{
0000008A  PUSH R1		Push register on stack 
0000008B  PUSH R0		Push register on stack 
0000008C  IN R0,0x3F		In from I/O location 
0000008D  PUSH R0		Push register on stack 
0000008E  LDS R0,0x005B		Load direct from data space 
00000090  PUSH R0		Push register on stack 
00000091  CLR R1		Clear Register 
00000092  PUSH R18		Push register on stack 
00000093  PUSH R19		Push register on stack 
00000094  PUSH R24		Push register on stack 
00000095  PUSH R25		Push register on stack 
00000096  PUSH R30		Push register on stack 
00000097  PUSH R31		Push register on stack 
00000098  PUSH R28		Push register on stack 
00000099  PUSH R29		Push register on stack 
0000009A  IN R28,0x3D		In from I/O location 
0000009B  IN R29,0x3E		In from I/O location 
	PORTC &= ~(1<<PC4);
0000009C  LDI R24,0x28		Load immediate 
0000009D  LDI R25,0x00		Load immediate 
0000009E  LDI R18,0x28		Load immediate 
0000009F  LDI R19,0x00		Load immediate 
000000A0  MOVW R30,R18		Copy register pair 
000000A1  LDD R18,Z+0		Load indirect with displacement 
000000A2  ANDI R18,0xEF		Logical AND with immediate 
000000A3  MOVW R30,R24		Copy register pair 
000000A4  STD Z+0,R18		Store indirect with displacement 
} 
000000A5  POP R29		Pop register from stack 
000000A6  POP R28		Pop register from stack 
000000A7  POP R31		Pop register from stack 
000000A8  POP R30		Pop register from stack 
000000A9  POP R25		Pop register from stack 
000000AA  POP R24		Pop register from stack 
000000AB  POP R19		Pop register from stack 
000000AC  POP R18		Pop register from stack 
000000AD  POP R0		Pop register from stack 
000000AE  STS 0x005B,R0		Store direct to data space 
000000B0  POP R0		Pop register from stack 
000000B1  OUT 0x3F,R0		Out to I/O location 
000000B2  POP R0		Pop register from stack 
000000B3  POP R1		Pop register from stack 
000000B4  RETI 		Interrupt return 
{
000000B5  PUSH R16		Push register on stack 
000000B6  PUSH R17		Push register on stack 
000000B7  PUSH R28		Push register on stack 
000000B8  PUSH R29		Push register on stack 
000000B9  IN R28,0x3D		In from I/O location 
000000BA  IN R29,0x3E		In from I/O location 
000000BB  SBIW R28,0x0E		Subtract immediate from word 
000000BC  IN R0,0x3F		In from I/O location 
000000BD  CLI 		Global Interrupt Disable 
000000BE  OUT 0x3E,R29		Out to I/O location 
000000BF  OUT 0x3F,R0		Out to I/O location 
000000C0  OUT 0x3D,R28		Out to I/O location 
--- C:\Users\Rain\Dropbox\ITT Grupp\PneumoMootor\PneumoMot2\Debug/.././main.c --
    PORTE |= (1<<PE6);
000000C1  LDI R24,0x2E		Load immediate 
000000C2  LDI R25,0x00		Load immediate 
000000C3  LDI R18,0x2E		Load immediate 
000000C4  LDI R19,0x00		Load immediate 
000000C5  MOVW R30,R18		Copy register pair 
000000C6  LDD R18,Z+0		Load indirect with displacement 
000000C7  ORI R18,0x40		Logical OR with immediate 
000000C8  MOVW R30,R24		Copy register pair 
000000C9  STD Z+0,R18		Store indirect with displacement 
    DDRC |= (1<<PC3)|(1<<PC4);
000000CA  LDI R24,0x27		Load immediate 
000000CB  LDI R25,0x00		Load immediate 
000000CC  LDI R18,0x27		Load immediate 
000000CD  LDI R19,0x00		Load immediate 
000000CE  MOVW R30,R18		Copy register pair 
000000CF  LDD R18,Z+0		Load indirect with displacement 
000000D0  ORI R18,0x18		Logical OR with immediate 
000000D1  MOVW R30,R24		Copy register pair 
000000D2  STD Z+0,R18		Store indirect with displacement 
    PORTC |= (1<<PC3)|(1<<PC4);
000000D3  LDI R24,0x28		Load immediate 
000000D4  LDI R25,0x00		Load immediate 
000000D5  LDI R18,0x28		Load immediate 
000000D6  LDI R19,0x00		Load immediate 
000000D7  MOVW R30,R18		Copy register pair 
000000D8  LDD R18,Z+0		Load indirect with displacement 
000000D9  ORI R18,0x18		Logical OR with immediate 
000000DA  MOVW R30,R24		Copy register pair 
000000DB  STD Z+0,R18		Store indirect with displacement 
000000DC  LDI R24,0x00		Load immediate 
000000DD  LDI R25,0x00		Load immediate 
000000DE  LDI R26,0xFA		Load immediate 
--- C:\Users\Rain\Dropbox\ITT Grupp\PneumoMootor\PneumoMot2\Debug/.././main.c --
000000DF  LDI R27,0x43		Load immediate 
000000E0  STD Y+1,R24		Store indirect with displacement 
000000E1  STD Y+2,R25		Store indirect with displacement 
000000E2  STD Y+3,R26		Store indirect with displacement 
000000E3  STD Y+4,R27		Store indirect with displacement 
--- c:\electronics\atmel\avr studio 6.0\extensions\atmel\avrgcc\3.4.1.95\avrtoolchain\bin\../lib/gcc/avr/4.6.2/../../../../avr/include/util/delay.h 
	__tmp = ((F_CPU) / 4e3) * __ms;
000000E4  LDD R22,Y+1		Load indirect with displacement 
000000E5  LDD R23,Y+2		Load indirect with displacement 
000000E6  LDD R24,Y+3		Load indirect with displacement 
000000E7  LDD R25,Y+4		Load indirect with displacement 
000000E8  LDI R18,0x66		Load immediate 
000000E9  LDI R19,0x66		Load immediate 
000000EA  LDI R20,0x66		Load immediate 
000000EB  LDI R21,0x45		Load immediate 
000000EC  CALL 0x000001F2		Call subroutine 
000000EE  MOVW R26,R24		Copy register pair 
000000EF  MOVW R24,R22		Copy register pair 
000000F0  STD Y+5,R24		Store indirect with displacement 
000000F1  STD Y+6,R25		Store indirect with displacement 
000000F2  STD Y+7,R26		Store indirect with displacement 
000000F3  STD Y+8,R27		Store indirect with displacement 
	if (__tmp < 1.0)
000000F4  LDI R17,0x01		Load immediate 
000000F5  LDD R22,Y+5		Load indirect with displacement 
000000F6  LDD R23,Y+6		Load indirect with displacement 
000000F7  LDD R24,Y+7		Load indirect with displacement 
--- c:\electronics\atmel\avr studio 6.0\extensions\atmel\avrgcc\3.4.1.95\avrtoolchain\bin\../lib/gcc/avr/4.6.2/../../../../avr/include/util/delay.h 
000000F8  LDD R25,Y+8		Load indirect with displacement 
000000F9  LDI R18,0x00		Load immediate 
000000FA  LDI R19,0x00		Load immediate 
000000FB  LDI R20,0x80		Load immediate 
000000FC  LDI R21,0x3F		Load immediate 
000000FD  CALL 0x00000171		Call subroutine 
000000FF  TST R24		Test for Zero or Minus 
00000100  BRLT PC+0x02		Branch if less than, signed 
00000101  LDI R17,0x00		Load immediate 
00000102  TST R17		Test for Zero or Minus 
00000103  BREQ PC+0x06		Branch if equal 
		__ticks = 1;
00000104  LDI R24,0x01		Load immediate 
00000105  LDI R25,0x00		Load immediate 
00000106  STD Y+10,R25		Store indirect with displacement 
00000107  STD Y+9,R24		Store indirect with displacement 
00000108  RJMP PC+0x0047		Relative jump 
	else if (__tmp > 65535)
00000109  LDI R17,0x01		Load immediate 
0000010A  LDD R22,Y+5		Load indirect with displacement 
0000010B  LDD R23,Y+6		Load indirect with displacement 
0000010C  LDD R24,Y+7		Load indirect with displacement 
0000010D  LDD R25,Y+8		Load indirect with displacement 
0000010E  LDI R18,0x00		Load immediate 
0000010F  SER R19		Set Register 
00000110  LDI R20,0x7F		Load immediate 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Build output:
The output from a build where nothing is actually build is useless.

Quote:
Dissasembly view:
A disassembly where the real interesting part (interrupt vector table) is missing is useless.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

PORTC &= ~(1<<PC4);
0000009C LDI R24,0x28 Load immediate
0000009D LDI R25,0x00 Load immediate
0000009E LDI R18,0x28 Load immediate
0000009F LDI R19,0x00 Load immediate
000000A0 MOVW R30,R18 Copy register pair
000000A1 LDD R18,Z+0 Load indirect with displacement
000000A2 ANDI R18,0xEF Logical AND with immediate
000000A3 MOVW R30,R24 Copy register pair
000000A4 STD Z+0,R18 Store indirect with displacement

-O0? But how would that affect interrupt servicing?

Stack problems? But how could that be on a big AVR with a trivial program?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sternst wrote:
Quote:
Build output:
The output from a build where nothing is actually build is useless.

Quote:
Dissasembly view:
A disassembly where the real interesting part (interrupt vector table) is missing is useless.

What build output can I post then that actually is useful? I just copyed the text from Studios build output.

And yes, I had no optimization at that point.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do a "clean" then capture the next full build output which will show the files being built. Because your build was up to date the output you showed above showed nothing happening. Also just attach the complete .lss file from the build.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bloody-orc wrote:
What build output can I post then that actually is useful? I just copyed the text from Studios build output.
Copy exactly that, but don't do a simple "build", do a "rebuild".

(and post the missing disassembly from $00 - $7f)

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
------ Rebuild All started: Project: PneumoMot2, Configuration: Debug AVR ------
Build started.
Project "PneumoMot2.cproj" (ReBuild target(s)):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreRebuild" in file "C:\Electronics\Atmel\AVR Studio 6.0\Vs\Compiler.targets" from project "C:\Users\Rain\Dropbox\ITT Grupp\PneumoMootor\PneumoMot2\PneumoMot2.cproj" (target "ReBuild" depends on it):
	Using "RunCompilerTask" task from assembly "C:\Electronics\Atmel\AVR Studio 6.0\Vs\Compiler.Task.dll".
	Task "RunCompilerTask"
		C:\Electronics\Atmel\AVR Studio 6.0\make\make.exe clean all 
		rm -rf  main.o main.d  
		rm -rf "PneumoMot2.elf" "PneumoMot2.a" "PneumoMot2.hex" "PneumoMot2.lss" "PneumoMot2.eep" "PneumoMot2.map" "PneumoMot2.srec"
		Building file: .././main.c
		Invoking: AVR/GNU C Compiler : (AVR_8_bit_GNU_Toolchain_3.4.1_830) 4.6.2
		"C:\Electronics\Atmel\AVR Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-gcc.exe" -funsigned-char -funsigned-bitfields -O2 -fpack-struct -fshort-enums -g2 -Wall -c -std=gnu99 -MD -MP -MF "main.d" -MT"main.d" -MT"main.o"  -mmcu=atmega2561   -o"main.o" ".././main.c" 
		Finished building: .././main.c
		Building target: PneumoMot2.elf
		Invoking: AVR/GNU Linker : (AVR_8_bit_GNU_Toolchain_3.4.1_830) 4.6.2
		"C:\Electronics\Atmel\AVR Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-gcc.exe" -o PneumoMot2.elf  main.o   -Wl,-Map="PneumoMot2.map" -Wl,--start-group -Wl,-lm -Wl,-lhomelab2561  -Wl,--end-group  -mmcu=atmega2561  
		Finished building target: PneumoMot2.elf
		"C:\Electronics\Atmel\AVR Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature  "PneumoMot2.elf" "PneumoMot2.hex"
		"C:\Electronics\Atmel\AVR Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-objcopy.exe" -j .eeprom  --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0  --no-change-warnings -O ihex "PneumoMot2.elf" "PneumoMot2.eep" || exit 0
		"C:\Electronics\Atmel\AVR Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-objdump.exe" -h -S "PneumoMot2.elf" > "PneumoMot2.lss"
		"C:\Electronics\Atmel\AVR Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature  "PneumoMot2.elf" "PneumoMot2.srec"
		"C:\Electronics\Atmel\AVR Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-size.exe" "PneumoMot2.elf"
		   text	   data	    bss	    dec	    hex	filename
		    350	      0	      0	    350	    15e	PneumoMot2.elf
	Done executing task "RunCompilerTask".
	Using "RunOutputFileVerifyTask" task from assembly "C:\Electronics\Atmel\AVR Studio 6.0\Vs\Compiler.Task.dll".
	Task "RunOutputFileVerifyTask"
				Program Memory Usage 	:	350 bytes   0,1 % Full
				Data Memory Usage 		:	0 bytes   0,0 % Full
	Done executing task "RunOutputFileVerifyTask".
Done building target "CoreRebuild" in project "PneumoMot2.cproj".
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
Target "ReBuild" in file "C:\Electronics\Atmel\AVR Studio 6.0\Vs\Avr.common.targets" from project "C:\Users\Rain\Dropbox\ITT Grupp\PneumoMootor\PneumoMot2\PneumoMot2.cproj" (entry point):
Done building target "ReBuild" in project "PneumoMot2.cproj".
Done building project "PneumoMot2.cproj".

Build succeeded.
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have failed to catch the vector. I have added comments to this:

Disassembly of section .text:

00000000 <__vectors>:
   0:	0c 94 66 00 	jmp	0xcc	; 0xcc <__ctors_end> // RESET
   4:	0c 94 88 00 	jmp	0x110	; 0x110 <__bad_interrupt> // INT0 
   8:	0c 94 88 00 	jmp	0x110	; 0x110 <__bad_interrupt> // INT1
   c:	0c 94 88 00 	jmp	0x110	; 0x110 <__bad_interrupt> // INT2
  10:	0c 94 88 00 	jmp	0x110	; 0x110 <__bad_interrupt> //  INT3
  14:	0c 94 88 00 	jmp	0x110	; 0x110 <__bad_interrupt> // INT4
  18:	0c 94 88 00 	jmp	0x110	; 0x110 <__bad_interrupt> // INT5
  1c:	0c 94 88 00 	jmp	0x110	; 0x110 <__bad_interrupt> // INT6
  20:	0c 94 88 00 	jmp	0x110	; 0x110 <__bad_interrupt> // INT7

Address 0x1C (0x0E in Atmel speak) is the INT6 vector. This has not been hooked to point to your ISR so it IS going to BADISR_vect.

I now returned to your first post to check that you were including but all I see is an include for "main.h". Can we see that? I strongly suspect it does not contain an include of

EDIT: having said that I tried to guess what was in your main.h to satisy all this pin() nonsense but try as I might I don't see how you can avoid getting:

Warning	2	type of '__vector_7' defaults to 'int' [enabled by default]	

So maybe you are including avr/interrupt.h? n which case I wonder if some of the PIN shenanigans is somehow causing it to misbehave?

EDIT2: I found the Robotic Home library with pin.h etc...

http://home.roboticlab.eu/en/files

But having cleared some more build errors I see something VERY odd in this code. The routine Init() is "static inline" but is defined after it is invoked? What's more now I go back to the .lss it has calls to _delay_ms() that are not in the code of the first post here - is this a different program all together?

Actually the more I look at it the more I think the .lss is nothing to do with the program we're supposed to be diagnosing here. It does show being defined but the only ISR() definition within it is the one for BADISR_vect but no sign of an attempted INT6_vect handler. So is this all a wild goose chase or what??

Can you build the code in the first post that was supposed to have a problem and show both the build output and the .lss file.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Actually the more I look at it the more I think the .lss is nothing to do with the program we're supposed to be diagnosing here.
Apparently the .lss belongs to the code in this post:
https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=1035819#1035819

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for all the help, I'll be throwing my laptop against the wall now.

Got access to another computer and tested the same code there and everything works. I'll be uninstalling everything from the first one now and giving it a very clean reinstall and see if that'll fix the problem.

Sorry to have wasted your time on a bug, that shouldn't have been there at the first place.

Cheers,
Rain

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sigh.... the victory was short lived.

The simple code with just one interrupt worked, but the actual code does not. on neither computer it would seem.

I have attached this time the whole project in one zip file.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That project is unbuildable for anyone who doesn't have "homelab" installed. (luckily I do as part of the earlier part of this investigation ;-))

Quote:
but the actual code does not.

OK so what does that mean? I can build the code without errors. In the .lss I see it hooked vectors 5, 6 and 17. So now what? You aren't expecting us to have the same hardware as you are you?

If it's just a functional problem with the code and not something you think is a build fault by the compiler/tools then I'm afraid it's up to you to use your debugging skills to find out why that is (which is the way we all program).