Shop OBEX P1 Docs P2 Docs Learn Events
Counter triggering counter — Parallax Forums

Counter triggering counter

pcrobotpcrobot Posts: 103
edited 2006-04-21 14:14 in BASIC Stamp
Hey,

I'm trying to get a counter to trigger another counter... So far I'm not having much success...

What I have:

DO

FOR counterone 1 to 60

HIGH 14
PAUSE 500
LOW 14
PAUSE 500

NEXT

IF counterone = 60
THEN countertwo + 1

LOOP

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Robotics
ro-bot-ics (noun)
the science or technology of robots, their design, manufacture, application, use, etc.

Comments

  • SSteveSSteve Posts: 808
    edited 2006-04-04 02:12
    You don't need the test "IF counterone = 60". You've already fallen out of the FOR/NEXT loop so you know you've gone through 60 values of counterone. You can simply increment countertwo after the NEXT statement.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows
  • pcrobotpcrobot Posts: 103
    edited 2006-04-04 02:57
    SSteve said...
    You don't need the test "IF counterone = 60". You've already fallen out of the FOR/NEXT loop so you know you've gone through 60 values of counterone. You can simply increment countertwo after the NEXT statement.
    I want it to add 1 to countertwo, then go through counterone again, add 1 to countertwo, etc.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-04-04 03:15
    counterone VAR Byte
    countertwo VAR Byte
     
    init:
     counterone = 1
     
    cntr_one:
      HIGH 14
      PAUSE 500
      LOW 14
      PAUSE 500
      counterone = counterone + 1
      if counterone < 61 then cntr_one
    
    cntr_two:
      countertwo = countertwo + 1
      goto init
    
  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2006-04-04 03:22
    pcrobot,

    What SSteve is saying, is that the line that reads "IF counterone = 60" is redundant, because the "FOR counterone 1 to 60"
    loop automatically takes care of this.

    
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
      counterone VAR  Byte
      countertwo VAR  Byte
    
    DO
       FOR counterone = 1 to 60
           HIGH 14
           PAUSE 500
           LOW 14
           PAUSE 500
       NEXT
       countertwo = countertwo + 1
       
       'IF counterone = 60 THEN countertwo = countertwo + 1
    
    LOOP
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • pcrobotpcrobot Posts: 103
    edited 2006-04-07 17:10
    OK, now, I want to save the value of counterone & countertwo whenever the pushbutton on PIN3 is pressed. But, it only goes for 1 second, then stops. confused.gif

    counterone  VAR BYTE
    countertwo  VAR Byte
    
    DO
    
    FOR counterone = 1 TO 60
    HIGH 14
    PAUSE 500
    LOW 14
    PAUSE 500
    
    DEBUG ? counterone
    
    IF IN3 = 1 THEN FOR eepromAddress 0 TO 58 STEP 2
    FOR eepromAddress, Word counterone, Word countertwo
    NEXT
    
    countertwo = countertwo + 1
    
    DEBUG ? countertwo
    
    LOOP
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.

    Post Edited (pcrobot) : 4/7/2006 7:15:54 PM GMT
  • FranklinFranklin Posts: 4,747
    edited 2006-04-07 18:38
    It looks like you need to study the BASIC manual a little longer. you have two for statements and only one next. I'm not 100% sure but I think that won't work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-07 19:32
    Not only two FOR statements, but no TO value in the second.· Also, besides what Steve and Beau were saying about the conditional for IF variable = 60 being redundant, so is the counter = counter + 1 since that too is being incremented by the FOR...NEXT loop.· Definately give the "What's A Microcontroller?" text a good read.

    http://www.parallax.com/dl/docs/books/edu/wamv2_2.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • pcrobotpcrobot Posts: 103
    edited 2006-04-10 17:41
    Well, then what code should I use to record the value of 2 counters (1 counter every 60 seconds, and the other every second) when a pushbutton is pushed? (without interupting the counters, or reseting.)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-10 18:19
    Could you please be more specific as to what you mean?· Exactly what needs to happen?· Do the counters need to run concurrently?·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • pcrobotpcrobot Posts: 103
    edited 2006-04-10 19:10
    Sorry...

    counterone flashes an LED on 500ms, then off 500ms. When it does that 60 times, countertwo adds 1, and counterone resets. I just want to send the value of each counter to the eeprom when the pushbutton is pressed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-04-10 19:42
    · I guess you figure to use this as a stop-watch.
    · By checking for a button-push you have to stop counting or account for it in your PAUSEs, by writing to eeprom you have to stop counting long enough to perform that operation.
    · Why don't you get a PocketWatch-B which will run all the time?· Have your program query the PW-B for the time when there is a button-push and write that to eeprom.
  • pcrobotpcrobot Posts: 103
    edited 2006-04-10 20:13
    I was thinking I'd cut some of the time off the LED off pause and use that for writing to the eeprom.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-10 20:27
    This code does what you ask...The problems I see are that you only have 1 second resolution on the timing, but 1/2 second to stop it and after writing the data to the EEPROM what do you plan on doing with it?
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    But1      PIN   0
    LED       PIN   1
    counter   VAR   byte
    index     VAR   byte
    do
      IF But1 = 1 THEN exit
      HIGH LED
      PAUSE 500
      IF But1 = 1 THEN EXIT
      LOW LED
      PAUSE 500
      counter = counter + 1
      IF counter = 60 THEN
        counter = 0
        index = index + 1
      endif
    loop
    WRITE 0, counter
    WRITE 1, index
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • pcrobotpcrobot Posts: 103
    edited 2006-04-14 22:41
    Thanks Chris!

    ... now... how do I save multiple values? (several values of counter, and index.)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-15 03:17
    You make the 0 and 1 variables (or one variable) and you increment them after each write.· With a single variable you would write the current value, then next value would be the current counter +1, then you increment by 2 and start over.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • pcrobotpcrobot Posts: 103
    edited 2006-04-18 20:51
    Now, why on earth does this keep resetting instead of continuing? jumpin.gif

    I've been working at it for at least an hour! shocked.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.
  • SSteveSSteve Posts: 808
    edited 2006-04-18 22:26
    What do you mean when you say it keeps resetting?

    Here's a coding tip. Instead of
        IF IN3 = 1 THEN WRITE eepromAddress1, month
        IF IN3 = 1 THEN WRITE eepromAddress2, day
        IF IN3 = 1 THEN WRITE eepromAddress3, hour
        IF IN3 = 1 THEN WRITE eepromAddress4, minute
    


    write it like this:
        IF IN3 = 1 THEN 
            WRITE eepromAddress1, month
            WRITE eepromAddress2, day
            WRITE eepromAddress3, hour
            WRITE eepromAddress4, minute
        ENDIF
    


    With the current version, you'll only get a partial timestamp if the button is released between statements.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-19 01:32
    Or better yet, try:
    IF IN3 = 1 THEN 
            WRITE eepromAddress, month
            WRITE eepromAddress + 1, day
            WRITE eepromAddress + 2, hour
            WRITE eepromAddress + 3, minute
        ENDIF
    

    Then you only have one address to increment by 4 each time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • SSteveSSteve Posts: 808
    edited 2006-04-19 05:56
    I was thinking of suggesting that also, but I decided to address one thing at a time. (No pun intended.) smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows
  • pcrobotpcrobot Posts: 103
    edited 2006-04-19 18:14
    SSteve said...
    What do you mean when you say it keeps resetting?
    Thanks for the tips...

    When I press the pushbutton (and it sends the variables to the EEPROM) then it starts the program over again... confused.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.
  • SSteveSSteve Posts: 808
    edited 2006-04-19 21:12
    I don't see anything in your code that would cause a reset. Perhaps something in your circuit is causing the stamp to reset when the button is pushed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-20 05:00
    Most likely the button (connection) is shorting out the supply rails.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • pcrobotpcrobot Posts: 103
    edited 2006-04-20 21:35
    Chris Savage (Parallax) said...
    Most likely the button (connection) is shorting out the supply rails.
    How would I fix that?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.
  • FranklinFranklin Posts: 4,747
    edited 2006-04-20 22:19
    How about a circuit diagram. To fix the problem of a switch shorting out the rails you don't connect it across the rails.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-21 04:01
    Please see the circuits listed in the BASIC Stamp Manual or the Editor Help File under the BUTTON command.· Match what you have to one of those.· I would also highly recommend reading the, "What's A Microcontroller?" text, available as a free PDF download from the bottom of the following link.

    http://www.parallax.com/detail.asp?product_id=28152


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com


    Post Edited (Chris Savage (Parallax)) : 4/21/2006 2:13:31 PM GMT
  • pcrobotpcrobot Posts: 103
    edited 2006-04-21 12:03
    I'm using the curcuit on page 76 of the WAM text along with the LED curcuit on page 314 of the "Robotics with the BOE-Bot" text.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-21 14:14
    If you're using that circuit, then re-check your wiring.· If in doubt remove it all and start over one connection at a time.· You'd be surprised how often this works for many.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.