PDA

View Full Version : Interrupt Or I Am Going To Die



kunguz
- 27th October 2006, 22:17
I have a problem with PORTB:4-7 interrupts ,I can actually get pic in to interrupt but can't get it out from interrupt to last process, here is my code below ; You can find schematics and ISIS simulation file which is processed in 6.9 in attachments.

PLEASE SOMEBODY HELP ,I AM BEGINING TO LOSE MY MIND!
device 16f84a
ON_INTERRUPT goto flash
intcon = %10001000
input portb.6 ' Bu pinleri sıfırladıktan sonra alıcı olarak ayarlamalısın

loop:
high porta
delayms 200
low porta
delayms 200
goto loop

disable

flash:
delayms 20
low porta
intcon.0 = 0
resume
enable

end

SteveB
- 27th October 2006, 22:45
You need to read PORTB in your ISR to clear the mismatch. Otherwise, like you have mentioned, you will never be able to get out of you ISR.

HTH,
Steve

sayzer
- 28th October 2006, 03:36
Also,

Instead of High PORTA use PORTA=255
and
Instead of LOW PORTA use PORTA=0



Note:
"...Bu pinleri sıfırladıktan sonra alıcı olarak ayarlamalısın"

anteni iyi ayarla! :D

---------------------------------------

kunguz
- 28th October 2006, 09:43
Thanks for replies, what I wonder is I don't know how to read portb; Can you just write down a sample code _?

Thanks in advance,

Saolasın Hocam :P

sayzer
- 28th October 2006, 11:23
Like what?

Example:

IF PORTB.6 = 0 then .....

or another one

WHILE PORTB.3 = 0
..
....
WEND

or

IF PORTB.2 = 1 AND PORTB.5 = 0 THEN .....

Etc..


These are some kind of readinds.
Make sure you make them input pin.


----------------

kunguz
- 28th October 2006, 12:09
So sorry but can you correct my code , I tried everything as in your sample code for PORTB.6 ; But can't get it out.

By the way my msn is [email protected]. (Olmadı bana burdan yardımcı olursan çok sevinirim, altı üstü bi interruptan çıkamadık)

Here is my new code below ;
device 16f84a
ON_INTERRUPT goto flash
intcon = %10001000
input portb.6 ' Bu pinleri sıfırladıktan sonra alıcı olarak ayarlamalısın

loop:
high porta
delayms 200
low porta
delayms 200
goto loop

disable

flash:
WHILE PORTb.6 = 1: WEND
intcon.0 = 0
delayms 20
low porta
CONTEXT RESTORE

end

sayzer
- 28th October 2006, 13:08
Couple of things to remember.

1. It is not a good idea to post an e-mail on the forum. You will get thousands of junks to your e-mail. I suggest that you remove it right away and PM to members instead.

2. You are not using PBP, but this is a PBP forum :)

3. Lets keep this issue on this forum, so that it can be some help to some other members having similar issue.


-----------------------------
Let me try to start by changing the code to PBP first.

In your schematic, I would use Interrupt on RB0 pin, instead of RB6 pin. May be you should change that first.

Then, assuming you are now using RB0/Int, we set Intcon Bit 4: RB0/INT External Interrupt Enable bit. Thus, we end up with INTCON = %10010000

Now the code should look like below but remember it is with PBP statements. You can get around it.




TRISA = %00000000 'All output.
TRISB = %00000001 'RB0 is input, rest is output.
INTCON = %10010000 'Enable global (Bit7) interrupt, enable RB0/Int (Bit4)
ON INTERRUPT GOTO FLASH


loop:
PORTA = 255
PAUSE 200
PORTA = 0
PAUSE 200
GOTO loop

disable

FLASH:
PORTA = 0
INTCON.0 = 0

RESUME
ENABLE

END



Also, why do you have to use interrupt?


-------------------

SteveB
- 28th October 2006, 14:02
Add this line before your main loop:

RBIF var INTCON.0

Add these two lines to your flash subroutine:

@ MOVE?BA PORTB 'Read PORTB by placing it WREG
RBIF = 0 'Clear the interrupt flag

Also, read the pic datasheet on interrupts and under the I/O Ports section. You should find were it mentions both of items added to the ISR.

Steve

kunguz
- 28th October 2006, 14:21
@ MOVE?BA PORTB

