Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

something about interrupt

Status
Not open for further replies.

johnson

New Member
dear all,

I have some problem regarding using an interrupt. When an external interrupt occurs, I want the program counter to jump to the specific label instead of continue from the code that interrupt occured. Any suggestion?
I wrote this in pic basic but it does not seem to be correct:

Code:
disable
isr:
    if (mode<=maxmode) then
        mode=mode+1
        intcon.1=0
        pause 50
        goto main
    endif
enable

the code shows that whenever interrupt occur, after operation the program should jump to main instead of continue the code.
 
You are probably having stack problems. Are you using the PIC BASIC PRO from microengineering labs? Are you using the ON INTERRUPT command? Is the code for the interrupt handler?... post some more of your code

Ivancho
 
hi,
yes, i am using using pic basic pro:> structure my code structure looks like follow:

Code:
option_reg =0
intcon = $90
on interrupt goto isr
mode var byte
maxmode var byte
.........

main:

.......

goto main

disable
isr:
    if (mode<=maxmode) then
        mode=mode+1
        intcon.1=0
        pause 50
        goto main
    endif
enable



thanks in advance:>


cheers
 
What version of PIC BASIC PRO are you using?... you are missing a RESUME on your program... The interrupt handler doesn't like to have jumps within the handler.... something to do with the stack, it will not be able to record and know where it was last at.

I would change your code like this.... (change the Goto Main... to ... RESUME Main), and change the DISABLE so that when the interrput jumps to the label you don't retrigger the interrupt if there was another interrupt signal.

Code:
option_reg =0 
intcon = $90 
on interrupt goto isr 
mode var byte 
maxmode var byte 
......... 

main: 

....... 

goto main 


isr: 
disable 
    if (mode<=maxmode) then 
        mode=mode+1 
        intcon.1=0 
        pause 50 
        RESUME main 'Resumes at Main if above condition is true
    endif 
     RESUME   'returns to where it was interrupted at since if conditions id false
enable

Make sure you understand that using the PIC BASIC ON INTERRUPT command will make your code quite long. When compiling the ON INTERRUPT will put a short subroutine after EACH STATEMENT ON YOUR PROGRAM that checks the state of the Global Interrupt Enable bit. So if you are doig a PAUSE 10000 on your main program, and a interrupt happens, the code will not be interrupted until the PAUSE 10000 is over with. But most of the time you doint' have such a delay so interrupts happen much faster. Sitll you have to understand that problem does exist.
If you can't live with that then you are going to have to make a interrupt handler with assembly within the BASIC program.

Ivancho
 
An interrupt routine must always be ended with a retfie the normal way. Otherwise a new interrupt can't occur (on a pic) or you will have stack overflow when it does happen enough times (other platform).

An interrupt routine and the main program should be seen as two independent programs, you cannot just jump from an interrupt routine back into normal code. what you can do is set a flag in your interrupt code, and then somewhere in the main program check that flag and act acordingly.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top