External interrupt on INT2 pin

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

hello all...

i want to use the INT2 pin on atmega32, so that the MCU detects the falling edge of the external signal and interrupts when the falling edge occurs..

i ahve been able to use INT0 and INT1 for this purpose, but havent been able to use INT2. could anyone help?

code for testin INT2 is

//simple code to test INT2, send a pulse of at PC0 pin

.NOLIST
.INCLUDE "C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m32def.inc"
.LIST

.def uni=R16//universal register for all operations
.def delay1=R17//delay register1

.CSEG
.ORG 0000

rjmp main
nop
nop
nop
nop
nop
rjmp Iservice2
nop

Iservice2://Start interrupt service routine when zero crossing is detected
	in uni,sreg
	push uni//push status register to stack
	ldi uni, 05
checksampleslow:
	sbic pinb, 2//check for 5 samples to discard voltage surges or so on
	rjmp endservice
	dec uni
	brne checksampleslow
trigger://Triggerin pulse sent through PC0
	Ldi uni, 0x01
	out portc, uni
	call delay
	ldi uni, 0x00
	out portc, uni
endservice://Endservice
	pop uni
	out sreg, uni
	reti

main:

	LDI uni,LOW(RAMEND)//Initialise Stackpointer
  	OUT SPL,uni
  	LDI	uni,HIGH(RAMEND)
  	OUT	SPH,uni

	ldi uni,0xFF//PortC as outport
	out ddrc, uni

	ldi uni,0b11100000//CLear interrupt flags
	out GIFR,uni

	ldi uni,0b00100000//Enable INT2
	out GICR, uni

	ldi uni,0b00000000//configure INT2 to occur on falling edge
	out MCUCSR, uni

	SEI//set Global I flag in SREG

wait://wait till interrupt occurs(falling edge on INT2)
	rjmp wait

delay://delay which is the thickness of the pulse at PC0
	ldi delay1, 28
loop2:
	dec delay1
	brne loop2
	ret

any help would be highly appreciated..

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

It works on simulations, how's your hardware?
...you haven't set the portb pull-ups, are they floating?
try this code:

//simple code to test INT2, send a pulse of at PC0 pin

.NOLIST
.INCLUDE "C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m32def.inc"
.LIST

.def uni=R16//universal register for all operations
.def delay1=R17//delay register1

.CSEG
.ORG 0000

rjmp main
nop
nop
nop
nop
nop
rjmp Iservice2
nop

Iservice2://Start interrupt service routine when zero crossing is detected
   in uni,sreg
   push uni//push status register to stack

trigger://Triggerin pulse sent through PC0
   Ldi uni, 0x01
   out portc, uni

endservice://Endservice
   pop uni
   out sreg, uni
   reti

main:

   LDI uni,LOW(RAMEND)//Initialise Stackpointer
     OUT SPL,uni
     LDI   uni,HIGH(RAMEND)
     OUT   SPH,uni

   ldi uni,0xFF//PortC as outport
   out ddrc, uni

   ldi uni,0b11100000//CLear interrupt flags
   out GIFR,uni

   ldi uni,0b00100000//Enable INT2
   out GICR, uni

   ldi uni,0b00000000//configure INT2 to occur on falling edge
   out MCUCSR, uni

   SEI//set Global I flag in SREG

wait://wait till interrupt occurs(falling edge on INT2)
   rjmp wait

Regards
heguli

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

I hav tried the first program in AVR studio and it works, but in real time working or in a Spice simulation it doesnt work.

trigger://Triggerin pulse sent through PC0 
   Ldi uni, 0x01 
   out portc, uni 

endservice://Endservice 

In ur program, this part of the code doesnt help. PC0 always stays high once the interrupt occurs. i jus want a pulse each time the interrupt occurs.

It works fine with INT0 and INT1, but only INT2 is causin the problem.

my circuit diagmram is here. i havent used any pull ups at portB

I want to send a pulse through PC0 when the falling edge of the sine wave is detected.[img][/img]

Attachment(s): 

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

in fact i just want to use INT2 to detect a rising or falling edge of a pulse signal. someone could help me to write such a code

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

I'm not sure what you want to do.
In last code PC0 is never set low so of course it will stay high.
This is code I wrote to detect zero-crossing @ 50 Hz

