PDA

View Full Version : 16f88 interrupt



tur_bot
- 27th March 2008, 16:56
hello,
i wanted to test an interrupt in a simple small code , i found a code on the internet and modified it and got this:
@ DEVICE INTRC_OSC, LVP_OFF, WDT_OFF, MCLR_OFF

DEFINE OSC 4

OSCCON=%01101000 ' INTRC = 8MHz
ANSEL=%00000000
CMCON=%00000111


OPTION_REG.6=1 'Trigger on rising edge
INTCON = %10010000 'Enable INTE
INTCON.1 = 0 'Clear RB0/INT External Interrupt Flag bit

On Interrupt Goto UpdateCounter

PORTB=0 ' PORTBs are outputs
Pause 500 ' Wait for startup
'LOW PORTB.6

loop:
low portb.6
HIGH PORTB.5
Pause 2000 ' Wait 2 second

low portb.6
LOW PORTB.5
Pause 2000 ' Wait 2 second
Goto loop ' Do it forever

Disable
UpdateCounter:
LOW PORTB.5
HIGH PORTB.6
pause 500
low portb.5
LOW PORTB.6
pause 500

INTCON.1=0 're-enable interrupts

resume
ENABLE
GOTO loop

END


the code works, but the interrupt routine doesn't work, doesn t light the led connected to pin portb.6.
I mean when the portb.0 is connected to ground the led connected to portb.5 blinks as soon as i connect the portb.0 to +5v the portb.5 stops to blink and nothing happens to portb.6 led.
can you help me on that please???
how can I use a digital signal to activate the interrupt for example, with an if statement??

if portb.0 = 1 , the interrupt is activated and the program jumps to the int subroutine and if portb.0 = 0 the program comes back to the main loop???????

please can any one help me??
thank you

Acetronics2
- 27th March 2008, 17:29
Hi,

I think your RB6 Port is already an f.OSC/4 output ...

Check for OSC Configs that free PortB.6 ...


Alain

savnik
- 27th March 2008, 18:41
hello,
i wanted to test an interrupt in a simple small code , i found a code on the internet and modified it and got this:
@ DEVICE INTRC_OSC, LVP_OFF, WDT_OFF, MCLR_OFF

DEFINE OSC 4

OSCCON=%01101000 ' INTRC = 8MHz

You have set 4 and 8 mhz

Darrel Taylor
- 27th March 2008, 19:54
tur_bot,

Tested the program here on a 16F88.
Works as expected.

Only thing I can think of is maybe the RB6 LED is backwards, burnt-out, or hooked up wrong.
<br>

tur_bot
- 31st March 2008, 17:46
tur_bot,

Tested the program here on a 16F88.
Works as expected.

Only thing I can think of is maybe the RB6 LED is backwards, burnt-out, or hooked up wrong.
<br>

hello
i woulk like to know how can i activate an interrupt digitally instead of using a switch.
because i wrote a program with need to jump to the interrupt when one of the 4 portb is low,
i.e. if portb.0=0 or portb.1=0 or portb.2=0 or portb.3 = 0 , the program should start the interrupt, i tried to use a subroutine to go that i.e. if portb.0=1 or portb.1=1 or .... gosub subroutine but it is very slow, i think that by using interrupt it will do the job.

can any one help me please. it s very urgent , it s for my project at uni and i have just a week to finish it.

thank you

skimask
- 31st March 2008, 18:27
can any one help me please. it s very urgent , it s for my project at uni and i have just a week to finish it.
thank you

Sounds to me like you should've started the 'project' for 'UNI' earlier...or maybe get a bit of help from the 'INSTRUCTOR' (if that's what they call them these days...I call them placeholders) or maybe even try some of your CLASSMATES.

Use another pin to trigger your 'PORTB.4' pin, write code to trigger that pin to trigger the other pin.

And no, I don't think this will solve your problem. If GOSUB'ing into your interrupt routine is slow, why would triggering an interrupt to go to the interrupt routine work any better? Your program is most likely hanging up in a loop somewhere or something similar making you think that it's not reacting fast enough, whereas triggering an interrupt in hardware may actually jump directly to that code.

mister_e
- 31st March 2008, 18:54
Look for interrupt on change. But you may need to change your current hardware.

tur_bot
- 1st April 2008, 17:44
Sounds to me like you should've started the 'project' for 'UNI' earlier...or maybe get a bit of help from the 'INSTRUCTOR' (if that's what they call them these days...I call them placeholders) or maybe even try some of your CLASSMATES.

