pulsin followed by serin2 problem


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2003
    Location
    plano, texas usa
    Posts
    8

    Default pulsin followed by serin2 problem

    I am measuring pulse length.This routine works fine as long as I comment out serin2 command. It appears that pulsin command is affected or timing when I add serin command. I no longer decode valid pulse that I am monoriting with a scope. Any Suggestions, I have tried numerous delays etc.

    Thanks in Advanced
    Stuck and sleepless












    wait_for_t0:

    if portb.0= 0 then wait_for_t0 ' loop until rssi goes high

    pulsin portd.4,1,PLENGTH1 ' MEASURE TIME C2 IS HIGH AND STORE
    IF PLENGTH1 > 255 AND PLENGTH1 < 270 THEN COUNTPULSes ' 42 usec error allowed


    serin2 b2,16780,1000,wait_for_t0,[WAIT ("$$"),cmnd] ' get command wait $$ timeout 1 secs added
    GOTO wait_for_t0
    Last edited by RSSHARPE; - 16th September 2005 at 17:08.

  2. #2
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    wait_for_t0:

    if portb.0= 0 then wait_for_t0 ' loop until rssi goes high

    pulsin portd.4,1,PLENGTH1 ' MEASURE TIME C2 IS HIGH AND STORE
    IF PLENGTH1 > 255 AND PLENGTH1 < 270 THEN COUNTPULSes ' 42 usec error allowed






    Pulsin, you have a "1". that means you are waiting for a HIGH pulse in order to get out of your loop:

    Since the high is already over with, you are not measuring that first "Pulse" You are losing that pulse and measuring the next one.



    Dwayne
    Last edited by Dwayne; - 16th September 2005 at 17:34.
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  3. #3
    Join Date
    Dec 2003
    Location
    plano, texas usa
    Posts
    8


    Did you find this post helpful? Yes | No

    Default reply to dwayne

    Dwayne,

    I use Portb.0 as key and Portd.4 to measure pulse. I am decodeing apulse stream from a radio to determine a time zero " time begins now pulse" the first tone is 1khz for approx. 10 cycles and changes to 2khz ,I detect this change and output a pulse for time begins now. I t was working fine until I added the serin2 command. I need this for a command structure input via the telemetry link. I have lots of time between keys 2 to 6 secs


    Thanks again

    Scott

  4. #4
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Scott,

    Scott>>
    wait_for_t0:

    if portb.0= 0 then wait_for_t0 ' loop until rssi goes high

    pulsin portd.4,1,PLENGTH1 ' MEASURE TIME C2 IS HIGH AND STORE
    IF PLENGTH1 > 255 AND PLENGTH1 < 270 THEN COUNTPULSes ' 42 usec error allowed


    serin2 b2,16780,1000,wait_for_t0,[WAIT ("$$"),cmnd] ' get command wait $$ timeout 1 secs added
    GOTO wait_for_t0<<

    Try changing it to this then:

    Code:
    wait_for_t0: 
    
    if portb.0= 0 then wait_for_t0 ' loop until rssi goes high
    
    pulsin portd.4,1,PLENGTH1 ' MEASURE TIME C2 IS HIGH AND STORE
    IF PLENGTH1 > 255 AND PLENGTH1 < 270 THEN COUNTPULSes ' 42 usec error allowed
    
    receivedata:
    serin2 b2,16780,1000,receivedata,[WAIT ("$$"),cmnd] ' get command wait $$ timeout 1 secs added
    GOTO wait_for_t0

    This way, if your Serin times out before it is supposed to , it will re-initialize itself and wait for your data again.

    I am taking this on assumption that you said there was plenty of time between the two signals...

    If you want, you could put a counter and if the counter goes above 10 loop back to the wait_for_t0.

    Since I don't fully understand your project... I apologize if I read you wrong.

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  5. #5
    Join Date
    Dec 2003
    Location
    plano, texas usa
    Posts
    8


    Did you find this post helpful? Yes | No

    Default reply

    INCLUDE "MODEDEFS.BAS"
    Define OSC 20 '20 meg clock`
    'define PULSIN_MAX 26000 ' MAX TIME TO READ PULSE 800US added
    ' Define LCD connections

    B2 var PORTB.2
    B1 VAR PORTB.1 ' FIRE LINE OR DECODED T"0"
    CNT VAR BYTE ' VARIBLE FOR COUNT OF PULSES
    PLENGTH1 VAR word ' VAR FOR FREQ MEASURE OF C2 first tone
    C2 var portc.2
    D4 var portd.4 'input pin
    plength2 var byte ' var for second freq
    ffid var word ' shot #
    cmnd var byte ' var for command number
    gosub radio_pwr_on
    main: input portb.0
    input portd.4
    gosub xmit_off
    gosub wait_for_t0







    wait_for_t0:

    if portb.0= 0 then wait_for_t0 ' loop until rssi goes high

    '
    pulsin portd.4,1,PLENGTH1 ' MEASURE TIME C2 IS HIGH AND STORE
    IF PLENGTH1 > 255 AND PLENGTH1 < 270 THEN COUNTPULSes ' 42 usec error allowed
    gosub get_comnd

    ' made into sub routine get_cmnd
    'serin2 b2,16780,1000,wait_for_t0,[WAIT ("$$"),cmnd] ' get command wait $$ timeout 1 secs added
    'HSEROUT ["debug command = ",dec2 cmnd,13,10]
    GOTO wait_for_t0

    COUNTPULSES: COUNT portd.4,8,CNT ' COUNT PULSES FOR 10 MILISECS
    IF CNT > 6 and cnt < 9 THEN DETECT2
    'HSEROUT [" debug count = ",DEC3 cnt,13,10]
    GOTO wait_for_t0

    DETECT2:
    pulsin portd.4,1,PLENGTH2 ' MEASURE PERIOD HIGH
    IF PLENGTH2 > 115 AND PLENGTH2 < 130 THEN FIRE ' 20 usec error

    GOTO main

    FIRE: LOW B1


    HIGH B1
    PAUSE 10
    LOW B1
    ffid = ffid + 1
    if ffid =65535 then ffid = 0 ' reset ffid id exceeds word size
    HSEROUT ["fired ok ffid # =",dec5 ffid,13,10]
    HSEROUT ["debug fired plength 1 =",DEC3 plength1,13,10]
    HSEROUT ["debug fired plength 2 =",DEC3 plength2,13,10]
    HSEROUT ["debug fired count = ",DEC3 cnt,13,10]
    goto main


    Radio_pwr_on: high portd.0
    pause 10
    low portd.0
    pause 500 ' wait for power to come up
    return

    Radio_pwr_off: high portd.1
    pause 10
    low portd.1
    return

    xmit_off : high portd.2
    pause 1
    return

    xmit_on : low portd.2
    pause 50
    return

    get_comnd: serin2 b2,16780,1000,wait_for_t0,[WAIT ("$$"),cmnd] ' get command wait $$ timeout 1 secs added
    HSEROUT ["debug command = ",dec2 cmnd,13,10]
    return






    command_decode: Select case cmnd
    case 1 ' command #1 T0 mode
    gosub xmit_on
    serout2 portc.2,84,["Buoy is in fire Mode",13,10]
    gosub xmit_off
    gosub wait_for_t0


    case 2
    gosub power_on_sbc ' command #2 turn on external power to device #1 SBC power on
    gosub xmit_on
    serout2 portc.2,84,["SBC power is on",13,10]
    gosub xmit_off


    case else
    return

    End select


    power_on_sbc: high portb.5
    return

    The problem is not with the serin2 command. It is the pulsin command with the addition of serin2 command. Everything was working until I added sub routine get_cmnd. The correct pulse stream is still coming in etc. It is not decoded properly at pulin command .Sorry for the mess of commented out code I have been trying everything I can think of.


    thanks

    Scott

  6. #6
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Scott...

    Thats it...

    you are going SUBROUTINE and instead of branching to the END of the subroutine, you are branching OUT of it with a goto statement!!!

    THAT IS WRONG! (Cruising for a bruising.)...Maybe some others can verify ths for me and you.

    If I were you, I would *always* branch to the Return statement when you are into a Subroutine. Helps clear the stacks and all that good stuff. If I were to place my bet, it would be located here.

    Dwayne

    edit:
    Took another quick look at your code...(very quick)

    Code:
    case else
    return
    
    End select
    I am not sure about this.. Its been a while.. But usually you want your return AFTER the end select...
    Last edited by Dwayne; - 16th September 2005 at 19:55.
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    It's amix of many things. One thing scratch my brain
    Code:
    main: 
        input PORTB.0
        input PORTD.4
        gosub xmit_off
        gosub wait_for_t0
    
    wait_for_t0: 
        if portb.0= 0 then wait_for_t0 ' loop until rssi goes high
    Take care of the Gosub / Return use. It's amazing how fast your program can behave weird when using few nested gosubs...

    the following snip is the source of your headache
    Code:
    wait_for_t0: 
        if portb.0= 0 then wait_for_t0 ' loop until rssi goes high
        
        pulsin portd.4,1,PLENGTH1 ' MEASURE TIME C2 IS HIGH AND STORE
        IF PLENGTH1 > 255 AND PLENGTH1 < 270 THEN COUNTPULSes ' 42 usec error allowed
        gosub get_comnd
            ' made into sub routine get_cmnd 
            'serin2 b2,16780,1000,wait_for_t0,[WAIT ("$$"),cmnd] ' get command wait $$ timeout 1 secs added
            'HSEROUT ["debug command = ",dec2 cmnd,13,10]
        GOTO wait_for_t0 
        '
        '
        '    
    get_comnd: 
        serin2 b2,16780,1000,wait_for_t0,[WAIT ("$$"),cmnd] ' get command wait $$ timeout 1 secs added
        HSEROUT ["debug command = ",dec2 cmnd,13,10]
        return
    easy to overflow the stack with this
    Last edited by mister_e; - 17th September 2005 at 18:57.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Lightbulb Gosub ...goto

    Hi, Steve

    have a look there : http://www.picbasic.co.uk/forum/showthread.php?t=1952

    I had a similar problem there, It seems that having GOTO',s outgoing and coming back to sub's did not work very well ...
    IF - Then, placed after the GOTO line ( in the sub ...) tests had always "yes" as a result ...
    This was added to a page boundary crossing ... ( worked on a 628, but no more on a 648 !!! )

    The solution for me was to place the program bits in good order ( all sub's at the end of the program and no "main" lines after ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Pulsin problem?
    By Skylar in forum mel PIC BASIC
    Replies: 3
    Last Post: - 27th May 2009, 15:40
  2. Serout2 and Serin2 problem
    By MrSafe in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 26th July 2007, 04:33
  3. Pulsin 16F819 problem
    By rekcahlaer in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th April 2007, 13:52
  4. a problem RF Signal with PULSIN
    By muskut in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd July 2005, 16:42
  5. Serin2 problem on 16F876
    By jrt4fun in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th May 2004, 17:24

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