IDE did not recognize this line

kunguz
- 28th October 2006, 14:26
RETLW PORTB.6 when I use this line in top flash block, it doesn't do anything and continue to it's job

SteveB
- 28th October 2006, 16:55
I shouldn't have been so brief in my first response, so here is a little more explaination. But, you would be well served to learn more about interrupts if this explaination is still confusing.

@ MOVE?BA PORTB

This is a PBP internal macro which reads PORTB and moves the value to W register. It results in the asm instruction: MOVF PORTB, W This is the simplist way to read PORTB to end the mismatch which triggers the interrupt on change. No variables and only one line of code are required.

RBIF var INTCON.0

This statement assigns the Interrupt Flag (at INTCON.0) used for the PORTB's interrupt on change to the name "RBIF" (which is what it is refered to in the PIC datasheets).

RBIF = 0 'Clear the interrupt flag

This statement clears the interrupt flag, which is also required before exiting the interrupt service routine (ISR), or the program will continue returning back to the ISR. No matter what type of interrupt you use, the Interrupt Flag for that particular interrupt must always be cleared before exiting the ISR, or you will end up in an endless loop.

Steve

SteveB
- 28th October 2006, 17:15
As Sayzer asked,

Also, why do you have to use interrupt?

Using interrupts may just be overcomplicating the application. Could you just pool the I/O line in question in your main loop?

Steve

sayzer
- 28th October 2006, 19:25
As Steve repeated,

May be, a code like the one below could do the job for you, may be.



TRISA = %00000000 'All output.
TRISB = %01000000 'RB6 is input, rest is output.

IN_PIN VAR PORTB.6


Loop:

WHILE IN_PIN
PORTA = 255
PAUSE 200
PORTA = 0
PAUSE 200
WEND
PORTA = 0

GOTO Loop

END



Not a real drop-in interrupt compatible code but may work in some cases.

Try...

kunguz
- 28th October 2006, 21:33
Thanks alot for your helps and replies;

It finally works with this code below , but to return to main progress takes approximetly 1:20 minute. I think there might be problem with my schematic; If ISIS is that good, may be simulation thinks about small arcs that is created by button .Which gives a unexpected voltage levels for a short time to the PORTB.6.So PIC interrupts it's self for more then one time.The reason that took so long, might be that. Is this the problem or is it still in software _?

device 16f84a
ON_INTERRUPT goto flash
intcon = %10001000
input portb.6

loop:
high porta
delayms 200
low porta
delayms 200
goto loop

disable

flash:
delayms 1000
MOVF PORTB, W
low porta
intcon.0 = 0
CONTEXT RESTORE

end

kunguz
- 28th October 2006, 22:00
After removing delayms1000 waiting for interrupt takes much shorter time like 1 sec. And I look with an osiloscope in simultion to the portb.6 which i see is a clear 5V. http://ww1.microchip.com/downloads/en/AppNotes/00566b.pdf after reading this I get the feeling like this circuit did not fit for a small pulse width. Is this the problem or am I doing something wrong in programming

kunguz
- 28th October 2006, 22:08
After using this new code below, I get value of sayi +2 each time I click.

device 16f84a
ON_INTERRUPT goto flash
intcon = %10001000
input portb.6 ' Bu pinleri sıfırladıktan sonra alıcı olarak ayarlamalısın
dim sayi as byte
sayi = 0

loop:
high porta
delayms 200
serout portb.3,16780,[Dec sayi ,13]
goto loop

disable

flash:
MOVF PORTB, W
low porta
intcon.0 = 0
sayi = sayi + 1
CONTEXT RESTORE

end

sayzer
- 29th October 2006, 11:33
Hi Kunguz,

In your code, which you said works, how did you get "HIGH PORTA" or "LOW PORTA" work?


?


-------------------

kunguz
- 29th October 2006, 18:28
May be it's about my IDE ; I am using PROTON SE 1.1.2.8 ,And you can find the working circuit in the attachment with assembly and PICBASIC codes in it.

mister_e
- 30th October 2006, 03:32
Certainely not an IDE problem :D There's few things in the world want to stay away of. Proton is one of these
:D

