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.

Interrupt problems!

Status
Not open for further replies.

amindzo

Member
Hi,
i found that interrupt in pic basic works in small programs but in big programs it doesn't work especially in programs that use alot of if sentences.for example , scanning keyboard with polling method(using if sentences) interrupt doesn't work. i wanted to scan keyboard and when serial data is coming the program goes to taking serial information and then goes back to scanning keyboard but it didn't work.but when i use this interrupt with other programs (in programs that we don't have scanning keyboard) it works. so i want to know that do you agree with me or my idea is wrong?
 
You will need to check your output files, but I suppose it's possible that interrupts are being disabled during some critical code section in your keypad routines. I can't think of any reason why they would do it that way though.

It is much more likely you are missing something else, like incorrect banking, stack overflowing, or incorrect paging etc, maybe even accidentally disabling the interrupt by some other method, like forgetting to put a return at the end of your code section etc. Run the code on a simulator, watch where it goes wrong, then work from there...I'm sure it will become blindingly obvious to you where the problem lies, as soon as you see your code execute.
 
Hi,
i don't do one thing. my program was about 1000 lines and it took 6355 word.
i don't specify the banks.should i specify the banks in basic or it is just for assembely.i used PIC16F877A. maby this is my problem.what's your idea?

oh! i forgot to say that in another program for scanning keyboard that just about 1250 word(less than a bank) i had this problem so i don't know is it related to the banks?
 
Last edited:
amindzo said:
Hi,
i don't do one thing. my program was about 1000 lines and it took 6355 word.
i don't specify the banks.should i specify the banks in basic or it is just for assembely.i used PIC16F877A. maby this is my problem.what's your idea?

The compiler should take care of the banking, which is one reason it's so big - I would also suggest you try optimising your code, for example are you using floating point variables?, there's rarely any need to, and they generate very slow and lengthy code.
 
so what should i do if i can't optimise my program? it's a weakness in picbasic that the interrupts don't work in big programs.
 
amindzo said:
so what should i do if i can't optimise my program? it's a weakness in picbasic that the interrupts don't work in big programs.

I see no reason why interrupts won't work in big programs?, it's more likely a bug in your code. Using interrupts in BASIC is always going to be problematic because you've no idea what is actually happening!.

Interrupts generally, in any language, are a major source of bugs, and tend to be VERY hard to track down.
 
Hi,
thank you. i think the best way to work with interrupts is writting program in assembely.but i have alot of problem with that.
 
Hi,
my program had alot of pause,lcdout and adcin. maby this is the problem.
but about pause,when i wanted to make 5 second delay i used this method:
for i=1 to 5000
pause 1
next i

but i don't know what should i do for lcdout and adcin instructions.
 
good advice so far. just a thought - how big are your interrupt routines? You should keep your interrupt handlers very small. If the amount of time you spend in the handler is longer than the time between interrupts, you will lose interrupts.
 
Good answer Philba, I forgot about that situation, you are correct, it would be easy for a noob to have an ISR that takes more time to complete than the period between interrupts.
 
because when you are in your interrupt routine, interrupts are disabled. If you take longer than the time between interrupts, you will miss some of the interrupts. For example, if interrupts happen every millisecond and your interrupt routine takes 1.5 mS, then you will miss every third interrupt.

what you need to do is set up your interrupt handlers (also called interrupt service routines or ISRs) so that they set flags or do the minimum amount of work. Let your main code loop do the complex and/or lengthy operations. Use flags to communicate from the ISR to main code. never wait in an ISR.
 
i don't have this problem because the interrupts happened every five minutes and my tinterrupt routinrnes executed in 1 second.
 
are there any other interrupts going on? the interrupt service routine blocks ALL interrupts. a 1 second ISR is very long. I would recommend structuring so that ISRs take microseconds but do what you feel you need to.

Other things to think about are race conditions and dead-locks. A race condition is where something can get changed in both the ISR and the main line code. A dead-lock is where each part winds up waiting for the other to make a change.
 
I would defenetly cut the ISR way down.

A general rule is to never call a function from a ISR. It generates stack isues very quickly.

In the interupt, simply set a boolean variable to 1, and then in the main loop, continuasly check if this variable has been set to 1. If it has then you know the interupt had been triggered. Then set variable to 0, and do the 1 second long code that is now done in your interupt routine...

basicly in pseduocode:

//happens when an interupt happens:
some_isr(){
bSomeInteruptHappend=1;
}


main loop:

while(somthing is true){
if(bSomeInteruptHappend==1){
bSomeInteruptHappend=0;
...
do whatever needs to be done when the inerupt happens
...
}
}

This way the interupt routine takes about 1 uS or so(depending on clockspeed ofcourse), and not 1 second. The chance of loosing an interupt now would be alot smaller.


Good luck


Cheers,
Magnus
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top