timer1_init:
	ldi	temp,0x00	;counter1
	out	tccr1a,temp	;up counter
	ldi	temp,0x80	;with overflow 
	out	timsk,temp	;interrupt
	ldi	temp,0x00	;counter1
	out	tccr1b,temp	;stopped

int0_init:
	ldi	temp,0x40	;enable
	out	gimsk,temp	;interrupt for
	ldi	temp,0x02	;irq0
	out	mcucr,temp	;on falling edge
.org	int0adr
	rjmp	ext_int0	;IRQ0 Handler
		
.org	tim1_ovfadr
	rjmp	tim_ovf1	;Timer1 Overflow Handler
ext_int0:
	ldi	temp,0xff	;load Hi register
	out	tcnt1h,temp	;for counter1
	ldi	temp,5		;load Lo register
	out	tcnt1l,temp	;for counter1
	ldi	temp,0x02	;start counter1 clk/8
	out	tccr1b,temp	;to get 0.2 mS
	clr	tick		;reset tick
	reti			;return from interrupt

tim_ovf1:
	ldi	temp,0xff	;load Hi register
	out	tcnt1h,temp	;for counter1
	ldi	temp,5		;load Lo register
	out	tcnt1l,temp	;for counter1
	inc	tick		;tick phase counter
	cpi	tick,15		;if tick = 15
	breq	motor_on	;turn motor ON
	cpi	tick,50		;if tick = 50 (zero crossing)
	breq	motor_off	;turn motor OFF
	cpi	tick,65		;if tick = 65
	breq	motor_on	;turn motor ON
	cpi	tick,99		;if tick = 99 (zero crossing)
	breq	motor_off	;turn motor OFF
	reti			;else return from interrupt

Code is written for 2313 @ 10MHz so you need to change timer. I used Timer1 cause Timer0 was already used, but 8-bit Timer is enough. You have to calculate your timer to interrupt every 0.2 ms. 100*0.2 ms = 20 ms = one wave. When Timer have done 99 interrupts ext_int0 detect a falling edge and reset 'tick' register, thus calibrating Timer. You can turn on your triac at any 'tick' value. You might need to save and restore SREG in Timer ISR.

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

@ Lennart

i want to use the INT2 pin.. i dont want to detect in any other pin.. i want to use the INT2 pin to interrupt the mcu when it detects the falling edge.

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

Yes, I understood that. Since my code is for INT0 you have to do some work of your own...
I didn't provide a code ready to use, I just gave an example how to detect zero-crossing and do something at the time you wish during wave.

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

Quote:
n ur program, this part of the code doesnt help. PC0 always stays high once the interrupt occurs. i jus want a pulse each time the interrupt occurs.
It was just a test that your int2 works in real time. How did you manage to set interrupts 0 and 1 to work?

During the interrupt, set the PC1 Don't use delay loop inside the interrupt, just load the register delay.
After wait: -line, make your delay loop witch finally clears the output PC1.

Regards
heguli

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

Quote:
It was just a test that your int2 works in real time

i tried that too.. but it aint workin in real time..

Quote:
How did you manage to set interrupts 0 and 1 to work?

For INT0 and INT1 this is wat i did:

.NOLIST
.INCLUDE "C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m32def.inc"
.LIST

.def uni=R16//universal register for all data transfers and interim storage of values
.def delay1=r17
.def checkreg=R18

.CSEG
.ORG 0000

rjmp main
nop
rjmp Iservice
nop

main:
//Initialization
	LDI uni,LOW(RAMEND) //Initialise Stackpointer
  	OUT SPL,uni
  	LDI	uni,HIGH(RAMEND)
  	OUT	SPH,uni

	ldi uni, 0xFF
	out DDRB, uni
	
	ldi uni,0b11100000//CLear interrupt flags
	out GIFR,uni

	ldi uni,0x40//
	out GICR, uni

	ldi uni,0b00000011//
	out MCUCR, uni

	SEI//set Global I flag in SREG

	clr checkreg

wait://wait till zero crossing
	rjmp wait
	
Iservice:
	in uni,sreg
	push uni//push status register to stack
	ldi uni,5
	sbrc checkreg,0
	rjmp check_low
check_high:	
	sbis pind,2
	rjmp endservice
	dec uni
	brne check_high
	ldi checkreg,1
	ldi uni,0b00000010//
	out MCUCR, uni
	rjmp trigger 
