PDA

View Full Version : interrupt newbie



trebdms
- 10th November 2005, 15:49
hello. just a newbie here.

im having problems using an interrupt on my subroutines. Is there a way where i could turn on a LED for 30secs. but in between that timeline, i could trigger an interrupt? so i could turn it off myself.

my subroutine contains this line of code:

low LED1 ' ON LED
pause 30000 ' Hold ON for 30 secs
high LED1 ' OFF LED

i read on the forum that interrupts trigger only after the "pause" command is done. without the pause, my interrupt works fine. but the LED just sits there turned ON. I would like to have it off after 30 secs. or right after an interrupt has been triggered.

is there any way around this? i know you guys know. thanks in advance!

-trebdms-
keepin'itreal

Dave
- 10th November 2005, 16:00
trebdms, Try taking a much smaller pause of say 10 Milliseconds instead of the full 30 seconds. That way your interrupt can be serviced within a much smaller time period. Do something like this:

low LED1 ' ON LED
timevariable = 0
while timevariable < 3000 ' Hold ON for 30 secs
pause 10
wend
high LED1 ' OFF LED

That way your interrupt routine can turn off led1 before the timeout expires.

Dave Purola,
N8NTA

CocaColaKid
- 10th November 2005, 16:08
How are you incrementing the timevariable? From what I can tell the timevariable will always be 0.

trebdms
- 10th November 2005, 16:40
thanks dave for the quick response. i just tried the code you posted, i still get the same results. my apologies...i must have been i bit vague on what i have posted. anyway, im still aiming for the same results... heres my code:


im using 12f675 by the way. One more thing, in setting up an interrupt on
GPIO.2, do i have to put a pull-up resistor on the pin?

------------------------------------------------------------------------
define OSC 20 'OSC (20Mhz)

INTCON=%00010000 'Enable Interrupt
OPTION_REG.6=0 'Trigger on Falling edge
CMCON = 7 'Disables Analog Inputs
ANSEL = 0 'Sets Analog Inputs as Digital I/O

on interrupt goto init
pause 500


VARS:

LED1 VAR GPIO.0 'LED Port
Rx VAR GPIO.3 'Receive Data Port
CS VAR GPIO.2 'Interuppt Port
BUFF2 var byte[17] 'Rx Recive read buff
SPEED con 188 'Sio data speed 4800bps

Cnt var BYTE 'Recive data count
RD1 VAR byte 'Read Data Counter
CN var BYTE 'Counter

X var word
cmd var word
CNT = 0
CN = 0

eeprom ["1111111111111111"]

INCLUDE "MODEDEFS.BAS"

TRISIO = %101010

'-----------------------------------------------------------------
' RX Data from remote
'-----------------------------------------------------------------

MAIN:

serin2 rx,SPEED,5,SUB,[wait("#"),str buff2\18\"@"]
IF BUFF2[0]=">" THEN

for cn = 0 to 16
read cn,rd1
if rd1 = buff2[cn] then
CNT=CNT+1
ENDIF
next cn

IF CNT = 16 THEN

IF BUFF2[16] = "1" THEN
cmd = 1

'trigger interrupt here
LOW CS
PAUSE 200
HIGH CS

endif

IF BUFF2[16] = "2" THEN
cmd = 2

'trigger interrupt here
LOW CS
PAUSE 200
HIGH CS

endif

gosub GetCmd

ENDIF

endif

SUB:
CNT = 0
rd1 = 0

goto main
end

'--------------------------------------------------------------------------
'Interrupt Handler
'--------------------------------------------------------------------------

disable

INIT:

pause 200
high LED1
pause 100

INTCON.1 = 0

RESUME

ENABLE

'--------------------------------------------------------------------------
'routines
'--------------------------------------------------------------------------
GetCmd:

select case cmd


case 1 ' BLINK LED

pause 100
FOR CN = 0 TO 1
HIGH LED1
PAUSE 30
LOW LED1
PAUSE 30
HIGH LED1
PAUSE 30
NEXT CN
RETURN


case 2 ' turn LED ON for 30 secs.

PAUSE 100
low spk
pause 30000
high spk
RETURN


end select
-------------------------------------------------------------------------

Its just that in case 2 subroutine... when i comment command "pause" the
interrupt works fine, but the 30sec auto-off doesnt work. when i put back the "pause" command, auto-off enabled, but the interrupt wont work in between the 30sec delay.

thanks again!

-trebdms-
keepin'itreal

CocaColaKid
- 10th November 2005, 16:52
I think the problem is the 30 sec pause itself. You need to split it up into small chunks. For example 300 x 10 ms each. This will allow the interrupt to take place every 10 ms if so needed. With the pause 3000 command the processor is can't do anything for 30 seconds because it's stuck in a do nothing loop and won't see the interrupt until the 30 seconds has elapsed.

J_Brittian
- 10th November 2005, 20:44
Hi trebdms,
My understanding of the interrupt command is it places a line of code checking the interrupt pin between every line in your program. So your bit of code would actually look like so:

low LED1 ' ON LED
'check interrupt
pause 30000 ' Hold ON for 30 secs
'check interrupt
high LED1 ' OFF LED

When I need pauses in a program using an interrupt I usually use a For....Next loop.

low LED1 ' ON LED
For y = 0 to 30000
pause 1
next y
high LED1 ' OFF LED

This way the interrupt pin gets checked every millisecond.

arniepj
- 11th November 2005, 01:42
Try using the internal timer interrupt and count ticks for the 30 second delay,then a port interrupt could occur any time.The clock.bas demonstrates the timer interrupt.http://melabs.com/resources/samples.htm

trebdms
- 11th November 2005, 04:29
hey guys... thanks for all your input. i'll try to test each and one of them. ill get back to you once i get the results. anyway, in using a 12f675 gpio.2 enabled interrupt, do i have to put a pull-up resistor on the gpio.2 pin? im manually triggering the interrupt by setting the pin HIGH and LOW.

thanks again!

-trebdms-
keepin'itreal
3rd world 063

trebdms
- 11th November 2005, 08:03
guys, i made some review on my code. it seems that my logic was wrong after all... my interrupt is being triggered whenever data is received from the remote. meaning.... this code, or anything like this wouldnt work after all.

---------------------
low LED1
pause 30000
high LED1
RETURN
---------------------
the "RETURN" command goes back to the MAIN and checks if there was data received. If yes, then eventually the interrupt would be triggered.

sorry again guys... should have thought about this before making the inquiry.

anyway, now heres the "REAL" problem... I would like to execute the "RETURN"
command in between the time limits. so i could check if there was an interrupt triggered. im working with this code right now :

----------------------------------------------------
while x <= 3000
low LED1
pause 1
x = x + 1
return ' check main if an interrupt occured
wend
pause 1
x = 0
high LED1
return
----------------------------------------------------
the problem, (I think?!) is that my counter x=x+1 doesnt seem to work whenever i go back to MAIN. and oh! still havent got a reply about the
pull-up resistor thing... is it really necessary?

anyway, still doing tests... any input will be highly appreciated. :)

bottles of buds for everyone! my treat! cheers!


-trebdms-
keepin'itreal
3rd world 063