Log in

View Full Version : interrupt enable


3dude_2231
09-02-2008, 15:52
Hi all

been thinking about interrupts,
I didn't really dig into Kevin's code,
but if I'm not mistaken, enabling the interrupts is done by a '#define',
and is done only once, to affect the entire code, I might be mistaken here, but..

I don't want the IR affecting my teleop period's maneuvers, so.
I wanna disable the interrupts altogether, and this can be done by putting this:
INTCONbits.GIE = 0;
at the beginning of teleop code,
and this:
INTCONbits.GIE = 1;
at the beginning op autonomous mode.

now, some questions:
1. am I right?,
does the GIE (general interrupts enable) bit apply to all of the interrupts?
I havn't dealt with ints for a while now..

2.is that even necessary?
are the interrupts enabled in teleop anyway?

thanks in advance,
Ran.

usbcd36
09-02-2008, 17:28
The answer to your second question is yes, interrupts are enabled in the teleop period. My question for you is this: why would the interrupts affect the teleop period anyway (i.e., are they simply unnecessary or do they cause problems?)?

3dude_2231
09-02-2008, 17:34
thanks, usbcd36

my answer to your question is:
..they might cause problems,
don't you agree that anything that can cause you robot to move to a position
you don't want him to move might be bad?

psy_wombats
09-02-2008, 17:41
Hopefully you don't have the interrupts actually trigerring the robot's movement. Otherwise, couldn't you add in the code an if to check if the robot is in autonomous before changing pwms based on IR inputs? What exactly would your interrupt look like? Turning on a flag that dictates what routine to run (only handled in autonomous), or are PWMs set in the interrupts?

dcbrown
09-02-2008, 18:24
INTCONbits.GIE = 0;


This will definitely cause the red-light-of-death it turned off for any length of time. The GIE bit is also known as GIEH -- you've just disabled ALL interupts including the high priority interrupt that exchanges data between the master processor and user processor. If you wanted to disable all user interrupts you'd use GIEL bit instead.

See pg 121 in the PIC18F8722 manual (DS39646B;39646b.pdf)

3dude_2231
09-02-2008, 18:45
:D
good thing it's in theory.

"If you wanted to disable all user interrupts you'd use GIEL bit instead."
aren't the 'IE's of kevin's code ISR in the GIEH?

nevermind, there are (as mentioned above) much smarter ways to do this :D

dcbrown
10-02-2008, 16:08
:D
aren't the 'IE's of kevin's code ISR in the GIEH?


No. And IEs are neither high or low in association - they just allow or disallow the associated interrupt from occuring.
The IP is what assigns the interrupt to high or low priority...

There are three things that control each interrupt, IP, IE, and IF.


. IP, Interrupt Priority - can be assigned to low or high if IPEN (interrupt
priority enable) is set which it should be. The high priority interrupt
handler is provided as part of the default code. Assigning any peripheral
interrupts to high priority should get the red-light-of-death as that
interrupt handler won't check for or clear any interrupt its not expecting.
. IE, Interrupt Enable - enable an interrupt to occur if or when IF is set.
. IF, Interrupt Flag - the pin or device sets this flag when interrupt conditions
are met. The flag is set regardless of whether IE is on or off allowing
code to poll for interrupt (request for service) conditions.

GIEH disables both high and low priority interrupts. GIEL enables/disables low prioriy interrupts. User's code should only assign interrupts to low priority.

The h/w logic for a low priority interrupt is something like;

if (GIEH && GIEL && (IPx=lo) && IEx && IFx) then interrupt processor...


There is one exception in Kevin's code base where he is setting up the local CCP hardware for PWM use - during the handful of lines that are setting up, the GIEH flag is used to disable all interrupts. But that is a one shot deal only done at setup. In all the other places I looked, the indivual IE is used to control specific interrups. As far as priority assignment, the following lines show that the interrupts are assigned to low priority.


interrupts.c:65: INTCON3bits.INT2IP = 0; // 0: interrupt 1 is low priority (leave at 0 for IFI controllers)
interrupts.c:100: INTCON2bits.INT3IP = 0; // 0: interrupt 2 is low priority (leave at 0 for IFI controllers)
interrupts.c:138: INTCON2bits.RBIP = 0; // 0: interrupts 3-6 are low priority (leave at 0 for IFI controllers)
serial_ports.c:313: IPR1bits.RC1IP = 0; // receive interrupt priority bit (must be 0 for IFI controllers) [130]
serial_ports.c:341: IPR1bits.TX1IP = 0; // transmit interrupt priority bit (must be 0 for IFI controllers) [130]
serial_ports.c:497: IPR3bits.RC2IP = 0; // receive interrupt priority bit (must be 0 for IFI controllers) [132]
serial_ports.c:526: IPR3bits.TX2IP = 0; // transmit interrupt priority bit (must be 0 for IFI controllers) [132]

:
etc.