Shop OBEX P1 Docs P2 Docs Learn Events
BS2 to BS2sx Upgrade, Programnolonger works. — Parallax Forums

BS2 to BS2sx Upgrade, Programnolonger works.

NWUpgradesNWUpgrades Posts: 292
edited 2009-10-01 01:50 in BASIC Stamp
I am running PBasic 2.4.2.I have a BS2 Stamp on a BOE board that the following code works fine on, but when I use my BS2sx chip, it does not work correctly. Is there something I need to do to make my programs run on the BS2sx? Thanks for the help.

' {$STAMP BS2sx}
' {$PBASIC 2.5}

DEBUG "PROGRAM RUNNING"

counter VAR Word

FREQOUT 4, 2000, 3000

FOR counter = 1 TO 300

· PULSOUT 13, 812

· PULSOUT 12, 651

· PAUSE 20

· NEXT

· END

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-09-30 00:53
    Did you remember to check the difference in frequency between the two? check out the comparison chart in the reference.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-09-30 00:59
    Not seeing anything on frequency. How would I change that?

    attachment.php?attachmentid=73905
    406 x 460 - 19K
  • DufferDuffer Posts: 374
    edited 2009-09-30 02:52
    The difference in processor speed (20 MHz vs 50 MHz processor clock frequency)·and therefore the timing/duration differences when using commands such as PULSOUT catches a lot of people out.

    Your PULSOUT commands on the BS2:
    · PULSOUT 13, 812

    · PULSOUT 12, 651
    produce a 1.624 mS and a 1.302 mS pulse respectively because the duration is in 2uS units. Because the BS2sx is 2.5 times faster, the duration unit is .8 uS.

    To get the same pulse width when running your code on the BS2sx, you would have to change your code to:

    · PULSOUT 13, 2030

    · PULSOUT 12, 1628

    See the "Fast Facts" box in the BASIC Stamp Editor help file for the PULSOUT, PULSIN, FREQOUT and other commands that are effected by the difference in processor speed.

    There is also some good information·under "Conditional Compilation Directives" in the help file·and the use of the Multiply Middle, */ operator to make your code processor independant. Consider the following code:
    
    
    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}
    
    DEBUG "PROGRAM RUNNING"
     
    #SELECT $STAMP                'PULSOUT/PULSIN Scaling - conditional compilation 
    #CASE BS2, BS2E, BS2PE 
    PScale CON $0100 
    #CASE BS2P, BS2PX, BS2SX 
    PScale CON $0280 
    #ENDSELECT
     
    #SELECT $STAMP                'FREQOUT Duration Scaling
     #CASE BS2
      FODScale CON $0100
     #CASE BS2P, BS2PX, BS2SX
      FODScale CON $03C6
    #ENDSELECT
     
    #SELECT $STAMP                'FREQOUT Freq Scaling
     #CASE BS2
      FOFScale CON $0100
     #CASE BS2P, BS2PX,BS2SX  
      FOFScale CON $0044
    #ENDSELECT
     
    counter VAR Word
     
    FREQOUT 4, 2000 */ FODScale, 3000 */ FOFScale     'with processor dependant scaling     
     
    
    FOR counter = 1 TO 300
      PULSOUT 13, 812 */ PScale          'with processor dependant scaling
      PULSOUT 12, 651 */ PScale          'with processor dependant scaling
      PAUSE 20
      NEXT
     
      END
    
     
    


    Good luck,
    Duffer




    attachment.php?attachmentid=73906
    61 x 7 - 51B
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-09-30 03:01
    That helpsa WHOLE bunch.· Thanks. Now I just need to figure out baudmode and I think I will beon my way.
    Thanks again·
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-09-30 03:10
    When running your example, the servos move just slightly between the Freqout output. However, if I remark· out the Freqout command, the servos turn like they are suppose too. However, there are 3 instances of "Program Running" in the Debug screen. Any suggestions?
  • DufferDuffer Posts: 374
    edited 2009-09-30 03:44
    Sorry, I tried to just copy your original code. I think the·DEBUG command belongs after the conditional compilation #SELECTs (just before the VAR statement).

    For setting the baud rate, you can again use conditional compilation as in the code below:
    #SELECT $STAMP                'Baud Rates
      #CASE BS2
        T1200       CON     813
        T2400       CON     396
        T4800       CON     188
        T9600       CON     84
        T19K2       CON     32
        T38K4       CON     6
      #CASE BS2P
        T1200       CON     2063
        T2400       CON     1021
        T4800       CON     500
        T9600       CON     240
        T19K2       CON     110
        T38K4       CON     45
    #ENDSELECT
    


    Look at the tables in the help file for the SERIN and SEROUT commands for the actual values to use in the #CASE statement groups for the processor(s) you're using.

    Then just use one of the constants in your command that uses a baud rate parameter, i.e.
    SERIN 1, T9600, [noparse][[/noparse]sData]

    Then you can change processors without having to change your code.

    Duffer

    ·
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-09-30 03:54
    That did not work. Still getting three "Program Running" in the Debug screen. That I can deal with, but the servos turn for a quick second and then stop and the Freqout command runs. There is no Loop statement, but it keeps repeating itself.
  • DufferDuffer Posts: 374
    edited 2009-09-30 16:32
    Chances are that your batteries are low and the Stamp is resetting itself. That's one of the reasons why a DEBUG statement such as the one in the code is there; to indicate when the program is resetting/restarting. The first command to move the servo pulls the voltage low enough to trigger the brownout detector and resets the Stamp and the program starts over.

    Duffer
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-09-30 18:40
    That makes sense. I will recharge the batteries and test it again.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-01 01:50
    I charged the batteries, tested to make sure I had the proper voltage and it still is not working correctly. If I remark out the Freqout code, the servos are turning correctly.
Sign In or Register to comment.