Menu

GOSUB Response Time

Help
MBB
2012-03-29
2013-05-30
  • MBB

    MBB - 2012-03-29

    I have the following code that is part of a larger program:

    ;Chip Settings
    #chip 16F876,20
    #config LVP=OFF, PWRTE=ON, OSC=HS

    #define T_1 PORTB.3
    #define Rec_1 PORTA.0

    ;Variables
    Dim A_Cnt As word

    Dir T_1 OUT
    Dir Rec_1 IN

    SET T_1 ON
    GOSUB Chk_Rec
    ‘******************************************

    Sub Chk_Rec
    A_Cnt = 0

    Loop1:

    A_Cnt = A_Cnt + 1

    If Rec_1 = 1 then
    SET T_1 OFF
    locate 1, 15
    print A_Cnt
    Goto Loop2
    End If

    Goto Loop1

    Loop2:

    End Sub

    When I run this code, I get an A_Cnt of 1 meaning the IF statement immediately "saw" PORTA.0 (T_1) as a high.

    When I connect an oscilloscope to PORTB.3 (T_1), I measure a pulse width of 1.4 milliseconds meaning it took 1.4 milliseconds for the PIC to go from the main program to the sub-routine.

    1.4 milliseconds seems like a very long time for the PIC to perform this simple operation.

    Am I doing something wrong?

     
  • gcha44

    gcha44 - 2012-03-29

    Hi,
    to call sub Chk_rec , you just type  "Chk_rec" , not  "gosub Chk_rec"
    If you want use "gosub"  then Ch_rec is a label you must type like that   "Chk_rec:"   
    and it ends with the "return" keyword

    Regards
    GC

     
  • MBB

    MBB - 2012-03-31

    I finally got to try your suggestion and it worked!

    Thanks for your help

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.