Problema with external interrupt

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

I use an AtMega8535 with avr studio. I set the MCUCR to 00000111 so, there should be an interrupt on every rising edge on PD2 another one on every change of logic state on PD3.The problem is that when the code is running i have an interrupt on every cycle of clock. It's beacuse of INT0 but I don't understand why. Can Somebody helps me? Here's the code. It's in assembly


;program function: Guitar tuner
;_________________________________

.device atmega8535
.nolist
.include "m8535def.inc"
.list

;============
;Declarations



;Interrupt vector table ---------------------------------------
.cseg
.org 0x00
rjmp INIT	;RESET
reti		;External Interrupt0 Vector Address
reti		;External Interrupt1 Vector Address
reti		;Timer2 compare match Vector Address
reti		;Timer2 overflow Vector Address
reti		;Timer1 Input Capture Vector Address
reti		;Timer1 Output Compare A Interrupt Vector Address
reti		;Timer1 Output Compare B Interrupt Vector Address
reti		;Overflow1 Interrupt Vector Address
reti		;Overflow0 Interrupt Vector Address
reti		;SPI Interrupt Vector Address
reti		;UART Receive Complete Interrupt Vector Address
reti		;UART Data Register Empty Interrupt Vector Address
reti		;UART Transmit Complete Interrupt Vector Address
reti		;ADC Conversion Complete Interrupt Vector Address
reti		;EEPROM Write Complete Interrupt Vector Address
reti		;Analog Comparator Interrupt Vector Address



;=============
;Start Program


INIT:

;SRAM va da $0060 a $025F

.def temp=r16
.def stato=r17		;0=accordatore 1=metronomo

clr temp
clr stato

sei	;Sets the Global Interrupt flag

ldi		temp,low(ramend)		;Inizializzazione stack pointer
out		SPL,temp
ldi		temp,high(ramend)
out		SPH,temp

		clr temp
		out pind, temp
		out	DDRD, temp	;PortD is input
		out	PortD, temp	;pull-up ON PortD pins
		
		ser temp
		out	DDRA, temp	;PortA is output
		out	PortA, temp ;turn off all LEDs
		
		ser temp
		out	DDRC, temp	;PortC is output
		out	PortC, temp ;turn off all LEDs

;Alla porta D son connessi 4 switch: 
		;PD3 Metronomo
		;PD4 accordatore
		;PD5 Tasto +
		;PD6 Tasto -
;gli altri pin non sono usati


ldi temp, 0b00000011
out MCUCR, temp				;interrupt abilitato sul fronte di salita per PD2

ldi temp, 0b00000100
out MCUCR, temp				;interrupt abilitato su qualunque cambio di stato per PD3


ldi temp, 0b11000000		;attiva l'interrupt request
out GICR, temp

;****PARTE DEL PWM NON PRESENTE*****


main:
rjmp main

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

Quote:
sei ;Sets the Global Interrupt flag
This is the LAST thing you need to do after EVERYTHING has been initialised.

You don't have ANY interrupts vectors setup above.

ldi temp, 0b00000011 
out MCUCR, temp            ;interrupt abilitato sul fronte di salita per PD2 

ldi temp, 0b00000100 
out MCUCR, temp            ;interrupt abilitato su qualunque cambio di stato per PD3 

With the second 2 lines you have destroyed what you did with the 1st 2 lines. You need to load the value from MCUCR then OR the other value and write it back or do it all in ONE go.

ldi temp, 0b00000111 
out MCUCR, temp            ;interrupt abilitato sul fronte di salita per PD2 e' su qualunque cambio di stato per PD3 
 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Quote:

ldi temp, 0b00000011
out MCUCR, temp ;interrupt abilitato sul fronte di salita per PD2

ldi temp, 0b00000100
out MCUCR, temp ;interrupt abilitato su qualunque cambio di stato per PD3


Quote:

I set the MCUCR to 00000111

No, you set it to 0b100. And that then means "The low level of INT0 generates an interrupt request" And when you read about low-level interrupts, they do indeed fire continuously when the condition is true.

Lee

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

OMG I was sure that i set it to 00000111. Sorry guys. Thanks anyway