Use another pin to trigger your 'PORTB.4' pin, write code to trigger that pin to trigger the other pin.

And no, I don't think this will solve your problem. If GOSUB'ing into your interrupt routine is slow, why would triggering an interrupt to go to the interrupt routine work any better? Your program is most likely hanging up in a loop somewhere or something similar making you think that it's not reacting fast enough, whereas triggering an interrupt in hardware may actually jump directly to that code.

my program is working fine but i just need to learn more about interrupt so i can make it better. by the way i started my project very early but not early enough (last summer).

about the small piece of code that i m using to learn about interrupt,I managed to improve my code and it s working but not as expected. the interrupt is activated on the falling edge but I want it to be activated on the rising edge.

i used a pull down resistor on the portb.0 and the main loop is running and when i connect a 5 volts to activate the interrupt nothing happens (everything stops ) but just when the 5 volts is taken off the interrupt runs for 2 second and the program is back to the main loop.

there is the code:
------------------------------------------------------------
@ DEVICE INTRC_OSC, LVP_OFF, WDT_OFF, MCLR_OFF

DEFINE OSC 4
OSCCON=%01101000
ANSEL=%00000000
CMCON=%00000111

OPTION_REG.6=1 'Trigger on rising edge


disable

clear

trisa = %11111111
trisb = %00000000
'Pause 500 ' Wait for startup
LOW PORTB.6
low portb.5

start:
goto loop

On Interrupt Goto UpdateCounter

INTCON = %10010000 'Enable INTE
disable


UpdateCounter:

high portb.6
Pause 2000 ' Wait 2 second

low portb.6
Pause 2000 ' Wait 2 second

low PORTB.5


INTCON.1=0 're-enable interrupts

resume
ENABLE
GOTO loop

loop:
high portb.5
Pause 2000 ' Wait 2 second

low portb.5
Pause 2000 ' Wait 2 second

low PORTB.6

Goto loop ' Do it forever

Disable


END
------------------------------

can you tell me what i did wrong , why the interrupt is not activated on the rising edge and how can I resolve it ??

thank you again for your advices ...

mister_e
- 1st April 2008, 17:58
there's a kinda mess in that :o

But if you want to trigger an INT0 interrupt, PORTB.0 must be set as an input.

mister_e
- 1st April 2008, 18:06
try this one


@ DEVICE INTRC_OSC, LVP_OFF, WDT_OFF, MCLR_OFF

DEFINE OSC 4
OSCCON=%01101000
ANSEL=%00000000
CMCON=%00000111

OPTION_REG.6=1 'Trigger on rising edge

trisa = %11111111
trisb = %00000001
CounterA var word

On Interrupt Goto UpdateCounter
INTCON = %10010000 'Enable INTE

PORTB=0
Pause 50 ' Wait for startup

loop:
TOGGLE PORTB.5
gosub dodelay
Goto loop

DoDelay:
for countera=0 to 200
pause 1
next
return


disable
UpdateCounter:
low PORTB.5
high portb.6
Pause 2000 ' Wait 2 second
low portb.6
INTCON.1=0 're-enable interrupts
resume
ENABLE

tur_bot
- 2nd April 2008, 10:57
try this one


@ DEVICE INTRC_OSC, LVP_OFF, WDT_OFF, MCLR_OFF

DEFINE OSC 4
OSCCON=%01101000
ANSEL=%00000000
CMCON=%00000111

OPTION_REG.6=1 'Trigger on rising edge

trisa = %11111111
trisb = %00000001
CounterA var word

On Interrupt Goto UpdateCounter
INTCON = %10010000 'Enable INTE

PORTB=0
Pause 50 ' Wait for startup

loop:
TOGGLE PORTB.5
gosub dodelay
Goto loop

DoDelay:
for countera=0 to 200
pause 1
next
return


disable
UpdateCounter:
low PORTB.5
high portb.6
Pause 2000 ' Wait 2 second
low portb.6
INTCON.1=0 're-enable interrupts
resume
ENABLE


thank you very much , it was the trisb=0000001 command that resolved the problem. it works as expected but one more thing is not right, the portb.6 output 1.62 volts when the program goes through interrupt instead of giving a 5 volts output (a good logic one) as expected.
is it supposed to be like this?????

thank you again.

mister_e
- 2nd April 2008, 11:35
Nope, seems you have a dead I/O, or faulty connections... or a dead output caused by a faulty connection ;)