check_low:	
	sbic pind,2
	rjmp endservice
	dec uni
	brne check_low
	ldi checkreg,0
	ldi uni,0b00000011//
	out MCUCR, uni
	rjmp trigger
trigger:
	ldi uni,0xff
	out portb, uni
	call delay
	ldi uni, 0x00
	out portb, uni
endservice:
	pop uni
	out sreg, uni
	reti


delay:
	ldi delay1,28
back1:
	dec delay1
	brne back1
	ret
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@ lennart :

Quote:
Since my code is for INT0 you have to do some work of your own...

as i said earlier when i tried using INT0 and INT1 it was working fine.. but when i tried INT2 it isnt workin and i need to use this interrrupt because the other two have been already used for other purposes..

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

Quote:
In ur program, this part of the code doesnt help. PC0 always stays high once the interrupt occurs. i jus want a pulse each time the interrupt occurs.

This implies that INT2 work...
How do you check that PC0 is always high?
Even if you make it low in main code it will go high 50 times/sec so if you are looking at a led it will appear to be on.

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

Quote:
This implies that INT2 work...

no INT2 doesnt work.. i jus meant i dont want PC0 to remain high even if interrupt works.. but it doesnt go high at all.. it always remains low

i am lookin at the output on a CRO

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

try this:

//simple code to test INT2, send a pulse of at PC0 pin

.NOLIST
.INCLUDE "C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m32def.inc"
.LIST

.def uni=R16//universal register for all operations
.def delay1=R17//delay register1

.CSEG
.ORG 0000

rjmp main
nop
nop
nop
nop
nop
rjmp Iservice2
nop

Iservice2://Start interrupt service routine when zero crossing is detected
   in uni,sreg
   push uni//push status register to stack
   ldi uni, 05
checksampleslow:
   sbic pinb, 2//check for 5 samples to discard voltage surges or so on
   rjmp endservice
   dec uni
   brne checksampleslow
trigger://Triggerin pulse sent through PC0
   Ldi uni, 0x01
   out portc, uni

   delay://delay which is the thickness of the pulse at PC0
   ldi delay1, 28
loop2:
   dec delay1
   brne loop2
   
   ldi uni, 0x00
   out portc, uni
endservice://Endservice
   pop uni
   out sreg, uni
   reti

main:

   LDI uni,LOW(RAMEND)//Initialise Stackpointer
     OUT SPL,uni
     LDI   uni,HIGH(RAMEND)
     OUT   SPH,uni

   ldi uni,0xFF//PortC as outport
   out ddrc, uni

   ldi uni,0b11100000//CLear interrupt flags
   out GIFR,uni

   ldi uni,0b00100000//Enable INT2
   out GICR, uni

   ldi uni,0b00000000//configure INT2 to occur on falling edge
   out MCUCSR, uni

   SEI//set Global I flag in SREG

wait://wait till interrupt occurs(falling edge on INT2)
   rjmp wait

Regards
heguli

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

