Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Problem with interupt function

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
Rickprakt

Bascom Member



Joined: 17 May 2011
Posts: 2

PostPosted: Tue May 17, 2011 3:36 pm    Post subject: Problem with interupt function Reply with quote

I looked around a bit in the forums and such.
I found a solution to my problem as a "Gifr = 64" function, but this does code isent used on my microprocessor and now my question is; are there any other name for the same thing on my microprocessor.
I use a ATMEGA 644 with regfile m644def.dat

Anyone know or have any tip?
Back to top
View user's profile
mattcro

Bascom Member



Joined: 03 Oct 2007
Posts: 324
Location: Scotland

uk.gif
PostPosted: Tue May 17, 2011 7:56 pm    Post subject: Reply with quote

The newer or larger AVRs like m644 have several interrupt control registers for the various peripherals (timers, UARTs...)

What interrupt are you having a problem with?

The GIFR = 64 code would clear one of the interrupt flags. That is usually done just before enabling the corresponding interrupt, so you do not get the interrupt firing immediately after it is enabled (eg if a pin change had already occurred when you enable the pin change interrupt).

Edit: looks like GIFR=64 clears the INT0 flag on smaller chips. So on the m644 you need to clear the INT0 flag by setting (not resetting) bit INTF0 in the EIFR register: Set EIFR.INTF0

_________________
If all else fails, read the manual. Even better: read the manual before something fails. If you can't find it in the manual, search the forum.
BascomAVR 2.0.8.2
Back to top
View user's profile
Rickprakt

Bascom Member



Joined: 17 May 2011
Posts: 2

PostPosted: Fri May 20, 2011 7:34 am    Post subject: Reply with quote

I having problem with interrupt INT0
I have a encoder on a stepper motor and the interrupt is for the encoder,
the position for the step engine jumps back and forth making the steps become off more and more for each time it goes up and down.
Pind.3 = the encoders b signal
Pind.2 = the encoders a signal
interrupter is on falling flank
the encoder is a HEDS 5540 optical encoder
this is how the encode interrupt looks like now:

Encode:
If Pind.3 <> Pind.2 Then
Position = Position + 1
Else
Position = Position - 1
End If
Print Position
Set EIFR.INTF0
Return
Back to top
View user's profile
mattcro

Bascom Member



Joined: 03 Oct 2007
Posts: 324
Location: Scotland

uk.gif
PostPosted: Fri May 20, 2011 7:01 pm    Post subject: Reply with quote

Don't do the Print statement inside the interrupt handler - it normally takes a relatively long time and will probably mess up the pulse counting at faster rotation speeds. Encoders like this can produce pulses very fast, so you need the interrupt handler to be as compact as possible.

You can do the print in your main program loop and, if necessary, use a short delay (waitms) to prevent it printing the value too often.

You can also try Incr Position and Decr Position - should be slightly faster than Position = Position + 1.

For the ultimate speed in interrupt handlers, you need to use the NOSAVE option and some assembler.

_________________
If all else fails, read the manual. Even better: read the manual before something fails. If you can't find it in the manual, search the forum.
BascomAVR 2.0.8.2
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum