View previous topic :: View next topic |
Author |
Message |
Rickprakt
Joined: 17 May 2011 Posts: 2
|
Posted: Tue May 17, 2011 3:36 pm Post subject: Problem with interupt function |
|
|
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 |
|
|
mattcro
Joined: 03 Oct 2007 Posts: 327 Location: Scotland
|
Posted: Tue May 17, 2011 7:56 pm Post subject: |
|
|
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.5 |
|
Back to top |
|
|
Rickprakt
Joined: 17 May 2011 Posts: 2
|
Posted: Fri May 20, 2011 7:34 am Post subject: |
|
|
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 |
|
|
mattcro
Joined: 03 Oct 2007 Posts: 327 Location: Scotland
|
Posted: Fri May 20, 2011 7:01 pm Post subject: |
|
|
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.5 |
|
Back to top |
|
|
|