Shop OBEX P1 Docs P2 Docs Learn Events
BS2 SERIN Question — Parallax Forums

BS2 SERIN Question

tweek.3867tweek.3867 Posts: 7
edited 2009-04-22 12:40 in BASIC Stamp
I'm currently using two BS2's wirelessly communicating via two transceivers. I'm having one issue, though,

The receiving program has a SERIN nested in a for loop, somewhat like this:

start:

FOR i = 0 TO n
· FOR j = 0 TO n
····OTHER CODE GOES HERE
··· SERIN SI, Baud, [noparse][[/noparse]serBinCheck]
··· IF serBinCheck = %1111 THEN·GoHere
··· PAUSE 16
· NEXT
NEXT

GOTO start

The issue I'm having, though, is that there is only occasionally something being sent. Basically, it is running something and then there is a natural pause in the loop already, and during that pause I want the SERIN to run. However, if nothing is being sent for it to receive at the time, then the SERIN function causes it to stall. So what I figure is the logical thing to do is add a timeout function (length 16) and then take out the PAUSE 16, so that the·SERIN will automatically do the PAUSE 16, or if something is received move off to the new location in the code. This is where my problem happens.

In order to add a timeout length, you have to add a GOTO location, in case the actual timeout occurs, but I just want it to continue the loop. I tried a simple work around and added a GOTO label right after the SERIN statement, like this:

··· SERIN SI, Baud, 16, continue, [noparse][[/noparse]serBinCheck]
··· continue:
··· IF serBinCheck = %1111 THEN ResetReps

But in doing that, it essentially breaks out of the for loop and ends up at the GOTO start, repeating the loop endlessly, which is something that breaks the program. I was thinking about being kind of skeevy about it and rather than using a for loop, just relying on the GOTO statements and manually updating the i and j counter variables, but I feel like there has to be a better way.

Any ideas would be incredible. Thanks so much!

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-04-22 00:42
    Hi, I think essentially your are doing the right thing with the timeout but 16 mSec is a very small window in which to capture the data you are sending. Try a bigger timeout value and see if you can find a value that works well for your application. Using a timeout is not going to "break out" of the loop.

    ·SERIN SI, Baud,300,continue, [noparse][[/noparse]serBinCheck]
    ··· IF serBinCheck = %1111 THEN·GoHere
    ···continue:

    Jeff T.
  • tweek.3867tweek.3867 Posts: 7
    edited 2009-04-22 00:47
    Hm. I'll give it a shot. The issue is that the time we have is essentially just a pulse to a number of servos, so I can't really change the pause duration too much. If I do, then it will mess up the walk of the robot I'm working on. The idea is to try and check the transceiver for information whenever it's not driving the servos.

    I probably just misjudged the timing, though, which is what made me think it was breaking out of the loop. I have a debug statement running prior to the loop starts so I know when it repeats and it was spitting out so fast I just assumed it was exiting the loop entirely, but you're very right in that 16mSec is a very small amount of time so that was probably fine.

    Thanks for the advice!
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-04-22 00:53
    Hi , my thoughts were if you extended the timeout you could prove the data was being received, after that you can gradually reduce the timeout value. If you are unable to get to a value small enough where you·can refresh the servos you might have to look at alternatives , maybe a PSC.

    Jeff T.
  • tweek.3867tweek.3867 Posts: 7
    edited 2009-04-22 00:54
    Cool. I'll go give it a shot now [noparse]:)[/noparse] Also, forgive my lack of knowledge, but what's a PSC?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-22 00:59
    Parallax Servo Controller ... a nice SX-based 16 servo controller that talks to the "master" microcontroller via serial commands and handles timed ramping, position feedback, etc.
  • tweek.3867tweek.3867 Posts: 7
    edited 2009-04-22 01:00
    Gotcha. Thanks.
  • ManetherenManetheren Posts: 117
    edited 2009-04-22 12:40
    In the RFID section it also uses the next statement. If you put the Next right before the continue it should continue on through the loop though you might have to tell it to go back to the loop again.

    SERIN SI, Baud,300,continue, [noparse][[/noparse]serBinCheck]
    IF serBinCheck = %1111 THEN GoHere
    NEXT
    continue:

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Manetheren
Sign In or Register to comment.