paulvits
- 30th October 2006, 15:26
DEFINE LOADER_USED 1
INCLUDE "modedefs.bas"
DEFINE HSER_BAUD 9600
DEFINE HSER_SPBRG 25 'Gebruik deze twee defines 25
dEFINE HSER_TXSTA 24h 'voor HSER met 9600 Baud
OPTION_REG = $7f ' Enable PORTB pullups
ADCON1 = 7 ' Make PORTA and PORTE digital
on interrupt goto myint
INTCON = $88
pause 50
TRISB = %11110000
led var portb.0

start:
pause 5
goto start
'***Start interruptroutine***
disable
myint:

high led
pause 500
low led
INTCON.0=0 'Clear interruptflag
resume
enable
end

sayzer
- 30th October 2006, 16:21
Hi paulvits,

As you can see Kunguz is all fine. He did not die.

What is your question?


-----------------------------

kunguz
- 30th October 2006, 18:13
Hi Paulvits ; first of all never use pause or a delay in interrupt ; I don't know why but it makes the chip return from an interrupt with a long time. Really really long. And before intcon.0 = 0 use this line; "MOVF PORTB, W" And let the magic happen .Remove PORTB and write down your interrupt port that's all ,Thanks steven and others I learned this with their helps

picnaut
- 31st October 2006, 20:13
Certainely not an IDE problem :D There's few things in the world want to stay away of. Proton is one of these
:D

They said the same thing about planes in the early days of flight. Sometimes progress takes a while to catch on.

;)

mister_e
- 1st November 2006, 04:56
Hey Picnaut :D

Why i had this feeling you couldn't resist to add your spices?

Are you saying we can fly? Really? Wohooo i missed it?

Is that also true that a man walked on the moon?


Sometimes progress takes a while to catch on.
I'm to old to wait 'till it's going to be at least good... if the day come.

There's a far better tool (not toy) comming up soon. Too bad only for 18Fs... 'till now. Even in pre-release it's already 1E10,000 : 1 better than this Programmer Disaster Software.

Happy for you that you finnaly get your multi I2CBUS. 2 year later but you have it now. That's true, progress takes a while to catch on.

picnaut
- 1st November 2006, 05:18
Hi Mister E,

Are you talking about Swordfish?
If so, it does look cool.

Unfortunately, I've begun to realize that, as a rule, virtually no one in industry takes Basic languages seriously - procedural or not.
So, unless you are purely a hobbyist or are planning on working 100% for yourself (and never for "the man"), a serious embedded engineer needs to learn C. It's sad, but true. Employers look for C (primarily) and assembly (is a plus).
It's frustrating but it's a reality, at least in North America.
I defy anyone to find one company in the States or Canada that's looking for basic programmers! I'll bet that there aren't any.

:)

Anyway, I don't mean to rant, but I've been frustrated by this lately.
So, I've bought some C books and dug my old notes out.
Basic has served me well (PBP and PDS) and has gotten me very comfortable with PICs, but it's on to the next level.

Cheers!

mister_e
- 1st November 2006, 05:32
C is a totally different approach. All language will do the job.

I also use C is some case. But 95% of what i do use BASIC (structured or not) + asm.

One reason why C is comming more and more popular on some forums is because it's too easy to find some crack/patch to remove the 30 Days Trial limitations. You already know, most serious C compiler pricing are much higher than Basic. You'll never find something really good covering ALL (most) PIC familly under 1,000$

I have nothing against C. It's a really nice and powerfull language. That what i learned at university... when i was young. C for programming is probably the same a Snap-On tool for mechanics... kind of

BTW, everybody knows that whatever you use, the guy/girl back to the keyboard make difference.

You can change your car transmission with a wise grip if you want :D

Good luck and don't give up. It really worth to know more programming language.

PS: I would never be a compiler developper... Microchip release too much different PIC model and familly /day/month/years. You have to be a huge team and have all of those PIC to double check what you do. Tedious job.

mister_e
- 1st November 2006, 05:41
And yes i talked about Swordfish, and yes it's really cool but from what i feel certainely not for beginner. But really powerful, BUT only for 18Fs...

Nothing's perfect :D

About jobs... it could be true. I work for myself so i can use whatever i want. But in some case my customers ask for a source code in C, ASM or Basic. Some don't care and just want to get the job done. i hate when someone ask for a pure asm... :eek:

Oh well.. sorry all for this testimonial :(