no that too aint workin .. :(

this is another simple program to count the number of times interrupt has occured and display it on the port.. it wokrs fine with INT0 and INT1.. only problem is INT2 :( and i need INT2 for my program.. anyone already used INT2 for any program??? please share in here

.NOLIST
.INCLUDE "C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m32def.inc"
.LIST

.def uni=R16
.def counter=R17

.CSEG
.ORG 0000

rjmp main
nop 
nop
nop
nop
nop
rjmp Iservice2

main:
	LDI uni,LOW(RAMEND)//Initialise Stackpointer
  	OUT SPL,uni
	ldi uni,HIGH(RAMEND)
	out SPH,uni
	
	clr counter

	ldi uni,0b11111111
	out ddrc,uni

	ldi uni,0b11100000
	out gifr, uni

	ldi uni, 0b00100000
	out gicr, uni

	ldi	uni, 0b01000000
	out mcucsr, uni

	sei

wait:
	rjmp wait

Iservice2:
	in uni, sreg
	push uni
	inc counter
	out portc,counter
	pop uni
	out sreg, uni
	reti

it works wen used in INTO and INT1
for example INTO:

.NOLIST
.INCLUDE "C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m32def.inc"
.LIST

.def uni=R16
.def counter=R17

.CSEG
.ORG 0000

rjmp main
nop 
rjmp Iservice0
nop
nop
nop


main:
	LDI uni,LOW(RAMEND)//Initialise Stackpointer
  	OUT SPL,uni
	ldi uni,HIGH(RAMEND)
	out SPH,uni
	
	clr counter

	ldi uni,0b11111111
	out ddrc,uni

	ldi uni,0b11100000
	out gifr, uni

	ldi uni, 0b01000000
	out gicr, uni

	ldi uni, 0b00000011
	out mcucr, uni

	sei

wait:
	rjmp wait

Iservice0:
	in uni, sreg
	push uni
	inc counter
	out portc,counter
	pop uni
	out sreg, uni
	reti

each time the signal went from zero to one it interrupted and it displayed the number of times the signal had a zero to one transformation. This worked with INT0. But the earlier code for INT2 didnt work. please help as to what may be the cause.

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

Try this code.
#include "IOM32.h"
#include "Includes.h"
#include "Constants.h"
#include "Functions.h"
#include "Variables.h"

#define _EINT() SREG |= 0x80
#define _NOP() asm( " nop " )
#define LED 0x01

void main( void ){
Initialize();
while( 1 )
{
_NOP();
}
}
/************************************************
@Fn: Initialize()
@Br: Initialization of MCU
@Pa: None
@Rt: None
************************************************/
void Initialize( void ){
MCUCR = ( 1 << ISC01 ) | ( 1 << ISC00 );
/* Any logical change on INT0 & INT1 generates an interrupt request */
MCUCSR |= ( 1 << ISC2 ); /* Rising edge to interrupt INT2 */
GICR = ( 1 << INT0 ) | ( 1 << INT1 ) | ( 1 << INT2 );
/* Enable INT0,INT1,INT2 */

PORTC = 0xFF;
DDRC = LED;

_EINT();
}

#pragma vector = INT0_vect
__interrupt void INT0_ISR( void ){
PORTC ^= LED;
}

#pragma vector = INT1_vect
__interrupt void INT1_ISR( void ){
PORTC ^= LED;
}

#pragma vector = INT2_vect
__interrupt void INT2_ISR( void ){
GICR &= ~( 1 << INT2 ); /* Disable INT2 */
PORTC ^= LED;
MCUCSR ^= ( 1 << ISC2 ); /* Change edge to interrupt INT2 */
GICR |= ( 1 << INT2 ); /* Re-enable the INT2 */
}

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

PB2 (INT2) must be set as an input. I see no where in your code that you are doing this.

Regards,
Steve A.

The Board helps those that help themselves.

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

Quote:
PB2 (INT2) must be set as an input. I see no where in your code that you are doing this.

Isn't that default set by chip?
INT2 share same pin as Analog comparator(AIN0), don't know if this can be an issue?

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

Since you are dealing with a mega 32 your interrupt vectors need to be set up correctly ( no rjmp but jmp) which means that the vector you think is going to your routine is going off to La-La Land.

Pete

P.S Why not copy the vector table to your app that way they are all ready there to use.

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

Quote:

need to be set up correctly ( no rjmp but jmp) which means that the vector you think is going to your routine is going off to La-La Land.

RJMP is fine (or any other instruction(s)) as long as they are spaced properly. I counted the OP's code twice, and it looks OK.

But yes, I agree, take the extra few minutes and .ORG all the vectors and it should eliminate some confusion.

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

True, you can put anything you want there as long as it works(you could even put #*&^$ there).Why tempt fate and rely on counting with your appendeges when it would only confuse with "OH should I have used two nop's between rjmps or should that have been maybe one or three?"

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

@Koshchi

Quote:
PB2 (INT2) must be set as an input.

i thought of that, and had tried configuring it as input.. didnt help

@suzhwt: i dont really understand C language.. so its kinda hard for me to understand ur program :( but i am still tryin.. if i want to just try if its workin how do i do it? i have win-avr as well as avrstudio4.

@digitool : i tried using jmp.. didnt help.. i know i have to copy the vector table .. but from wher ? and do i have to use org along with it ? could someone post exactly wat i have to paste in my program?

@Lennart

Quote:
INT2 share same pin as Analog comparator

thought of that too and tried disabling ACME by writing a '1' to it(bit3 in SFIOR).. still didnt work .. darn!!

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

here's the revised code after incorporating the changes, it still doesnt work:(

.NOLIST 
.INCLUDE "C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m32def.inc" 
.LIST 

.def uni=R16 
.def counter=R17 

.CSEG 
.ORG 0x00 
rjmp main
.ORG 0x06 
rjmp Iservice2 
.org 0x2A
main: 
   LDI uni,LOW(RAMEND)//Initialise Stackpointer 
   OUT SPL,uni 
   ldi uni,HIGH(RAMEND) 
   out SPH,uni 
    
   clr counter//clear counter

   ldi uni,0b00001000//disable Analog comparator by writing logical 1 to ACME
   out sfior, uni

   ldi uni,0b11111111//port C = OUTPORT
   out ddrc,uni
   
   ldi uni,0x00//PORTB = inport
   out ddrb, uni 

   ldi uni,0b11100000//clear interrupt flags by writing logical "1"
   out gifr, uni 

   ldi uni, 0b00100000//enable INT2
   out gicr, uni 

   ldi uni, 0b01000000 //INT2 configured for rising edge
   out mcucsr, uni 

   sei //Global interrupt flag enabled

wait: 
   rjmp wait //wait for interrupt

Iservice2: 
   in uni, sreg 
   push uni // push status flag to stack
   inc counter // increment counter
   out portc,counter //display counter value through LED's at portC
   pop uni 
   out sreg, uni //pop back SREG into uni
   reti //return
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@suzhwt: i dont exactly know wat u were doin in ur program, but if i got it right i tried doin this:

in the ISR:
disabling INT2 in GICR
configuring ISC2 in MCUCSR to rising edge
enabling INT2 again

code:

ISR: 
in uni, sreg
push uni
ldi uni,0x00
out gicr, uni
inc counter
out portc, counter
ldi uni,0b00000000
out mcucsr,uni
ldi uni,0b01000000
out mcucsr,uni
ldi uni,0b00100000
out gicr, uni
pop uni
out sreg, uni
reti

it didnt work,:(

could it have anythin to do with DIEOE,DIEOV or DI??

on page57 of mega32 datasheet, there's a table mentioning somethin about INT2 enable etc, didnt know wat it was. the table is shown in the pic

Attachment(s): 

Last Edited: Sat. May 5, 2007 - 07:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you disabled the JTAG on PortC ? I have not sat down and tried to run your code just looking for things that stand out.

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

yes, JTAG has been disabled.. as i already mentioned.. the program worked fine with INT1 and INT0 (by only makin changes to GICR and MCUCR,MCUCSR) .. the problem seems to be with INT2

i tried a simple program like this:

.NOLIST 
.INCLUDE "C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m32def.inc" 
.LIST 

.def uni=R16 
.def counter=R17 

.CSEG 
.ORG 0x00 
rjmp main 
.ORG 0x06 
rjmp Iservice2 
.org 0x2A 
main: 
   LDI uni,LOW(RAMEND)//Initialise Stackpointer 
   OUT SPL,uni 
   ldi uni,HIGH(RAMEND) 
   out SPH,uni 
    
   clr counter//clear counter 

   ldi uni,0b11111111//port C = OUTPORT 
   out ddrc,uni 
    
   ldi uni,0x00//PORTB = inport 
   out ddrb, uni 
   clr uni
wait: 
   sbis pinb, 2
   rjmp wait
   inc uni
   out portc, uni
   call delay
   rjmp wait

delay:
   ldi counter,11
back2:
   ldi XL,255
   ldi XH,255
back1:   
   sbiw XH:XL,1
   brne back1
   dec counter
   brne back2
   ret

This worked.. so it has to be a problem on INT2 i guess.
INT1, INT0, normal PB3 input port all workin. wat els could it be now?
has anyone already used rising or falling edge on INT2 to jump to ISR of INT2?? If yes please post it in here. it could help

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

PC0 isn't a pin that's used by JTAG I believe.
Can you try to make a simple program like turning a led on at some other pin if you change PB2 i.e. from hi to lo to test if your transformer connection have blown the pin.

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

this works:

//simple code to test INT2, send a pulse of at PC0 pin

.NOLIST
.INCLUDE "C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m32def.inc"
.LIST

.def uni=R16//universal register for all operations
.def delay1=R17//delay register1

.CSEG
.ORG 0000
rjmp main
.org 0x006 //INT2 External Interrupt Request 2
rjmp Iservice2


Iservice2://Start interrupt service routine when zero crossing is detected
   in uni,sreg
   push uni//push status register to stack
   ldi uni, 05
checksampleslow:
   sbic pinb, 2//check for 5 samples to discard voltage surges or so on
   rjmp endservice
   dec uni
   brne checksampleslow
trigger://Triggerin pulse sent through PC0
   Ldi uni, 0x01
   out portc, uni

delay://delay which is the thickness of the pulse at PC0
   ldi delay1, 28
   loop2:
   dec delay1
   brne loop2
   
   ldi uni, 0x00
   out portc, uni
endservice://Endservice
   pop uni
   out sreg, uni
   reti

main:

   LDI uni,LOW(RAMEND)//Initialise Stackpointer
     OUT SPL,uni
     LDI   uni,HIGH(RAMEND)
     OUT   SPH,uni

   ldi uni,0xFF//PortC as outport
   out ddrc, uni

   in uni, GICR//disable int2
   cbr uni, (1<<int2)
   out GICR, uni


   ldi uni,0b00000000//configure INT2 to occur on falling edge
   out MCUCSR, uni

   in uni, GIFR//CLear interrupt flag
   sbr uni, (1<<intf2)
   out GIFR, uni

   nop//just in case nop's, cause I don't know how long does it take to clear the flag
   nop
   nop

   in uni, GICR//enable int2
   sbr uni, (1<<int2)
   out GICR, uni
   

   SEI//set Global I flag in SREG

wait://wait till interrupt occurs(falling edge on INT2)
   rjmp wait

Regards
heguli

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

@heguli :

Quote:
this works:

how did u test if it works??? all the programs work in avr studio simulation.. but doesnt work in spice simulations like proteus VSM

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

just a wild quess :lol:
In datasheet, there is moore about int2:

Quote:
When changing the ISC2
bit, an interrupt can occur. Therefore, it is recommended to first disable INT2 by clearing
its Interrupt Enable bit in the GICR Register. Then, the ISC2 bit can be changed. Finally,
the INT2 Interrupt Flag should be cleared by writing a logical one to its Interrupt Flag bit
(INTF2) in the GIFR Register before the interrupt is re-enabled.

...so I tought this might do the trick.

You didn't try that code on the chip?
What about Lennart's tought about handling the port, is it still working?

Regards
heguli

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

Quote:

all the programs work in avr studio simulation.. but doesnt work in spice simulations like proteus VSM

WHOA, WHOA, WHOA--

Have we been watching and thinking about this thread because a spice simulation failed?!?

Try it on a real chip, THEN report back.

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

Quote:
on page57 of mega32 datasheet, there's a table mentioning somethin about INT2 enable etc, didnt know wat it was. the table is shown in the pic

I tried to look at that table in datasheet and must admit I do not understand shit...
Never used m32, isn't there some other Freak who know if you need to set some bits in a register to make INT2 work. What is default state of PB2?

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

Quote:
how did u test if it works??? all the programs work in avr studio simulation.. but doesnt work in spice simulations like proteus VSM
You do have the chip, right?

Regards
heguli

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

Quote:
You do have the chip, right?

:D :D
Let's pray for that...

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

yeah i do have.. i always try it on spice simulations before testing in real coz i already lost 3 chips for god knows wat reason(as lennart already knows----remember the lamp dimmer and triac triggering?) lol.. but watever.. will try it tom on the real chip and report back on monday.. thanks for the help

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

Quote:
i already lost 3 chips for god knows wat reason(as lennart already knows----remember the lamp dimmer and triac triggering?) lol..

That's why I wanted you to test your PB2 pin :D

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

Quote:
yeah i do have.. i always try it on spice simulations before testing in real coz i already lost 3 chips for god knows wat reason
Oh man, Lee was right!!!! ...all this effort we have put out :D ...well, maybe you shouldn't connect the transformers other end to the avr. That way you can save few chips. Some sort of isolation might be in order like opto?
At least tell us on monday how did you do.

Regards
heguli

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

ITS working!! sorry for the inconvenience.. but i didnt want to take the chance of tryin it out on the chip once the onchip simulator didnt work.. hence i posted it here.. so the problem was after all the simulator software... sorry for the trouble :oops: :mrgreen: thanks for the help though:)

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

Guess I learned a lesson...
Ask if it's the real chip that doesn't work :roll:

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

Hi there all .. thanks for all the help .. please visit
http://autolightcontrol.googlepages.com
.. most details of the project has been published online .. further details will be added as and when time permitts. thank you once again