Shop OBEX P1 Docs P2 Docs Learn Events
Reset BS2SX — Parallax Forums

Reset BS2SX

ManuelManuel Posts: 105
edited 2005-08-03 20:13 in BASIC Stamp
Hello:
Is it possible to me to reset my BS2sx by connecting a pin to the reset and using the·low command?
Or is there a better way to do that with code?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Best Regards

Manuel C. Reinhard

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-02 22:56
    If you want to do that, you can. That will do a *hard* reset: all I/Os will be cleared to inputs and all variables to zero.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • ManuelManuel Posts: 105
    edited 2005-08-03 00:32
    Does that mean that i have to define all my outputs before i can use them as outputs?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Best Regards

    Manuel C. Reinhard
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-03 01:20
    You should alias pins for readabilty, but most PBASIC commands take care of setting IO pin direction. For example:

    · HIGH 0

    makes pin 0 and output and sets it to 1. In your case with reset, you might do this:

    · Reset··· PIN··· 0

    The pin will be initialized (after power-up or hard reset) as an input, so it can be left alone.· Then, if you have some emergency that causes you to want to do a hard reset, do this:

    Emergency_Reset:
    · LOW Reset
    · END

    You don't need to do anything else -- and be sure you don't do anything with the pin called Reset except use it as I've shown you above.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • YanroyYanroy Posts: 96
    edited 2005-08-03 14:30
    Barring the most crazy scenarios I can come up with, you probably don't need to do an actual hardware reset.· Just put a label at the top of your program (above where you initialize your variables) and jump to that to "reset".
  • ManuelManuel Posts: 105
    edited 2005-08-03 17:51
    I tried to reset my variables without turn off, but when it gets to the section where variables are changed, they wont change

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Best Regards

    Manuel C. Reinhard
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-03 18:04
    Then you're doing something wrong. You may want to post your code for more detailed assistance.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • YanroyYanroy Posts: 96
    edited 2005-08-03 18:04
    Can you explain that in a little more detail?· I've never heard of anything like that happening...
  • ManuelManuel Posts: 105
    edited 2005-08-03 18:25
    Ok, here is the code, there are some variables im not using and i will delete when everything is done:

    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}
    INPUT 1
    INPUT 2
    INPUT 3
    to_see VAR Word
    sensor CON 5
    met VAR Word
    mes VAR Word
    to_cont VAR Byte
    x VAR Byte
    meters VAR Word
    met_two VAR Byte
    meters = 0
    q VAR Word
    enter VAR Byte
    LCD CON 0
    LcdCls········· CON···· $0C
    LcdOn1· ········CON···· $16
    LCDBaud······ CON···· 110
    Scale······ CON···· $0CD
    LcdLine1······· CON···· $80
    LcdLine2······· CON···· $94
    prendido:
    SEROUT LCD, LcdBaud, [noparse][[/noparse]$11]
    HIGH LCD
    PAUSE 100
    · SEROUT LCD, LcdBaud, [noparse][[/noparse]$11, $16]
    start:
    · SEROUT LCD, LcdBaud, [noparse][[/noparse]$0c]
    · SEROUT LCD, LcdBaud, [noparse][[/noparse]LcdLine1, "Insert"]
    · PAUSE 1000
    · SEROUT LCD, LcdBaud, [noparse][[/noparse]$0c]
    · SEROUT LCD, LcdBaud, [noparse][[/noparse]LcdLine1, "length ", LCDLine2, "in· meters"]
    · PAUSE 1000
    ··· SEROUT LCD, LcdBaud, [noparse][[/noparse]$0c]
    · SEROUT LCD, LcdBaud, [noparse][[/noparse]LcdLine1, "For 400 meters", LCDLine2, "press 1"]
    · PAUSE 1000
    ··· SEROUT LCD, LcdBaud, [noparse][[/noparse]$0c]
    ··· SEROUT LCD, LcdBaud, [noparse][[/noparse]LcdLine1, "When finished", LCDline2, "press enter"]
    PAUSE 1000
    · SEROUT LCD, LcdBaud, [noparse][[/noparse]$0c]
    ··· SEROUT LCD, LcdBaud, [noparse][[/noparse]LcdLine1, "Press enter ", LCDline2, " to continue "]
    PAUSE 1000
    GOTO enters
    enters:
    BUTTON 3, 1, 10, 20, enter, 1, metros
    PAUSE 20
    BUTTON 2, 1, 10, 20, enter, 1, cuatro
    PAUSE 20
    GOTO enters
    ·
    metros:
    · SEROUT LCD, LcdBaud, [noparse][[/noparse]$0c]
    · SEROUT LCD, LcdBaud, [noparse][[/noparse]lcdline1, "Meters", Lcdline2,"· ", DEC meters/10, DEC met]
    · PAUSE 50
    · GOTO add
    add:
    BUTTON 4, 1, 10, 20, enter, 1, cien
    PAUSE 30
    BUTTON 1, 1, 10, 20, enter, 1, diez
    PAUSE 30
    BUTTON 2, 1, 10, 20, enter, 1, uno
    PAUSE 30
    BUTTON 3, 1, 10, 20, enter, 1, cont
    PAUSE 30
    GOTO add
    cien:
    meters = meters+100 MAX 2470
    GOTO metros
    diez:
    meters = meters+10 MAX 2470
    GOTO metros
    uno:
    met = met+1
    IF met = 10 THEN cambio
    GOTO metros
    cambio:
    meters = meters +10
    met = 0
    GOTO metros
    cuatro:
    meters = 400
    GOTO cont
    cont:
    SEROUT lcd, lcdbaud, [noparse][[/noparse]$0c]
    SEROUT LCD, LCDbaud, [noparse][[/noparse]lcdline1, DEC meters/10, DEC met , " Meters", lcdline2, "Press enter"]
    PAUSE 1500
    met_two = ((met * 265)/10)
    q =(((meters/10)*265)+((meters/10)/4)+met_two)
    ·
    SEROUT LCD, LCDbaud, [noparse][[/noparse]lcdline2, "To continue"]
    PAUSE 1000
    SEROUT LCD, LCDbaud, [noparse][[/noparse]lcdline2, "1 to cancel"]
    ······ PAUSE 1000
    sigue:
    BUTTON 3, 1, 10, 20, enter, 1, preparar
    PAUSE 20
    BUTTON 2, 1, 10, 20, enter, 1, resetear
    GOTO sigue
    ·
    preparar:
    · SEROUT LCD, LcdBaud, [noparse][[/noparse]$0c]
    · GOTO contar
    ·
    contar:
    DO
    SEROUT lcd, lcdbaud, [noparse][[/noparse]lcdline1, $09, $09, $09, DEC ((mes * 377)/10000),"/", DEC meters/10, DEC met , lcdline2, "Meters"]·· 'check variable overflow
    IF IN9 = 1 THEN mes = mes + 1
    DO: LOOP WHILE IN9 = 1
    LOOP WHILE mes < q
    Finalizar:
    HIGH 9
    PAUSE 500
    LOW 9
    · SEROUT LCD, LcdBaud, [noparse][[/noparse]$0c]
    · PAUSE 50
    SEROUT lcd, lcdbaud, [noparse][[/noparse]lcdline1, "Finished ", DEC meters/10, DEC met, " mts.", lcdline2, "Press enter"]
    ending:
    BUTTON 3, 1, 10, 20, enter, 1, reset_var
    PAUSE 20
    GOTO ending
    · Reset_var:
    met = 0
    meters = 0
    mes = 0
    GOTO start
    END


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Best Regards

    Manuel C. Reinhard
  • ManuelManuel Posts: 105
    edited 2005-08-03 18:28
    lol there·are some things in spanish and everything to display in the lcds was in spanish because the users of my meter counter only speak spanish.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Best Regards

    Manuel C. Reinhard
  • YanroyYanroy Posts: 96
    edited 2005-08-03 18:46
    Luckily spanish and french are close enough relatives that I can figure out the gist of what it says.· I still don't understand your problem, however.· It looks to me like it should zero all your variables and then start over, right after what I assume is the LCD startup routine.· It should work fine, unless I'm missing something big.· What exactly are you experiencing when it goes wrong?
  • ManuelManuel Posts: 105
    edited 2005-08-03 18:49
    When it gets to the reset routine i go again to the meter selecting stage and then to the[noparse]:([/noparse]from Do to the end)
    The problem is that it wont display me in the lcd anymore that the variable increases. The variable stays stuck at 0.
    DO

    SEROUT lcd, lcdbaud, [noparse][[/noparse]lcdline1, $09, $09, $09, DEC ((mes * 377)/10000),"/", DEC meters/10, DEC met , lcdline2, "Meters"] 'check variable overflow

    IF IN9 = 1 THEN mes = mes + 1

    DO: LOOP WHILE IN9 = 1

    LOOP WHILE mes < q

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Best Regards

    Manuel C. Reinhard
  • YanroyYanroy Posts: 96
    edited 2005-08-03 18:58
    Ok, nothing jumps out at me as to why that would happen.· What I recommend is that right after your block of VAR statements where you declare your variables, set them all to zero (or whatever default value they're supposed to have).· Then instead of jumping to START when you do your reset, jump to the very first line of the program (right after your PBASIC and STAMP directives).· That should imitate a hardware reset as closely as possible.· To make it an even more accurate imitation, you can set the pins to inputs first...
  • ManuelManuel Posts: 105
    edited 2005-08-03 19:01
    Thx, i will do that and see what happens.(Could my BS exlode? omg!)
    LOL

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Best Regards

    Manuel C. Reinhard
  • YanroyYanroy Posts: 96
    edited 2005-08-03 19:03
    You know, if that doesn't work, you should probably just go with your initial thought of a hardware reset - at least that's guaranteed to work!· I was just trying to save you an I/O line.

    PS (and to the powers that be) - there should really be some kind of chat room for this back-and-forth posting.
  • ManuelManuel Posts: 105
    edited 2005-08-03 19:17
    yes, that would come handy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Best Regards

    Manuel C. Reinhard
  • ManuelManuel Posts: 105
    edited 2005-08-03 19:19
    lol, it worked. set vvariables to 0 before setting them to variables and now it works, thx a lot.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Best Regards

    Manuel C. Reinhard
  • Tom WalkerTom Walker Posts: 509
    edited 2005-08-03 20:13
    After giving this scenario a little thought, it DOES make sense. Remember that creating and using variables is something that is handled by the compiler and not something that "tokenizes" and downloads to the Stamp. Only the code that actually DOES something is downloaded. The VAR declarations just signal to the compiler that space needs to be allocated, which it does at the time of the COMPILE. So, when you jump tot he beginning of the program, you are really juming to the first "active" instruction (token), hence, the variables will not automatically be cleared out.

    HTH.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
Sign In or Register to comment.