Searching \ for '[PIC] Interrupts not working on 18F1320 + C18' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ints.htm?key=interrupt
Search entire site for: 'Interrupts not working on 18F1320 + C18'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] Interrupts not working on 18F1320 + C18'
2011\10\03@203330 by Philip Pemberton

face
flavicon
face
OK, this is just getting weird...

I had external interrupts working in the JAL prototype of my remote-control receiver code, but I'm rewriting it in C18 (mainly because I can do floating-point calculations for timer preload and threshold values; JAL AIUI only handles integer math).

The thing is, I'm not seeing any interrupts -- none at all. I put a breakpoint on the "goto ISR" line, and the PIC didn't break. I also didn't see anything on the logic analyser....

I must be doing something stupid, but I can't for the life of me figure out what:

#include <p18cxxx.h>
#pragma config OSC = HS     // High Speed Crystal oscillator
#pragma config WDT = OFF    // Watchdog timer off
#pragma config LVP = OFF    // Low-voltage programming off
#pragma config MCLRE = ON   // MCLR (reset) on
#pragma config FSCM = OFF   // Failsafe clock monitor off

// timer0 prescaler settings
#define TIMER0_USE_PRESCALER
#define TIMER0_PRESCALER_SETTING 5

// Infra-red receiver
#define PIN_IR                PORTBbits.RB0
#define PIN_IR_DIR            TRISBbits.TRISB0

void isr(void);

// ISR stub code
#pragma code HIGH_INTERRUPT_VECTOR = 0x8
void high_ISR (void)
{
    _asm
        goto isr
    _endasm
}
#pragma code

// Interrupt Service Routine
#pragma interrupt isr
void isr(void)
{
    unsigned char tval;
    char overflow;

    // Store timer value and overflow flag and rearm the timer
    tval = TMR0L;
    TMR0L = 0;
    overflow = INTCONbits.TMR0IF;
    INTCONbits.TMR0IF = 0;

    // detect RB0 int flag
    if (INTCONbits.INT0IF) {
        char pol;

        // clear interrupt flag
        INTCONbits.INT0IF = 0;

        // store bit polarity, then flip to other polarity
        pol = INTCON2bits.INTEDG0;
        INTCON2bits.INTEDG0 = !INTCON2bits.INTEDG0;
    }
}

void main(void)
{
    // Initialise pin directions
    LATA = LATB = 0;        // Clear port holding registers
    TRISA = TRISB = 0;        // Default to all outputs
    PIN_IR_DIR = 1;            // IR pin is an input

    // Set up timer 0
    T0CON = 0;            // Clear timer control register
#ifdef TIMER0_USE_PRESCALER
    T0CONbits.PSA = 1;        // Assign prescaler to timer0
    T0CONbits.T0PS0 = (TIMER0_PRESCALER_SETTING & 1)==1;
    T0CONbits.T0PS1 = (TIMER0_PRESCALER_SETTING & 2)==2;
    T0CONbits.T0PS2 = (TIMER0_PRESCALER_SETTING & 4)==4;
#else
    T0CONbits.PSA = 0;        // Disable prescaler
#endif
    TMR0L = 0;            // Clear timer0 value

    // Set up interrupts
    INTCON2bits.INTEDG0 = IPOL_ACT;    // Trigger RB0 interrupt on
                    // active-going edge
    INTCONbits.INT0IF = 0;        // Clear RB0 interrupt flag
    INTCONbits.INT0IE = 1;        // Enable INT0 interrupt
    // The ISR handles the timer-0 overflow interrupt.
    INTCONbits.GIE = 1;        // Enable interrupts (globally)

    debug_word(0xCAFE);
    debug_word(0xBABE);

    for (;;) {
    }
}


Can anyone see what I'm doing wrong here? The chip seems to be acting as if GIE were never set, but the SFR window suggests it *is* being set (as is INT0IE)...

Thanks,
-- Phil.
spam_OUTpiclistTakeThisOuTspamphilpem.me.uk
http://www.philpem.me.uk

2011\10\03@210119 by peter green

flavicon
face
Philip Pemberton wrote:
{Quote hidden}

As for the int0 intterrupt it looks to me like you may have RB0 set as an analog input.

> Thanks,
>

2011\10\04@020220 by Ruben Jönsson

flavicon
face
{Quote hidden}

The TMR0 part in the interrupt routine is always executed even if the interrupt source is RB0. But maby that is the intention?

/Ruben

==============================
Ruben Jönsson
AB Liros Electronic
Box 9124, 200 39 Malmö, Sweden
TEL INT +46 40142078
FAX INT +46 40947388
.....rubenKILLspamspam@spam@pp.sbbs.se
==============================

2011\10\04@175349 by Philip Pemberton

face
flavicon
face
On 04/10/11 02:01, peter green wrote:
> What intterrupts are you expecting?

RB0 interrupt-on-edge.

> Your code seems to talk about a
> timer interrupt but doesn't seem to actually enable the timer interrupt.

That's in the code I trimmed out for the sake of brevity :)

It uses TMR0 to measure the delta-T between pulses, and also (later on) for the time-out.

> As for the int0 intterrupt it looks to me like you may have RB0 set as
> an analog input.

Yep, that's what it was.

Well, I feel thoroughly stupid now....!

Solution: "ADCON1 = 0x7F;"

Thanks,
-- Phil.
piclistspamKILLspamphilpem.me.uk
http://www.philpem.me.uk

More... (looser matching)
- Last day of these posts
- In 2011 , 2012 only
- Today
- New search...