interrupt newbie


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    trebdms's Avatar
    trebdms Guest

    Unhappy interrupt newbie

    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

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3


    Did you find this post helpful? Yes | No

    Default

    How are you incrementing the timevariable? From what I can tell the timevariable will always be 0.

  4. #4
    trebdms's Avatar
    trebdms Guest


    Did you find this post helpful? Yes | No

    Default hello again

    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

  5. #5


    Did you find this post helpful? Yes | No

    Default

    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.

  6. #6
    J_Brittian's Avatar
    J_Brittian Guest


    Did you find this post helpful? Yes | No

    Default

    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.

  7. #7
    Join Date
    Aug 2005
    Posts
    57


    Did you find this post helpful? Yes | No

    Default

    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

  8. #8
    trebdms's Avatar
    trebdms Guest


    Did you find this post helpful? Yes | No

    Smile

    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

  9. #9
    trebdms's Avatar
    trebdms Guest


    Did you find this post helpful? Yes | No

    Lightbulb hello again.

    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

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  2. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  3. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  4. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 20:58
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts